Commit 07caad17 authored by Sapphie's avatar Sapphie
Browse files

Begin optimiser implementation

parent 92317d94
...@@ -276,28 +276,82 @@ object CPSOptimizerHigh extends CPSOptimizer(SymbolicCPSTreeModule) ...@@ -276,28 +276,82 @@ object CPSOptimizerHigh extends CPSOptimizer(SymbolicCPSTreeModule)
protected val unstable: ValuePrimitive => Boolean = ??? protected val unstable: ValuePrimitive => Boolean = ???
protected val blockAllocTag: PartialFunction[ValuePrimitive, Literal] = ??? protected val blockAllocTag: PartialFunction[ValuePrimitive, Literal] = {
protected val blockTag: ValuePrimitive = ??? case BlockAlloc(t) => t
protected val blockLength: ValuePrimitive = ??? }
protected val blockTag: ValuePrimitive = BlockTag
protected val blockLength: ValuePrimitive = BlockLength
protected val identity: ValuePrimitive = ??? protected val identity: ValuePrimitive = Id
protected val leftNeutral: Set[(Literal, ValuePrimitive)] = ??? protected val leftNeutral: Set[(Literal, ValuePrimitive)] = Set(
protected val rightNeutral: Set[(ValuePrimitive, Literal)] = ??? (IntLit(L3Int(0)), IntAdd),
(IntLit(L3Int(1)), IntMul),
(IntLit(L3Int((-1 << 1) >> 1)), IntBitwiseAnd),
(IntLit(L3Int(0)), IntBitwiseOr),
(IntLit(L3Int(0)), IntBitwiseXOr)
)
protected val rightNeutral: Set[(ValuePrimitive, Literal)] = Set(
(IntAdd, IntLit(L3Int(0))),
(IntSub, IntLit(L3Int(0))),
(IntMul, IntLit(L3Int(1))),
(IntDiv, IntLit(L3Int(1))),
(IntShiftLeft, IntLit(L3Int(0))),
(IntShiftRight, IntLit(L3Int(0))),
(IntBitwiseAnd, IntLit(L3Int((-1 << 1) >> 1))),
(IntBitwiseOr, IntLit(L3Int(0))),
(IntBitwiseXOr, IntLit(L3Int(0))),
)
protected val leftAbsorbing: Set[(Literal, ValuePrimitive)] = Set(
(IntLit(L3Int(0)), IntMul),
(IntLit(L3Int(0)), IntMod),
(IntLit(L3Int(0)), IntBitwiseAnd),
(IntLit(L3Int((-1 << 1) >> 1)), IntBitwiseOr),
(IntLit(L3Int(0)), IntShiftLeft),
(IntLit(L3Int(0)), IntShiftRight)
)
protected val rightAbsorbing: Set[(ValuePrimitive, Literal)] = Set(
(IntMul, IntLit(L3Int(0))),
(IntBitwiseAnd, IntLit(L3Int(0))),
(IntBitwiseOr, IntLit(L3Int((-1 << 1) >> 1)))
)
protected val leftAbsorbing: Set[(Literal, ValuePrimitive)] = ??? protected val sameArgReduce: PartialFunction[(ValuePrimitive, Atom), Atom] = {
protected val rightAbsorbing: Set[(ValuePrimitive, Literal)] = ??? case (IntBitwiseAnd | IntBitwiseOr, a) => a
case (IntSub | IntBitwiseXOr | IntMod, _) => AtomL(IntLit(L3Int(0)))
case (IntDiv, _) => AtomL(IntLit(L3Int(1)))
}
protected val sameArgReduce: PartialFunction[(ValuePrimitive, Atom), Atom] =
???
protected val sameArgReduceC: PartialFunction[TestPrimitive, Boolean] = ??? protected val sameArgReduceC: PartialFunction[TestPrimitive, Boolean] = {
case IntLt => false
case IntLe | Eq => true
}
protected val vEvaluator: PartialFunction[(ValuePrimitive, Seq[Literal]), protected val vEvaluator: PartialFunction[(ValuePrimitive, Seq[Literal]),
Literal] = ??? Literal] = {
case (vPrim, Seq(IntLit(x), IntLit(y))) => vPrim match {
case IntAdd => IntLit(x + y)
case IntSub => IntLit(x - y)
case IntMod => IntLit(x % y)
case IntDiv => IntLit(x / y)
case IntMul => IntLit(x * y)
case IntBitwiseAnd => IntLit(x & y)
case IntBitwiseOr => IntLit(x | y)
case IntBitwiseXOr => IntLit(x ^ y)
case IntShiftLeft => IntLit(x << y)
case IntShiftRight => IntLit(x >> y)
}
}
protected val cEvaluator: PartialFunction[(TestPrimitive, Seq[Literal]), protected val cEvaluator: PartialFunction[(TestPrimitive, Seq[Literal]),
Boolean] = ??? Boolean] = {
case (IntLe, Seq(IntLit(x), IntLit(y))) => x <= y
case (IntLt, Seq(IntLit(x), IntLit(y))) => x < y
case (Eq, Seq(l1, l2)) => l1 == l2
}
} }
object CPSOptimizerLow extends CPSOptimizer(SymbolicCPSTreeModuleLow) object CPSOptimizerLow extends CPSOptimizer(SymbolicCPSTreeModuleLow)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment