Commit 63f24da2 authored by Luca Bataillard's avatar Luca Bataillard
Browse files

fix constant folding (all tests pass)

parent 79a9e1d0
......@@ -9,7 +9,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
protected def rewrite(tree: Tree): Tree = {
val simplifiedTree = fixedPoint(tree)(shrink)
val maxSize = size(simplifiedTree) * 3 / 2
fixedPoint(simplifiedTree, 2) { t => inline(t, maxSize) }
fixedPoint(simplifiedTree, 8) { t => inline(t, maxSize) }
}
private case class Count(applied: Int = 0, asValue: Int = 0)
......@@ -168,7 +168,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
val newArgs = replaceArgs(args, s)
def getApp(b: Boolean): AppC = {
val contToUse = if (b) thenC else elseC
AppC(contToUse, newArgs)
AppC(contToUse, Seq())
}
val allLitOpt = newArgs.map(_.asLiteral)
val isAllLit = allLitOpt.forall(_.isDefined)
......@@ -271,7 +271,6 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
val notUsedAsValue = s.census.get(oldFun.name).fold(false)(count => count.asValue == 0)
val nonRecursive = notUsedAsValue && !census(oldFun.body).contains(oldFun.name)
/* TODO ask about stopping inlining of recursive functions */
if (nonRecursive && sameLen(oldFun.args, args)) {
val fun = copyF(oldFun, s.aSubst, s.cSubst)
val newState = s.withASubst(fun.args, args).withCSubst(fun.retC, retC)
......
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