[pypy-commit] pypy faster-rstruct-2: add support & test for gc_load_indexed of a list of chars
antocuni
pypy.commits at gmail.com
Mon May 22 13:03:51 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct-2
Changeset: r91375:d5be1a60c5a3
Date: 2017-05-22 18:47 +0200
http://bitbucket.org/pypy/pypy/changeset/d5be1a60c5a3/
Log: add support & test for gc_load_indexed of a list of chars
diff --git a/rpython/translator/backendopt/test/test_writeanalyze.py b/rpython/translator/backendopt/test/test_writeanalyze.py
--- a/rpython/translator/backendopt/test/test_writeanalyze.py
+++ b/rpython/translator/backendopt/test/test_writeanalyze.py
@@ -2,6 +2,7 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rtyper.lltypesystem.rstr import STR
+from rpython.rtyper.lltypesystem.rlist import LIST_OF
from rpython.translator.translator import TranslationContext, graphof
from rpython.translator.backendopt.writeanalyze import WriteAnalyzer, top_set
from rpython.translator.backendopt.writeanalyze import ReadWriteAnalyzer
@@ -412,10 +413,9 @@
class TestGcLoadStoreIndexed(BaseTest):
Analyzer = ReadWriteAnalyzer
- def _analyze_graph_single(self, t, wa, fn):
+ def _analyze_graph(self, t, wa, fn):
graph = graphof(t, fn)
result = wa.analyze(graph.startblock.operations[-1])
- result = list(result)
return result
def test_gc_load_indexed_str(self):
@@ -433,16 +433,46 @@
t, wa = self.translate(f, [str])
# check that the effect of direct_read
- direct_effects = self._analyze_graph_single(t, wa, direct_read)
- assert len(direct_effects) == 1
- effect = direct_effects[0]
- what, T, field = effect
- assert what == 'readinteriorfield'
- assert T == lltype.Ptr(STR)
- assert field == 'chars'
+ direct_effects = self._analyze_graph(t, wa, direct_read)
+ assert direct_effects == frozenset([
+ ('readinteriorfield', lltype.Ptr(STR), 'chars')
+ ])
#
# typed_read contains many effects because it reads the vtable etc.,
# but we want to check that it contains also the same effect as
# direct_read
- typed_effects = self._analyze_graph_single(t, wa, typed_read)
- assert effect in typed_effects
+ typed_effects = self._analyze_graph(t, wa, typed_read)
+ assert direct_effects.issubset(typed_effects)
+
+ def test_gc_load_indexed_list_of_chars(self):
+ from rpython.rlib.buffer import ByteBuffer
+
+ def typed_read(buf):
+ return buf.typed_read(lltype.Signed, 0)
+
+ def direct_read(buf):
+ return buf.data[0]
+
+ def f(x):
+ buf = ByteBuffer(8)
+ return direct_read(buf), typed_read(buf)
+
+ t, wa = self.translate(f, [str])
+ # check that the effect of direct_read
+ LIST = LIST_OF(lltype.Char)
+ PLIST = lltype.Ptr(LIST)
+ direct_effects = self._analyze_graph(t, wa, direct_read)
+ assert direct_effects == frozenset([
+ ('readstruct', PLIST, 'length'),
+ ('readstruct', PLIST, 'items'),
+ ('readarray', LIST.items),
+ ])
+
+ # typed_read contains many effects because it reads the vtable etc.,
+ # but we want to check that it contains also the expected effects
+ typed_effects = self._analyze_graph(t, wa, typed_read)
+ expected = frozenset([
+ ('readstruct', PLIST, 'items'),
+ ('readarray', LIST.items),
+ ])
+ assert expected.issubset(typed_effects)
diff --git a/rpython/translator/backendopt/writeanalyze.py b/rpython/translator/backendopt/writeanalyze.py
--- a/rpython/translator/backendopt/writeanalyze.py
+++ b/rpython/translator/backendopt/writeanalyze.py
@@ -157,5 +157,7 @@
elif isinstance(ofs, llmemory.FieldOffset):
T = ofs.TYPE
return ('readinteriorfield', lltype.Ptr(T), ofs.fldname)
+ elif isinstance(ofs, llmemory.ArrayItemsOffset):
+ return ('readarray', lltype.Ptr(ofs.TYPE))
else:
assert False, 'implement me'
More information about the pypy-commit
mailing list