From 1df77d5ded1fc5b5de4988b85e4f907bbb30b94d Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Thu, 23 May 2019 07:39:10 +0200 Subject: [PATCH] Collected all type inference in pass2 together. --- src/main/java/dk/camelot64/kickc/Compiler.java | 13 ++++++++----- .../model/iterator/ProgramExpressionIterator.java | 10 +++++----- .../kickc/passes/Pass2FixInlineConstructorsNew.java | 2 +- .../ref/examples/bresenham/bitmap-bresenham.asm | 6 +++--- src/test/ref/examples/sinplotter/sine-plotter.asm | 12 ++++++------ src/test/ref/inline-pointer-1.asm | 6 +++--- src/test/ref/inline-string-3.asm | 6 +++--- src/test/ref/line-anim.asm | 12 ++++++------ src/test/ref/pointer-plus-0.asm | 10 ++++------ 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/Compiler.java b/src/main/java/dk/camelot64/kickc/Compiler.java index 6e35e5a99..0aff5a280 100644 --- a/src/main/java/dk/camelot64/kickc/Compiler.java +++ b/src/main/java/dk/camelot64/kickc/Compiler.java @@ -231,9 +231,16 @@ public class Compiler { private void pass2Optimize() { List optimizations = new ArrayList<>(); + + optimizations.add(new Pass2FixInlineConstructorsNew(program)); + optimizations.add(new PassNAddNumberTypeConversions(program)); optimizations.add(new PassNAddArrayNumberTypeConversions(program)); optimizations.add(new PassNTypeInference(program)); + optimizations.add(new PassNAddTypeConversionAssignment(program)); + optimizations.add(new Pass2InlineCast(program)); + optimizations.add(new PassNCastSimplification(program)); + optimizations.add(new PassNTypeIdSimplification(program)); optimizations.add(new Pass2SizeOfSimplification(program)); optimizations.add(new Pass2CullEmptyBlocks(program)); @@ -243,6 +250,7 @@ public class Compiler { optimizations.add(new Pass2AliasElimination(program)); optimizations.add(new Pass2SelfPhiElimination(program)); optimizations.add(new Pass2IdenticalPhiElimination(program)); + optimizations.add(new Pass2DuplicateRValueIdentification(program)); optimizations.add(new Pass2ConditionalJumpSimplification(program)); optimizations.add(new Pass2ConditionalAndOrRewriting(program)); optimizations.add(new Pass2ConstantRValueConsolidation(program)); @@ -253,19 +261,14 @@ public class Compiler { optimizations.add(new Pass2ConstantStringConsolidation(program)); optimizations.add(new PassNStatementIndices(program)); optimizations.add(new PassNVariableReferenceInfos(program)); - optimizations.add(new Pass2FixInlineConstructorsNew(program)); - optimizations.add(new PassNAddTypeConversionAssignment(program)); optimizations.add(new Pass2RangeResolving(program)); optimizations.add(new Pass2ComparisonOptimization(program)); - optimizations.add(new Pass2InlineCast(program)); - optimizations.add(new PassNCastSimplification(program)); optimizations.add(new Pass2InlineDerefIdx(program)); optimizations.add(new Pass2DeInlineWordDerefIdx(program)); optimizations.add(new PassNSimplifyConstantZero(program)); optimizations.add(new PassNSimplifyExpressionWithZero(program)); optimizations.add(new PassNEliminateUnusedVars(program, true)); optimizations.add(new Pass2EliminateUnusedBlocks(program)); - optimizations.add(new Pass2DuplicateRValueIdentification(program)); pass2Execute(optimizations); } diff --git a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java index 1995dbf5e..4411ffd80 100644 --- a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java +++ b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramExpressionIterator.java @@ -27,15 +27,15 @@ public class ProgramExpressionIterator { // Iterate all symbols ProgramValueHandler programValueHandler = (programValue, currentStmt, stmtIt, currentBlock) -> { if(programValue.get() instanceof ConstantBinary) { - handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryConstant(programValue), null, null, null); + handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryConstant(programValue), currentStmt, stmtIt, currentBlock); } else if(programValue.get() instanceof ConstantUnary) { - handler.execute(new ProgramExpressionUnary.ProgramExpressionUnaryConstant(programValue), null, null, null); + handler.execute(new ProgramExpressionUnary.ProgramExpressionUnaryConstant(programValue), currentStmt, stmtIt, currentBlock); } else if(programValue.get() instanceof PointerDereferenceIndexed) { - handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryPointerDereferenceIndexed(programValue), null, null, null); + handler.execute(new ProgramExpressionBinary.ProgramExpressionBinaryPointerDereferenceIndexed(programValue), currentStmt, stmtIt, currentBlock); } else if(programValue.get() instanceof ConstantCastValue) { - handler.execute(new ProgramExpressionUnary.ProgramExpressionUnaryConstantCast(programValue), null, null, null); + handler.execute(new ProgramExpressionUnary.ProgramExpressionUnaryConstantCast(programValue), currentStmt, stmtIt, currentBlock); } else if(programValue.get() instanceof CastValue) { - handler.execute(new ProgramExpressionUnary.ProgramExpressionUnaryCast(programValue), null, null, null); + handler.execute(new ProgramExpressionUnary.ProgramExpressionUnaryCast(programValue), currentStmt, stmtIt, currentBlock); } }; ProgramValueIterator.execute(program.getScope(), programValueHandler); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructorsNew.java b/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructorsNew.java index e8c83cf29..9bb996f01 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructorsNew.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2FixInlineConstructorsNew.java @@ -77,7 +77,7 @@ public class Pass2FixInlineConstructorsNew extends Pass2SsaOptimization { // Convert list to a word constructor in a new tmp variable Scope currentScope = Pass2FixInlineConstructorsNew.this.getScope().getScope(currentBlock.getScope()); VariableIntermediate tmpVar = currentScope.addVariableIntermediate(); - tmpVar.setTypeInferred(constructType); + //tmpVar.setTypeInferred(constructType); // Move backward - to insert before the current statement stmtIt.previous(); // Add assignment of the new tmpVar diff --git a/src/test/ref/examples/bresenham/bitmap-bresenham.asm b/src/test/ref/examples/bresenham/bitmap-bresenham.asm index c6f38704b..5c7a99cac 100644 --- a/src/test/ref/examples/bresenham/bitmap-bresenham.asm +++ b/src/test/ref/examples/bresenham/bitmap-bresenham.asm @@ -336,11 +336,11 @@ init_screen: { bitmap_clear: { .label bitmap = 9 .label y = 2 - .label _4 = 9 + .label _3 = 9 lda bitmap_plot_xlo - sta _4 + sta _3 lda bitmap_plot_xhi - sta _4+1 + sta _3+1 lda #0 sta y b1: diff --git a/src/test/ref/examples/sinplotter/sine-plotter.asm b/src/test/ref/examples/sinplotter/sine-plotter.asm index e86b7ba4e..a7f77bdfb 100644 --- a/src/test/ref/examples/sinplotter/sine-plotter.asm +++ b/src/test/ref/examples/sinplotter/sine-plotter.asm @@ -178,11 +178,11 @@ bitmap_plot: { .label plotter = 6 .label plotter_1 = $10 .label x = 4 - .label _4 = 6 + .label _3 = 6 lda bitmap_plot_yhi,x - sta _4+1 + sta _3+1 lda bitmap_plot_ylo,x - sta _4 + sta _3 lda x and #<$fff8 sta _1 @@ -729,11 +729,11 @@ divr16u: { bitmap_clear: { .label bitmap = 2 .label y = $16 - .label _4 = 2 + .label _3 = 2 lda bitmap_plot_ylo - sta _4 + sta _3 lda bitmap_plot_yhi - sta _4+1 + sta _3+1 lda #0 sta y b1: diff --git a/src/test/ref/inline-pointer-1.asm b/src/test/ref/inline-pointer-1.asm index 4da10ae54..3bf16934c 100644 --- a/src/test/ref/inline-pointer-1.asm +++ b/src/test/ref/inline-pointer-1.asm @@ -14,9 +14,9 @@ main: { // puta(byte register(A) ph, byte register(X) pl) puta: { .label screen = 2 - .label _2 = 2 - sta _2+1 - stx _2 + .label _1 = 2 + sta _1+1 + stx _1 lda #'a' ldy #0 sta (screen),y diff --git a/src/test/ref/inline-string-3.asm b/src/test/ref/inline-string-3.asm index 1e2abba8f..1881a03a3 100644 --- a/src/test/ref/inline-string-3.asm +++ b/src/test/ref/inline-string-3.asm @@ -8,15 +8,15 @@ main: { .label PTR = $9ffe .label SCREEN = $400 .label ptr = 2 - .label _7 = 2 + .label _6 = 2 lda #STRING sta PTR+1 lda PTR - sta _7 + sta _6 lda PTR+1 - sta _7+1 + sta _6+1 ldy #0 lda (ptr),y sta SCREEN diff --git a/src/test/ref/line-anim.asm b/src/test/ref/line-anim.asm index e787357ed..862d9a41b 100644 --- a/src/test/ref/line-anim.asm +++ b/src/test/ref/line-anim.asm @@ -81,11 +81,11 @@ bitmap_plot: { .label x = 3 .label plotter = 5 .label plotter_1 = 7 - .label _4 = 5 + .label _3 = 5 lda bitmap_plot_yhi,x - sta _4+1 + sta _3+1 lda bitmap_plot_ylo,x - sta _4 + sta _3 lda x and #<$fff8 sta _1 @@ -428,11 +428,11 @@ screen_fill: { bitmap_clear: { .label bitmap = 3 .label y = 2 - .label _4 = 3 + .label _3 = 3 lda bitmap_plot_ylo - sta _4 + sta _3 lda bitmap_plot_yhi - sta _4+1 + sta _3+1 lda #0 sta y b1: diff --git a/src/test/ref/pointer-plus-0.asm b/src/test/ref/pointer-plus-0.asm index 8fc352c78..999a7535a 100644 --- a/src/test/ref/pointer-plus-0.asm +++ b/src/test/ref/pointer-plus-0.asm @@ -7,27 +7,25 @@ main: { .label _0 = 2 .label _2 = 2 lda #msg1 - sta first.msg+1 + sta first.return+1 jsr first ldy #0 lda (_0),y sta SCREEN lda #msg2 - sta first.msg+1 + sta first.return+1 jsr first ldy #0 lda (_2),y sta SCREEN+1 rts } -// first(byte* zeropage(2) msg) first: { .label return = 2 - .label msg = 2 rts } msg1: .text "hello world!@"