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

arigo at codespeak.net arigo at codespeak.net
Tue Sep 12 17:08:25 CEST 2006


Author: arigo
Date: Tue Sep 12 17:08:24 2006
New Revision: 32225

Added:
   pypy/dist/pypy/jit/hintannotator/test/test_toy.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/hintannotator/bookkeeper.py
   pypy/dist/pypy/jit/hintannotator/model.py
   pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
Log:
(pedronis, arigo)

hint-annotate the TLC.  Simple support for indirect_call.


Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/bookkeeper.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py	Tue Sep 12 17:08:24 2006
@@ -14,7 +14,6 @@
         self._cache = {}
 
     def specialize(self, input_args_hs, key=None, alt_name=None):
-        from pypy.jit.hintannotator import model as hintmodel
         # get the specialized graph -- for now, no specialization
         graph = self.cachedgraph(key, alt_name)
 
@@ -56,6 +55,9 @@
         self.virtual_containers = {}
         self.descs = {}
         self.annotator = hannotator
+        # circular imports hack
+        global hintmodel
+        from pypy.jit.hintannotator import model as hintmodel
 
     def getdesc(self, graph):
         try:
@@ -84,7 +86,6 @@
         try:
             origin = self.originflags[self.position_key]
         except KeyError:
-            from pypy.jit.hintannotator import model as hintmodel
             if len(self.position_key) == 3:
                 graph, block, i = self.position_key
                 spaceop = block.operations[i]
@@ -101,13 +102,11 @@
         pass
 
     def immutableconstant(self, const):
-        from pypy.jit.hintannotator import model as hintmodel
         res = hintmodel.SomeLLAbstractConstant(const.concretetype, {})
         res.const = const.value
         return res
 
     def immutablevalue(self, value):        
-        from pypy.jit.hintannotator import model as hintmodel
         res = hintmodel.SomeLLAbstractConstant(lltype.typeOf(value), {})
         res.const = value
         return res
@@ -165,6 +164,36 @@
         graph = desc.specialize(args_hs, key=key, alt_name=alt_name)
         return graph
 
+    def graph_call(self, graph, fixed, args_hs):
+        input_args_hs = list(args_hs)
+        graph = self.get_graph_for_call(graph, fixed, input_args_hs)
+
+        # propagate fixing of arguments in the function to the caller
+        for inp_arg_hs, arg_hs in zip(input_args_hs, args_hs):
+            if isinstance(arg_hs, hintmodel.SomeLLAbstractConstant):
+                assert len(inp_arg_hs.origins) == 1
+                [o] = inp_arg_hs.origins.keys()
+                if o.read_fixed():
+                    for o in arg_hs.origins:
+                        o.set_fixed()
+        
+        hs_res = self.annotator.recursivecall(graph,
+                                              self.position_key,
+                                              input_args_hs)
+        # look on which input args the hs_res result depends on
+        if isinstance(hs_res, hintmodel.SomeLLAbstractConstant):
+            deps_hs = []
+            for hs_inputarg, hs_arg in zip(input_args_hs, args_hs):
+                if isinstance(hs_inputarg, hintmodel.SomeLLAbstractConstant):
+                    assert len(hs_inputarg.origins) == 1
+                    [o] = hs_inputarg.origins.keys()
+                    if o in hs_res.origins:
+                        deps_hs.append(hs_arg)
+            if fixed:
+                deps_hs.append(hs_res)
+            hs_res = hintmodel.reorigin(hs_res, *deps_hs)
+        return hs_res
+
 # get current bookkeeper
 
 def getbookkeeper():

Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Tue Sep 12 17:08:24 2006
@@ -6,6 +6,7 @@
 UNARY_OPERATIONS = """same_as hint getfield setfield getsubstruct getarraysize setarrayitem
                       cast_pointer
                       direct_call
+                      indirect_call
                       int_is_true int_neg
                       uint_is_true
                       cast_int_to_char
@@ -270,6 +271,27 @@
         ARRAY = hs_v1.concretetype.TO
         return SomeLLAbstractVariable(lltype.Ptr(ARRAY.OF))
 
+    def indirect_call(hs_v1, *args_hs):
+        hs_graph_list = args_hs[-1]
+        args_hs = args_hs[:-1]
+        assert hs_graph_list.is_constant()
+        graph_list = hs_graph_list.const
+        assert graph_list      # XXX for now
+
+        bookkeeper = getbookkeeper()
+        fixed = bookkeeper.myorigin().read_fixed()
+        results_hs = [bookkeeper.graph_call(graph, fixed, args_hs)
+                      for graph in graph_list]
+        hs_res = annmodel.unionof(*results_hs)
+
+        if isinstance(hs_res, SomeLLAbstractConstant):
+            hs_res.myorigin = bookkeeper.myorigin()
+
+        # we need to make sure that hs_res does not become temporarily less
+        # general as a result of calling another specialized version of the
+        # function
+        return annmodel.unionof(hs_res, bookkeeper.current_op_binding())
+
 
 class __extend__(SomeLLAbstractConstant):
 
@@ -309,34 +331,10 @@
         if not hasattr(fnobj, 'graph'):
             raise NotImplementedError("XXX call to externals or primitives")
 
-        input_args_hs = list(args_hs)
         fixed = bookkeeper.myorigin().read_fixed()
-        graph = bookkeeper.get_graph_for_call(fnobj.graph, fixed, input_args_hs)
+        hs_res = bookkeeper.graph_call(fnobj.graph, fixed, args_hs)
 
-        # propagate fixing of arguments in the function to the caller
-        for inp_arg_hs, arg_hs in zip(input_args_hs, args_hs):
-            if isinstance(arg_hs, SomeLLAbstractConstant):
-                assert len(inp_arg_hs.origins) == 1
-                [o] = inp_arg_hs.origins.keys()
-                if o.read_fixed():
-                    for o in arg_hs.origins:
-                        o.set_fixed()
-        
-        hs_res = bookkeeper.annotator.recursivecall(graph,
-                                                    bookkeeper.position_key,
-                                                    input_args_hs)
-        # look on which input args the hs_res result depends on
         if isinstance(hs_res, SomeLLAbstractConstant):
-            deps_hs = []
-            for hs_inputarg, hs_arg in zip(input_args_hs, args_hs):
-                if isinstance(hs_inputarg, SomeLLAbstractConstant):
-                    assert len(hs_inputarg.origins) == 1
-                    [o] = hs_inputarg.origins.keys()
-                    if o in hs_res.origins:
-                        deps_hs.append(hs_arg)
-            if fixed:
-                deps_hs.append(hs_res)
-            hs_res = reorigin(hs_res, *deps_hs)
             hs_res.myorigin = bookkeeper.myorigin()
 
         # we need to make sure that hs_res does not become temporarily less

Modified: pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/test/test_annotator.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/test/test_annotator.py	Tue Sep 12 17:08:24 2006
@@ -434,18 +434,6 @@
     _, x_v, y_v = gdesc._cache[None].getargs()
     assert ha.binding(x_v).is_fixed()
     assert ha.binding(y_v).is_fixed()
-    
-def test_hannotate_tl():
-    from pypy.jit.tl import tl
-    hannotate(tl.interp, [str, int, int], policy=P_OOPSPEC)
-
-def test_hannotate_tl_novirtual():
-    from pypy.jit.tl import tl
-    hannotate(tl.interp, [str, int, int], policy=P_OOPSPEC_NOVIRTUAL)
-
-def test_hannotate_tlr_novirtual():
-    from pypy.jit.tl import tlr
-    hannotate(tlr.interpret, [str, int], policy=P_OOPSPEC_NOVIRTUAL)
 
 def test_hannotate_plus_minus():
     def ll_plus_minus(s, x, y):

Added: pypy/dist/pypy/jit/hintannotator/test/test_toy.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/hintannotator/test/test_toy.py	Tue Sep 12 17:08:24 2006
@@ -0,0 +1,20 @@
+from pypy.jit.hintannotator.test.test_annotator import hannotate, P_OOPSPEC
+from pypy.jit.hintannotator.test.test_annotator import P_OOPSPEC_NOVIRTUAL
+
+
+def test_hannotate_tl():
+    from pypy.jit.tl import tl
+    hannotate(tl.interp, [str, int, int], policy=P_OOPSPEC)
+
+def test_hannotate_tl_novirtual():
+    from pypy.jit.tl import tl
+    hannotate(tl.interp, [str, int, int], policy=P_OOPSPEC_NOVIRTUAL)
+
+def test_hannotate_tlr_novirtual():
+    from pypy.jit.tl import tlr
+    hannotate(tlr.interpret, [str, int], policy=P_OOPSPEC_NOVIRTUAL)
+
+def test_hannotate_tlc_novirtual():
+    from pypy.jit.tl import tlc
+    hannotate(tlc.interp_without_call, [str, int, int],
+              policy=P_OOPSPEC_NOVIRTUAL)



More information about the Pypy-commit mailing list