1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-13 18:30:21 +00:00

Working on improvements regarding global initializers and unnecessary unwinding of constant structs. Moved most unwinding to separate package.

This commit is contained in:
jespergravgaard 2020-01-07 08:28:57 +01:00
parent 4eaa0c5385
commit 26be14f7ee
31 changed files with 2 additions and 107 deletions

View File

@ -245,7 +245,6 @@ public class Compiler {
program.setGraph(new Pass1ProcedureCallsReturnValue(program).generate());
new PassNUnwindLValueLists(program).execute();
new Pass1UnwindStructVersions(program).execute();
getLog().append("\nCONTROL FLOW GRAPH SSA");
getLog().append(program.getGraph().toString(program));

View File

@ -89,7 +89,7 @@ public class StructUnwinding {
@Override
public boolean isBulkCopyable() {
return getArraySpec()!=null || getSymbolType() instanceof SymbolTypeStruct;
return getArraySpec()!=null;
}
@Override

View File

@ -1,60 +0,0 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.ControlFlowBlock;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.StructUnwinding;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.symbols.StructDefinition;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
import dk.camelot64.kickc.model.values.RValue;
import dk.camelot64.kickc.model.values.StructUnwoundPlaceholder;
import dk.camelot64.kickc.model.values.VariableRef;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/** Find the versioned unwound structs - and update the StructUnwinding data structure */
public class Pass1UnwindStructVersions extends Pass1Base {
public Pass1UnwindStructVersions(Program program) {
super(program);
}
@Override
public boolean step() {
boolean modified = false;
StructUnwinding structUnwinding = getProgram().getStructUnwinding();
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
for(Statement statement : block.getStatements()) {
if(statement instanceof StatementAssignment) {
StatementAssignment assignment = (StatementAssignment) statement;
if(assignment.getOperator() == null && assignment.getlValue() instanceof VariableRef && assignment.getrValue2() instanceof StructUnwoundPlaceholder) {
VariableRef structVarRef = (VariableRef) assignment.getlValue();
if(structUnwinding.getVariableUnwinding(structVarRef) == null) {
StructUnwoundPlaceholder placeholder = (StructUnwoundPlaceholder) assignment.getrValue2();
SymbolTypeStruct typeStruct = placeholder.getTypeStruct();
StructDefinition structDefinition = typeStruct.getStructDefinition(getProgram().getScope());
StructUnwinding.VariableUnwinding versionedUnwinding = structUnwinding.createVariableUnwinding(structVarRef, structDefinition);
Collection<Variable> members = structDefinition.getAllVariables(false);
Iterator<Variable> memberDefIt = members.iterator();
List<RValue> unwoundMembers = placeholder.getUnwoundMembers();
Iterator<RValue> memberUnwoundIt = unwoundMembers.iterator();
while(memberDefIt.hasNext()) {
Variable memberVar = memberDefIt.next();
RValue memberVal = memberUnwoundIt.next();
versionedUnwinding.setMemberUnwinding(memberVar.getLocalName(), memberVal);
}
getLog().append("Adding versioned struct unwinding for "+assignment.getlValue().toString(getProgram()));
modified = true;
}
}
}
}
}
return modified;
}
}

View File

@ -1199,7 +1199,7 @@ public class TestPrograms {
@Test
public void testStruct17() throws IOException, URISyntaxException {
compileAndCompare("struct-17", log());
compileAndCompare("struct-17");
}
@Test

View File

@ -191,8 +191,6 @@ Culled Empty Block (label) @35
Culled Empty Block (label) @36
Unwinding list assignment { (byte~) main::$5_x, (byte~) main::$5_y, (byte~) main::$5_dist } ← { (byte) getCharToProcess::return_x, (byte) getCharToProcess::return_y, (byte) getCharToProcess::return_dist }
Unwinding list assignment { (byte) getCharToProcess::return_x#0, (byte) getCharToProcess::return_y#0, (byte) getCharToProcess::return_dist#0 } ← { (byte) getCharToProcess::return_x#2, (byte) getCharToProcess::return_y#2, (byte) getCharToProcess::return_dist#2 }
Adding versioned struct unwinding for (struct ProcessingChar) getCharToProcess::return#0
Adding versioned struct unwinding for (struct ProcessingChar) getCharToProcess::return#1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -504,8 +504,6 @@ Unwinding list assignment { (signed word~) show_letter::$2_x, (signed word~) sho
Unwinding list assignment { (signed word~) show_letter::$7_x, (signed word~) show_letter::$7_y } ← { (signed word) rotate::return_x, (signed word) rotate::return_y }
Unwinding list assignment { (signed word) rotate::return_x#0, (signed word) rotate::return_y#0 } ← { (signed word) rotate::return_x#3, (signed word) rotate::return_y#3 }
Unwinding list assignment { (signed word) rotate::return_x#1, (signed word) rotate::return_y#1 } ← { (signed word) rotate::return_x#3, (signed word) rotate::return_y#3 }
Adding versioned struct unwinding for (struct SplineVector16) rotate::return#0
Adding versioned struct unwinding for (struct SplineVector16) rotate::return#1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -4,7 +4,6 @@ Adding struct value member variable copy *((byte*)&(struct foo) bar+(const byte)
Rewriting struct pointer member access *((struct foo*) main::barp).thing1
Rewriting struct pointer member access *((struct foo*) main::barp).thing2
Identified constant variable (struct foo*) main::barp
Adding versioned struct unwinding for (struct foo) bar
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -11,7 +11,6 @@ Rewriting struct pointer member access *((struct foo*) main::barp).thing2
Rewriting struct pointer member access *((struct foo*) main::barp).thing3
Identified constant variable (struct foo*) main::barp
Culled Empty Block (label) main::@2
Adding versioned struct unwinding for (struct foo) bar
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -2,7 +2,6 @@ Adding struct value member variable copy *((byte*)&(struct foo) bar+(const byte)
Adding struct value member variable copy *((byte*)&(struct foo) bar+(const byte) OFFSET_STRUCT_FOO_THING2) ← (byte) 'b'
Replacing struct member reference (struct foo) bar.thing1 with member unwinding reference *((byte*)&(struct foo) bar+(const byte) OFFSET_STRUCT_FOO_THING1)
Replacing struct member reference (struct foo) bar.thing2 with member unwinding reference *((byte*)&(struct foo) bar+(const byte) OFFSET_STRUCT_FOO_THING2)
Adding versioned struct unwinding for (struct foo) bar
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -5,7 +5,6 @@ Adding struct value member variable copy (byte) aa_b ← (byte) 1
Rewriting struct pointer member access *((struct A*) main::a).b
Warning! Adding boolean cast to non-boolean sub-expression *((byte*~) main::$2)
Identified constant variable (struct A*) main::a
Adding versioned struct unwinding for (struct A) aa#0
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -4,7 +4,6 @@ Replacing struct member reference (struct Point) point.x with member unwinding r
Replacing struct member reference (struct Point) point.y with member unwinding reference *((byte*)&(struct Point) point+(const byte) OFFSET_STRUCT_POINT_Y)
Replacing struct member reference (struct Point) point.x with member unwinding reference *((byte*)&(struct Point) point+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) point.y with member unwinding reference *((byte*)&(struct Point) point+(const byte) OFFSET_STRUCT_POINT_Y)
Adding versioned struct unwinding for (struct Point) point
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -6,8 +6,6 @@ Replacing struct member reference (struct Point) main::point1.x with member unwi
Replacing struct member reference (struct Point) main::point1.y with member unwinding reference *((byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_Y)
Replacing struct member reference (struct Point) main::point2.x with member unwinding reference *((byte*)&(struct Point) main::point2+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) main::point2.y with member unwinding reference *((byte*)&(struct Point) main::point2+(const byte) OFFSET_STRUCT_POINT_Y)
Adding versioned struct unwinding for (struct Point) main::point1
Adding versioned struct unwinding for (struct Point) main::point2
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -2,7 +2,6 @@ Adding struct value member variable copy *((byte*)&(struct Point) main::point1+(
Adding struct value member variable copy *((byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3
Replacing struct member reference (struct Point) main::point1.x with member unwinding reference *((byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) main::point1.y with member unwinding reference *((byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_Y)
Adding versioned struct unwinding for (struct Point) main::point1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -20,7 +20,6 @@ Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_P).y
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).x
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).y
Adding versioned struct unwinding for (struct Vector) main::v
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -12,7 +12,6 @@ Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_P).y
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).x
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).y
Adding versioned struct unwinding for (struct Vector) main::v
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -22,9 +22,6 @@ Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_P).y
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).x
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).y
Adding versioned struct unwinding for (struct Vector) main::v
Adding versioned struct unwinding for (struct Point) main::p1
Adding versioned struct unwinding for (struct Point) main::p2
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -16,9 +16,6 @@ Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_P).y
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).x
Rewriting struct pointer member access *((struct Point*)&(struct Vector) main::v+(const byte) OFFSET_STRUCT_VECTOR_Q).y
Adding versioned struct unwinding for (struct Point) main::p1
Adding versioned struct unwinding for (struct Point) main::p2
Adding versioned struct unwinding for (struct Vector) main::v
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -4,7 +4,6 @@ Adding struct value member variable copy *((byte*)&(struct Point) main::point1+(
Rewriting struct pointer member access *((struct Point*) main::ptr).x
Rewriting struct pointer member access *((struct Point*) main::ptr).y
Identified constant variable (struct Point*) main::ptr
Adding versioned struct unwinding for (struct Point) main::point1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -11,8 +11,6 @@ Converted procedure struct value parameter to member unwinding in call (void~) m
Replacing struct member reference (struct Point) print::p.x with member unwinding reference (byte) print::p_x
Replacing struct member reference (struct Point) print::p.y with member unwinding reference (byte) print::p_y
Culled Empty Block (label) @1
Adding versioned struct unwinding for (struct Point) main::point1
Adding versioned struct unwinding for (struct Point) main::point2
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -33,10 +33,6 @@ Unwinding list assignment { (byte~) main::$0_x, (byte~) main::$0_y } ← { (byte
Unwinding list assignment { (byte~) main::$1_x, (byte~) main::$1_y } ← { (byte) getPoint::return_x, (byte) getPoint::return_y }
Unwinding list assignment { (byte) getPoint::return_x#0, (byte) getPoint::return_y#0 } ← { (byte) getPoint::return_x#3, (byte) getPoint::return_y#3 }
Unwinding list assignment { (byte) getPoint::return_x#1, (byte) getPoint::return_y#1 } ← { (byte) getPoint::return_x#3, (byte) getPoint::return_y#3 }
Adding versioned struct unwinding for (struct Point) main::point1
Adding versioned struct unwinding for (struct Point) main::point2
Adding versioned struct unwinding for (struct Point) getPoint::return#0
Adding versioned struct unwinding for (struct Point) getPoint::return#1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -9,7 +9,6 @@ Replacing struct member reference (struct Point) main::point1.initials with memb
Replacing struct member reference (struct Point) main::point1.x with member unwinding reference *((byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) main::point1.initials with member unwinding reference (byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Replacing struct member reference (struct Point) main::point1.initials with member unwinding reference (byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Adding versioned struct unwinding for (struct Point) main::point1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -12,8 +12,6 @@ Replacing struct member reference (struct Point) main::point1.initials with memb
Replacing struct member reference (struct Point) main::point2.x with member unwinding reference *((byte*)&(struct Point) main::point2+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) main::point2.initials with member unwinding reference (byte*)&(struct Point) main::point2+(const byte) OFFSET_STRUCT_POINT_INITIALS
Replacing struct member reference (struct Point) main::point2.initials with member unwinding reference (byte*)&(struct Point) main::point2+(const byte) OFFSET_STRUCT_POINT_INITIALS
Adding versioned struct unwinding for (struct Point) main::point1
Adding versioned struct unwinding for (struct Point) main::point2
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -6,7 +6,6 @@ Adding struct value member variable copy *((byte*)&(struct Point) main::point1+(
Replacing struct member reference (struct Point) main::point1.x with member unwinding reference *((byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) main::point1.initials with member unwinding reference (byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Replacing struct member reference (struct Point) main::point1.initials with member unwinding reference (byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Adding versioned struct unwinding for (struct Point) main::point1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -6,7 +6,6 @@ Adding struct value member variable copy *((byte*)&(struct Point) main::point1+(
Replacing struct member reference (struct Point) main::point1.x with member unwinding reference *((byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) main::point1.initials with member unwinding reference (byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Replacing struct member reference (struct Point) main::point1.initials with member unwinding reference (byte*)&(struct Point) main::point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Adding versioned struct unwinding for (struct Point) main::point1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -6,7 +6,6 @@ Adding struct value member variable copy *((byte*)&(struct Point) point1+(const
Replacing struct member reference (struct Point) point1.x with member unwinding reference *((byte*)&(struct Point) point1+(const byte) OFFSET_STRUCT_POINT_X)
Replacing struct member reference (struct Point) point1.initials with member unwinding reference (byte*)&(struct Point) point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Replacing struct member reference (struct Point) point1.initials with member unwinding reference (byte*)&(struct Point) point1+(const byte) OFFSET_STRUCT_POINT_INITIALS
Adding versioned struct unwinding for (struct Point) point1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -30,8 +30,6 @@ Culled Empty Block (label) @1
Culled Empty Block (label) point::@1
Unwinding list assignment { (byte~) main::$0_x, (byte~) main::$0_y } ← { (byte) point::return_x, (byte) point::return_y }
Unwinding list assignment { (byte) point::return_x#0, (byte) point::return_y#0 } ← { (byte) point::return_x#2, (byte) point::return_y#2 }
Adding versioned struct unwinding for (struct Point) point::return#0
Adding versioned struct unwinding for (struct Point) point::return#1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -4,7 +4,6 @@ Adding struct value member variable copy *((byte*)&(struct Point) main::p+(const
Rewriting struct pointer member access *((struct Point*) main::q).x
Rewriting struct pointer member access *((struct Point*) main::q).y
Identified constant variable (struct Point*) main::q
Adding versioned struct unwinding for (struct Point) main::p
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -7,7 +7,6 @@ Rewriting struct pointer member access *((struct Point*) set::ptr).x
Rewriting struct pointer member access *((struct Point*) set::ptr).y
Identified constant variable (struct Point*) main::q
Culled Empty Block (label) @1
Adding versioned struct unwinding for (struct Point) main::p
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -40,10 +40,6 @@ Unwinding list assignment { (byte~) main::$0_x, (byte~) main::$0_y } ← { (byte
Unwinding list assignment { (byte~) main::$1_x, (byte~) main::$1_y } ← { (byte) get::return_x, (byte) get::return_y }
Unwinding list assignment { (byte) get::return_x#0, (byte) get::return_y#0 } ← { (byte) get::return_x#5, (byte) get::return_y#5 }
Unwinding list assignment { (byte) get::return_x#1, (byte) get::return_y#1 } ← { (byte) get::return_x#5, (byte) get::return_y#5 }
Adding versioned struct unwinding for (struct Point) get::return#0
Adding versioned struct unwinding for (struct Point) get::return#1
Adding versioned struct unwinding for (struct Point) get::return#2
Adding versioned struct unwinding for (struct Point) get::return#3
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -33,8 +33,6 @@ Unwinding list assignment { (byte~) main::$0_x, (byte~) main::$0_y } ← { (byte
Unwinding list assignment { (byte~) main::$1_x, (byte~) main::$1_y } ← { (byte) get::return_x, (byte) get::return_y }
Unwinding list assignment { (byte) get::return_x#0, (byte) get::return_y#0 } ← { (byte) get::return_x#3, (byte) get::return_y#3 }
Unwinding list assignment { (byte) get::return_x#1, (byte) get::return_y#1 } ← { (byte) get::return_x#3, (byte) get::return_y#3 }
Adding versioned struct unwinding for (struct Point) get::return#0
Adding versioned struct unwinding for (struct Point) get::return#1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from

View File

@ -14,7 +14,6 @@ Replacing struct member reference (struct Point) print::p.x with member unwindin
Replacing struct member reference (struct Point) print::p.y with member unwinding reference (byte) print::p_y
Identified constant variable (struct Point*) main::ptr
Culled Empty Block (label) @1
Adding versioned struct unwinding for (struct Point) main::point#0
CONTROL FLOW GRAPH SSA
@begin: scope:[] from