Commits

Armin Rigo committed a9fed72

(fijal, arigo)
Kill one useless argument to raw_load and raw_store. Add support for
raw_storage_getitem().

Comments (0)

Files changed (7)

pypy/jit/codewriter/jtransform.py

                                   op.result)
 
     def rewrite_op_raw_store(self, op):
+        assert op.args[3].concretetype == op.args[1].value
         kind = getkind(op.args[3].concretetype)[0]
+        size = llmemory.sizeof(op.args[1].value)
+        c_size = Constant(size, lltype.Signed)
         return SpaceOperation('raw_store_%s' % kind,
-                              [op.args[0], op.args[2], op.args[3]],
+                              [op.args[0], c_size, op.args[2], op.args[3]],
                               None)
 
     def _rewrite_equality(self, op, opname):

pypy/rlib/rawstorage.py

 def alloc_raw_storage(size):
     return lltype.malloc(RAW_STORAGE, size, flavor='raw')
 
+def raw_storage_getitem(TP, storage, index):
+    "NOT_RPYTHON"
+    return rffi.cast(rffi.CArrayPtr(TP), rffi.ptradd(storage, index))[0]
+
 def raw_storage_setitem(storage, index, item):
-    # NOT_RPYTHON
+    "NOT_RPYTHON"
     TP = rffi.CArrayPtr(lltype.typeOf(item))
     rffi.cast(TP, rffi.ptradd(storage, index))[0] = item
 
 def free_raw_storage(storage):
     lltype.free(storage, flavor='raw')
 
+class RawStorageGetitemEntry(ExtRegistryEntry):
+    _about_ = raw_storage_getitem
+
+    def compute_result_annotation(self, s_TP, s_storage, s_index):
+        assert s_TP.is_constant()
+        return annmodel.lltype_to_annotation(s_TP.const)
+
+    def specialize_call(self, hop):
+        assert hop.args_r[1].lowleveltype == RAW_STORAGE_PTR
+        v_storage = hop.inputarg(hop.args_r[1], arg=1)
+        v_index   = hop.inputarg(lltype.Signed, arg=2)
+        hop.exception_cannot_occur()
+        v_addr = hop.genop('cast_ptr_to_adr', [v_storage],
+                           resulttype=llmemory.Address)
+        return hop.genop('raw_load', [v_addr, v_index],
+                         resulttype=hop.r_result.lowleveltype)
+
 class RawStorageSetitemEntry(ExtRegistryEntry):
     _about_ = raw_storage_setitem
 
         v_storage, v_index, v_item = hop.inputargs(hop.args_r[0],
                                                    lltype.Signed,
                                                    hop.args_r[2])
-        c_typ = hop.inputconst(lltype.Void, hop.args_r[2].lowleveltype)
         hop.exception_cannot_occur()
         v_addr = hop.genop('cast_ptr_to_adr', [v_storage],
                            resulttype=llmemory.Address)
-        return hop.genop('raw_store', [v_addr, c_typ, v_index, v_item])
+        return hop.genop('raw_store', [v_addr, v_index, v_item])

pypy/rlib/test/test_rawstorage.py

 
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.rlib.rawstorage import alloc_raw_storage, free_raw_storage,\
-     raw_storage_setitem
+     raw_storage_setitem, raw_storage_getitem
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin
 
-def raw_storage_getitem(storage, index, TP):
-    return rffi.cast(rffi.CArrayPtr(TP), rffi.ptradd(storage, index))[0]
-
 def test_untranslated_storage():
     r = alloc_raw_storage(15)
     raw_storage_setitem(r, 3, 1<<30)
-    res = raw_storage_getitem(r, 3, lltype.Signed)
+    res = raw_storage_getitem(lltype.Signed, r, 3)
     free_raw_storage(r)
     assert res == 1<<30
 
         def f(i):
             r = alloc_raw_storage(24)
             raw_storage_setitem(r, 3, i)
-            return r
-        ll_r = self.interpret(f, [1<<30], malloc_check=False)
-        assert raw_storage_getitem(ll_r, 3, lltype.Signed) == 1 << 30
-        free_raw_storage(ll_r)
+            res = raw_storage_getitem(lltype.Signed, r, 3)
+            free_raw_storage(r)
+            return res
+        x = self.interpret(f, [1<<30])
+        assert x == 1 << 30

pypy/rpython/llinterp.py

 
     op_raw_memmove = op_raw_memcopy # this is essentially the same here
 
-    def op_raw_load(self, addr, typ, offset):
+    def op_raw_load(self, RESTYPE, addr, offset):
         checkadr(addr)
-        assert offset.TYPE == typ
-        value = getattr(addr, str(typ).lower())[offset.repeat]
-        assert lltype.typeOf(value) == typ
-        return value
-
-    def op_raw_store(self, addr, typ, offset, value):
-        checkadr(addr)
-        assert lltype.typeOf(value) == typ
         if isinstance(offset, int):
             from pypy.rpython.lltypesystem import rffi
             ll_p = rffi.cast(rffi.CCHARP, addr)
-            ll_p = rffi.cast(rffi.CArrayPtr(typ), rffi.ptradd(ll_p, offset))
+            ll_p = rffi.cast(rffi.CArrayPtr(RESTYPE),
+                             rffi.ptradd(ll_p, offset))
+            value = ll_p[0]
+        else:
+            assert offset.TYPE == RESTYPE
+            value = getattr(addr, str(RESTYPE).lower())[offset.repeat]
+        assert lltype.typeOf(value) == RESTYPE
+        return value
+    op_raw_load.need_result_type = True
+
+    def op_raw_store(self, addr, offset, value):
+        checkadr(addr)
+        ARGTYPE = lltype.typeOf(value)
+        if isinstance(offset, int):
+            from pypy.rpython.lltypesystem import rffi
+            ll_p = rffi.cast(rffi.CCHARP, addr)
+            ll_p = rffi.cast(rffi.CArrayPtr(ARGTYPE),
+                             rffi.ptradd(ll_p, offset))
             ll_p[0] = value
         else:
-            assert offset.TYPE == typ
-            getattr(addr, str(typ).lower())[offset.repeat] = value
+            assert offset.TYPE == ARGTYPE
+            getattr(addr, str(ARGTYPE).lower())[offset.repeat] = value
 
     def op_stack_malloc(self, size): # mmh
         raise NotImplementedError("backend only")

pypy/rpython/memory/gctransform/framework.py

         c_len = rmodel.inputconst(lltype.Signed, len(livevars) )
         base_addr = hop.genop("direct_call", [self.incr_stack_ptr, c_len ],
                               resulttype=llmemory.Address)
-        c_type = rmodel.inputconst(lltype.Void, llmemory.Address)
         for k,var in enumerate(livevars):
             c_k = rmodel.inputconst(lltype.Signed, k * sizeofaddr)
             v_adr = gen_cast(hop.llops, llmemory.Address, var)
-            hop.genop("raw_store", [base_addr, c_type, c_k, v_adr])
+            hop.genop("raw_store", [base_addr, c_k, v_adr])
         return livevars
 
     def pop_roots(self, hop, livevars):
                               resulttype=llmemory.Address)
         if self.gcdata.gc.moving_gc:
             # for moving collectors, reload the roots into the local variables
-            c_type = rmodel.inputconst(lltype.Void, llmemory.Address)
             for k,var in enumerate(livevars):
                 c_k = rmodel.inputconst(lltype.Signed, k * sizeofaddr)
-                v_newaddr = hop.genop("raw_load", [base_addr, c_type, c_k],
+                v_newaddr = hop.genop("raw_load", [base_addr, c_k],
                                       resulttype=llmemory.Address)
                 hop.genop("gc_reload_possibly_moved", [v_newaddr, var])
 

pypy/rpython/raddress.py

 class __extend__(pairtype(TypedAddressAccessRepr, IntegerRepr)):
 
     def rtype_getitem((r_acc, r_int), hop):
-        c_type = hop.inputconst(lltype.Void, r_acc.type)
         v_addr, v_offs = hop.inputargs(hop.args_r[0], lltype.Signed)
         c_size = hop.inputconst(lltype.Signed, sizeof(r_acc.type))
         v_offs_mult = hop.genop('int_mul', [v_offs, c_size],
                                 resulttype=lltype.Signed)
-        return hop.genop('raw_load', [v_addr, c_type, v_offs_mult],
+        return hop.genop('raw_load', [v_addr, v_offs_mult],
                          resulttype = r_acc.type)
 
     def rtype_setitem((r_acc, r_int), hop):
-        c_type = hop.inputconst(lltype.Void, r_acc.type)
         v_addr, v_offs, v_value = hop.inputargs(hop.args_r[0], lltype.Signed, r_acc.type)
         c_size = hop.inputconst(lltype.Signed, sizeof(r_acc.type))
         v_offs_mult = hop.genop('int_mul', [v_offs, c_size],
                                 resulttype=lltype.Signed)
-        return hop.genop('raw_store', [v_addr, c_type, v_offs_mult, v_value])
+        return hop.genop('raw_store', [v_addr, v_offs_mult, v_value])
 
 
 class __extend__(pairtype(AddressRepr, IntegerRepr)):

pypy/translator/c/funcgen.py

     #address operations
     def OP_RAW_STORE(self, op):
         addr = self.expr(op.args[0])
-        TYPE = op.args[1].value
-        offset = self.expr(op.args[2])
-        value = self.expr(op.args[3])
+        offset = self.expr(op.args[1])
+        value = self.expr(op.args[2])
+        TYPE = op.args[2].concretetype
         typename = cdecl(self.db.gettype(TYPE).replace('@', '*@'), '')
         return ('((%(typename)s) (%(addr)s + %(offset)s))[0] = %(value)s;' %
                 locals())
 
     def OP_RAW_LOAD(self, op):
         addr = self.expr(op.args[0])
-        TYPE = op.args[1].value
-        offset = self.expr(op.args[2])
+        offset = self.expr(op.args[1])
         result = self.expr(op.result)
+        TYPE = op.result.concretetype
         typename = cdecl(self.db.gettype(TYPE).replace('@', '*@'), '')
         return ("%(result)s = ((%(typename)s) (%(addr)s + %(offset)s))[0];" %
                 locals())