diff python/transform.py @ 175:a51b3c956386

Added function call in expressions
author Windel Bouwman
date Fri, 19 Apr 2013 22:15:54 +0200
parents 3eb06f5fb987
children 5fd02aa38b42
line wrap: on
line diff
--- a/python/transform.py	Fri Apr 19 19:22:52 2013 +0200
+++ b/python/transform.py	Fri Apr 19 22:15:54 2013 +0200
@@ -31,7 +31,6 @@
    def onInstruction(self, i):
       if type(i) is ImmLoad:
          i.target.constval = i.value
-         print(type(i.value), i.value)
       elif type(i) is BinaryOperator:
          a = i.value1
          b = i.value2
@@ -39,15 +38,12 @@
             op = i.operation
             if op == '+':
                i2 = ImmLoad(i.result, a.constval + b.constval)
-               print(i2)
                i.Parent.replaceInstruction(i, i2)
             elif op == '*':
                i2 = ImmLoad(i.result, a.constval * b.constval)
-               print(i2)
                i.Parent.replaceInstruction(i, i2)
             elif op == '-':
                i2 = ImmLoad(i.result, a.constval - b.constval)
-               print(i2)
                i.Parent.replaceInstruction(i, i2)
 
 class DeadCodeDeleter(BasicBlockPass):
@@ -62,3 +58,18 @@
          return False
       bb.Instructions = list(filter(instructionUsed, bb.Instructions))
 
+def isAllocPromotable(allocinst):
+   # Check if alloc value is only used by load and store operations.
+   assert type(allocinst) is Alloc
+   for use in ai.value.used_by:
+      print(use.user, use)
+      if not type(use.user) in [Load, Store]:
+         # TODO: check volatile
+         return False
+         otherUse = True
+   return True
+
+class Mem2RegPromotor(FunctionPass):
+   def onFunction(self, f):
+      print(f)
+