diff python/transform.py @ 240:6259856841a0

Remove project
author Windel Bouwman
date Mon, 22 Jul 2013 22:37:33 +0200
parents 63bb40758066
children c4370696ccc7
line wrap: on
line diff
--- a/python/transform.py	Mon Jul 22 17:57:25 2013 +0200
+++ b/python/transform.py	Mon Jul 22 22:37:33 2013 +0200
@@ -1,4 +1,8 @@
-from ir import * 
+"""
+ Transformation to optimize IR-code
+"""
+
+from ir import *
 # Standard passes:
 
 class FunctionPass:
@@ -13,21 +17,25 @@
    def prepare(self):
       pass
 
+
 class BasicBlockPass(FunctionPass):
-   def onFunction(self, f):
-      for bb in f.BasicBlocks:
-         self.onBasicBlock(bb)
-   def onBasicBlock(self, bb):
-      """ Override this virtual method """
-      raise NotImplementedError()
-      
+    def onFunction(self, f):
+        for bb in f.BasicBlocks:
+            self.onBasicBlock(bb)
+
+    def onBasicBlock(self, bb):
+        """ Override this virtual method """
+        raise NotImplementedError()
+
+
 class InstructionPass(BasicBlockPass):
-   def onBasicBlock(self, bb):
-      for ins in iter(bb.Instructions):
-         self.onInstruction(ins)
-   def onInstruction(self, ins):
-      """ Override this virtual method """
-      raise NotImplementedError()
+    def onBasicBlock(self, bb):
+        for ins in iter(bb.Instructions):
+            self.onInstruction(ins)
+
+    def onInstruction(self, ins):
+        """ Override this virtual method """
+        raise NotImplementedError()
 
 # Usefull transforms:
 class ConstantFolder(InstructionPass):
@@ -90,7 +98,8 @@
    def onBasicBlock(self, bb):
       def instructionUsed(ins):
          if len(ins.defs) == 0:
-            # In case this instruction does not define any variables, assume it is usefull.
+            # In case this instruction does not define any 
+            # variables, assume it is usefull.
             return True
          for d in ins.defs:
             if d.IsUsed:
@@ -111,13 +120,12 @@
                     continue
                 # update all references:
                 t_new = constMap[ins.value]
-                print('Replace {} with {}'.format(t_old, t_new))
                 for use in t_old.used_by:
                     use.replaceValue(t_old, t_new)
                 bb.removeInstruction(ins)
             else:
                 constMap[ins.value] = ins.target
-            
+
 
 def isAllocPromotable(allocinst):
    # Check if alloc value is only used by load and store operations.
@@ -129,6 +137,7 @@
          otherUse = True
    return True
 
+
 class CleanPass(FunctionPass):
     def onFunction(self, f):
         bbs = list(f.BasicBlocks)
@@ -149,6 +158,7 @@
                           pred.LastInstruction.changeTarget(bb, ins.target)
                     f.removeBasicBlock(bb)
 
+
 class Mem2RegPromotor(FunctionPass):
    def onFunction(self, f):
       # TODO