[pypy-svn] r65582 - in pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Jun 4 18:52:43 CEST 2009


Author: antocuni
Date: Thu Jun  4 18:52:41 2009
New Revision: 65582

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py
Log:
add a hook for optimizations to get called during the find_nodes phase


Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py	Thu Jun  4 18:52:41 2009
@@ -52,6 +52,9 @@
                 if box is not None:
                     self.nodes[box] = InstanceNode(box)
 
+            for optimization in self.optlist:
+                optimization.find_nodes_for_op(self, op)
+
     def _find_nodes_in_guard_maybe(self, op):
         if op.is_guard():
             assert len(op.suboperations) == 1
@@ -148,16 +151,34 @@
     def __init__(self):
         'NOT_RPYTHON'
         operations = [None] * (rop._LAST+1)
+        find_nodes = [None] * (rop._LAST+1)
         for key, value in rop.__dict__.items():
             if key.startswith('_'):
                 continue
             methname = key.lower()
-            if hasattr(self, methname):
-                func = getattr(self, methname).im_func
-            else:
-                func = getattr(self, 'handle_default_op').im_func
-            operations[value] = func
+            operations[value] = self._get_handle_method(methname)
+            find_nodes[value] = self._get_find_nodes_method(methname)
         self.operations = operations
+        self.find_nodes_ops = find_nodes
+
+    def _get_handle_method(self, methname):
+        'NOT_RPYTHON'
+        if hasattr(self, methname):
+            return getattr(self, methname).im_func
+        else:
+            return getattr(self, 'handle_default_op').im_func
+
+    def _get_find_nodes_method(self, methname):
+        'NOT_RPYTHON'
+        methname = 'find_nodes_' + methname
+        if hasattr(self, methname):
+            return getattr(self, methname).im_func
+        return None
+
+    def find_nodes_for_op(self, spec, op):
+        func = self.find_nodes_ops[op.opnum]
+        if func:
+            func(self, spec, op)
 
     def handle_op(self, spec, op):
         func = self.operations[op.opnum]
@@ -188,14 +209,6 @@
         instnode.source = op.args[0].constbox()
         return op
 
-##     def guard_nonvirtualized(self, spec, op):
-##         return
-
-##     def handle_default_op(self, spec, op):
-##         if op.is_guard():
-##             return self.optimize_guard(op)
-##         return op
-
 
 
 # -------------------------------------------------------------------

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py	Thu Jun  4 18:52:41 2009
@@ -25,15 +25,24 @@
         def handle_default_op(self, spec, op):
             return 'default op', op
 
+        def find_nodes_int_add(self, spec, op):
+            op.found = 42
+
     myopt = MyOpt()
     myopt2 = MyOpt2()
     op = ResOperation(rop.INT_ADD, [], None)
     assert myopt.handle_op(None, op) == ('hello world', op)
     assert myopt2.handle_op(None, op) == ('hello world', op)
+    myopt.find_nodes_for_op(None, op)
+    assert not hasattr(op, 'found')
+    myopt2.find_nodes_for_op(None, op)
+    assert op.found == 42
 
     op = ResOperation(rop.INT_SUB, [], None)
     assert myopt.handle_op(None, op) == op
     assert myopt2.handle_op(None, op) == ('default op', op)
+    myopt2.find_nodes_for_op(None, op)
+    assert not hasattr(op, 'found')
 
 
 class LLtypeMixin(object):



More information about the Pypy-commit mailing list