mirror of
https://github.com/KarolS/millfork.git
synced 2025-02-21 21:29:00 +00:00
Fix optimizations of unused labels
This commit is contained in:
parent
8412075175
commit
510f85960c
@ -52,7 +52,7 @@ object FlowAnalyzer {
|
||||
}
|
||||
val labelMap: () => Option[Map[String, Int]] = () => req match {
|
||||
case FlowInfoRequirement.NoRequirement => None
|
||||
case _ => Some(code.flatMap(_.parameter.extractLabels).groupBy(identity).mapValues(_.size).view.force)
|
||||
case _ => Some(code.filter(m => m.opcode != MOpcode.LABEL).flatMap(_.parameter.extractLabels).groupBy(identity).mapValues(_.size).view.force)
|
||||
}
|
||||
val holder = new FlowHolder(forwardFlow, reverseFlow)
|
||||
code.zipWithIndex.map{ case (line, i) => FlowInfo(holder, i, labelMap) -> line}
|
||||
|
@ -2065,7 +2065,7 @@ object AlwaysGoodOptimizations {
|
||||
|
||||
val UnusedLabelRemoval = new RuleBasedAssemblyOptimization("Unused label removal",
|
||||
needsFlowInfo = FlowInfoRequirement.JustLabels,
|
||||
(Elidable & HasOpcode(LABEL) & HasCallerCount(0)) ~~> (_ => Nil)
|
||||
(Elidable & HasOpcode(LABEL) & HasCallerCount(0) & ParameterIsLocalLabel) ~~> (_ => Nil)
|
||||
)
|
||||
|
||||
val OperationsAroundShifting = new RuleBasedAssemblyOptimization("Operations around shifting",
|
||||
|
@ -52,7 +52,7 @@ object FlowAnalyzer {
|
||||
}
|
||||
val labelMap: () => Option[Map[String, Int]] = () => req match {
|
||||
case FlowInfoRequirement.NoRequirement => None
|
||||
case _ => Some(code.flatMap(_.parameter.extractLabels).groupBy(identity).mapValues(_.size).view.force)
|
||||
case _ => Some(code.filter(m => m.opcode != Opcode.LABEL).flatMap(_.parameter.extractLabels).groupBy(identity).mapValues(_.size).view.force)
|
||||
}
|
||||
val holder = new FlowHolder(forwardFlow, reverseFlow)
|
||||
code.zipWithIndex.map{ case (line, i) => FlowInfo(holder, i, labelMap) -> line}
|
||||
|
@ -1575,6 +1575,16 @@ case class HasCallerCount(count: Int) extends AssemblyLinePattern {
|
||||
override def hitRate: Double = 0.31
|
||||
}
|
||||
|
||||
object ParameterIsLocalLabel extends AssemblyLinePattern {
|
||||
override def matchLineTo(ctx: AssemblyMatchingContext, flowInfo: FlowInfo, line: AssemblyLine): Boolean =
|
||||
line match {
|
||||
case AssemblyLine0(Opcode.LABEL, _, MemoryAddressConstant(Label(l))) => l.startsWith(".")
|
||||
case _ => false
|
||||
}
|
||||
|
||||
override def hitRate: Double = 0.056
|
||||
}
|
||||
|
||||
case class MatchElidableCopyOf(i: Int, firstLinePattern: AssemblyLinePattern, lastLinePattern: AssemblyLinePattern) extends AssemblyPattern {
|
||||
override def matchTo(ctx: AssemblyMatchingContext, code: List[(FlowInfo, AssemblyLine)]): Option[List[(FlowInfo, AssemblyLine)]] = {
|
||||
val pattern = ctx.get[List[AssemblyLine]](i)
|
||||
|
@ -1284,7 +1284,7 @@ object AlwaysGoodI80Optimizations {
|
||||
|
||||
val UnusedLabelRemoval = new RuleBasedAssemblyOptimization("Unused label removal",
|
||||
needsFlowInfo = FlowInfoRequirement.JustLabels,
|
||||
(Elidable & HasOpcode(LABEL) & HasCallerCount(0)) ~~> (_ => Nil)
|
||||
(Elidable & HasOpcode(LABEL) & HasCallerCount(0) & ParameterIsLocalLabel) ~~> (_ => Nil)
|
||||
)
|
||||
|
||||
val BranchInPlaceRemoval = new RuleBasedAssemblyOptimization("Branch in place",
|
||||
|
@ -47,7 +47,7 @@ object FlowAnalyzer {
|
||||
}
|
||||
val labelMap: (() => Option[Map[String, Int]]) = () => req match {
|
||||
case FlowInfoRequirement.NoRequirement => None
|
||||
case _ => Some(code.flatMap(_.parameter.extractLabels).groupBy(identity).mapValues(_.size).view.force)
|
||||
case _ => Some(code.filter(m => m.opcode != ZOpcode.LABEL).flatMap(_.parameter.extractLabels).groupBy(identity).mapValues(_.size).view.force)
|
||||
}
|
||||
val holder = new FlowHolder(forwardFlow, reverseFlow)
|
||||
code.zipWithIndex.map{ case (line, i) => FlowInfo(holder, i, labelMap) -> line}
|
||||
|
@ -1311,6 +1311,16 @@ case class HasCallerCount(count: Int) extends AssemblyLinePattern {
|
||||
override def hitRate: Double = 0.056
|
||||
}
|
||||
|
||||
object ParameterIsLocalLabel extends AssemblyLinePattern {
|
||||
override def matchLineTo(ctx: AssemblyMatchingContext, flowInfo: FlowInfo, line: ZLine): Boolean =
|
||||
line match {
|
||||
case ZLine0(ZOpcode.LABEL, _, MemoryAddressConstant(Label(l))) => l.startsWith(".")
|
||||
case _ => false
|
||||
}
|
||||
|
||||
override def hitRate: Double = 0.056
|
||||
}
|
||||
|
||||
case class MatchElidableCopyOf(i: Int, firstLinePattern: AssemblyLinePattern, lastLinePattern: AssemblyLinePattern) extends AssemblyPattern {
|
||||
override def matchTo(ctx: AssemblyMatchingContext, code: List[(FlowInfo, ZLine)]): Option[List[(FlowInfo, ZLine)]] = {
|
||||
val pattern = ctx.get[List[ZLine]](i)
|
||||
|
Loading…
x
Reference in New Issue
Block a user