Commit 2ae235d7 authored by Sapphie's avatar Sapphie
Browse files

Implement blocktag reduction

parent 63f24da2
...@@ -22,6 +22,8 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }] ...@@ -22,6 +22,8 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
cEnv: Map[Name, Cnt] = Map.empty, cEnv: Map[Name, Cnt] = Map.empty,
fEnv: Map[Name, Fun] = Map.empty) { fEnv: Map[Name, Fun] = Map.empty) {
def eEnv: Map[Atom, (ValuePrimitive, Seq[Atom])] =
eInvEnv.map(_.swap)
def dead(s: Name): Boolean = def dead(s: Name): Boolean =
! census.contains(s) ! census.contains(s)
def appliedOnce(s: Name): Boolean = def appliedOnce(s: Name): Boolean =
...@@ -140,6 +142,14 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }] ...@@ -140,6 +142,14 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
// Right Absorbing // Right Absorbing
case Seq(a1, AtomL(l2)) if rightAbsorbing((prim, l2)) => case Seq(a1, AtomL(l2)) if rightAbsorbing((prim, l2)) =>
shrink(body, s.withASubst(name, l2)) shrink(body, s.withASubst(name, l2))
case Seq(a1) if prim == blockTag && s.eEnv.isDefinedAt(a1) =>
val maybeBlockAlloc = s.eEnv(a1)._1
blockAllocTag.lift(maybeBlockAlloc) match {
case Some(tag) =>
shrink(body, s.withASubst(name, AtomL(tag)))
case None =>
noOp
}
case _ => noOp case _ => noOp
} }
} }
......
...@@ -14,15 +14,15 @@ object Main { ...@@ -14,15 +14,15 @@ object Main {
val stats = new Statistics() val stats = new Statistics()
val backEnd: Tree => TerminalPhaseResult = ( val backEnd: Tree => TerminalPhaseResult = (
CL3ToCPSTranslator CL3ToCPSTranslator
andThen treePrinter("---------- After CPS translation") // andThen treePrinter("---------- After CPS translation")
andThen CPSOptimizerHigh andThen CPSOptimizerHigh
andThen treePrinter("---------- After Optimization (High)") // andThen treePrinter("---------- After Optimization (High)")
andThen treeChecker andThen treeChecker
andThen CPSValueRepresenter andThen CPSValueRepresenter
andThen treePrinter("---------- After value representation") // andThen treePrinter("---------- After value representation")
andThen treeChecker andThen treeChecker
andThen CPSHoister andThen CPSHoister
andThen treePrinter("---------- After hoisting") // andThen treePrinter("---------- After hoisting")
andThen CPSOptimizerLow andThen CPSOptimizerLow
andThen treePrinter("---------- After Optimization (Low)") andThen treePrinter("---------- After Optimization (Low)")
andThen treeChecker andThen treeChecker
......
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