1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-05 09:28:54 +00:00

If a function has one small parameter, pass it via the accumulator

This commit is contained in:
Karol Stasiak 2018-06-23 23:14:53 +02:00
parent 3d47c51804
commit bc21e5befc
5 changed files with 14 additions and 1 deletions

View File

@ -169,6 +169,8 @@ object ReverseFlowAnalyzer {
result = result.copy(x = Important, y = Important)
case _ =>
})
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
result = result.copy(a = Important)
case _ =>
}
if (ZeropageRegisterOptimizations.functionsThatUsePseudoregisterAsInput(fun.name)) {

View File

@ -35,6 +35,8 @@ object SingleAssignmentVariableOptimization extends AssemblyOptimization[Assembl
override def optimize(f: NormalFunction, code: List[AssemblyLine], options: CompilationOptions): List[AssemblyLine] = {
val paramVariables = f.params match {
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
Set[String]()
case NormalParamSignature(ps) =>
ps.map(_.name).toSet
case _ =>

View File

@ -105,6 +105,8 @@ object VariableToRegisterOptimization extends AssemblyOptimization[AssemblyLine]
override def optimize(f: NormalFunction, code: List[AssemblyLine], options: CompilationOptions): List[AssemblyLine] = {
val paramVariables = f.params match {
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
Set[String]()
case NormalParamSignature(ps) =>
ps.map(_.name).toSet
case _ =>

View File

@ -23,6 +23,11 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
ctx.env.nameCheck(ctx.function.code)
val chunk = MosStatementCompiler.compile(ctx, ctx.function.code)
val storeParamsFromRegisters = ctx.function.params match {
case NormalParamSignature(List(param@MemoryVariable(_, typ, _))) if typ.size == 1 =>
List(AssemblyLine.absolute(STA, param))
case _ => Nil
}
val phReg =
if (ctx.options.flag(CompilationFlag.ZeropagePseudoregister)) {
val reg = ctx.env.get[VariableInMemory]("__reg")
@ -34,7 +39,7 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
)
} else Nil
val prefix = (if (ctx.function.interrupt) {
val prefix = storeParamsFromRegisters ++ (if (ctx.function.interrupt) {
if (ctx.options.flag(CompilationFlag.EmitNative65816Opcodes)) {
if (ctx.options.flag(CompilationFlag.ZeropagePseudoregister)) {

View File

@ -1067,6 +1067,8 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
case _ => Nil
}
secondViaMemory ++ thirdViaRegisters :+ AssemblyLine.absoluteOrLongAbsolute(JSR, function, ctx.options)
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
compile(ctx, params.head, Some(b -> RegisterVariable(MosRegister.A, b)), BranchSpec.None) ++ List(AssemblyLine.absoluteOrLongAbsolute(JSR, function, ctx.options))
case NormalParamSignature(paramVars) =>
params.zip(paramVars).flatMap {
case (paramExpr, paramVar) =>