[pypy-svn] r55637 - pypy/branch/c-backend-fun/pypy/translator/oosupport

fijal at codespeak.net fijal at codespeak.net
Fri Jun 6 21:18:23 CEST 2008


Author: fijal
Date: Fri Jun  6 21:18:20 2008
New Revision: 55637

Modified:
   pypy/branch/c-backend-fun/pypy/translator/oosupport/treebuilder.py
Log:
Complicate treebuilder some more. Inline operations which are immediately
before. This assumes left-to-right parameter computation!


Modified: pypy/branch/c-backend-fun/pypy/translator/oosupport/treebuilder.py
==============================================================================
--- pypy/branch/c-backend-fun/pypy/translator/oosupport/treebuilder.py	(original)
+++ pypy/branch/c-backend-fun/pypy/translator/oosupport/treebuilder.py	Fri Jun  6 21:18:20 2008
@@ -33,18 +33,21 @@
 
 # TODO: analyze graphs to determine which functions calls could have
 # side effects and which can be inlined safely.
-def can_be_inlined(op, block):
-    for exit in block.exits:
-        if op.result in exit.args:
-            break
-    else:
-        return True
+def can_be_inlined(op):
     try:
         llop = LL_OPERATIONS[op.opname]
         return llop.canfold
     except KeyError:
         return False
 
+def check_not_in_exit(v, block):
+    for exit in block.exits:
+        if v in exit.args:
+            break
+    else:
+        return True
+    return False
+
 def build_op_map(block):
     var_count = {}
     var_to_op = {}
@@ -69,12 +72,29 @@
         for i, v in enumerate(op.args):
             if var_count.get(v, None) == 1 and v not in block.inputargs: # "inline" the operation
                 sub_i, sub_op = var_to_op[v]
-                if can_be_inlined(sub_op, block):
+                if can_be_inlined(sub_op):
                     op.args[i] = SubOperation(sub_op)
                     block.operations[sub_i] = None
+    # another pass
+    for num_op, op in enumerate(block.operations):
+        if op is not None:
+            for i, v in enumerate(op.args):
+                if (var_count.get(v, None) == 1 and v not in block.inputargs
+                    and check_not_in_exit(v, block)):
+                    sub_i, sub_op = var_to_op[v]
+                    safe = True
+                    for k in range(sub_i + 1, num_op):
+                        if block.operations[sub_i] is not None:
+                            safe = False
+                            break
+                    if safe:
+                        op.args[i] = SubOperation(sub_op)
+                        block.operations[sub_i] = None
+                    
     if block.operations != ():
         block.operations = [op for op in block.operations if op is not None]
 
+
 def build_trees(graph):
     if not getattr(graph, 'tree_built', False):
         for block in graph.iterblocks():



More information about the Pypy-commit mailing list