Commit 6f1eb15a authored by Eva Darulova's avatar Eva Darulova

fixing bug in SSA phase, which didn't work correctly for let stmts

parent a0b6cc1b
......@@ -27,7 +27,6 @@ object SSATransformerPhase extends DaisyPhase {
override val name = "SSA transformer"
override val description = "Transforms the function bodies into SSA form."
override val definedOptions: Set[CmdLineOptionDef[Any]] = Set()
//implicit val debugSection = DebugSectionRanges
var reporter: Reporter = null
......@@ -37,9 +36,7 @@ object SSATransformerPhase extends DaisyPhase {
reporter.info("\nStarting SSA transformation phase")
val timer = ctx.timers.ssa.start
// we need to actually replace the function bodies,
// so we need to create a copy of the whole program
// need to replace function bodies, create a copy of the whole program
val newDefs = prg.defs.map(fnc =>
if (!fnc.body.isEmpty) {
......@@ -51,14 +48,6 @@ object SSATransformerPhase extends DaisyPhase {
fnc
})
// println("Original program:")
// println(prg)
// println("\nNew program:")
// println(lang.PrettyPrinter.withIDs(Program(prg.id, newDefs)))
timer.stop
reporter.info("Finished SSA transformation phase")
......@@ -81,11 +70,29 @@ object SSATransformerPhase extends DaisyPhase {
merge(lhs, rhs, recons)
// This is not ideal, because we are repeating computation
case Let(id, value, body) =>
val inlined = replace(Map((Variable(id) -> value)), body)
toSSA(inlined)
val ssaValue = toSSA(value)
val ssaBody = toSSA(body)
val tmp = ssaValue match {
case l: Let => replaceBody(ssaValue, id, ssaBody)
case _ =>
Let(id, ssaValue, ssaBody)
}
tmp
}
private def replaceBody(expr: Expr, nextId: Identifier, nextBody: Expr): Expr = expr match {
case Let(id, value, x @ Let(id2, value2, body)) =>
Let(id, value, replaceBody(x, id, nextBody))
case Let(id, value, body) =>
Let(id, value,
Let(nextId, body, nextBody))
}
def merge(lhs: Expr, rhs: Expr, recons: (Seq[Expr]) => Expr): Expr = (lhs, rhs) match {
......
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