Mercurial > lcfOS
diff python/transform.py @ 219:1fa3e0050b49
Expanded ad hoc code generator
author | Windel Bouwman |
---|---|
date | Sat, 06 Jul 2013 12:38:09 +0200 |
parents | 460db5669efa |
children | 1c7364bd74c7 |
line wrap: on
line diff
--- a/python/transform.py Fri Jul 05 15:30:22 2013 +0200 +++ b/python/transform.py Sat Jul 06 12:38:09 2013 +0200 @@ -78,19 +78,28 @@ return True class CleanPass(FunctionPass): - def onFunction(self, f): + def onFunction(self, f): bbs = list(f.BasicBlocks) for bb in bbs: # TODO: determine check for 'empty' + + # If a block only contains a branch, it can be removed: if len(bb.Instructions) == 1: # This block is empty. # find predecessors of this block and replace this block reference with the jumped reference. ins = bb.LastInstruction if type(ins) is Branch: - print(ins, bb.Predecessors) - for pred in bb.Predecessors: - pred.LastInstruction.changeTarget(bb, ins.target) - f.removeBasicBlock(bb) + print('Removing block {}'.format(bb)) + #print(ins, bb.Predecessors) + preds = bb.Predecessors + if bb in preds: + # Do not remove if preceeded by itself + pass + else: + for pred in bb.Predecessors: + print('predecessor: {}'.format(pred)) + pred.LastInstruction.changeTarget(bb, ins.target) + f.removeBasicBlock(bb) class Mem2RegPromotor(FunctionPass): def onFunction(self, f):