[pypy-svn] r22678 - pypy/branch/jit-refactoring/pypy/jit

pedronis at codespeak.net pedronis at codespeak.net
Thu Jan 26 12:59:26 CET 2006


Author: pedronis
Date: Thu Jan 26 12:59:23 2006
New Revision: 22678

Modified:
   pypy/branch/jit-refactoring/pypy/jit/llabstractinterp.py
   pypy/branch/jit-refactoring/pypy/jit/llcontainer.py
   pypy/branch/jit-refactoring/pypy/jit/llvalue.py
   pypy/branch/jit-refactoring/pypy/jit/vlist.py
Log:
use AConstant and AVariable for LLAbstractValue.runtimevar, these have a getgenvar(builder) to retrieve a stored
corresponding rgenop API var/const opaque object, or to lazily comnpute such a const object in the context of 
the given builder.



Modified: pypy/branch/jit-refactoring/pypy/jit/llabstractinterp.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/llabstractinterp.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/llabstractinterp.py	Thu Jan 26 12:59:23 2006
@@ -1,8 +1,8 @@
 import operator
-from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
+from pypy.objspace.flow.model import Variable, Constant
 from pypy.objspace.flow.model import checkgraph, c_last_exception
 from pypy.rpython.lltypesystem import lltype
-from pypy.jit.llvalue import LLAbstractValue, const, aconst, AConstant, AVariable
+from pypy.jit.llvalue import LLAbstractValue, AConstant, AVariable, const
 from pypy.jit.llvalue import ll_no_return_value
 from pypy.jit.llvalue import FlattenMemo, MatchMemo, FreezeMemo, UnfreezeMemo
 from pypy.jit.llcontainer import LLAbstractContainer, virtualcontainervalue
@@ -51,10 +51,6 @@
     def getruntimevars(self):
         assert not self.frozen, "getruntimevars(): not for frozen states"
         return [a.runtimevar for a in self.flatten()]
-
-    def getgenvars(self, builder):
-        assert not self.frozen, "getgenvars(): not for frozen states"
-        return [a.getgenvar(builder) for a in self.flatten()]
     
     def flatten(self, memo=None):
         if memo is None:
@@ -175,10 +171,10 @@
         args_a = []
         for i, v in enumerate(origgraph.getargs()):
             if i in arghints:
-                a = LLAbstractValue(aconst(arghints[i]))
+                a = LLAbstractValue(AConstant(arghints[i]))
                 a.concrete = self.policy.concrete_args
             else:
-                a = LLAbstractValue(AVariable(), input=v.concretetype)
+                a = LLAbstractValue(AVariable(v.concretetype))
             args_a.append(a)
         graphstate = self.schedule_graph(args_a, origgraph)
         graphstate.complete()
@@ -199,8 +195,8 @@
     def schedule(self, inputstate, builder):
         #print "SCHEDULE", args_a, origblock
         frozenstate = self.schedule_getstate(inputstate)
-        args_v = inputstate.getgenvars(builder)
-        return LinkState(args_v, frozenstate)
+        args_v = inputstate.getruntimevars()
+        return LinkState(builder, args_v, frozenstate)
 
     def schedule_getstate(self, inputstate):
         # NOTA BENE: copyblocks can get shared between different copygraphs!
@@ -257,19 +253,21 @@
     exitcase = None
     llexitcase = None
 
-    def __init__(self, args_v, frozenstate):
+    def __init__(self, builder, args_v, frozenstate):
         self.args_v = args_v
+        self.args_genv = [v.getgenvar(builder) for v in args_v]
         self.frozenstate = frozenstate
         self.link = None
 
     def setreturn(self):
-        rgenop.closereturnlink(self.link, self.args_v[0])
+        rgenop.closereturnlink(self.link, self.args_genv[0])
 
     def settarget(self, block, blockargs):
         args = []
-        for v1, v2 in zip(self.args_v, blockargs):
-            if isinstance(v2, Constant):
-                assert v1 == v2
+        for v1, v2 in zip(self.args_genv, blockargs):
+            assert isinstance(v2, (AVariable, AConstant))
+            if isinstance(v2, AConstant):
+                assert v1.value == v2.value # sanity check violating encapsulation
             else:
                 args.append(v1)
         rgenop.closelink(self.link, args, block)
@@ -284,7 +282,7 @@
         self.name = '%s_%d' % (origgraph.name, n)
         # The 'args_v' attribute is needed by try_to_complete(),
         # which looks for it on either a GraphState or a LinkState
-        self.args_v = inputstate.getgenvars(None)
+        self.args_v = inputstate.getruntimevars()
         self.frozenstate = frozenstate
         #self.a_return = None
         self.state = "before"
@@ -439,7 +437,7 @@
                     # except block of the copygraph.
                     args_v = [builder.binding(v).forcevarorconst(builder)
                               for v in origblock.inputargs]
-                    ls = LinkState(args_v, frozenstate=None)
+                    ls = LinkState(builder, args_v, frozenstate=None)
                     raise InsertNextLink(ls)
                 else:
                     # finishing a handle_call_inlining(): link back to
@@ -481,7 +479,7 @@
             else:
                 a = builder.bindings[origblock.exitswitch]
                 v = a.forcevarorconst(builder)
-                if isinstance(v, Variable):
+                if isinstance(v, AVariable):
                     newexitswitch = v
                     links = origblock.exits
                 else:
@@ -524,7 +522,7 @@
 
         assert len(newlinkstates) == 2
 
-        false_link, true_link = rgenop.closeblock2(b, newexitswitch)
+        false_link, true_link = rgenop.closeblock2(b, newexitswitch.getgenvar(self))
         cases = {False: false_link, True: true_link}
         for ls in newlinkstates:
             ls.link = cases[ls.exitcase]
@@ -537,8 +535,9 @@
         return rgenop.genconst(self.newblock, llvalue)
     
     def binding(self, v):
+        assert isinstance(v, (Constant, Variable))
         if isinstance(v, Constant):
-            return LLAbstractValue(aconst(v.value, v.concretetype))
+            return LLAbstractValue(AConstant(v.value, v.concretetype))
         else:
             return self.bindings[v]
 
@@ -568,7 +567,7 @@
         # can constant-fold
         print 'fold:', constant_op.__name__, concretevalues
         concreteresult = constant_op(*concretevalues)
-        a_result = LLAbstractValue(aconst(concreteresult))
+        a_result = LLAbstractValue(AConstant(concreteresult))
         if any_concrete and self.interp.policy.concrete_propagate:
             a_result.concrete = True
         else:
@@ -576,14 +575,11 @@
         return a_result
 
     def residual(self, op, args_a):
+        T= op.result.concretetype
         retvar = self.genop(op.opname,
                               [a.forcegenvarorconst(self) for a in args_a],
-                              op.result.concretetype)
-        return LLAbstractValue(retvar)
-
-    def residual_direct_call(self, name, block, args_a,):
-        
-        return LLAbstractValue(retvar)
+                              T)
+        return LLAbstractValue(AVariable(T, genvar=retvar))
     
     def residualize(self, op, args_a, constant_op=None):
         if constant_op:
@@ -757,10 +753,11 @@
                 new_args_a.append(a)
         args_a = new_args_a
         TYPE = lltype.FuncType(ARGS, op.result.concretetype)
-        a_func = LLAbstractValue(rgenop.gengraphconst(self.newblock,
-                                                      graphstate.name,
-                                                      graphstate.startblock,
-                                                      TYPE))
+        genconst = rgenop.gengraphconst(self.newblock,
+                                        graphstate.name,
+                                        graphstate.startblock,
+                                        TYPE)
+        a_func = LLAbstractValue(AConstant(genconst.value, TYPE, genvar=genconst)) # XXX const.value!
         return self.residual(op, [a_func] + args_a) 
 
     def op_getfield(self, op, a_ptr, a_attrname):
@@ -785,7 +782,7 @@
 
     def op_getarraysize(self, op, a_ptr):
         if hasllcontent(a_ptr):
-            return LLAbstractValue(aconst(a_ptr.content.length))
+            return LLAbstractValue(AConstant(a_ptr.content.length))
         return self.residualize(op, [a_ptr], len)
 
     def op_getarrayitem(self, op, a_ptr, a_index):
@@ -868,7 +865,7 @@
         args_a = []
         for a in argtuple:
             if not isinstance(a, LLAbstractValue):
-                a = LLAbstractValue(aconst(a))
+                a = LLAbstractValue(AConstant(a))
             args_a.append(a)
         # end of rather XXX'edly hackish parsing
 

Modified: pypy/branch/jit-refactoring/pypy/jit/llcontainer.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/llcontainer.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/llcontainer.py	Thu Jan 26 12:59:23 2006
@@ -1,6 +1,5 @@
-from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
 from pypy.rpython.lltypesystem import lltype
-from pypy.jit.llvalue import LLAbstractValue, const
+from pypy.jit.llvalue import LLAbstractValue, AConstant, const
 
 
 class LLAbstractContainer(object):
@@ -53,7 +52,7 @@
         RESULT_TYPE = lltype.Ptr(self.T)
         if self.a_parent is not None:
             parentindex = const(self.parentindex, lltype.Void)
-            v_parent = self.a_parent.forcevarorconst(builder)
+            v_parent = self.a_parent.forcegenvarorconst(builder)
             v_result = builder.genop('getsubstruct',
                                      [v_parent, parentindex], RESULT_TYPE)
         else:
@@ -82,7 +81,7 @@
                     assert isinstance(a_value.content, LLVirtualContainer)
                     a_value.content.buildcontent(builder, v_subptr)
                 else:
-                    v_value = a_value.forcevarorconst(builder)
+                    v_value = a_value.forcegenvarorconst(builder)
                     self.setop(builder, v_target, name, v_value)
 
     def flatten(self, memo):
@@ -216,7 +215,7 @@
         a.content.parentindex = parentindex
     else:
         # primitive initialized to zero
-        a = LLAbstractValue(aconst(T._defl()))
+        a = LLAbstractValue(AConstant(T._defl()))
     return a
 
 def hasllcontent(a_ptr):

Modified: pypy/branch/jit-refactoring/pypy/jit/llvalue.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/llvalue.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/llvalue.py	Thu Jan 26 12:59:23 2006
@@ -1,18 +1,26 @@
-from pypy.objspace.flow.model import Variable, Constant
+from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython import rgenop
 from pypy.tool.uid import Hashable
 
 class AVariable(object):
-    def __init__(self, genvar=None):
+    def __init__(self, T, genvar=None):
+        self.concretetype = T
         self.genvar = genvar
 
     def getgenvar(self, builder):
         return self.genvar
     
 class AConstant(Hashable):
-    def getgenvar(self, v, builder):
+    def __init__(self, value, T=None, genvar=None):
+        Hashable.__init__(self, value)   
+        self.concretetype = T or lltype.typeOf(value)
+        self.genvar = genvar
         
+    def getgenvar(self, builder):
+        if self.genvar is None:
+            self.genvar = builder.genconst(self.value)
+        return self.genvar
 
 class LLAbstractValue(object):
     """An abstract value, propagated through the blocks of the low-level
@@ -27,17 +35,13 @@
 
     concrete = False   # concrete constants propagate eagerly
 
-    def __init__(self, runtimevar=None, genvar=None, content=None, input=None):
-        self.runtimevar = runtimevar    # None or a Variable or a Constant
-        self.genvar     = genvar
+    def __init__(self, runtimevar=None, content=None):
+        self.runtimevar = runtimevar    # None or a AVariable or a AConstant
         self.content    = content       # None or an LLAbstractContainer
         self.origin     = []  # list of frozen values: the sources that did or
                               # could allow 'self' to be computed as a constant
-        self.input = input
         
     def __repr__(self):
-        if self.input:
-            return '<input>'
         if self.runtimevar is None:
             if self.content is None:
                 return '<dummy>'
@@ -46,7 +50,7 @@
         else:
             # runtime value -- display more precisely if it's a
             # Variable or a Constant
-            if isinstance(self.runtimevar, Variable):
+            if isinstance(self.runtimevar, AVariable):
                 kind = 'runtime'
             elif self.concrete:
                 kind = 'concrete'
@@ -56,8 +60,6 @@
 
     def freeze(self, memo):
         # turn a run-time value into a frozen value
-        if self.input:
-            return LLFrozenRuntimeValue(self)
         if self.runtimevar is not None:
             if self.concrete:
                 return LLFrozenConcreteValue(self)
@@ -78,8 +80,6 @@
             return frozen_dummy_value   # dummy
 
     def getconcretetype(self):
-        if self.input:
-            return self.input
         if self.runtimevar is not None:
             return self.runtimevar.concretetype
         elif self.content is not None:
@@ -91,23 +91,14 @@
         if self.runtimevar is None:
             if self.content is None:
                 raise ValueError("ll_dummy_value.forcevarorconst()")
-            XXX + self.content.build_runtime_container(builder)
+            genvar = self.content.build_runtime_container(builder)
+            assert self.content.T == genvar.concretetype.TO # sanity check
+            self.runtimevar = AVariable(lltype.Ptr(self.content.T), genvar=genvar)
             self.content = None
         return self.runtimevar
 
     def forcegenvarorconst(self, builder):
-        if self.runtimevar is None:
-            if self.content is None:
-                raise ValueError("ll_dummy_value.forcevarorconst()")
-            self.genvar = self.content.build_runtime_container(builder)
-            self.content = None
-        return self.getgenvar(builder)
-
-    def getgenvar(self, builder):
-        if self.genvar is None:
-            assert isinstance(self.runtimevar, AConstant)
-            self.genvar = builder.genconst(self.runtimevar.value)
-        return self.genvar
+        return self.forcevarorconst(builder).getgenvar(builder)
     
     def maybe_get_constant(self):
         if isinstance(self.runtimevar, AConstant):
@@ -119,9 +110,7 @@
         """Recursively flatten the LLAbstractValue into a list of run-time
         LLAbstractValues.
         """
-        if self.input:
-            memo.result.append(self)
-        elif self.runtimevar is not None:
+        if self.runtimevar is not None:
             if not self.concrete:   # skip concrete values, they don't need
                                     # to be present in the residual graph at all
                 memo.result.append(self)
@@ -205,12 +194,12 @@
         # never shared
         propagateconst = memo.propagateconsts.next()
         if isinstance(propagateconst, AConstant):
-            v = propagateconst        # allowed to propagate as a Constant
-            assert v.concretetype == self.concretetype
-            result = LLAbstractValue(v)
+            c = propagateconst        # allowed to propagate as a Constant
+            assert c.concretetype == self.concretetype
+            result = LLAbstractValue(c)
         else:
-            v = rgenop.geninputarg(block, self.concretetype)
-            result = LLAbstractValue(v, genvar=v)
+            gen_v = rgenop.geninputarg(block, self.concretetype)
+            result = LLAbstractValue(AVariable(self.concretetype, genvar=gen_v))
         result.origin.append(self)
         return result
 
@@ -285,11 +274,6 @@
     c.concretetype = T or lltype.typeOf(value)
     return c
 
-def aconst(value, T=None):
-    c = AConstant(value)
-    c.concretetype = T or lltype.typeOf(value)
-    return c
-
-ll_no_return_value = LLAbstractValue(aconst(None, lltype.Void))
+ll_no_return_value = LLAbstractValue(AConstant(None, lltype.Void))
 ll_dummy_value = LLAbstractValue()
 frozen_dummy_value = LLFrozenDummyValue()

Modified: pypy/branch/jit-refactoring/pypy/jit/vlist.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/vlist.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/vlist.py	Thu Jan 26 12:59:23 2006
@@ -1,6 +1,6 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.rtyper import LowLevelOpList
-from pypy.jit.llvalue import LLAbstractValue, aconst, ll_dummy_value
+from pypy.jit.llvalue import LLAbstractValue, AConstant, ll_dummy_value
 from pypy.jit.llcontainer import LLAbstractContainer
 
 
@@ -39,7 +39,7 @@
         return LLVirtualList(self.T, items_a)
 
     def build_runtime_container(self, builder):
-        items_v = [a.forcevarorconst(builder) for a in self.items_a]
+        items_v = [a.forcegenvarorconst(builder) for a in self.items_a]
         v_result = self.T.list_builder(builder, items_v)
         return v_result
 
@@ -47,10 +47,10 @@
     # High-level operations
 
     def oop_len(self, op):
-        return LLAbstractValue(aconst(len(self.items_a)))
+        return LLAbstractValue(AConstant(len(self.items_a)))
 
     def oop_nonzero(self, op):
-        return LLAbstractValue(aconst(bool(self.items_a)))
+        return LLAbstractValue(AConstant(bool(self.items_a)))
 
     def oop_getitem(self, op, a_index):
         c_index = a_index.maybe_get_constant()



More information about the Pypy-commit mailing list