Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r76377:f0188254b0f3
Date: 2015-03-15 05:02 +0000
http://bitbucket.org/pypy/pypy/changeset/f0188254b0f3/
Log: Create .replace() method on Constant and Variable: make variable
substitution API a bit nicer.
diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -215,13 +215,12 @@
return uniqueitems([w for w in result if isinstance(w, Constant)])
def renamevariables(self, mapping):
- self.inputargs = [mapping.get(a, a) for a in self.inputargs]
- for op in self.operations:
- op.args = [mapping.get(a, a) for a in op.args]
- op.result = mapping.get(op.result, op.result)
- self.exitswitch = mapping.get(self.exitswitch, self.exitswitch)
+ self.inputargs = [a.replace(mapping) for a in self.inputargs]
+ self.operations = [op.replace(mapping) for op in self.operations]
+ if self.exitswitch is not None:
+ self.exitswitch = self.exitswitch.replace(mapping)
for link in self.exits:
- link.args = [mapping.get(a, a) for a in link.args]
+ link.args = [a.replace(mapping) for a in link.args]
def closeblock(self, *exits):
assert self.exits == [], "block already closed"
@@ -327,6 +326,8 @@
newvar.concretetype = self.concretetype
return newvar
+ def replace(self, mapping):
+ return mapping.get(self, self)
class Constant(Hashable):
@@ -356,6 +357,9 @@
# cannot count on it not mutating at runtime!
return False
+ def replace(self, mapping):
+ return self
+
class FSException(object):
def __init__(self, w_type, w_value):
@@ -431,8 +435,8 @@
", ".join(map(repr, self.args)))
def replace(self, mapping):
- newargs = [mapping.get(arg, arg) for arg in self.args]
- newresult = mapping.get(self.result, self.result)
+ newargs = [arg.replace(mapping) for arg in self.args]
+ newresult = self.result.replace(mapping)
return type(self)(self.opname, newargs, newresult, self.offset)
class Atom(object):
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -76,8 +76,8 @@
self.offset = -1
def replace(self, mapping):
- newargs = [mapping.get(arg, arg) for arg in self.args]
- newresult = mapping.get(self.result, self.result)
+ newargs = [arg.replace(mapping) for arg in self.args]
+ newresult = self.result.replace(mapping)
newop = type(self)(*newargs)
newop.result = newresult
newop.offset = self.offset
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -616,7 +616,7 @@
assert len(links) == len(new_args)
for link, args in zip(links, new_args):
link.args = args
- for block in graph.iterblocks():
+ for block in entrymap:
block.renamevariables(renaming)
def remove_identical_vars(graph):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit