diff --git a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java index dadf6a6a3..c4e9c65b0 100644 --- a/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java +++ b/src/main/java/dk/camelot64/kickc/model/iterator/ProgramValueIterator.java @@ -50,7 +50,7 @@ public class ProgramValueIterator { * @param symbolVariable The symbol variable * @param programValueHandler The programValueHandler to execute */ - private static void execute(SymbolVariable symbolVariable, ProgramValueHandler programValueHandler) { + public static void execute(SymbolVariable symbolVariable, ProgramValueHandler programValueHandler) { if(symbolVariable.getType() instanceof SymbolTypeArray) { execute(new ProgramValue.TypeArraySize((SymbolTypeArray) symbolVariable.getType()), programValueHandler, null, null, null); } diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNVariableReferenceInfos.java b/src/main/java/dk/camelot64/kickc/passes/PassNVariableReferenceInfos.java index f7d46b8a5..a8e07a3e7 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNVariableReferenceInfos.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNVariableReferenceInfos.java @@ -5,8 +5,11 @@ import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.VariableReferenceInfos; import dk.camelot64.kickc.model.iterator.ProgramValue; import dk.camelot64.kickc.model.iterator.ProgramValueIterator; -import dk.camelot64.kickc.model.statements.*; -import dk.camelot64.kickc.model.symbols.ConstantVar; +import dk.camelot64.kickc.model.statements.Statement; +import dk.camelot64.kickc.model.statements.StatementAssignment; +import dk.camelot64.kickc.model.statements.StatementCall; +import dk.camelot64.kickc.model.statements.StatementPhiBlock; +import dk.camelot64.kickc.model.symbols.SymbolVariable; import dk.camelot64.kickc.model.values.*; import java.util.*; @@ -80,43 +83,49 @@ public class PassNVariableReferenceInfos extends Pass2Base { blockReferencedVars.put(blockLabel, getReferencedVars(blockLabel, new ArrayList<>())); blockUsedVars.put(blockLabel, getUsedVars(blockLabel, new ArrayList<>())); for(Statement statement : block.getStatements()) { + Collection referenced = getReferenced(statement); Collection defined = getDefinedVars(statement); - Collection referencedVars = getReferencedVars(statement); // Add variable definitions to the statement stmtDefined.put(statement.getIndex(), defined); - // Add variable reference to the statement - stmtReferenced.put(statement.getIndex(), referencedVars); // Identify statement defining variables for(VariableRef variableRef : defined) { symbolVarReferences.putIfAbsent(variableRef, new ArrayList<>()); Collection references = symbolVarReferences.get(variableRef); references.add(new VariableReferenceInfos.ReferenceInStatement(statement.getIndex(), VariableReferenceInfos.ReferenceToSymbolVar.ReferenceType.DEFINE, variableRef)); } - // Gather statements referencing variables - for(VariableRef variableRef : referencedVars) { - if(!defined.contains(variableRef)) { - symbolVarReferences.putIfAbsent(variableRef, new ArrayList<>()); - Collection references = symbolVarReferences.get(variableRef); - references.add(new VariableReferenceInfos.ReferenceInStatement(statement.getIndex(), VariableReferenceInfos.ReferenceToSymbolVar.ReferenceType.USE, variableRef)); + // Gather statements referencing variables/constants + Collection varRefs = new ArrayList<>(); + for(SymbolVariableRef referencedVarRef : referenced) { + if(referencedVarRef instanceof VariableRef) { + varRefs.add((VariableRef) referencedVarRef); + } + if(!defined.contains(referencedVarRef)) { + symbolVarReferences.putIfAbsent(referencedVarRef, new ArrayList<>()); + Collection references = symbolVarReferences.get(referencedVarRef); + references.add( + new VariableReferenceInfos.ReferenceInStatement( + statement.getIndex(), + VariableReferenceInfos.ReferenceToSymbolVar.ReferenceType.USE, + referencedVarRef)); } } - // Gather statements referencing constants - Collection referencedConsts = getReferencedConsts(statement); - for(ConstantRef constantRef : referencedConsts) { - symbolVarReferences.putIfAbsent(constantRef, new ArrayList<>()); - Collection references = symbolVarReferences.get(constantRef); - references.add(new VariableReferenceInfos.ReferenceInStatement(statement.getIndex(), VariableReferenceInfos.ReferenceToSymbolVar.ReferenceType.USE, constantRef)); - } + // Add variable reference to the statement + stmtReferenced.put(statement.getIndex(), varRefs); } } - // Gather constants referencing other constants - for(ConstantVar constantVar : getSymbols().getAllConstants(true)) { - Collection referencedConsts = getReferencedConsts(constantVar.getValue()); - for(ConstantRef constantRef : referencedConsts) { - symbolVarReferences.putIfAbsent(constantRef, new ArrayList<>()); - Collection references = symbolVarReferences.get(constantRef); - references.add(new VariableReferenceInfos.ReferenceInSymbol(constantVar.getRef(), VariableReferenceInfos.ReferenceToSymbolVar.ReferenceType.USE, constantRef)); - } + // Gather symbols in the symbol table referencing other variables/constants + Collection allSymbolVariables = getProgram().getScope().getAllSymbolVariables(true); + for(SymbolVariable referencingVar : allSymbolVariables) { + ProgramValueIterator.execute(referencingVar, + (programValue, currentStmt, stmtIt, currentBlock) -> { + RValue rValue = programValue.get(); + if(rValue instanceof SymbolVariableRef) { + SymbolVariableRef referencedVar = (SymbolVariableRef) rValue; + symbolVarReferences.putIfAbsent(referencedVar, new ArrayList<>()); + Collection references = symbolVarReferences.get(referencedVar); + references.add(new VariableReferenceInfos.ReferenceInSymbol((SymbolVariableRef) referencingVar.getRef(), VariableReferenceInfos.ReferenceToSymbolVar.ReferenceType.USE, referencedVar)); + } + }); } getProgram().setVariableReferenceInfos(new VariableReferenceInfos(blockReferencedVars, blockUsedVars, stmtReferenced, stmtDefined, symbolVarReferences)); } @@ -236,30 +245,13 @@ public class PassNVariableReferenceInfos extends Pass2Base { */ private Collection getReferencedVars(Statement statement) { LinkedHashSet referencedVars = new LinkedHashSet<>(); - for(SymbolRef symbolRef : getReferenced(statement)) { - if(symbolRef instanceof VariableRef) { - referencedVars.add((VariableRef) symbolRef); - } - } + getReferenced(statement) + .stream() + .filter(symbolVariableRef -> symbolVariableRef instanceof VariableRef) + .forEach(symbolVariableRef -> referencedVars.add((VariableRef) symbolVariableRef)); return referencedVars; } - /** - * Get the constants referenced (used or defined) in a statement - * - * @param statement The statement to examine - * @return The referenced constants - */ - private Collection getReferencedConsts(Statement statement) { - LinkedHashSet referencedConsts = new LinkedHashSet<>(); - for(SymbolRef symbolRef : getReferenced(statement)) { - if(symbolRef instanceof ConstantRef) { - referencedConsts.add((ConstantRef) symbolRef); - } - } - return referencedConsts; - } - /** * Get the variables / constants referenced (used or defined) in a statement * @@ -268,41 +260,12 @@ public class PassNVariableReferenceInfos extends Pass2Base { */ private Collection getReferenced(Statement statement) { LinkedHashSet referenced = new LinkedHashSet<>(); - if(statement instanceof StatementPhiBlock) { - StatementPhiBlock phiBlock = (StatementPhiBlock) statement; - for(StatementPhiBlock.PhiVariable phiVariable : phiBlock.getPhiVariables()) { - referenced.add(phiVariable.getVariable()); - for(StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) { - referenced.addAll(getReferenced(phiRValue.getrValue())); + ProgramValueIterator.execute(statement, + (programValue, currentStmt, stmtIt, currentBlock) -> { + if(programValue.get() instanceof SymbolVariableRef) + referenced.add((SymbolVariableRef) programValue.get()); } - } - } else if(statement instanceof StatementAssignment) { - StatementAssignment assignment = (StatementAssignment) statement; - referenced.addAll(getReferenced(assignment.getlValue())); - referenced.addAll(getReferenced(assignment.getrValue1())); - referenced.addAll(getReferenced(assignment.getrValue2())); - } else if(statement instanceof StatementConditionalJump) { - StatementConditionalJump conditionalJump = (StatementConditionalJump) statement; - referenced.addAll(getReferenced(conditionalJump.getrValue1())); - referenced.addAll(getReferenced(conditionalJump.getrValue2())); - } else if(statement instanceof StatementCall) { - StatementCall call = (StatementCall) statement; - referenced.addAll(getReferenced(call.getlValue())); - if(call.getParameters() != null) { - for(RValue param : call.getParameters()) { - referenced.addAll(getReferenced(param)); - } - } - } else if(statement instanceof StatementReturn) { - StatementReturn statementReturn = (StatementReturn) statement; - referenced.addAll(getReferenced(statementReturn.getValue())); - } else if(statement instanceof StatementAsm) { - // No references in ASM atm. - } else if(statement instanceof StatementKickAsm) { - // No references in ASM atm. - } else { - throw new RuntimeException("Unknown statement type " + statement); - } + , null, null); return referenced; } diff --git a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.asm b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.asm index 25765fb26..95f19bc0a 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.asm +++ b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.asm @@ -1,7 +1,7 @@ .pc = $801 "Basic" :BasicUpstart(main) .pc = $80d "Program" - .const ITEM_COUNT = 2 + .const ITEM_COUNT = 3 .const ITEM_SIZE = 5 jsr main main: { @@ -37,4 +37,4 @@ main: { bne b1 rts } - items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 diff --git a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.cfg b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.cfg index 9df706ca2..e6f78ebed 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.cfg +++ b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.cfg @@ -11,7 +11,7 @@ main: scope:[main] from @1 [4] phi() [ ] ( main:2 [ ] ) to:main::@1 main::@1: scope:[main] from main main::@3 - [5] (byte*) main::cur_item#4 ← phi( main/(const byte[$0]) items#0 main::@3/(byte*) main::cur_item#1 ) [ main::item#4 main::cur_item#4 ] ( main:2 [ main::item#4 main::cur_item#4 ] ) + [5] (byte*) main::cur_item#4 ← phi( main/(const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 main::@3/(byte*) main::cur_item#1 ) [ main::item#4 main::cur_item#4 ] ( main:2 [ main::item#4 main::cur_item#4 ] ) [5] (byte) main::item#4 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::item#1 ) [ main::item#4 main::cur_item#4 ] ( main:2 [ main::item#4 main::cur_item#4 ] ) to:main::@2 main::@2: scope:[main] from main::@1 main::@2 diff --git a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.log b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.log index d1a706fd0..44dc34a1c 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.log +++ b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.log @@ -1,10 +1,10 @@ PARSING src/test/java/dk/camelot64/kickc/test/kc/array-length-symbolic.kc // Illustrates symbolic array lengths -byte ITEM_COUNT = 2; +byte ITEM_COUNT = 3; byte ITEM_SIZE = 5; -byte[ITEM_COUNT*ITEM_SIZE] items = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +byte[ITEM_COUNT*ITEM_SIZE] items = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Fills the array item by item with $is, where i is the item# and s is the sub# void main() { @@ -42,10 +42,10 @@ SYMBOLS INITIAL CONTROL FLOW GRAPH @begin: scope:[] from - (byte) ITEM_COUNT ← (byte/signed byte/word/signed word/dword/signed dword) 2 + (byte) ITEM_COUNT ← (byte/signed byte/word/signed word/dword/signed dword) 3 (byte) ITEM_SIZE ← (byte/signed byte/word/signed word/dword/signed dword) 5 (byte~) $0 ← (byte) ITEM_COUNT * (byte) ITEM_SIZE - (byte[$0]) items ← { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } + (byte[$0]) items ← { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } to:@1 main: scope:[main] from (byte*) main::cur_item ← (byte[$0]) items @@ -80,7 +80,6 @@ main::@return: scope:[main] from main::@4 to:@end @end: scope:[] from @1 -Eliminating unused variable (byte~) $0 and assignment [2] (byte~) $0 ← (byte) ITEM_COUNT * (byte) ITEM_SIZE Removing empty block main::@4 PROCEDURE MODIFY VARIABLE ANALYSIS @@ -90,9 +89,10 @@ Completing Phi functions... CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN @begin: scope:[] from - (byte) ITEM_COUNT#0 ← (byte/signed byte/word/signed word/dword/signed dword) 2 + (byte) ITEM_COUNT#0 ← (byte/signed byte/word/signed word/dword/signed dword) 3 (byte) ITEM_SIZE#0 ← (byte/signed byte/word/signed word/dword/signed dword) 5 - (byte[$0]) items#0 ← { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } + (byte~) $0 ← (byte) ITEM_COUNT#0 * (byte) ITEM_SIZE#0 + (byte[$0]) items#0 ← { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } to:@1 main: scope:[main] from @1 (byte) ITEM_SIZE#3 ← phi( @1/(byte) ITEM_SIZE#5 ) @@ -142,6 +142,7 @@ main::@return: scope:[main] from main::@3 @end: scope:[] from @2 SYMBOL TABLE SSA +(byte~) $0 (label) @1 (label) @2 (label) @begin @@ -215,13 +216,14 @@ Succesful SSA optimization Pass2RedundantPhiElimination Simple Condition (bool~) main::$4 if((byte) main::sub#1!=rangelast(0,main::$1)) goto main::@2 Simple Condition (bool~) main::$5 if((byte) main::item#1!=rangelast(0,main::$0)) goto main::@1 Succesful SSA optimization Pass2ConditionalJumpSimplification -Constant (const byte) ITEM_COUNT#0 = 2 +Constant (const byte) ITEM_COUNT#0 = 3 Constant (const byte) ITEM_SIZE#0 = 5 -Constant (const byte[$0]) items#0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } +Constant (const byte[$0]) items#0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } Constant (const byte) main::item#0 = 0 Constant (const byte) main::sub#0 = 0 Succesful SSA optimization Pass2ConstantIdentification -Constant (const byte[$0]) main::cur_item#0 = items#0 +Constant (const byte) $0 = ITEM_COUNT#0*ITEM_SIZE#0 +Constant (const byte*) main::cur_item#0 = items#0 Constant (const byte/signed word/word/dword/signed dword) main::$0 = ITEM_COUNT#0-1 Succesful SSA optimization Pass2ConstantIdentification Resolved ranged next value main::item#1 ← ++ main::item#4 to ++ @@ -239,11 +241,12 @@ Inlining constant with var siblings (const byte) main::item#0 Inlining constant with var siblings (const byte) main::item#0 Inlining constant with var siblings (const byte) main::sub#0 Inlining constant with var siblings (const byte) main::sub#0 -Inlining constant with var siblings (const byte[$0]) main::cur_item#0 -Inlining constant with var siblings (const byte[$0]) main::cur_item#0 +Inlining constant with var siblings (const byte*) main::cur_item#0 +Inlining constant with var siblings (const byte*) main::cur_item#0 Constant inlined main::sub#0 = (byte/signed byte/word/signed word/dword/signed dword) 0 Constant inlined main::$1 = (const byte) ITEM_SIZE#0-(byte/signed byte/word/signed word/dword/signed dword) 1 -Constant inlined main::cur_item#0 = (const byte[$0]) items#0 +Constant inlined $0 = (const byte) ITEM_COUNT#0*(const byte) ITEM_SIZE#0 +Constant inlined main::cur_item#0 = (const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 Constant inlined main::$0 = (const byte) ITEM_COUNT#0-(byte/signed byte/word/signed word/dword/signed dword) 1 Constant inlined main::item#0 = (byte/signed byte/word/signed word/dword/signed dword) 0 Succesful SSA optimization Pass2ConstantInlining @@ -298,7 +301,7 @@ main: scope:[main] from @1 [4] phi() [ ] ( main:2 [ ] ) to:main::@1 main::@1: scope:[main] from main main::@3 - [5] (byte*) main::cur_item#4 ← phi( main/(const byte[$0]) items#0 main::@3/(byte*) main::cur_item#1 ) [ main::item#4 main::cur_item#4 ] ( main:2 [ main::item#4 main::cur_item#4 ] ) + [5] (byte*) main::cur_item#4 ← phi( main/(const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 main::@3/(byte*) main::cur_item#1 ) [ main::item#4 main::cur_item#4 ] ( main:2 [ main::item#4 main::cur_item#4 ] ) [5] (byte) main::item#4 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::item#1 ) [ main::item#4 main::cur_item#4 ] ( main:2 [ main::item#4 main::cur_item#4 ] ) to:main::@2 main::@2: scope:[main] from main::@1 main::@2 @@ -348,7 +351,7 @@ Loop head: main::@1 tails: main::@3 blocks: main::@3 main::@2 main::@1 depth: 1 VARIABLE REGISTER WEIGHTS (byte) ITEM_COUNT (byte) ITEM_SIZE -(byte[$0]) items +(byte[ITEM_COUNT#0*ITEM_SIZE#0]) items (void()) main() (byte~) main::$2 202.0 (byte~) main::$3 202.0 @@ -386,7 +389,7 @@ INITIAL ASM :BasicUpstart(main) .pc = $80d "Program" //SEG1 Global Constants & labels - .const ITEM_COUNT = 2 + .const ITEM_COUNT = 3 .const ITEM_SIZE = 5 //SEG2 @begin bbegin: @@ -413,7 +416,7 @@ main: { .label item = 2 //SEG10 [5] phi from main to main::@1 [phi:main->main::@1] b1_from_main: - //SEG11 [5] phi (byte*) main::cur_item#4 = (const byte[$0]) items#0 [phi:main->main::@1#0] -- pbuz1=pbuc1 + //SEG11 [5] phi (byte*) main::cur_item#4 = (const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 [phi:main->main::@1#0] -- pbuz1=pbuc1 lda #items @@ -485,7 +488,7 @@ main: { //SEG32 [15] return [ ] ( main:2 [ ] ) rts } - items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 REGISTER UPLIFT POTENTIAL REGISTERS Statement [7] (byte~) main::$2 ← (byte) main::item#4 << (byte/signed byte/word/signed word/dword/signed dword) 4 [ main::item#4 main::cur_item#4 main::sub#2 main::$2 ] ( main:2 [ main::item#4 main::cur_item#4 main::sub#2 main::$2 ] ) always clobbers reg byte a @@ -515,7 +518,7 @@ ASSEMBLER BEFORE OPTIMIZATION :BasicUpstart(main) .pc = $80d "Program" //SEG1 Global Constants & labels - .const ITEM_COUNT = 2 + .const ITEM_COUNT = 3 .const ITEM_SIZE = 5 //SEG2 @begin bbegin: @@ -538,7 +541,7 @@ main: { .label cur_item = 2 //SEG10 [5] phi from main to main::@1 [phi:main->main::@1] b1_from_main: - //SEG11 [5] phi (byte*) main::cur_item#4 = (const byte[$0]) items#0 [phi:main->main::@1#0] -- pbuz1=pbuc1 + //SEG11 [5] phi (byte*) main::cur_item#4 = (const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 [phi:main->main::@1#0] -- pbuz1=pbuc1 lda #items @@ -602,7 +605,7 @@ main: { //SEG32 [15] return [ ] ( main:2 [ ] ) rts } - items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ASSEMBLER OPTIMIZATIONS Removing instruction jmp b1 @@ -637,11 +640,11 @@ FINAL SYMBOL TABLE (label) @begin (label) @end (byte) ITEM_COUNT -(const byte) ITEM_COUNT#0 ITEM_COUNT = (byte/signed byte/word/signed word/dword/signed dword) 2 +(const byte) ITEM_COUNT#0 ITEM_COUNT = (byte/signed byte/word/signed word/dword/signed dword) 3 (byte) ITEM_SIZE (const byte) ITEM_SIZE#0 ITEM_SIZE = (byte/signed byte/word/signed word/dword/signed dword) 5 -(byte[$0]) items -(const byte[$0]) items#0 items = { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } +(byte[ITEM_COUNT#0*ITEM_SIZE#0]) items +(const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 items = { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } (void()) main() (byte~) main::$2 reg byte a 202.0 (byte~) main::$3 reg byte a 202.0 @@ -674,7 +677,7 @@ Score: 3422 :BasicUpstart(main) .pc = $80d "Program" //SEG1 Global Constants & labels - .const ITEM_COUNT = 2 + .const ITEM_COUNT = 3 .const ITEM_SIZE = 5 //SEG2 @begin //SEG3 [1] phi from @begin to @1 [phi:@begin->@1] @@ -688,7 +691,7 @@ Score: 3422 main: { .label cur_item = 2 //SEG10 [5] phi from main to main::@1 [phi:main->main::@1] - //SEG11 [5] phi (byte*) main::cur_item#4 = (const byte[$0]) items#0 [phi:main->main::@1#0] -- pbuz1=pbuc1 + //SEG11 [5] phi (byte*) main::cur_item#4 = (const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 [phi:main->main::@1#0] -- pbuz1=pbuc1 lda #items @@ -741,5 +744,5 @@ main: { //SEG32 [15] return [ ] ( main:2 [ ] ) rts } - items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + items: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 diff --git a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.sym b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.sym index a8e9bcdf4..6d7b4a04d 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.sym +++ b/src/test/java/dk/camelot64/kickc/test/ref/array-length-symbolic.sym @@ -2,11 +2,11 @@ (label) @begin (label) @end (byte) ITEM_COUNT -(const byte) ITEM_COUNT#0 ITEM_COUNT = (byte/signed byte/word/signed word/dword/signed dword) 2 +(const byte) ITEM_COUNT#0 ITEM_COUNT = (byte/signed byte/word/signed word/dword/signed dword) 3 (byte) ITEM_SIZE (const byte) ITEM_SIZE#0 ITEM_SIZE = (byte/signed byte/word/signed word/dword/signed dword) 5 -(byte[$0]) items -(const byte[$0]) items#0 items = { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } +(byte[ITEM_COUNT#0*ITEM_SIZE#0]) items +(const byte[ITEM_COUNT#0*ITEM_SIZE#0]) items#0 items = { (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 0 } (void()) main() (byte~) main::$2 reg byte a 202.0 (byte~) main::$3 reg byte a 202.0 diff --git a/src/test/java/dk/camelot64/kickc/test/ref/bresenham.cfg b/src/test/java/dk/camelot64/kickc/test/ref/bresenham.cfg index 0b50a5fbc..174105715 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/bresenham.cfg +++ b/src/test/java/dk/camelot64/kickc/test/ref/bresenham.cfg @@ -14,7 +14,7 @@ main::@1: scope:[main] from main main::@2 [5] (byte) main::y#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte) main::y#4 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [5] (byte) main::e#3 ← phi( main/(const byte) main::yd#0/(byte/signed byte/word/signed word/dword/signed dword) 2 main::@2/(byte) main::e#5 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [5] (byte) main::x#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte) main::x#1 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) - [5] (byte*) main::cursor#3 ← phi( main/(const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte*) main::cursor#5 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) + [5] (byte*) main::cursor#3 ← phi( main/(const byte[40*25]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte*) main::cursor#5 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [6] *((byte*) main::cursor#3) ← (const byte) STAR#0 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [7] (byte) main::x#1 ← (byte) main::x#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::cursor#3 main::e#3 main::y#2 main::x#1 ] ( main:2 [ main::cursor#3 main::e#3 main::y#2 main::x#1 ] ) [8] (byte*) main::cursor#1 ← (byte*) main::cursor#3 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::e#3 main::y#2 main::x#1 main::cursor#1 ] ( main:2 [ main::e#3 main::y#2 main::x#1 main::cursor#1 ] ) diff --git a/src/test/java/dk/camelot64/kickc/test/ref/bresenham.log b/src/test/java/dk/camelot64/kickc/test/ref/bresenham.log index 705f161ce..7521dc574 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/bresenham.log +++ b/src/test/java/dk/camelot64/kickc/test/ref/bresenham.log @@ -125,7 +125,6 @@ main::@return: scope:[main] from main::@4 to:@end @end: scope:[] from @1 -Eliminating unused variable (word/signed word/dword/signed dword~) $0 and assignment [1] (word/signed word/dword/signed dword~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 40 * (byte/signed byte/word/signed word/dword/signed dword) 25 Removing empty block main::@4 PROCEDURE MODIFY VARIABLE ANALYSIS @@ -136,6 +135,7 @@ Completing Phi functions... CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN @begin: scope:[] from (byte) STAR#0 ← (byte/signed byte/word/signed word/dword/signed dword) 81 + (word/signed word/dword/signed dword~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 40 * (byte/signed byte/word/signed word/dword/signed dword) 25 (byte[$0]) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024 to:@1 main: scope:[main] from @1 @@ -218,6 +218,7 @@ main::@return: scope:[main] from main::@2 @end: scope:[] from @2 SYMBOL TABLE SSA +(word/signed word/dword/signed dword~) $0 (label) @1 (label) @2 (label) @begin @@ -348,7 +349,8 @@ Simple Condition (bool~) main::$10 if((byte) main::xd#0>(byte) main::e#1) goto m Simple Condition (bool~) main::$15 if((byte) main::x#1<(byte/signed word/word/dword/signed dword~) main::$14) goto main::@1 Succesful SSA optimization Pass2ConditionalJumpSimplification Constant (const byte) STAR#0 = 81 -Constant (const byte*) SCREEN#0 = ((byte*))1024 +Constant (const word/signed word/dword/signed dword) $0 = 40*25 +Constant (const byte[$0]) SCREEN#0 = ((byte*))1024 Constant (const byte) main::x#0 = 4 Constant (const byte) main::y#0 = 4 Constant (const byte) main::x1#0 = 39 @@ -356,7 +358,7 @@ Constant (const byte) main::y1#0 = 24 Succesful SSA optimization Pass2ConstantIdentification Constant (const byte) main::xd#0 = main::x1#0-main::x#0 Constant (const byte) main::yd#0 = main::y1#0-main::y#0 -Constant (const byte/word/signed word/dword/signed dword) main::$3 = main::y#0*40 +Constant (const byte/signed word/word/dword/signed dword) main::$3 = main::y#0*40 Constant (const byte/signed word/word/dword/signed dword) main::$14 = main::x1#0+1 Succesful SSA optimization Pass2ConstantIdentification Constant (const byte) main::e#0 = main::yd#0/2 @@ -378,12 +380,13 @@ Inlining constant with var siblings (const byte*) main::cursor#0 Inlining constant with var siblings (const byte*) main::cursor#0 Inlining constant with var siblings (const byte*) main::cursor#0 Inlining constant with var siblings (const byte*) main::cursor#0 -Constant inlined main::cursor#0 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 +Constant inlined main::cursor#0 = (const byte[40*25]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 Constant inlined main::$3 = (byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40 Constant inlined main::$14 = (const byte) main::x1#0+(byte/signed byte/word/signed word/dword/signed dword) 1 Constant inlined main::x#0 = (byte/signed byte/word/signed word/dword/signed dword) 4 -Constant inlined main::$4 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40 +Constant inlined main::$4 = (const byte[40*25]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40 Constant inlined main::y#0 = (byte/signed byte/word/signed word/dword/signed dword) 4 +Constant inlined $0 = (byte/signed byte/word/signed word/dword/signed dword) 40*(byte/signed byte/word/signed word/dword/signed dword) 25 Constant inlined main::e#0 = (const byte) main::yd#0/(byte/signed byte/word/signed word/dword/signed dword) 2 Succesful SSA optimization Pass2ConstantInlining Block Sequence Planned @begin @1 @end main main::@1 main::@3 main::@2 main::@return @@ -449,7 +452,7 @@ main::@1: scope:[main] from main main::@2 [5] (byte) main::y#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte) main::y#4 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [5] (byte) main::e#3 ← phi( main/(const byte) main::yd#0/(byte/signed byte/word/signed word/dword/signed dword) 2 main::@2/(byte) main::e#5 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [5] (byte) main::x#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte) main::x#1 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) - [5] (byte*) main::cursor#3 ← phi( main/(const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte*) main::cursor#5 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) + [5] (byte*) main::cursor#3 ← phi( main/(const byte[40*25]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte*) main::cursor#5 ) [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [6] *((byte*) main::cursor#3) ← (const byte) STAR#0 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::cursor#3 main::x#2 main::e#3 main::y#2 ] ) [7] (byte) main::x#1 ← (byte) main::x#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::cursor#3 main::e#3 main::y#2 main::x#1 ] ( main:2 [ main::cursor#3 main::e#3 main::y#2 main::x#1 ] ) [8] (byte*) main::cursor#1 ← (byte*) main::cursor#3 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::e#3 main::y#2 main::x#1 main::cursor#1 ] ( main:2 [ main::e#3 main::y#2 main::x#1 main::cursor#1 ] ) @@ -494,7 +497,7 @@ Loop head: main::@1 tails: main::@2 blocks: main::@2 main::@1 main::@3 depth: 1 VARIABLE REGISTER WEIGHTS -(byte[$0]) SCREEN +(byte[40*25]) SCREEN (byte) STAR (void()) main() (byte*) main::cursor @@ -581,7 +584,7 @@ main: { //SEG13 [5] phi (byte) main::x#2 = (byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#2] -- vbuz1=vbuc1 lda #4 sta x - //SEG14 [5] phi (byte*) main::cursor#3 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#3] -- pbuz1=pbuc1 + //SEG14 [5] phi (byte*) main::cursor#3 = (const byte[40*25]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#3] -- pbuz1=pbuc1 lda #SCREEN+4*$28+4 @@ -729,7 +732,7 @@ main: { //SEG13 [5] phi (byte) main::x#2 = (byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#2] -- vbuz1=vbuc1 lda #4 sta x - //SEG14 [5] phi (byte*) main::cursor#3 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#3] -- pbuz1=pbuc1 + //SEG14 [5] phi (byte*) main::cursor#3 = (const byte[40*25]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#3] -- pbuz1=pbuc1 lda #SCREEN+4*$28+4 @@ -834,8 +837,8 @@ FINAL SYMBOL TABLE (label) @1 (label) @begin (label) @end -(byte[$0]) SCREEN -(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024 +(byte[40*25]) SCREEN +(const byte[40*25]) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024 (byte) STAR (const byte) STAR#0 STAR = (byte/signed byte/word/signed word/dword/signed dword) 81 (void()) main() @@ -912,7 +915,7 @@ main: { ldx #yd/2 //SEG13 [5] phi (byte) main::x#2 = (byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#2] -- vbuz1=vbuc1 sta x - //SEG14 [5] phi (byte*) main::cursor#3 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#3] -- pbuz1=pbuc1 + //SEG14 [5] phi (byte*) main::cursor#3 = (const byte[40*25]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 4*(byte/signed byte/word/signed word/dword/signed dword) 40+(byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main->main::@1#3] -- pbuz1=pbuc1 lda #SCREEN+4*$28+4 diff --git a/src/test/java/dk/camelot64/kickc/test/ref/bresenham.sym b/src/test/java/dk/camelot64/kickc/test/ref/bresenham.sym index 7023d2c24..5ec99ec96 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/bresenham.sym +++ b/src/test/java/dk/camelot64/kickc/test/ref/bresenham.sym @@ -1,8 +1,8 @@ (label) @1 (label) @begin (label) @end -(byte[$0]) SCREEN -(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024 +(byte[40*25]) SCREEN +(const byte[40*25]) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024 (byte) STAR (const byte) STAR#0 STAR = (byte/signed byte/word/signed word/dword/signed dword) 81 (void()) main() diff --git a/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.cfg b/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.cfg index 0cc190f39..98390ed16 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.cfg +++ b/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.cfg @@ -15,7 +15,7 @@ main::@1: scope:[main] from main main::@2 [5] (byte) main::e#3 ← phi( main/(const byte) main::yd#0/(byte/signed byte/word/signed word/dword/signed dword) 2 main::@2/(byte) main::e#5 ) [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) [5] (byte) main::x#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@2/(byte) main::x#1 ) [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) [5] (word) main::idx#3 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0+(byte/signed byte/word/signed word/dword/signed dword) 0*(byte/signed byte/word/signed word/dword/signed dword) 40 main::@2/(word) main::idx#5 ) [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) - [6] *((const byte*) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) + [6] *((const byte[40*25]) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) [7] (byte) main::x#1 ← (byte) main::x#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::idx#3 main::e#3 main::y#2 main::x#1 ] ( main:2 [ main::idx#3 main::e#3 main::y#2 main::x#1 ] ) [8] (word) main::idx#1 ← (word) main::idx#3 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::e#3 main::y#2 main::x#1 main::idx#1 ] ( main:2 [ main::e#3 main::y#2 main::x#1 main::idx#1 ] ) [9] (byte) main::e#1 ← (byte) main::e#3 + (const byte) main::yd#0 [ main::y#2 main::x#1 main::idx#1 main::e#1 ] ( main:2 [ main::y#2 main::x#1 main::idx#1 main::e#1 ] ) diff --git a/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.log b/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.log index 95daa5c0e..492879beb 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.log +++ b/src/test/java/dk/camelot64/kickc/test/ref/bresenhamarr.log @@ -123,7 +123,6 @@ main::@return: scope:[main] from main::@4 to:@end @end: scope:[] from @1 -Eliminating unused variable (word/signed word/dword/signed dword~) main::$0 and assignment [1] (word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 40 * (byte/signed byte/word/signed word/dword/signed dword) 25 Removing empty block main::@4 PROCEDURE MODIFY VARIABLE ANALYSIS @@ -136,6 +135,7 @@ CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN to:@1 main: scope:[main] from @1 (byte) main::STAR#0 ← (byte/signed byte/word/signed word/dword/signed dword) 81 + (word/signed word/dword/signed dword~) main::$0 ← (byte/signed byte/word/signed word/dword/signed dword) 40 * (byte/signed byte/word/signed word/dword/signed dword) 25 (byte[main::$0]) main::screen#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024 (byte) main::x0#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 (byte) main::y0#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 @@ -218,6 +218,7 @@ SYMBOL TABLE SSA (label) @begin (label) @end (void()) main() +(word/signed word/dword/signed dword~) main::$0 (byte~) main::$1 (bool~) main::$10 (byte/signed word/word/dword/signed dword~) main::$11 @@ -335,7 +336,8 @@ Simple Condition (bool~) main::$10 if((byte) main::xd#0>=(byte) main::e#1) goto Simple Condition (bool~) main::$15 if((byte) main::x#1<(byte/signed word/word/dword/signed dword~) main::$14) goto main::@1 Succesful SSA optimization Pass2ConditionalJumpSimplification Constant (const byte) main::STAR#0 = 81 -Constant (const byte*) main::screen#0 = ((byte*))1024 +Constant (const word/signed word/dword/signed dword) main::$0 = 40*25 +Constant (const byte[main::$0]) main::screen#0 = ((byte*))1024 Constant (const byte) main::x#0 = 0 Constant (const byte) main::y#0 = 0 Constant (const byte) main::x1#0 = 39 @@ -364,6 +366,7 @@ Inlining constant with var siblings (const word) main::idx#0 Inlining constant with var siblings (const word) main::idx#0 Inlining constant with var siblings (const word) main::idx#0 Constant inlined main::idx#0 = (byte/signed byte/word/signed word/dword/signed dword) 0+(byte/signed byte/word/signed word/dword/signed dword) 0*(byte/signed byte/word/signed word/dword/signed dword) 40 +Constant inlined main::$0 = (byte/signed byte/word/signed word/dword/signed dword) 40*(byte/signed byte/word/signed word/dword/signed dword) 25 Constant inlined main::$14 = (const byte) main::x1#0+(byte/signed byte/word/signed word/dword/signed dword) 1 Constant inlined main::x#0 = (byte/signed byte/word/signed word/dword/signed dword) 0 Constant inlined main::$4 = (byte/signed byte/word/signed word/dword/signed dword) 0*(byte/signed byte/word/signed word/dword/signed dword) 40 @@ -434,7 +437,7 @@ main::@1: scope:[main] from main main::@2 [5] (byte) main::e#3 ← phi( main/(const byte) main::yd#0/(byte/signed byte/word/signed word/dword/signed dword) 2 main::@2/(byte) main::e#5 ) [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) [5] (byte) main::x#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@2/(byte) main::x#1 ) [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) [5] (word) main::idx#3 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0+(byte/signed byte/word/signed word/dword/signed dword) 0*(byte/signed byte/word/signed word/dword/signed dword) 40 main::@2/(word) main::idx#5 ) [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) - [6] *((const byte*) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) + [6] *((const byte[40*25]) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) [7] (byte) main::x#1 ← (byte) main::x#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::idx#3 main::e#3 main::y#2 main::x#1 ] ( main:2 [ main::idx#3 main::e#3 main::y#2 main::x#1 ] ) [8] (word) main::idx#1 ← (word) main::idx#3 + (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::e#3 main::y#2 main::x#1 main::idx#1 ] ( main:2 [ main::e#3 main::y#2 main::x#1 main::idx#1 ] ) [9] (byte) main::e#1 ← (byte) main::e#3 + (const byte) main::yd#0 [ main::y#2 main::x#1 main::idx#1 main::e#1 ] ( main:2 [ main::y#2 main::x#1 main::idx#1 main::e#1 ] ) @@ -490,7 +493,7 @@ VARIABLE REGISTER WEIGHTS (word) main::idx#2 11.0 (word) main::idx#3 11.0 (word) main::idx#5 16.5 -(byte[main::$0]) main::screen +(byte[40*25]) main::screen (byte) main::x (byte) main::x#1 3.666666666666667 (byte) main::x#2 11.0 @@ -580,7 +583,7 @@ main: { jmp b1 //SEG20 main::@1 b1: - //SEG21 [6] *((const byte*) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) -- pbuc1_derefidx_vwuz1=vbuc2 + //SEG21 [6] *((const byte[40*25]) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) -- pbuc1_derefidx_vwuz1=vbuc2 lda #main::@1#3] -- register_copy //SEG20 main::@1 b1: - //SEG21 [6] *((const byte*) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) -- pbuc1_derefidx_vwuz1=vbuc2 + //SEG21 [6] *((const byte[40*25]) main::screen#0 + (word) main::idx#3) ← (const byte) main::STAR#0 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ( main:2 [ main::idx#3 main::x#2 main::e#3 main::y#2 ] ) -- pbuc1_derefidx_vwuz1=vbuc2 lda #