1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-08 13:31:03 +00:00

Simplified constant inlining pass2

This commit is contained in:
jespergravgaard 2019-05-23 12:33:15 +02:00
parent 682d007ba8
commit 430c128cc3
2 changed files with 11 additions and 21 deletions

View File

@ -230,17 +230,19 @@ public class Compiler {
} }
private void pass2Optimize() { private void pass2Optimize() {
List<Pass2SsaOptimization> optimizations = getPass2Optimizations();
pass2Execute(optimizations);
}
private List<Pass2SsaOptimization> getPass2Optimizations() {
List<Pass2SsaOptimization> optimizations = new ArrayList<>(); List<Pass2SsaOptimization> optimizations = new ArrayList<>();
optimizations.add(new Pass2FixInlineConstructorsNew(program)); optimizations.add(new Pass2FixInlineConstructorsNew(program));
optimizations.add(new PassNAddNumberTypeConversions(program)); optimizations.add(new PassNAddNumberTypeConversions(program));
optimizations.add(new PassNAddArrayNumberTypeConversions(program)); optimizations.add(new PassNAddArrayNumberTypeConversions(program));
optimizations.add(new PassNTypeInference(program)); optimizations.add(new PassNTypeInference(program));
optimizations.add(new PassNAddTypeConversionAssignment(program)); optimizations.add(new PassNAddTypeConversionAssignment(program));
optimizations.add(new Pass2InlineCast(program)); optimizations.add(new Pass2InlineCast(program));
optimizations.add(new PassNCastSimplification(program)); optimizations.add(new PassNCastSimplification(program));
optimizations.add(new PassNTypeIdSimplification(program)); optimizations.add(new PassNTypeIdSimplification(program));
optimizations.add(new Pass2SizeOfSimplification(program)); optimizations.add(new Pass2SizeOfSimplification(program));
optimizations.add(new PassNStatementIndices(program)); optimizations.add(new PassNStatementIndices(program));
@ -266,7 +268,7 @@ public class Compiler {
optimizations.add(new PassNSimplifyExpressionWithZero(program)); optimizations.add(new PassNSimplifyExpressionWithZero(program));
optimizations.add(new PassNEliminateUnusedVars(program, true)); optimizations.add(new PassNEliminateUnusedVars(program, true));
optimizations.add(new Pass2EliminateUnusedBlocks(program)); optimizations.add(new Pass2EliminateUnusedBlocks(program));
pass2Execute(optimizations); return optimizations;
} }
private void pass2UnrollLoops() { private void pass2UnrollLoops() {
@ -297,26 +299,15 @@ public class Compiler {
private void pass2InlineConstants() { private void pass2InlineConstants() {
// Constant inlining optimizations - as the last step to ensure that constant identification has been completed // Constant inlining optimizations - as the last step to ensure that constant identification has been completed
List<Pass2SsaOptimization> constantOptimizations = new ArrayList<>(); List<Pass2SsaOptimization> constantOptimizations = new ArrayList<>();
constantOptimizations.add(new PassNStatementIndices(program)); constantOptimizations.add(new PassNStatementIndices(program));
constantOptimizations.add(new PassNVariableReferenceInfos(program)); constantOptimizations.add(new PassNVariableReferenceInfos(program));
constantOptimizations.add(new Pass2MultiplyToShiftRewriting(program)); constantOptimizations.add(new Pass2MultiplyToShiftRewriting(program));
constantOptimizations.add(new Pass2AliasElimination(program));
constantOptimizations.add(new Pass2ConstantInlining(program)); constantOptimizations.add(new Pass2ConstantInlining(program));
constantOptimizations.add(new Pass2ConstantStringConsolidation(program));
constantOptimizations.add(new Pass2IdenticalPhiElimination(program));
constantOptimizations.add(new Pass2ConstantRValueConsolidation(program));
constantOptimizations.add(new Pass2ConstantIdentification(program));
constantOptimizations.add(new Pass2ConstantValues(program));
constantOptimizations.add(new Pass2ConstantAdditionElimination(program)); constantOptimizations.add(new Pass2ConstantAdditionElimination(program));
constantOptimizations.add(new Pass2ConstantSimplification(program)); constantOptimizations.add(new Pass2ConstantSimplification(program));
constantOptimizations.add(new PassNCastSimplification(program)); constantOptimizations.addAll(getPass2Optimizations());
constantOptimizations.add(new Pass2ConstantIfs(program));
constantOptimizations.add(new Pass2InlineDerefIdx(program));
constantOptimizations.add(new PassNEliminateUnusedVars(program, true));
constantOptimizations.add(new PassNSimplifyConstantZero(program));
constantOptimizations.add(new PassNSimplifyExpressionWithZero(program));
pass2Execute(constantOptimizations); pass2Execute(constantOptimizations);
} }

View File

@ -3,8 +3,8 @@
:BasicUpstart(bbegin) :BasicUpstart(bbegin)
.pc = $80d "Program" .pc = $80d "Program"
.label SCREEN = $400 .label SCREEN = $400
.label msg = 4 .label msg = 3
.label idx = 3 .label idx = 5
bbegin: bbegin:
lda #<0 lda #<0
sta msg sta msg
@ -13,7 +13,6 @@ bbegin:
jsr main jsr main
rts rts
main: { main: {
.label f = hello
lda #<msg1 lda #<msg1
sta msg sta msg
lda #>msg1 lda #>msg1
@ -31,7 +30,7 @@ do10: {
lda #0 lda #0
sta i sta i
b1: b1:
jsr main.f jsr hello
inc i inc i
lda #$a lda #$a
cmp i cmp i