[pypy-svn] r31799 - in pypy/dist/pypy/jit: codegen/i386 codegen/i386/test codegen/llgraph timeshifter

pedronis at codespeak.net pedronis at codespeak.net
Tue Aug 29 17:22:58 CEST 2006


Author: pedronis
Date: Tue Aug 29 17:22:55 2006
New Revision: 31799

Modified:
   pypy/dist/pypy/jit/codegen/i386/ri386genop.py
   pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py
   pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
   pypy/dist/pypy/jit/timeshifter/rcontainer.py
   pypy/dist/pypy/jit/timeshifter/rtimeshift.py
   pypy/dist/pypy/jit/timeshifter/rvalue.py
Log:
(arigo, pedronis)

introduce and use genop_malloc_fixedsize. implement for codegen/llgraph and a first rough pass at 
a codegen/i386 version.




Modified: pypy/dist/pypy/jit/codegen/i386/ri386genop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/ri386genop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/ri386genop.py	Tue Aug 29 17:22:55 2006
@@ -2,6 +2,7 @@
 from pypy.jit.codegen.i386.ri386 import *
 from pypy.jit.codegen.model import AbstractRGenOp, CodeGenBlock, CodeGenLink
 from pypy.jit.codegen.model import GenVar, GenConst
+from pypy.rpython import objectmodel
 
 WORD = 4
 
@@ -23,13 +24,15 @@
     def operand(self, block):
         return block.stack_access(self.stackpos)
 
+    def __repr__(self):
+        return 'var@%d' % (self.stackpos,)
+
 
 class TypeConst(GenConst):
 
     def __init__(self, kind):
         self.kind = kind
 
-
 ##class Const(GenConst):
 
 ##    def revealconst(self, TYPE):
@@ -72,6 +75,10 @@
             return lltype.cast_primitive(T, self.value)
     revealconst._annspecialcase_ = 'specialize:arg(1)'
 
+    def __repr__(self):
+        return "const=%s" % (imm(self.value).assembler(),)
+        
+
 
 class FnPtrConst(IntConst):
     def __init__(self, value, mc):
@@ -96,6 +103,9 @@
             assert 0, "XXX not implemented"
     revealconst._annspecialcase_ = 'specialize:arg(1)'
 
+    def __repr__(self):
+        return "const=%r" % (self.addr,)
+
 
 class Block(CodeGenBlock):
     def __init__(self, rgenop, mc):
@@ -120,7 +130,6 @@
         return self.emit_getfield(gv_ptr, offset)
 
     def genop_setfield(self, offset, gv_ptr, gv_value):
-        offset = self.rgenop.offsetscomp.offsetof(T, name)
         return self.emit_setfield(gv_ptr, offset, gv_value)
 
     def genop_getsubstruct(self, offset, gv_ptr):
@@ -129,6 +138,9 @@
     def genop_getarrayitem(self, arraytoken, gv_ptr, gv_index):
         return self.emit_getarrayitem(gv_ptr, arraytoken, gv_index)
 
+    def genop_malloc_fixedsize(self, size):
+        return self.emit_malloc_fixedsize(size)
+
     def close1(self):
         return Link(self)
 
@@ -259,6 +271,18 @@
         self.mc.MOVZX(eax, al)
         return self.push(eax)
 
