mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-11 12:29:46 +00:00
Fix bad code deduplication
This commit is contained in:
parent
30c979cc39
commit
6b33cc49a8
@ -18,6 +18,10 @@ abstract class Deduplicate[T <: AbstractCode](env: Environment, options: Compila
|
|||||||
}
|
}
|
||||||
runStage(compiledFunctions, deduplicateIdenticalFunctions)
|
runStage(compiledFunctions, deduplicateIdenticalFunctions)
|
||||||
runStage(compiledFunctions, eliminateTailJumps)
|
runStage(compiledFunctions, eliminateTailJumps)
|
||||||
|
runStage(compiledFunctions, eliminateTailJumps)
|
||||||
|
runStage(compiledFunctions, eliminateTailJumps)
|
||||||
|
runStage(compiledFunctions, eliminateRemainingTrivialTailJumps)
|
||||||
|
runStage(compiledFunctions, eliminateRemainingTrivialTailJumps)
|
||||||
runStage(compiledFunctions, eliminateRemainingTrivialTailJumps)
|
runStage(compiledFunctions, eliminateRemainingTrivialTailJumps)
|
||||||
fixDoubleRedirects(compiledFunctions)
|
fixDoubleRedirects(compiledFunctions)
|
||||||
// println(compiledFunctions.map {
|
// println(compiledFunctions.map {
|
||||||
@ -28,6 +32,8 @@ abstract class Deduplicate[T <: AbstractCode](env: Environment, options: Compila
|
|||||||
// }.mkString(" ; "))
|
// }.mkString(" ; "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def removeChains(map: Map[String, String]): Map[String, String] = map.filterNot{case (_, to) => map.contains(to)}
|
||||||
|
|
||||||
def runStage(compiledFunctions: mutable.Map[String, CompiledFunction[T]],
|
def runStage(compiledFunctions: mutable.Map[String, CompiledFunction[T]],
|
||||||
function: (String, Map[String, Either[String, CodeAndAlignment[T]]]) => Seq[(String, CompiledFunction[T])]): Unit = {
|
function: (String, Map[String, Either[String, CodeAndAlignment[T]]]) => Seq[(String, CompiledFunction[T])]): Unit = {
|
||||||
bySegment(compiledFunctions).foreach {
|
bySegment(compiledFunctions).foreach {
|
||||||
@ -195,7 +201,7 @@ abstract class Deduplicate[T <: AbstractCode](env: Environment, options: Compila
|
|||||||
.map(name -> _)
|
.map(name -> _)
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
val fallthroughPredecessors = fallThroughList.groupBy(_._2).mapValues(_.head._1) // TODO: be smarter than head
|
val fallthroughPredecessors = removeChains(fallThroughList).groupBy(_._2).mapValues(_.head._1) // TODO: be smarter than head
|
||||||
fallthroughPredecessors.foreach {
|
fallthroughPredecessors.foreach {
|
||||||
case (to, from) =>
|
case (to, from) =>
|
||||||
options.log.debug(s"Fallthrough from $from to $to")
|
options.log.debug(s"Fallthrough from $from to $to")
|
||||||
@ -228,7 +234,7 @@ abstract class Deduplicate[T <: AbstractCode](env: Environment, options: Compila
|
|||||||
.map(name -> _)
|
.map(name -> _)
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
val fallthroughPredecessors = fallThroughList.groupBy(_._2).mapValues(_.keySet)
|
val fallthroughPredecessors = removeChains(fallThroughList).groupBy(_._2).mapValues(_.keySet)
|
||||||
fallthroughPredecessors.foreach {
|
fallthroughPredecessors.foreach {
|
||||||
case (to, froms) =>
|
case (to, froms) =>
|
||||||
for (from <- froms) {
|
for (from <- froms) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user