mirror of
https://github.com/KarolS/millfork.git
synced 2024-06-11 15:29:34 +00:00
Compare commits
5 Commits
6af84d1628
...
6f294d6dec
Author | SHA1 | Date | |
---|---|---|---|
|
6f294d6dec | ||
|
9866c974ad | ||
|
ef2f5b5918 | ||
|
a70a1c0e6b | ||
|
790c836771 |
|
@ -662,7 +662,7 @@ object Main {
|
||||||
c.changeFlag(CompilationFlag.CompactReturnDispatchParams, v)
|
c.changeFlag(CompilationFlag.CompactReturnDispatchParams, v)
|
||||||
}.description("Whether parameter values in return dispatch statements may overlap other objects. Enabled by default.")
|
}.description("Whether parameter values in return dispatch statements may overlap other objects. Enabled by default.")
|
||||||
boolean("-fbounds-checking", "-fno-bounds-checking").action { (c, v) =>
|
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.")
|
}.description("Whether should insert bounds checking on array access.")
|
||||||
boolean("-flenient-encoding", "-fno-lenient-encoding").action { (c, v) =>
|
boolean("-flenient-encoding", "-fno-lenient-encoding").action { (c, v) =>
|
||||||
c.changeFlag(CompilationFlag.LenientTextEncoding, v)
|
c.changeFlag(CompilationFlag.LenientTextEncoding, v)
|
||||||
|
|
|
@ -15,7 +15,7 @@ object DangerousOptimizations {
|
||||||
// TODO: try to guess when overflow can happen
|
// TODO: try to guess when overflow can happen
|
||||||
needsFlowInfo = FlowInfoRequirement.BothFlows,
|
needsFlowInfo = FlowInfoRequirement.BothFlows,
|
||||||
(Elidable & HasOpcode(CLC)).? ~
|
(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)) ~
|
(HasOpcode(TAY) & DoesntMatterWhatItDoesWith(State.N, State.Z, State.A)) ~
|
||||||
(Linear & Not(ConcernsY)).*
|
(Linear & Not(ConcernsY)).*
|
||||||
|
@ -25,7 +25,7 @@ object DangerousOptimizations {
|
||||||
ctx.get[List[AssemblyLine]](1) :+ last.copy(parameter = last.parameter.+(ctx.get[Constant](0)).quickSimplify)
|
ctx.get[List[AssemblyLine]](1) :+ last.copy(parameter = last.parameter.+(ctx.get[Constant](0)).quickSimplify)
|
||||||
},
|
},
|
||||||
(Elidable & HasOpcode(CLC)).? ~
|
(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)) ~
|
(HasOpcode(TAX) & DoesntMatterWhatItDoesWith(State.N, State.Z, State.A)) ~
|
||||||
(Linear & Not(ConcernsX)).*
|
(Linear & Not(ConcernsX)).*
|
||||||
|
|
|
@ -48,7 +48,7 @@ abstract class CallGraph(program: Program, log: Logger) {
|
||||||
case f: FunctionDeclarationStatement =>
|
case f: FunctionDeclarationStatement =>
|
||||||
allFunctions += f.name
|
allFunctions += f.name
|
||||||
allFunctions += f.name + ".trampoline" // TODO: ???
|
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))
|
f.statements.getOrElse(Nil).foreach(s => this.add(Some(f.name), Nil, s))
|
||||||
case s: Statement =>
|
case s: Statement =>
|
||||||
s.getAllExpressions.foreach(e => add(currentFunction, callingFunctions, e))
|
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 {
|
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 {
|
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() {}
|
| void success() {}
|
||||||
""".stripMargin)
|
""".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
Block a user