comparison 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
comparison
equal deleted inserted replaced
218:494828a7adf1 219:1fa3e0050b49
76 return False 76 return False
77 otherUse = True 77 otherUse = True
78 return True 78 return True
79 79
80 class CleanPass(FunctionPass): 80 class CleanPass(FunctionPass):
81 def onFunction(self, f): 81 def onFunction(self, f):
82 bbs = list(f.BasicBlocks) 82 bbs = list(f.BasicBlocks)
83 for bb in bbs: 83 for bb in bbs:
84 # TODO: determine check for 'empty' 84 # TODO: determine check for 'empty'
85
86 # If a block only contains a branch, it can be removed:
85 if len(bb.Instructions) == 1: 87 if len(bb.Instructions) == 1:
86 # This block is empty. 88 # This block is empty.
87 # find predecessors of this block and replace this block reference with the jumped reference. 89 # find predecessors of this block and replace this block reference with the jumped reference.
88 ins = bb.LastInstruction 90 ins = bb.LastInstruction
89 if type(ins) is Branch: 91 if type(ins) is Branch:
90 print(ins, bb.Predecessors) 92 print('Removing block {}'.format(bb))
91 for pred in bb.Predecessors: 93 #print(ins, bb.Predecessors)
92 pred.LastInstruction.changeTarget(bb, ins.target) 94 preds = bb.Predecessors
93 f.removeBasicBlock(bb) 95 if bb in preds:
96 # Do not remove if preceeded by itself
97 pass
98 else:
99 for pred in bb.Predecessors:
100 print('predecessor: {}'.format(pred))
101 pred.LastInstruction.changeTarget(bb, ins.target)
102 f.removeBasicBlock(bb)
94 103
95 class Mem2RegPromotor(FunctionPass): 104 class Mem2RegPromotor(FunctionPass):
96 def onFunction(self, f): 105 def onFunction(self, f):
97 # TODO 106 # TODO
98 print(f) 107 print(f)