[pypy-svn] r22653 - in pypy/dist/pypy/jit: . test

ac at codespeak.net ac at codespeak.net
Wed Jan 25 16:14:36 CET 2006


Author: ac
Date: Wed Jan 25 16:14:36 2006
New Revision: 22653

Modified:
   pypy/dist/pypy/jit/llabstractinterp.py
   pypy/dist/pypy/jit/llcontainer.py
   pypy/dist/pypy/jit/llvalue.py
   pypy/dist/pypy/jit/test/test_jit_tl.py
   pypy/dist/pypy/jit/test/test_jit_tlr.py
   pypy/dist/pypy/jit/test/test_llabstractinterp.py
   pypy/dist/pypy/jit/test/test_vlist.py
   pypy/dist/pypy/jit/vlist.py
Log:
(pedronis, arre)
More refactoring to use rgenop.



Modified: pypy/dist/pypy/jit/llabstractinterp.py
==============================================================================
--- pypy/dist/pypy/jit/llabstractinterp.py	(original)
+++ pypy/dist/pypy/jit/llabstractinterp.py	Wed Jan 25 16:14:36 2006
@@ -3,8 +3,7 @@
 from pypy.objspace.flow.model import Block, Link, FunctionGraph
 from pypy.objspace.flow.model import checkgraph, c_last_exception
 from pypy.rpython.lltypesystem import lltype
-from pypy.translator.simplify import eliminate_empty_blocks, join_blocks
-from pypy.jit.llvalue import LLAbstractValue, const, newvar, dupvar
+from pypy.jit.llvalue import LLAbstractValue, 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
@@ -176,11 +175,11 @@
                 a = LLAbstractValue(const(arghints[i]))
                 a.concrete = self.policy.concrete_args
             else:
-                a = LLAbstractValue(dupvar(v))
+                a = LLAbstractValue(input=v.concretetype)
             args_a.append(a)
         graphstate = self.schedule_graph(args_a, origgraph)
         graphstate.complete()
-        return graphstate.copygraph
+        return rgenop.buildgraph(graphstate.startblock)
 
     def schedule_graph(self, args_a, origgraph):
         inputstate = LLBlockState(None, args_a, origgraph.startblock)
@@ -260,6 +259,9 @@
         self.frozenstate = frozenstate
         self.link = None
 
+    def setreturn(self):
+            rgenop.closereturnlink(self.link, self.args_v[0])
+
     def settarget(self, block, blockargs):
         args = []
         for v1, v2 in zip(self.args_v, blockargs):
@@ -267,8 +269,7 @@
                 assert v1 == v2
             else:
                 args.append(v1)
-        self.link.args = args
-        self.link.settarget(block)
+        rgenop.closelink(self.link, args, block)
 
 
 class GraphState(object):
@@ -277,17 +278,7 @@
     def __init__(self, interp, origgraph, inputstate, frozenstate, n):
         self.interp = interp
         self.origgraph = origgraph
-        name = '%s_%d' % (origgraph.name, n)
-        self.copygraph = FunctionGraph(name, Block([]))   # grumble
-        interp.graphs.append(self.copygraph)
-        for orig_v, copy_v in [(origgraph.getreturnvar(),
-                                self.copygraph.getreturnvar()),
-                               (origgraph.exceptblock.inputargs[0],
-                                self.copygraph.exceptblock.inputargs[0]),
-                               (origgraph.exceptblock.inputargs[1],
-                                self.copygraph.exceptblock.inputargs[1])]:
-            if hasattr(orig_v, 'concretetype'):
-                copy_v.concretetype = orig_v.concretetype
+        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.getruntimevars()
@@ -296,8 +287,7 @@
         self.state = "before"
 
     def settarget(self, block, blockargs):
-        block.isstartblock = True
-        self.copygraph.startblock = block
+        self.startblock = block
 
     def complete(self):
         assert self.state != "during"
@@ -313,7 +303,6 @@
                 continue
 
     def try_to_complete(self):
-        graph = self.copygraph
         interp = self.interp
         pending = [self]   # pending list of a GraphState and many LinkStates
         seen = {}
@@ -405,21 +394,9 @@
                         # resolve the LinkState to go to the return
                         # or except block
                         if len(ls.args_v) == 1:
-                            target = graph.returnblock
+                            ls.setreturn()
                         elif len(ls.args_v) == 2:
-                            target = graph.exceptblock
-                        else:
-                            raise Exception("uh?")
-                        ls.settarget(target, target.inputargs)
-                    else:
-                        # the LinkState is already going to a return or except
-                        # block; make sure that it is really the one from
-                        # 'graph' -- by patching 'graph' if necessary.
-                        if len(ls.link.target.inputargs) == 1:
-                            #self.a_return = state.args_a[0]
-                            graph.returnblock = ls.link.target
-                        elif len(link.target.inputargs) == 2:
-                            graph.exceptblock = ls.link.target
+                            XXX_handle_exception_here
                         else:
                             raise Exception("uh?")
 
@@ -427,17 +404,6 @@
             raise RestartCompleting
 
         # the graph should be complete now; sanity-check
-        try:
-            checkgraph(graph)
-        except Exception, e:
-            print 'INVALID GRAPH:'
-            import traceback
-            traceback.print_exc()
-            print 'graph.show()...'
-            graph.show()
-            raise
-        eliminate_empty_blocks(graph)
-        join_blocks(graph)
         self.state = "after"
 
     def flowin(self, state, key):
@@ -612,6 +578,10 @@
                               [a.forcevarorconst(self) for a in args_a],
                               op.result.concretetype)
         return LLAbstractValue(retvar)
+
+    def residual_direct_call(self, name, block, args_a,):
+        
+        return LLAbstractValue(retvar)
     
     def residualize(self, op, args_a, constant_op=None):
         if constant_op:
@@ -769,13 +739,13 @@
         graphstate = self.interp.schedule_graph(args_a, origgraph)
         #print 'SCHEDULE_GRAPH', args_a, '==>', graphstate.copygraph.name
         if graphstate.state != "during":
-            print 'ENTERING', graphstate.copygraph.name, args_a
+            print 'ENTERING', graphstate.name, args_a
             graphstate.complete()
             #if graphstate.a_return is not None:
             #    a = graphstate.a_return.unfreeze(UnfreezeMemo())
             #    if a.maybe_get_constant() is not None:
             #        a_real_result = a    # propagate a constant result
-            print 'LEAVING', graphstate.copygraph.name#, graphstate.a_return
+            print 'LEAVING', graphstate.name#, graphstate.a_return
 
         ARGS = []
         new_args_a = []
@@ -785,9 +755,10 @@
                 new_args_a.append(a)
         args_a = new_args_a
         TYPE = lltype.FuncType(ARGS, op.result.concretetype)
-        fptr = lltype.functionptr(
-           TYPE, graphstate.copygraph.name, graph=graphstate.copygraph)
-        a_func = LLAbstractValue(const(fptr))
+        a_func = LLAbstractValue(rgenop.gengraphconst(self.newblock,
+                                                      graphstate.name,
+                                                      graphstate.startblock,
+                                                      TYPE))
         return self.residual(op, [a_func] + args_a) 
 
     def op_getfield(self, op, a_ptr, a_attrname):

Modified: pypy/dist/pypy/jit/llcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/llcontainer.py	(original)
+++ pypy/dist/pypy/jit/llcontainer.py	Wed Jan 25 16:14:36 2006
@@ -1,6 +1,6 @@
 from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
 from pypy.rpython.lltypesystem import lltype
-from pypy.jit.llvalue import LLAbstractValue, newvar, const
+from pypy.jit.llvalue import LLAbstractValue, const
 
 
 class LLAbstractContainer(object):

Modified: pypy/dist/pypy/jit/llvalue.py
==============================================================================
--- pypy/dist/pypy/jit/llvalue.py	(original)
+++ pypy/dist/pypy/jit/llvalue.py	Wed Jan 25 16:14:36 2006
@@ -15,13 +15,16 @@
 
     concrete = False   # concrete constants propagate eagerly
 
-    def __init__(self, runtimevar=None, content=None):
+    def __init__(self, runtimevar=None, content=None, input=None):
         self.runtimevar = runtimevar    # None or a Variable or a Constant
         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>'
@@ -40,6 +43,8 @@
 
     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)
@@ -60,6 +65,8 @@
             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:
@@ -85,7 +92,9 @@
         """Recursively flatten the LLAbstractValue into a list of run-time
         LLAbstractValues.
         """
-        if self.runtimevar is not None:
+        if self.input:
+            memo.result.append(self)
+        elif 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)
@@ -96,7 +105,8 @@
         else:
             pass    # dummy
 
-# ____________________________________________________________
+# _____________________________________________________________
+
 
 class LLFrozenValue(object):
     """An abstract value frozen in a saved state.
@@ -152,7 +162,7 @@
 
     def __init__(self, a_value):
         # get the necessary information from the a_value
-        self.concretetype = a_value.runtimevar.concretetype
+        self.concretetype = a_value.getconcretetype()
         self.origin = a_value.origin
 
     def flatten(self, memo):
@@ -247,16 +257,6 @@
     c.concretetype = T or lltype.typeOf(value)
     return c
 
-def newvar(T):
-    v = Variable()
-    v.concretetype = T
-    return v
-
-def dupvar(v):
-    v1 = Variable(v)
-    v1.concretetype = v.concretetype
-    return v1
-
 ll_no_return_value = LLAbstractValue(const(None, lltype.Void))
 ll_dummy_value = LLAbstractValue()
 frozen_dummy_value = LLFrozenDummyValue()

Modified: pypy/dist/pypy/jit/test/test_jit_tl.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_jit_tl.py	(original)
+++ pypy/dist/pypy/jit/test/test_jit_tl.py	Wed Jan 25 16:14:36 2006
@@ -36,7 +36,7 @@
     #interp.graphs[0].show()
 
     # return a summary of the instructions left in graph2
-    return summary(interp)
+    return summary(graph2)
 
 
 def run_jit(code):

Modified: pypy/dist/pypy/jit/test/test_jit_tlr.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_jit_tlr.py	(original)
+++ pypy/dist/pypy/jit/test/test_jit_tlr.py	Wed Jan 25 16:14:36 2006
@@ -97,6 +97,6 @@
     res = llinterp.eval_graph(graph2, [17])
     assert res == 289
 
-    insns = summary(interp)
+    insns = summary(graph2)
     assert insns == {'int_add': 2,
                      'int_is_true': 1}

Modified: pypy/dist/pypy/jit/test/test_llabstractinterp.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_llabstractinterp.py	(original)
+++ pypy/dist/pypy/jit/test/test_llabstractinterp.py	Wed Jan 25 16:14:36 2006
@@ -6,7 +6,7 @@
 from pypy.rpython import rstr
 from pypy.annotation import model as annmodel
 from pypy.jit.llabstractinterp import LLAbstractInterp, Policy
-
+from pypy.objspace.flow import model as flowmodel
 
 def annotation(a, x):
     T = lltype.typeOf(x)
@@ -54,15 +54,31 @@
     result1 = llinterp.eval_graph(graph1, argvalues)
     result2 = llinterp.eval_graph(graph2, argvalues2)
     assert result1 == result2
-    return graph2, summary(interp)
+    return graph2, summary(graph2)
 
-def summary(interp):
+def summary(graph):
     # return a summary of the instructions left in all the residual graphs
     insns = {}
-    for copygraph in interp.itercopygraphs():
-        for block in copygraph.iterblocks():
+    graphs = [graph]
+    found = set((graph,))
+    while graphs:
+        graph = graphs.pop()
+        for block in graph.iterblocks():
             for op in block.operations:
                 insns[op.opname] = insns.get(op.opname, 0) + 1
+                for arg in op.args:
+                    if isinstance(arg, flowmodel.Constant):
+                        if (isinstance(arg.concretetype, lltype.Ptr) and
+                            isinstance(arg.concretetype.TO, lltype.FuncType)):
+                            try:
+                                graph = arg.value._obj.graph
+                                graph.rgenop
+                            except AttributeError:
+                                pass
+                            else:
+                                if graph not in found:
+                                    graphs.append(graph)
+                                    found.add(graph)
     return insns
 
 P_INLINE = Policy(inlining=True)

Modified: pypy/dist/pypy/jit/test/test_vlist.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_vlist.py	(original)
+++ pypy/dist/pypy/jit/test/test_vlist.py	Wed Jan 25 16:14:36 2006
@@ -33,8 +33,7 @@
 
     assert result1 == result2
 
-    return graph2, summary(interp)
-
+    return graph2, summary(graph2)
 
 def test_fixed_newlistfill_force():
     def fn(n):

Modified: pypy/dist/pypy/jit/vlist.py
==============================================================================
--- pypy/dist/pypy/jit/vlist.py	(original)
+++ pypy/dist/pypy/jit/vlist.py	Wed Jan 25 16:14:36 2006
@@ -1,6 +1,6 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.rtyper import LowLevelOpList
-from pypy.jit.llvalue import LLAbstractValue, newvar, const, ll_dummy_value
+from pypy.jit.llvalue import LLAbstractValue, const, ll_dummy_value
 from pypy.jit.llcontainer import LLAbstractContainer
 
 



More information about the Pypy-commit mailing list