[pypy-svn] r65594 - pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp

antocuni at codespeak.net antocuni at codespeak.net
Thu Jun 4 23:05:44 CEST 2009


Author: antocuni
Date: Thu Jun  4 23:05:43 2009
New Revision: 65594

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py
Log:
add a hook to allow optimizations to add their own fields to InstanceNodes;
this way, fields definition is kept togheter with the methods that operate on
them



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 23:05:43 2009
@@ -27,20 +27,26 @@
     def __init__(self, optlist):
         self.optlist = optlist
 
+    def newnode(self, *args, **kwds): # XXX RPython
+        node = InstanceNode(*args, **kwds)
+        for opt in self.optlist:
+            opt.init_node(node)
+        return node
+
     def getnode(self, box):
         try:
             return self.nodes[box]
         except KeyError:
             if isinstance(box, Const):
-                node = InstanceNode(box, const=True)
+                node = self.newnode(box, const=True)
             else:
-                node = InstanceNode(box)
+                node = self.newnode(box)
             self.nodes[box] = node
             return node
 
     def find_nodes(self):
         for box in self.loop.inputargs:
-            self.nodes[box] = InstanceNode(box, escaped=False,)
+            self.nodes[box] = self.newnode(box, escaped=False,)
                                            #startbox=True)
 
         for op in self.loop.operations:
@@ -48,14 +54,14 @@
             if self._is_pure_and_constfoldable(op):
                 box = op.result
                 assert box is not None
-                self.nodes[box] = InstanceNode(box.constbox(), const=True)
+                self.nodes[box] = self.newnode(box.constbox(), const=True)
             else:
                 # default case
                 for box in op.args:
                     self.getnode(box)
                 box = op.result
                 if box is not None:
-                    self.nodes[box] = InstanceNode(box)
+                    self.nodes[box] = self.newnode(box)
 
             for optimization in self.optlist:
                 optimization.find_nodes_for_op(self, op)
@@ -120,7 +126,7 @@
                 # all constant arguments: constant-fold away
                 box = op.result
                 assert box is not None
-                instnode = InstanceNode(box.constbox(), const=True)
+                instnode = self.newnode(box.constbox(), const=True)
                 self.nodes[box] = instnode
                 return
         return op
@@ -183,6 +189,9 @@
             return getattr(self, methname).im_func
         return None
 
+    def init_node(self, node):
+        pass
+
     def find_nodes_for_op(self, spec, op):
         func = self.find_nodes_ops[op.opnum]
         if func:
@@ -204,7 +213,7 @@
         if node.cls is not None:
             # assert that they're equal maybe
             return
-        node.cls = InstanceNode(op.args[1], const=True)
+        node.cls = spec.newnode(op.args[1], const=True)
         return op
 
     def guard_value(self, spec, op):
@@ -225,12 +234,12 @@
         # XXX: how does this relate to OptimizeGuards.guard_class?
         instnode = spec.getnode(op.args[0])
         if instnode.cls is None:
-            instnode.cls = InstanceNode(op.args[1], const=True)
+            instnode.cls = spec.newnode(op.args[1], const=True)
 
     def find_nodes_new_with_vtable(self, spec, op):
         box = op.result
-        instnode = InstanceNode(box, escaped=False)
-        instnode.cls = InstanceNode(op.args[0], const=True)
+        instnode = spec.newnode(box, escaped=False)
+        instnode.cls = spec.newnode(op.args[0], const=True)
         spec.nodes[box] = instnode
 
 ##     def find_nodes_setfield_gc(self, spec, op):



More information about the Pypy-commit mailing list