comparison python/transform.py @ 177:460db5669efa

Added clean pass for IR
author Windel Bouwman
date Mon, 22 Apr 2013 23:54:54 +0200
parents 5fd02aa38b42
children 1fa3e0050b49
comparison
equal deleted inserted replaced
176:5fd02aa38b42 177:460db5669efa
75 # TODO: check volatile 75 # TODO: check volatile
76 return False 76 return False
77 otherUse = True 77 otherUse = True
78 return True 78 return True
79 79
80 class CleanPass(FunctionPass):
81 def onFunction(self, f):
82 bbs = list(f.BasicBlocks)
83 for bb in bbs:
84 # TODO: determine check for 'empty'
85 if len(bb.Instructions) == 1:
86 # This block is empty.
87 # find predecessors of this block and replace this block reference with the jumped reference.
88 ins = bb.LastInstruction
89 if type(ins) is Branch:
90 print(ins, bb.Predecessors)
91 for pred in bb.Predecessors:
92 pred.LastInstruction.changeTarget(bb, ins.target)
93 f.removeBasicBlock(bb)
94
80 class Mem2RegPromotor(FunctionPass): 95 class Mem2RegPromotor(FunctionPass):
81 def onFunction(self, f): 96 def onFunction(self, f):
82 # TODO 97 # TODO
83 print(f) 98 print(f)
84 99