+    def op_cast_pointer(self, (gv_x,), gv_RESTYPE):
+        return gv_x
+
+    gc_malloc = objectmodel.CDefinedIntSymbolic("((long)GC_local_malloc)", 13) # XXX XXX
+
+    def emit_malloc_fixedsize(self, size):
+        # XXX boehm only, no atomic/non atomic distinction for now
+        self.mc.PUSH(imm(size))
+        self.mc.CALL(rel32(cast_ptr_to_int(llhelper(gc_malloc, [lltype.Signed], lltype.Address)))
+        self.stackdepth += 1 # maybe?
+        return self.push(eax)
+
     def emit_getfield(self, gv_ptr, offset):
         # XXX only for int fields
         self.mc.MOV(edx, gv_ptr.operand(self))
@@ -436,6 +460,11 @@
     fieldToken._annspecialcase_ = 'specialize:memo'
     fieldToken = staticmethod(fieldToken)
 
+    def allocToken(T):
+        return llmemory.sizeof(T)
+    allocToken._annspecialcase_ = 'specialize:memo'
+    allocToken = staticmethod(allocToken)
+    
     def arrayToken(A):
         return (llmemory.ArrayLengthOffset(A),
                 llmemory.ArrayItemsOffset(A),

Modified: pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py	Tue Aug 29 17:22:55 2006
@@ -24,6 +24,11 @@
         arrayToken._annspecialcase_ = 'specialize:memo'
         arrayToken = staticmethod(arrayToken)
 
+        def allocToken(T):
+            return len(T._names)
+        allocToken._annspecialcase_ = 'specialize:memo'
+        allocToken = staticmethod(allocToken)
+
         def constFieldName(T, name):
             return IntConst(list(T._names).index(name))
         constFieldName._annspecialcase_ = 'specialize:memo'

Modified: pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/llgraph/rgenop.py	Tue Aug 29 17:22:55 2006
@@ -9,6 +9,9 @@
     def __init__(self, v):
         self.v = v
 
+    def __repr__(self):
+        return repr(RGenOp.reveal(self))
+
 
 class LLConst(GenConst):
     def __init__(self, v):
@@ -18,6 +21,8 @@
         return llimpl.revealconst(T, self.v)
     revealconst._annspecialcase_ = 'specialize:arg(1)'
 
+    def __repr__(self):
+        return repr(RGenOp.reveal(self))
 
 gv_Void = LLConst(llimpl.constTYPE(lltype.Void))
 
@@ -52,8 +57,13 @@
     def genop_getarrayitem(self, gv_ITEMTYPE, gv_ptr, gv_index):
         vars_gv = [gv_ptr.v, gv_index.v]
         return LLVar(llimpl.genop(self.b, 'getarrayitem', vars_gv,
-                                  gv_ITEMTYPE.v))        
-        
+                                  gv_ITEMTYPE.v))
+
+    def genop_malloc_fixedsize(self, (gv_TYPE, gv_PTRTYPE)):
+        vars_gv = [gv_TYPE.v]
+        return LLVar(llimpl.genop(self.b, 'malloc', vars_gv,
+                                  gv_PTRTYPE.v))
+                                  
     def close1(self):
         return LLLink(llimpl.closeblock1(self.b))
 
@@ -97,6 +107,11 @@
     fieldToken._annspecialcase_ = 'specialize:memo'
     fieldToken = staticmethod(fieldToken)
 
+    def allocToken(TYPE):
+        return (LLConst(llimpl.constTYPE(TYPE)), LLConst(llimpl.constTYPE(lltype.Ptr(TYPE))))
+    allocToken._annspecialcase_ = 'specialize:memo'
+    allocToken = staticmethod(allocToken)
+
     def arrayToken(A):
         return LLConst(llimpl.constTYPE(A.OF))
     arrayToken._annspecialcase_ = 'specialize:memo'

Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py	Tue Aug 29 17:22:55 2006
@@ -32,6 +32,9 @@
     def __init__(self, RGenOp, TYPE):
         self.TYPE = TYPE
         self.PTRTYPE = lltype.Ptr(TYPE)
+        self.alloctoken = RGenOp.allocToken(self.TYPE)
+
+        # XXX
         self.gv_type = RGenOp.constTYPE(self.TYPE)
         self.gv_ptrtype = RGenOp.constTYPE(self.PTRTYPE)
 
@@ -201,17 +204,15 @@
                 box.enter_block(newblock, incoming, memo)
 
     def force_runtime_container(self, builder):
-        genop = builder.genop
         typedesc = self.typedesc
         boxes = self.content_boxes
         self.content_boxes = None
-        op_args = [typedesc.gv_type]
-        genvar = genop('malloc', op_args, typedesc.gv_ptrtype)
+        genvar = builder.genop_malloc_fixedsize(typedesc.alloctoken)
         # force all the boxes pointing to this VirtualStruct
         for box in self.substruct_boxes:
             # XXX using getsubstruct would be nicer
             op_args = [genvar]
-            box.genvar = genop('cast_pointer', op_args, box.gv_type)
+            box.genvar = builder.genop('cast_pointer', op_args, box.gv_type)
             box.content = None
         self.substruct_boxes = None
         fielddescs = typedesc.fielddescs

Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py	Tue Aug 29 17:22:55 2006
@@ -322,6 +322,9 @@
     def genop_getarrayitem(self, arraytoken, gv_ptr, gv_index):
         return self.block.genop_getarrayitem(arraytoken, gv_ptr, gv_index)
 
+    def genop_malloc_fixedsize(self, alloctoken):
+        return self.block.genop_malloc_fixedsize(alloctoken)
+
     def constTYPE(self, T):
         return self.rgenop.constTYPE(T)
     constTYPE._annspecialcase_ = 'specialize:arg(1)'

Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvalue.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rvalue.py	Tue Aug 29 17:22:55 2006
@@ -34,8 +34,7 @@
         if not self.genvar:
             return '<dummy>'
         else:
-            from pypy.jit.codegen.llgraph.rgenop import rgenop
-            return '<%r>' % (rgenop.reveal(self.genvar),)
+            return '<%r>' % (self.genvar,)
 
     def is_constant(self):
         return bool(self.genvar) and self.genvar.is_const



More information about the Pypy-commit mailing list