module Kempe.IR.Opt ( optimize
) where
import Kempe.IR
optimize :: [Stmt] -> [Stmt]
optimize :: [Stmt] -> [Stmt]
optimize = [Stmt] -> [Stmt]
successiveBumps
successiveBumps :: [Stmt] -> [Stmt]
successiveBumps :: [Stmt] -> [Stmt]
successiveBumps [] = []
successiveBumps
((MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntPlusIR (Reg Temp
DataPointer) (ConstInt Int64
i)))
:(MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntMinusIR (Reg Temp
DataPointer) (ConstInt Int64
i')))
:[Stmt]
ss) | Int64
i Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
i' = [Stmt] -> [Stmt]
successiveBumps [Stmt]
ss
successiveBumps
((MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntMinusIR (Reg Temp
DataPointer) (ConstInt Int64
i)))
:(MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntPlusIR (Reg Temp
DataPointer) (ConstInt Int64
i')))
:[Stmt]
ss) | Int64
i Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
i' = [Stmt] -> [Stmt]
successiveBumps [Stmt]
ss
successiveBumps
((MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntPlusIR (Reg Temp
DataPointer) (ConstInt Int64
i)))
:(MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntPlusIR (Reg Temp
DataPointer) (ConstInt Int64
i')))
:[Stmt]
ss) =
Temp -> Exp -> Stmt
MovTemp Temp
DataPointer (IntBinOp -> Exp -> Exp -> Exp
ExprIntBinOp IntBinOp
IntPlusIR (Temp -> Exp
Reg Temp
DataPointer) (Int64 -> Exp
ConstInt (Int64 -> Exp) -> Int64 -> Exp
forall a b. (a -> b) -> a -> b
$ Int64
iInt64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+Int64
i')) Stmt -> [Stmt] -> [Stmt]
forall a. a -> [a] -> [a]
: [Stmt] -> [Stmt]
successiveBumps [Stmt]
ss
successiveBumps
((MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntMinusIR (Reg Temp
DataPointer) (ConstInt Int64
i)))
:(MovTemp Temp
DataPointer (ExprIntBinOp IntBinOp
IntMinusIR (Reg Temp
DataPointer) (ConstInt Int64
i')))
:[Stmt]
ss) =
Temp -> Exp -> Stmt
MovTemp Temp
DataPointer (IntBinOp -> Exp -> Exp -> Exp
ExprIntBinOp IntBinOp
IntMinusIR (Temp -> Exp
Reg Temp
DataPointer) (Int64 -> Exp
ConstInt (Int64 -> Exp) -> Int64 -> Exp
forall a b. (a -> b) -> a -> b
$ Int64
iInt64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+Int64
i')) Stmt -> [Stmt] -> [Stmt]
forall a. a -> [a] -> [a]
: [Stmt] -> [Stmt]
successiveBumps [Stmt]
ss
successiveBumps (Stmt
s:[Stmt]
ss) = Stmt
s Stmt -> [Stmt] -> [Stmt]
forall a. a -> [a] -> [a]
: [Stmt] -> [Stmt]
successiveBumps [Stmt]
ss