Skip to content
Snippets Groups Projects
Commit 2ccfd18a authored by Haley Sapphie Owsianko's avatar Haley Sapphie Owsianko
Browse files

Merge branch 'optimiser' into 'master'

Begin optimiser implementation

See merge request !1
parents 92317d94 07caad17
No related branches found
No related tags found
1 merge request!1Begin optimiser implementation
......@@ -276,28 +276,82 @@ object CPSOptimizerHigh extends CPSOptimizer(SymbolicCPSTreeModule)
protected val unstable: ValuePrimitive => Boolean = ???
protected val blockAllocTag: PartialFunction[ValuePrimitive, Literal] = ???
protected val blockTag: ValuePrimitive = ???
protected val blockLength: ValuePrimitive = ???
protected val blockAllocTag: PartialFunction[ValuePrimitive, Literal] = {
case BlockAlloc(t) => t
}
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 rightNeutral: Set[(ValuePrimitive, Literal)] = ???
protected val leftNeutral: Set[(Literal, ValuePrimitive)] = Set(
(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 rightAbsorbing: Set[(ValuePrimitive, Literal)] = ???
protected val sameArgReduce: PartialFunction[(ValuePrimitive, Atom), Atom] = {
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]),
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]),
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment