diff 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
line wrap: on
line diff
--- a/python/transform.py	Sat Apr 20 12:00:51 2013 +0200
+++ b/python/transform.py	Mon Apr 22 23:54:54 2013 +0200
@@ -77,6 +77,21 @@
          otherUse = True
    return True
 
+class CleanPass(FunctionPass):
+   def onFunction(self, f):
+      bbs = list(f.BasicBlocks)
+      for bb in bbs:
+         # TODO: determine check for 'empty'
+         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)
+
 class Mem2RegPromotor(FunctionPass):
    def onFunction(self, f):
       # TODO