mirror of https://github.com/KarolS/millfork.git
Compare commits
5 Commits
6af84d1628
...
6f294d6dec
Author | SHA1 | Date |
---|---|---|
Karol Stasiak | 6f294d6dec | |
Karol Stasiak | 9866c974ad | |
Karol Stasiak | ef2f5b5918 | |
Karol Stasiak | a70a1c0e6b | |
Karol Stasiak | 790c836771 |
|
@ -662,7 +662,7 @@ object Main {
|
|||
c.changeFlag(CompilationFlag.CompactReturnDispatchParams, v)
|
||||
}.description("Whether parameter values in return dispatch statements may overlap other objects. Enabled by default.")
|
||||
boolean("-fbounds-checking", "-fno-bounds-checking").action { (c, v) =>
|
||||
c.changeFlag(CompilationFlag.VariableOverlap, v)
|
||||
c.changeFlag(CompilationFlag.CheckIndexOutOfBounds, v)
|
||||
}.description("Whether should insert bounds checking on array access.")
|
||||
boolean("-flenient-encoding", "-fno-lenient-encoding").action { (c, v) =>
|
||||
c.changeFlag(CompilationFlag.LenientTextEncoding, v)
|
||||
|
|
|
@ -15,7 +15,7 @@ object DangerousOptimizations {
|
|||
// TODO: try to guess when overflow can happen
|
||||
needsFlowInfo = FlowInfoRequirement.BothFlows,
|
||||
(Elidable & HasOpcode(CLC)).? ~
|
||||
(Elidable & HasClear(State.C) & HasOpcode(ADC) & MatchImmediate(0) & DoesntMatterWhatItDoesWith(State.V, State.C)) ~
|
||||
(Elidable & HasClear(State.C) & HasClear(State.D) & HasOpcode(ADC) & MatchImmediate(0) & DoesntMatterWhatItDoesWith(State.V, State.C)) ~
|
||||
(
|
||||
(HasOpcode(TAY) & DoesntMatterWhatItDoesWith(State.N, State.Z, State.A)) ~
|
||||
(Linear & Not(ConcernsY)).*
|
||||
|
@ -25,7 +25,7 @@ object DangerousOptimizations {
|
|||
ctx.get[List[AssemblyLine]](1) :+ last.copy(parameter = last.parameter.+(ctx.get[Constant](0)).quickSimplify)
|
||||
},
|
||||
(Elidable & HasOpcode(CLC)).? ~
|
||||
(Elidable & HasClear(State.C) & HasOpcode(ADC) & MatchImmediate(0) & DoesntMatterWhatItDoesWith(State.V, State.C)) ~
|
||||
(Elidable & HasClear(State.C) & HasClear(State.D) & HasOpcode(ADC) & MatchImmediate(0) & DoesntMatterWhatItDoesWith(State.V, State.C)) ~
|
||||
(
|
||||
(HasOpcode(TAX) & DoesntMatterWhatItDoesWith(State.N, State.Z, State.A)) ~
|
||||
(Linear & Not(ConcernsX)).*
|
||||
|
|
|
@ -48,7 +48,7 @@ abstract class CallGraph(program: Program, log: Logger) {
|
|||
case f: FunctionDeclarationStatement =>
|
||||
allFunctions += f.name
|
||||
allFunctions += f.name + ".trampoline" // TODO: ???
|
||||
if (f.address.isDefined || f.interrupt) entryPoints += f.name
|
||||
if (f.address.isDefined || f.interrupt || f.kernalInterrupt) entryPoints += f.name
|
||||
f.statements.getOrElse(Nil).foreach(s => this.add(Some(f.name), Nil, s))
|
||||
case s: Statement =>
|
||||
s.getAllExpressions.foreach(e => add(currentFunction, callingFunctions, e))
|
||||
|
|
|
@ -722,7 +722,7 @@ case class StandardReturnDispatchLabel(labels:List[Expression]) extends ReturnDi
|
|||
}
|
||||
|
||||
case class ReturnDispatchBranch(label: ReturnDispatchLabel, function: Expression, params: List[Expression]) extends Node {
|
||||
def getAllExpressions: List[Expression] = label.getAllExpressions ++ params
|
||||
def getAllExpressions: List[Expression] = label.getAllExpressions ++ params :+ function
|
||||
}
|
||||
|
||||
case class ReturnDispatchStatement(indexer: Expression, params: List[LhsExpression], branches: List[ReturnDispatchBranch]) extends ExecutableStatement {
|
||||
|
|
|
@ -167,4 +167,22 @@ class ReturnDispatchSuite extends FunSuite with Matchers {
|
|||
| void success() {}
|
||||
""".stripMargin)
|
||||
}
|
||||
test("Optimization test") {
|
||||
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
|
||||
"""
|
||||
| byte output @$c000
|
||||
| void main () {
|
||||
| if true {
|
||||
| return [1] {
|
||||
| 1 @ success
|
||||
| }
|
||||
| }
|
||||
| }
|
||||
| void success() {
|
||||
| output = 42
|
||||
| }
|
||||
""".stripMargin) { m =>
|
||||
m.readByte(0xc000) should equal(42)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue