Author: Ronan Lamy <ronan.l...@gmail.com> Branch: Changeset: r76378:3400c234a4a2 Date: 2015-03-09 17:20 +0000 http://bitbucket.org/pypy/pypy/changeset/3400c234a4a2/
Log: create Link.replace() and use it diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py --- a/rpython/flowspace/model.py +++ b/rpython/flowspace/model.py @@ -140,6 +140,12 @@ newlink.llexitcase = self.llexitcase return newlink + def replace(self, mapping): + def rename(v): + if v is not None: + return v.replace(mapping) + return self.copy(rename) + def settarget(self, targetblock): assert len(self.args) == len(targetblock.inputargs), ( "output args mismatch") diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py --- a/rpython/translator/simplify.py +++ b/rpython/translator/simplify.py @@ -132,9 +132,6 @@ the block's single list of exits. """ renaming = {} - def rename(v): - return renaming.get(v, v) - for block in graph.iterblocks(): if not (block.canraise and block.exits[-1].exitcase is Exception): @@ -151,10 +148,10 @@ while len(query.exits) == 2: newrenaming = {} for lprev, ltarg in zip(exc.args, query.inputargs): - newrenaming[ltarg] = rename(lprev) + newrenaming[ltarg] = lprev.replace(renaming) op = query.operations[0] if not (op.opname in ("is_", "issubtype") and - newrenaming.get(op.args[0]) == last_exception): + op.args[0].replace(newrenaming) == last_exception): break renaming.update(newrenaming) case = query.operations[0].args[-1].value @@ -177,19 +174,16 @@ # construct the block's new exits exits = [] for case, oldlink in switches: - link = oldlink.copy(rename) + link = oldlink.replace(renaming) assert case is not None link.last_exception = last_exception link.last_exc_value = last_exc_value # make the above two variables unique renaming2 = {} - def rename2(v): - return renaming2.get(v, v) for v in link.getextravars(): renaming2[v] = Variable(v) - link = link.copy(rename2) + link = link.replace(renaming2) link.exitcase = case - link.prevblock = block exits.append(link) block.recloseblock(*(preserve + exits)) @@ -311,8 +305,6 @@ renaming = {} for vprev, vtarg in zip(link.args, link.target.inputargs): renaming[vtarg] = vprev - def rename(v): - return renaming.get(v, v) def rename_op(op): op = op.replace(renaming) # special case... @@ -326,9 +318,12 @@ link.prevblock.operations.append(rename_op(op)) exits = [] for exit in link.target.exits: - newexit = exit.copy(rename) + newexit = exit.replace(renaming) exits.append(newexit) - newexitswitch = rename(link.target.exitswitch) + if link.target.exitswitch: + newexitswitch = link.target.exitswitch.replace(renaming) + else: + newexitswitch = None link.prevblock.exitswitch = newexitswitch link.prevblock.recloseblock(*exits) if (isinstance(newexitswitch, Constant) and _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit