subroutine inlining is an optimizer step

This commit is contained in:
Irmen de Jong 2020-07-01 12:41:10 +02:00
parent 307558a7e7
commit ec7b9f54c2
2 changed files with 4 additions and 4 deletions

View File

@ -26,10 +26,10 @@ internal fun Program.reorderStatements() {
reorder.applyModifications() reorder.applyModifications()
} }
internal fun Program.inlineSubroutines() { internal fun Program.inlineSubroutines(): Int {
val reorder = SubroutineInliner(this) val reorder = SubroutineInliner(this)
reorder.visit(this) reorder.visit(this)
reorder.applyModifications() return reorder.applyModifications()
} }
internal fun Program.addTypecasts(errors: ErrorReporter) { internal fun Program.addTypecasts(errors: ErrorReporter) {

View File

@ -150,7 +150,6 @@ private fun processAst(programAst: Program, errors: ErrorReporter, compilerOptio
programAst.reorderStatements() programAst.reorderStatements()
programAst.addTypecasts(errors) programAst.addTypecasts(errors)
errors.handle() errors.handle()
programAst.inlineSubroutines()
programAst.checkValid(compilerOptions, errors) programAst.checkValid(compilerOptions, errors)
errors.handle() errors.handle()
programAst.checkIdentifiers(errors) programAst.checkIdentifiers(errors)
@ -164,9 +163,10 @@ private fun optimizeAst(programAst: Program, errors: ErrorReporter) {
// keep optimizing expressions and statements until no more steps remain // keep optimizing expressions and statements until no more steps remain
val optsDone1 = programAst.simplifyExpressions() val optsDone1 = programAst.simplifyExpressions()
val optsDone2 = programAst.optimizeStatements(errors) val optsDone2 = programAst.optimizeStatements(errors)
val optsDone3 = programAst.inlineSubroutines()
programAst.constantFold(errors) // because simplified statements and expressions could give rise to more constants that can be folded away: programAst.constantFold(errors) // because simplified statements and expressions could give rise to more constants that can be folded away:
errors.handle() errors.handle()
if (optsDone1 + optsDone2 == 0) if (optsDone1 + optsDone2 + optsDone3 == 0)
break break
} }