[pypy-commit] pypy less-stringly-ops: move consider() from SpaceOperation to HLOperaation; add op.hint

rlamy noreply at buildbot.pypy.org
Sat Nov 23 13:44:05 CET 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r68288:b1788bf86873
Date: 2013-11-23 13:43 +0100
http://bitbucket.org/pypy/pypy/changeset/b1788bf86873/

Log:	move consider() from SpaceOperation to HLOperaation; add op.hint

	NB: The HLOperation are now precisely those that are handled by the
	annotator.

diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -439,12 +439,6 @@
         newresult = mapping.get(self.result, self.result)
         return type(self)(self.opname, newargs, newresult, self.offset)
 
-    def consider(self, annotator, *argcells):
-        consider_meth = getattr(annotator, 'consider_op_' + self.opname, None)
-        if not consider_meth:
-            raise Exception("unknown op: %r" % op)
-        return consider_meth(*argcells)
-
 class Atom(object):
     def __init__(self, name):
         self.__name__ = name # make save_global happy
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -83,6 +83,12 @@
     def constfold(self):
         return None
 
+    def consider(self, annotator, *argcells):
+        consider_meth = getattr(annotator, 'consider_op_' + self.opname, None)
+        if not consider_meth:
+            raise Exception("unknown op: %r" % op)
+        return consider_meth(*argcells)
+
 class PureOperation(HLOperation):
     pure = True
 
@@ -333,6 +339,7 @@
 add_operator('newtuple', None, pure=True, pyfunc=lambda *args:args)
 add_operator('newlist', None)
 add_operator('newslice', 3)
+add_operator('hint', None)
 
 
 class Pow(PureOperation):
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -6,7 +6,7 @@
 """
 import py
 
-from rpython.flowspace.model import (SpaceOperation, Variable, Constant,
+from rpython.flowspace.model import (Variable, Constant,
                                      c_last_exception, checkgraph, mkentrymap)
 from rpython.flowspace.operation import OverflowingOperation, op
 from rpython.rlib import rarithmetic
@@ -814,10 +814,10 @@
 
     def run(self, vlist, vmeth, appendblock):
         # first check that the 'append' method object doesn't escape
-        for op in appendblock.operations:
-            if op.opname == 'simple_call' and op.args[0] is vmeth:
+        for hlop in appendblock.operations:
+            if hlop.opname == 'simple_call' and hlop.args[0] is vmeth:
                 pass
-            elif vmeth in op.args:
+            elif vmeth in hlop.args:
                 raise DetectorFailed      # used in another operation
         for link in appendblock.exits:
             if vmeth in link.args:
@@ -922,20 +922,19 @@
         link = iterblock.exits[0]
         vlist = self.contains_vlist(link.args)
         assert vlist
-        for op in iterblock.operations:
-            res = self.variable_families.find_rep(op.result)
+        for hlop in iterblock.operations:
+            res = self.variable_families.find_rep(hlop.result)
             if res is viterfamily:
                 break
         else:
             raise AssertionError("lost 'iter' operation")
-        vlist2 = Variable(vlist)
         chint = Constant({'maxlength': True})
-        iterblock.operations += [
-            SpaceOperation('hint', [vlist, op.args[0], chint], vlist2)]
+        hint = op.hint(vlist, hlop.args[0], chint)
+        iterblock.operations.append(hint)
         link.args = list(link.args)
         for i in range(len(link.args)):
             if link.args[i] is vlist:
-                link.args[i] = vlist2
+                link.args[i] = hint.result
 
         # - wherever the list exits the loop body, add a 'hint({fence})'
         for block in loopbody:
@@ -954,8 +953,9 @@
                     vlist2 = newblock.inputargs[index]
                     vlist3 = Variable(vlist2)
                     newblock.inputargs[index] = vlist3
-                    newblock.operations.append(
-                        SpaceOperation('hint', [vlist3, chints], vlist2))
+                    hint = op.hint(vlist3, chints)
+                    hint.result = vlist2
+                    newblock.operations.append(hint)
         # done!
 
 


More information about the pypy-commit mailing list