Maciej Fijalkowski avatar Maciej Fijalkowski committed e32c245

(agaynor, fijal) more jtransform support

Comments (0)

Files changed (3)

pypy/jit/backend/llgraph/runner.py

         return llimpl.grab_exc_value()
 
     def arraydescrof(self, A):
-        assert A.OF != lltype.Void
-        assert isinstance(A, lltype.GcArray) or A._hints.get('nolength', False)
         size = symbolic.get_size(A)
-        if isinstance(A.OF, lltype.Ptr) or isinstance(A.OF, lltype.Primitive):
-            token = history.getkind(A.OF)[0]
-        elif isinstance(A.OF, lltype.Struct):
-            token = 's'
+        if isinstance(A, lltype.GcStruct):
+            token = 'S'
         else:
-            token = '?'
+            assert A.OF != lltype.Void
+            assert isinstance(A, lltype.GcArray) or A._hints.get('nolength', False)
+            if isinstance(A.OF, lltype.Ptr) or isinstance(A.OF, lltype.Primitive):
+                token = history.getkind(A.OF)[0]
+            elif isinstance(A.OF, lltype.Struct):
+                token = 's'
+            else:
+                token = '?'
         return self.getdescr(size, token)
 
     # ---------- the backend-dependent operations ----------

pypy/jit/codewriter/jtransform.py

         self.vable_flags = {}
         renamings = {}
         renamings_constants = {}    # subset of 'renamings', {Var:Const} only
-        newoperations = []
+        self._newoperations = newoperations = []
         #
         def do_rename(var, var_or_const):
             if var.concretetype is lltype.Void:
     def rewrite_op_jit_record_known_class(self, op):
         return SpaceOperation("record_known_class", [op.args[0], op.args[1]], None)
 
+    def rewrite_op_cast_adr_to_ptr(self, op):
+        # HACK
+        prev_op = self._newoperations.pop()
+        if prev_op.opname != 'getinteriorfield_gc_i':
+            raise Exception("Must cast_adr_to_ptr of directly read adr")
+        prev_op.opname = 'getinteriorfield_gc_r'
+        prev_op.result = op.result
+        return prev_op
+
     def rewrite_op_cast_bool_to_int(self, op): pass
     def rewrite_op_cast_bool_to_uint(self, op): pass
     def rewrite_op_cast_char_to_int(self, op): pass

pypy/jit/codewriter/test/test_jtransform.py

     assert op1.args == [v1]
     assert op1.result == v2
 
+def test_malloc_varsize_struct():
+    S = lltype.GcStruct('x', ('a', lltype.Signed),
+                        ('b', lltype.Array(lltype.Signed)))
+    v0 = varoftype(lltype.Signed)
+    v1 = varoftype(lltype.Ptr(S))
+    c_S = Constant(S, lltype.Void)
+    c_flavor = Constant({'flavor': 'gc'}, lltype.Void)
+    op = SpaceOperation('malloc_varsize', [c_S, c_flavor, v0], v1)
+    op1 = Transformer(FakeCPU()).rewrite_operation(op)
+    assert op1.opname == 'new_array'
+    assert op1.args == [('arraydescr', S), v0]
+    assert op1.result == v1
+
 def test_str_concat():
     # test that the oopspec is present and correctly transformed
     PSTR = lltype.Ptr(rstr.STR)
         SpaceOperation("cast_adr_to_ptr", [v1], v2)
     ]
 
-    op1 = Transformer(FakeCPU()).optimize_block(block)
+    Transformer(FakeCPU()).optimize_block(block)
+    [op1] = block.operations
     assert op1.opname == "getinteriorfield_gc_r"
-    assert op1.args == [v, const(0), ('interiorfielddescr', S, 'data')]
+    assert op1.args == [v0, const(0), ('interiorfielddescr', S, 'data')]
     assert op1.result == v2
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.