Author: Carl Friedrich Bolz <[email protected]>
Branch: spaceops-are-variables
Changeset: r74247:bb92eb8f9823
Date: 2014-10-26 13:53 +0100
http://bitbucket.org/pypy/pypy/changeset/bb92eb8f9823/
Log: fix some of the transformations
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -120,7 +120,7 @@
op1_ovf = op1.ovfchecked()
block.operations[i - 1] = op1_ovf
del block.operations[i]
- block.renamevariables({op.result: op1_ovf.result})
+ block.renamevariables({op: op1_ovf})
def simplify_exceptions(graph):
"""The exception handling caused by non-implicit exceptions
@@ -206,9 +206,7 @@
if postfx:
Op = getattr(op, '_'.join(['getitem'] + postfx))
newop = Op(*last_op.args)
- newop.result = last_op.result
- block.operations[-1] = newop
-
+ block.renamevariables({last_op: newop})
def remove_dead_exceptions(graph):
"""Exceptions can be removed if they are unreachable"""
@@ -264,14 +262,15 @@
def rename(v):
return renaming.get(v, v)
def rename_op(op):
- op = op.replace(renaming)
+ new_op = op.replace(renaming)
+ renaming[op] = new_op
# special case...
- if op.opname == 'indirect_call':
- if isinstance(op.args[0], Constant):
- assert isinstance(op.args[-1], Constant)
- del op.args[-1]
- op.opname = 'direct_call'
- return op
+ if new_op.opname == 'indirect_call':
+ if isinstance(new_op.args[0], Constant):
+ assert isinstance(new_op.args[-1], Constant)
+ del new_op.args[-1]
+ new_op.opname = 'direct_call'
+ return new_op
for op in link.target.operations:
link.prevblock.operations.append(rename_op(op))
exits = []
@@ -424,7 +423,7 @@
else:
# if CanRemove, only mark dependencies of the result
# on the input variables
- deps = variable_flow.setdefault(op.result, [])
+ deps = variable_flow.setdefault(op, [])
deps.extend(op.args)
if isinstance(block.exitswitch, Variable):
@@ -467,7 +466,7 @@
# look for removable operations whose result is never used
for i in range(len(block.operations)-1, -1, -1):
op = block.operations[i]
- if op.result not in read_vars:
+ if op not in read_vars:
if canremove(op, block):
del block.operations[i]
elif op.opname == 'simple_call':
@@ -578,7 +577,7 @@
tgts = []
start_op = block.operations[-1]
cond_v = start_op.args[0]
- if block.exitswitch == start_op.result:
+ if block.exitswitch == start_op:
for exit in block.exits:
tgt = exit.target
if tgt == block:
@@ -586,7 +585,7 @@
rrenaming = dict(zip(tgt.inputargs,exit.args))
if len(tgt.operations) == 1 and tgt.operations[0].opname ==
'bool':
tgt_op = tgt.operations[0]
- if tgt.exitswitch == tgt_op.result and
rrenaming.get(tgt_op.args[0]) == cond_v:
+ if tgt.exitswitch == tgt_op and
rrenaming.get(tgt_op.args[0]) == cond_v:
tgts.append((exit.exitcase, tgt))
return tgts
@@ -602,7 +601,7 @@
for case, tgt in tgts:
exit = cand.exits[case]
rrenaming = dict(zip(tgt.inputargs,exit.args))
- rrenaming[tgt.operations[0].result] = cand.operations[-1].result
+ rrenaming[tgt.operations[0]] = cand.operations[-1]
def rename(v):
return rrenaming.get(v,v)
newlink = tgt.exits[case].copy(rename)
@@ -650,10 +649,10 @@
continue
for op in block.operations:
if op.opname == 'newlist' and not op.args:
- vlist = variable_families.find_rep(op.result)
+ vlist = variable_families.find_rep(op)
newlist_v[vlist] = block
if op.opname == 'iter':
- viter = variable_families.find_rep(op.result)
+ viter = variable_families.find_rep(op)
iter_v[viter] = block
loops = []
for block, viter in loopnextblocks:
@@ -681,8 +680,8 @@
for j in range(i + 1, len(block.operations)):
op2 = block.operations[j]
if (op2.opname == 'simple_call' and len(op2.args) == 2
- and op2.args[0] is op.result):
- append_v.append((op.args[0], op.result, block))
+ and op2.args[0] is op):
+ append_v.append((op.args[0], op, block))
break
if not append_v:
return
@@ -784,7 +783,7 @@
return self.escapes[block]
except KeyError:
for op in block.operations:
- if op.result is self.vmeth:
+ if op is self.vmeth:
continue # the single getattr(vlist, 'append') is ok
if op.opname == 'getitem':
continue # why not allow getitem(vlist, index) too
@@ -923,7 +922,7 @@
vlist = self.contains_vlist(link.args)
assert vlist
for hlop in iterblock.operations:
- res = self.variable_families.find_rep(hlop.result)
+ res = self.variable_families.find_rep(hlop)
if res is viterfamily:
break
else:
@@ -934,7 +933,7 @@
link.args = list(link.args)
for i in range(len(link.args)):
if link.args[i] is vlist:
- link.args[i] = hint.result
+ link.args[i] = hint
# - wherever the list exits the loop body, add a 'hint({fence})'
for block in loopbody:
@@ -953,6 +952,8 @@
vlist2 = newblock.inputargs[index]
vlist3 = Variable(vlist2)
newblock.inputargs[index] = vlist3
+ # XXX
+ import pdb; pdb.set_trace()
hint = op.hint(vlist3, chints)
hint.result = vlist2
newblock.operations.append(hint)
diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py
--- a/rpython/translator/transform.py
+++ b/rpython/translator/transform.py
@@ -42,13 +42,13 @@
op = block.operations[i]
if (op.opname == 'newlist' and
len(op.args) == 1):
- length1_lists[op.result] = op.args[0]
+ length1_lists[op] = op.args[0]
elif (op.opname == 'mul' and
op.args[0] in length1_lists):
- new_op = SpaceOperation('alloc_and_set',
- (op.args[1],
length1_lists[op.args[0]]),
- op.result)
- block.operations[i] = new_op
+ # XXX hackish
+ op.__class__ = SpaceOperation
+ op.opname = 'alloc_and_set'
+ op.args = [op.args[1], length1_lists[op.args[0]]]
# lst += string[x:y]
# -->
@@ -65,15 +65,15 @@
op = block.operations[i]
if (op.opname == 'getslice' and
self.gettype(op.args[0]) is str):
- slice_sources[op.result] = op.args
+ slice_sources[op] = op.args
elif (op.opname == 'inplace_add' and
op.args[1] in slice_sources and
self.gettype(op.args[0]) is list):
v_string, v_x, v_y = slice_sources[op.args[1]]
- new_op = SpaceOperation('extend_with_str_slice',
- [op.args[0], v_x, v_y, v_string],
- op.result)
- block.operations[i] = new_op
+ # XXX hackish
+ op.__class__ = SpaceOperation
+ op.opname = 'extend_with_str_slice'
+ op.args = [op.args[0], v_x, v_y, v_string]
# lst += char*count [or count*char]
# -->
@@ -93,18 +93,18 @@
s1 = self.annotation(op.args[1])
if (isinstance(s0, annmodel.SomeChar) and
isinstance(s1, annmodel.SomeInteger)):
- mul_sources[op.result] = op.args[0], op.args[1]
+ mul_sources[op] = op.args[0], op.args[1]
elif (isinstance(s1, annmodel.SomeChar) and
isinstance(s0, annmodel.SomeInteger)):
- mul_sources[op.result] = op.args[1], op.args[0]
+ mul_sources[op] = op.args[1], op.args[0]
elif (op.opname == 'inplace_add' and
op.args[1] in mul_sources and
self.gettype(op.args[0]) is list):
v_char, v_count = mul_sources[op.args[1]]
- new_op = SpaceOperation('extend_with_char_count',
- [op.args[0], v_char, v_count],
- op.result)
- block.operations[i] = new_op
+ # XXX hackish
+ op.__class__ = SpaceOperation
+ op.opname = 'extend_with_char_count'
+ op.args = [op.args[0], v_char, v_count]
# x in [2, 3]
# -->
@@ -120,7 +120,7 @@
for i in range(len(block.operations)):
op = block.operations[i]
if op.opname == 'newlist':
- newlist_sources[op.result] = op.args
+ newlist_sources[op] = op.args
elif op.opname == 'contains' and op.args[0] in newlist_sources:
items = {}
for v in newlist_sources[op.args[0]]:
@@ -168,9 +168,9 @@
"Fix a block whose end can never be reached at run-time."
# search the operation that cannot succeed
can_succeed = [op for op in block.operations
- if op.result.annotation is not None]
+ if op.annotation is not None]
cannot_succeed = [op for op in block.operations
- if op.result.annotation is None]
+ if op.annotation is None]
n = len(can_succeed)
# check consistency
assert can_succeed == block.operations[:n]
@@ -178,7 +178,7 @@
assert 0 <= n < len(block.operations)
# chop off the unreachable end of the block
del block.operations[n+1:]
- self.setbinding(block.operations[n].result, annmodel.s_ImpossibleValue)
+ self.setbinding(block.operations[n], annmodel.s_ImpossibleValue)
# insert the equivalent of 'raise AssertionError'
graph = self.annotated[block]
msg = "Call to %r should have raised an exception" % (getattr(graph,
'func', None),)
diff --git a/rpython/translator/unsimplify.py b/rpython/translator/unsimplify.py
--- a/rpython/translator/unsimplify.py
+++ b/rpython/translator/unsimplify.py
@@ -17,11 +17,11 @@
for v in op.args:
if isinstance(v, Variable):
vars.setdefault(v, True)
- vars[op.result] = False
+ vars[op] = False
vars = [v for v, keep in vars.items() if keep]
mapping = {}
for v in vars:
- mapping[v] = v.copy()
+ mapping[v] = v.copy_as_var()
newblock = Block(vars)
newblock.operations.extend(newops)
newblock.closeblock(Link(link.args, link.target))
@@ -31,7 +31,7 @@
return newblock
def insert_empty_startblock(annotator, graph):
- vars = [v.copy() for v in graph.startblock.inputargs]
+ vars = [v.copy_as_var() for v in graph.startblock.inputargs]
newblock = Block(vars)
newblock.closeblock(Link(vars, graph.startblock))
graph.startblock = newblock
@@ -53,24 +53,23 @@
#but only for variables that are produced in the old block and needed in
#the new one
varmap = {}
- vars_produced_in_new_block = set()
def get_new_name(var):
if var is None:
return None
if isinstance(var, Constant):
return var
- if var in vars_produced_in_new_block:
- return var
if var not in varmap:
- varmap[var] = var.copy()
+ varmap[var] = var.copy_as_var()
return varmap[var]
moved_operations = block.operations[index:]
new_moved_ops = []
+ vars_produced_in_new_block = set()
for op in moved_operations:
repl = dict((arg, get_new_name(arg)) for arg in op.args)
newop = op.replace(repl)
new_moved_ops.append(newop)
- vars_produced_in_new_block.add(op.result)
+ varmap[op] = newop
+ vars_produced_in_new_block.add(op)
moved_operations = new_moved_ops
links = block.exits
block.exits = None
@@ -87,7 +86,7 @@
assert index == 0
linkargs = list(_forcelink)
for v in varmap:
- if v not in linkargs:
+ if v not in linkargs and v not in vars_produced_in_new_block:
# 'v' was not specified by _forcelink, but we found out that
# we need it! Hack: if it is 'concretetype is lltype.Void'
# then it's ok to recreate its value in the target block.
@@ -111,7 +110,7 @@
i += 1
moved_operations.insert(i, newop)
else:
- linkargs = varmap.keys()
+ linkargs = [var for var in varmap.keys() if var not in
vars_produced_in_new_block]
newblock = Block([get_new_name(v) for v in linkargs])
newblock.operations = moved_operations
newblock.recloseblock(*links)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit