1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-01 06:29:53 +00:00

8080: tail call optimization

This commit is contained in:
Karol Stasiak 2019-06-24 00:47:07 +02:00
parent 869211658a
commit 4654698891

View File

@ -113,8 +113,24 @@ object LaterI80Optimizations {
},
)
val TailCall = new RuleBasedAssemblyOptimization("Tail call",
needsFlowInfo = FlowInfoRequirement.NoRequirement,
(Elidable & HasOpcode(CALL)) ~
(Elidable & HasOpcodeIn(ZOpcodeClasses.NoopDiscards)).* ~
(Elidable & HasOpcode(RET) & HasRegisters(NoRegisters)) ~~> { code =>
List(code.head.copy(opcode = JP))
},
(Elidable & HasOpcode(CALL)) ~
HasOpcode(LABEL).* ~
(Elidable & HasOpcodeIn(ZOpcodeClasses.NoopDiscards)).*.capture(0) ~
(Elidable & HasOpcode(RET) & HasRegisters(NoRegisters)) ~~> { (code, ctx) =>
ctx.get[List[ZLine]](0) ++ (code.head.copy(opcode = JP) :: code.tail)
},
)
val All: List[AssemblyOptimization[ZLine]] = List(
VariousSmallOptimizations,
FreeHL
FreeHL,
TailCall,
)
}