Author: Ronan Lamy <[email protected]>
Branch: expressions-2
Changeset: r74553:0642cf37c18a
Date: 2014-11-09 01:11 +0000
http://bitbucket.org/pypy/pypy/changeset/0642cf37c18a/
Log: Allow expressions to tell which variables they depend on
diff --git a/rpython/annotator/expression.py b/rpython/annotator/expression.py
--- a/rpython/annotator/expression.py
+++ b/rpython/annotator/expression.py
@@ -21,3 +21,7 @@
return V_Type(mapping[self.arg])
else:
return self
+
+ @property
+ def dependencies(self):
+ return self.arg.dependencies
diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -323,6 +323,10 @@
def replace(self, mapping):
return mapping.get(self, self)
+ @property
+ def dependencies(self):
+ return set([self])
+
class Constant(Hashable):
__slots__ = ["concretetype"]
@@ -354,6 +358,10 @@
def replace(self, mapping):
return self
+ @property
+ def dependencies(self):
+ return set()
+
class FSException(object):
def __init__(self, w_type, w_value):
diff --git a/rpython/translator/backendopt/ssa.py
b/rpython/translator/backendopt/ssa.py
--- a/rpython/translator/backendopt/ssa.py
+++ b/rpython/translator/backendopt/ssa.py
@@ -151,21 +151,23 @@
variables_created = variables_created_in(block)
seen = set(variables_created)
variables_used = []
- def record_used_var(v):
- if v not in seen:
- variables_used.append(v)
- seen.add(v)
+ def record_dependencies(arg):
+ if arg is None:
+ return
+ for v in arg.dependencies:
+ if v not in seen:
+ variables_used.append(v)
+ seen.add(v)
for op in block.operations:
for arg in op.args:
- record_used_var(arg)
- record_used_var(block.exitswitch)
+ record_dependencies(arg)
+ record_dependencies(block.exitswitch)
for link in block.exits:
for arg in link.args:
- record_used_var(arg)
+ record_dependencies(arg)
for v in variables_used:
- if (isinstance(v, Variable) and
- v._name not in ('last_exception_', 'last_exc_value_')):
+ if (v._name not in ('last_exception_', 'last_exc_value_')):
pending.append((block, v))
while pending:
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -477,9 +477,11 @@
# figure out which variables are ever read
for op in block.operations:
if not canremove(op, block): # the inputs are always needed
- read_vars.update(op.args)
+ for arg in op.args:
+ read_vars.update(arg.dependencies)
else:
- dependencies[op.result].update(op.args)
+ for arg in op.args:
+ dependencies[op.result].update(arg.dependencies)
if isinstance(block.exitswitch, Variable):
read_vars.add(block.exitswitch)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit