[pypy-svn] r25838 - pypy/dist/pypy/rpython/memory

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Apr 15 02:06:57 CEST 2006


Author: cfbolz
Date: Sat Apr 15 02:06:54 2006
New Revision: 25838

Modified:
   pypy/dist/pypy/rpython/memory/gctransform.py
Log:
try to safe some push/popping of stack roots: after a cast_pointer or same_as,
don't push/pop both variables. After a getfield or getarrayitem don't push/pop
the resulting variable if the parent is already known to be part of the root
set.


Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py	Sat Apr 15 02:06:54 2006
@@ -956,15 +956,25 @@
         return newgcdependencies
 
     def protect_roots(self, op, livevars, block, index=-1):
-        livevars = [var for var in livevars if not var_ispyobj(var)]
+        livevars = dict.fromkeys(
+            [var for var in livevars if not var_ispyobj(var)], True)
         if not needs_conservative_livevar_calculation(block):
             if index == -1:
                 index = block.operations.index(op) # XXX hum
             needed = {}
-            for other_op in block.operations[index:]:
-                for arg in other_op.args:
+            for before_op in block.operations[:index]:
+                if before_op.result not in livevars:
+                    continue
+                if before_op.opname in ("cast_pointer", "same_as"):
+                    del livevars[before_op.result]
+                elif before_op.opname in ("getfield", "getarrayitem"):
+                    if (before_op.args[0] in livevars or
+                        isinstance(before_op.args[0], Constant)):
+                        del livevars[before_op.result]
+            for after_op in block.operations[index:]:
+                for arg in after_op.args:
                     needed[arg] = True
-                needed[other_op.result] = True
+                needed[after_op.result] = True
             for exit in block.exits:
                 for arg in exit.args:
                     needed[arg] = True
@@ -973,6 +983,8 @@
                 if var in needed:
                     newlivevars.append(var)
             livevars = newlivevars
+        else:
+            livevars = livevars.keys()
         newops = list(self.push_roots(livevars))
         index = len(newops)
         newops.append(op)



More information about the Pypy-commit mailing list