mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-19 15:29:48 +00:00
Implemented a less verbose statement print for uplift performance
This commit is contained in:
parent
88d765324a
commit
58500b39e0
@ -244,7 +244,7 @@ public class Compiler {
|
|||||||
new Pass4RegistersFinalize(program).allocate(true);
|
new Pass4RegistersFinalize(program).allocate(true);
|
||||||
|
|
||||||
// Initial Code generation
|
// Initial Code generation
|
||||||
new Pass4CodeGeneration(program).generate();
|
new Pass4CodeGeneration(program, true).generate();
|
||||||
new Pass4AssertNoCpuClobber(program).check();
|
new Pass4AssertNoCpuClobber(program).check();
|
||||||
program.getLog().append("INITIAL ASM");
|
program.getLog().append("INITIAL ASM");
|
||||||
program.getLog().append(program.getAsm().toString());
|
program.getLog().append(program.getAsm().toString());
|
||||||
@ -284,7 +284,7 @@ public class Compiler {
|
|||||||
public void pass5GenerateAndOptimizeAsm(Program program) {
|
public void pass5GenerateAndOptimizeAsm(Program program) {
|
||||||
|
|
||||||
// Final ASM code generation before optimization
|
// Final ASM code generation before optimization
|
||||||
new Pass4CodeGeneration(program).generate();
|
new Pass4CodeGeneration(program, true).generate();
|
||||||
new Pass4AssertNoCpuClobber(program).check();
|
new Pass4AssertNoCpuClobber(program).check();
|
||||||
|
|
||||||
List<Pass5AsmOptimization> pass5Optimizations = new ArrayList<>();
|
List<Pass5AsmOptimization> pass5Optimizations = new ArrayList<>();
|
||||||
|
@ -136,7 +136,7 @@ public class ControlFlowBlock {
|
|||||||
}
|
}
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
for (Statement statement : statements) {
|
for (Statement statement : statements) {
|
||||||
out.append(" " + statement.toString(program) + "\n");
|
out.append(" " + statement.toString(program, true) + "\n");
|
||||||
}
|
}
|
||||||
if (defaultSuccessor != null) {
|
if (defaultSuccessor != null) {
|
||||||
out.append(" to:");
|
out.append(" to:");
|
||||||
|
@ -74,5 +74,4 @@ public class LiveRangeEquivalenceClassSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|||||||
})
|
})
|
||||||
public interface Statement {
|
public interface Statement {
|
||||||
|
|
||||||
String toString(Program program);
|
String toString(Program program, boolean aliveInfo);
|
||||||
|
|
||||||
/** Set the index of the statement. Indexes are used during live range analysis. */
|
/** Set the index of the statement. Indexes are used during live range analysis. */
|
||||||
void setIndex(Integer idx);
|
void setIndex(Integer idx);
|
||||||
|
@ -14,7 +14,7 @@ public class StatementAsm extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
return "asm { "+asmLines.getText()+" }";
|
return "asm { "+asmLines.getText()+" }";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,18 +90,18 @@ public class StatementAssignment extends StatementBase implements StatementLValu
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toString(null);
|
return toString(null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
return
|
return
|
||||||
super.idxString() +
|
super.idxString() +
|
||||||
lValue.toString(program) + " ← " +
|
lValue.toString(program) + " ← " +
|
||||||
(rValue1==null?"":rValue1.toString(program)+" ") +
|
(rValue1==null?"":rValue1.toString(program)+" ") +
|
||||||
(operator==null?"":operator+" ") +
|
(operator==null?"":operator+" ") +
|
||||||
rValue2.toString(program) +
|
rValue2.toString(program) +
|
||||||
super.aliveString(program);
|
(aliveInfo?super.aliveString(program):"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,7 +41,7 @@ public abstract class StatementBase implements Statement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toString(null);
|
return toString(null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String aliveString(Program program) {
|
public String aliveString(Program program) {
|
||||||
|
@ -97,7 +97,7 @@ public class StatementCall extends StatementBase implements StatementLValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
StringBuilder res = new StringBuilder();
|
StringBuilder res = new StringBuilder();
|
||||||
res.append(super.idxString());
|
res.append(super.idxString());
|
||||||
if (lValue != null) {
|
if (lValue != null) {
|
||||||
@ -118,7 +118,9 @@ public class StatementCall extends StatementBase implements StatementLValue {
|
|||||||
if (parametersByAssignment) {
|
if (parametersByAssignment) {
|
||||||
res.append("param-assignment");
|
res.append("param-assignment");
|
||||||
}
|
}
|
||||||
res.append(super.aliveString(program));
|
if(aliveInfo) {
|
||||||
|
res.append(super.aliveString(program));
|
||||||
|
}
|
||||||
return res.toString();
|
return res.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public class StatementConditionalJump extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
out.append(super.idxString());
|
out.append(super.idxString());
|
||||||
out.append("if(");
|
out.append("if(");
|
||||||
@ -93,7 +93,9 @@ public class StatementConditionalJump extends StatementBase {
|
|||||||
out.append(rValue2.toString(program));
|
out.append(rValue2.toString(program));
|
||||||
out.append(") goto ");
|
out.append(") goto ");
|
||||||
out.append(destination.getFullName());
|
out.append(destination.getFullName());
|
||||||
out.append(super.aliveString(program));
|
if(aliveInfo) {
|
||||||
|
out.append(super.aliveString(program));
|
||||||
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ public class StatementJump extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
return super.idxString() + "goto " + destination.getFullName()+ super.aliveString(program);
|
return super.idxString() + "goto " + destination.getFullName()+ (aliveInfo?super.aliveString(program):"");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ public class StatementLabel extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
return super.idxString() + label.getFullName() + ":"+super.aliveString(program);
|
return super.idxString() + label.getFullName() + ":"+(aliveInfo?super.aliveString(program):"");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,14 +63,16 @@ public class StatementPhiBlock extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
List<PhiVariable> variables = new ArrayList<>(phiVariables);
|
List<PhiVariable> variables = new ArrayList<>(phiVariables);
|
||||||
Collections.reverse(variables);
|
Collections.reverse(variables);
|
||||||
if(phiVariables.size()==0) {
|
if(phiVariables.size()==0) {
|
||||||
s.append(super.idxString());
|
s.append(super.idxString());
|
||||||
s.append("phi()");
|
s.append("phi()");
|
||||||
s.append(super.aliveString(program));
|
if(aliveInfo) {
|
||||||
|
s.append(super.aliveString(program));
|
||||||
|
}
|
||||||
s.append("\n ");
|
s.append("\n ");
|
||||||
}
|
}
|
||||||
for (PhiVariable phiVariable : variables) {
|
for (PhiVariable phiVariable : variables) {
|
||||||
@ -85,7 +87,9 @@ public class StatementPhiBlock extends StatementBase {
|
|||||||
s.append(rValue==null?"null":rValue.toString(program));
|
s.append(rValue==null?"null":rValue.toString(program));
|
||||||
}
|
}
|
||||||
s.append(" )");
|
s.append(" )");
|
||||||
s.append(super.aliveString(program));
|
if(aliveInfo) {
|
||||||
|
s.append(super.aliveString(program));
|
||||||
|
}
|
||||||
s.append("\n ");
|
s.append("\n ");
|
||||||
}
|
}
|
||||||
if(s.length()>0) {
|
if(s.length()>0) {
|
||||||
|
@ -30,8 +30,8 @@ public class StatementProcedureBegin extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
return super.idxString() + "proc " + procedure.toString(program) + super.aliveString(program);
|
return super.idxString() + "proc " + procedure.toString(program) + (aliveInfo?super.aliveString(program):"");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class StatementProcedureEnd extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
return super.idxString() + "endproc // " + procedure.getFullName() + "()"+super.aliveString(program);
|
return super.idxString() + "endproc // " + procedure.getFullName() + "()"+(aliveInfo?super.aliveString(program):"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@ public class StatementReturn extends StatementBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Program program) {
|
public String toString(Program program, boolean aliveInfo) {
|
||||||
return super.idxString() + "return " + (value == null ? "" : value.toString(program)) + super.aliveString(program);
|
return super.idxString() + "return " + (value == null ? "" : value.toString(program)) + (aliveInfo?super.aliveString(program):"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,7 +26,7 @@ public class StatementSequence {
|
|||||||
if(!(statement instanceof StatementLabel) && !(statement instanceof StatementProcedureBegin) && !(statement instanceof StatementProcedureEnd)) {
|
if(!(statement instanceof StatementLabel) && !(statement instanceof StatementProcedureBegin) && !(statement instanceof StatementProcedureEnd)) {
|
||||||
out.append(" ");
|
out.append(" ");
|
||||||
}
|
}
|
||||||
out.append(statement.toString(program)+"\n");
|
out.append(statement.toString(program, true)+"\n");
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
@ -622,7 +622,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
for (PrePostModifier mod : modifiers) {
|
for (PrePostModifier mod : modifiers) {
|
||||||
Statement stmt = new StatementAssignment((LValue) mod.child, mod.operator, mod.child);
|
Statement stmt = new StatementAssignment((LValue) mod.child, mod.operator, mod.child);
|
||||||
parser.sequence.addStatement(stmt);
|
parser.sequence.addStatement(stmt);
|
||||||
parser.program.getLog().append("Adding pre/post-modifier "+stmt.toString(parser.program));
|
parser.program.getLog().append("Adding pre/post-modifier "+stmt.toString(parser.program, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class Pass2ConditionalJumpSimplification extends Pass2SsaOptimization {
|
|||||||
conditionalJump.setOperator(conditionAssignment.getOperator());
|
conditionalJump.setOperator(conditionAssignment.getOperator());
|
||||||
conditionalJump.setrValue2(conditionAssignment.getrValue2());
|
conditionalJump.setrValue2(conditionAssignment.getrValue2());
|
||||||
simpleConditionVars.add(conditionVar);
|
simpleConditionVars.add(conditionVar);
|
||||||
getLog().append("Simple Condition " + conditionVar.toString(getProgram()) + " " + conditionalJump.toString(getProgram()));
|
getLog().append("Simple Condition " + conditionVar.toString(getProgram()) + " " + conditionalJump.toString(getProgram(), true));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class Pass2UnaryNotSimplification extends Pass2SsaOptimization {
|
|||||||
assignment.setrValue1(tempAssignment.getrValue1());
|
assignment.setrValue1(tempAssignment.getrValue1());
|
||||||
assignment.setOperator(newOperator==null?null:Operator.getBinary(newOperator));
|
assignment.setOperator(newOperator==null?null:Operator.getBinary(newOperator));
|
||||||
assignment.setrValue2(tempAssignment.getrValue2());
|
assignment.setrValue2(tempAssignment.getrValue2());
|
||||||
getLog().append("Inversing boolean not "+assignment.toString(getProgram()) +" from "+tempAssignment.toString(getProgram()));
|
getLog().append("Inversing boolean not "+assignment.toString(getProgram(), true) +" from "+tempAssignment.toString(getProgram(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@ import dk.camelot64.kickc.fragment.AsmFragment;
|
|||||||
import dk.camelot64.kickc.fragment.AsmFragmentManager;
|
import dk.camelot64.kickc.fragment.AsmFragmentManager;
|
||||||
import dk.camelot64.kickc.fragment.AsmFragmentSignature;
|
import dk.camelot64.kickc.fragment.AsmFragmentSignature;
|
||||||
import dk.camelot64.kickc.model.*;
|
import dk.camelot64.kickc.model.*;
|
||||||
import dk.camelot64.kickc.parser.KickCParser;
|
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -17,8 +15,12 @@ public class Pass4CodeGeneration {
|
|||||||
|
|
||||||
private Program program;
|
private Program program;
|
||||||
|
|
||||||
public Pass4CodeGeneration(Program program) {
|
/** Should the generated ASM contain verbose alive info for the statements (costs a bit more to generate). */
|
||||||
|
boolean verboseAliveInfo;
|
||||||
|
|
||||||
|
public Pass4CodeGeneration(Program program, boolean verboseAliveInfo) {
|
||||||
this.program = program;
|
this.program = program;
|
||||||
|
this.verboseAliveInfo = verboseAliveInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlFlowGraph getGraph() {
|
ControlFlowGraph getGraph() {
|
||||||
@ -193,7 +195,7 @@ public class Pass4CodeGeneration {
|
|||||||
*/
|
*/
|
||||||
public void generateStatementAsm(AsmProgram asm, ControlFlowBlock block, Statement statement, AsmCodegenAluState aluState, boolean genCallPhiEntry) {
|
public void generateStatementAsm(AsmProgram asm, ControlFlowBlock block, Statement statement, AsmCodegenAluState aluState, boolean genCallPhiEntry) {
|
||||||
|
|
||||||
asm.startSegment(statement.getIndex(), statement.toString(program));
|
asm.startSegment(statement.getIndex(), statement.toString(program, verboseAliveInfo));
|
||||||
|
|
||||||
// IF the previous statement was added to the ALU register - generate the composite ASM fragment
|
// IF the previous statement was added to the ALU register - generate the composite ASM fragment
|
||||||
if (aluState.hasAluAssignment()) {
|
if (aluState.hasAluAssignment()) {
|
||||||
|
@ -127,7 +127,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base {
|
|||||||
}
|
}
|
||||||
// Generate ASM
|
// Generate ASM
|
||||||
try {
|
try {
|
||||||
new Pass4CodeGeneration(program).generate();
|
new Pass4CodeGeneration(program, false).generate();
|
||||||
} catch (AsmFragmentManager.UnknownFragmentException e) {
|
} catch (AsmFragmentManager.UnknownFragmentException e) {
|
||||||
unknownFragments.add(e.getFragmentSignature());
|
unknownFragments.add(e.getFragmentSignature());
|
||||||
if (program.getLog().isVerboseUplift()) {
|
if (program.getLog().isVerboseUplift()) {
|
||||||
@ -240,7 +240,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base {
|
|||||||
if(overlap) {
|
if(overlap) {
|
||||||
if (program.getLog().isVerboseUplift()) {
|
if (program.getLog().isVerboseUplift()) {
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Overlap register " + allocation + " in " + statement.toString(program));
|
msg.append("Overlap register " + allocation + " in " + statement.toString(program, true));
|
||||||
program.getLog().append(msg.toString());
|
program.getLog().append(msg.toString());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -69,7 +69,7 @@ public class Pass4RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Statement ").append(statement.toString(getProgram()));
|
msg.append("Statement ").append(statement.toString(getProgram(), true));
|
||||||
msg.append(" always clobbers ");
|
msg.append(" always clobbers ");
|
||||||
for (Registers.Register register : alwaysClobbered) {
|
for (Registers.Register register : alwaysClobbered) {
|
||||||
msg.append(register).append(" ");
|
msg.append(register).append(" ");
|
||||||
@ -132,10 +132,10 @@ public class Pass4RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
|
|||||||
combination.allocate(getProgram().getScope());
|
combination.allocate(getProgram().getScope());
|
||||||
// Generate ASM
|
// Generate ASM
|
||||||
AsmProgram asm = new AsmProgram();
|
AsmProgram asm = new AsmProgram();
|
||||||
asm.startSegment(statement.getIndex(), statement.toString(getProgram()));
|
asm.startSegment(statement.getIndex(), statement.toString(getProgram(), true));
|
||||||
Pass4CodeGeneration.AsmCodegenAluState aluState = new Pass4CodeGeneration.AsmCodegenAluState();
|
Pass4CodeGeneration.AsmCodegenAluState aluState = new Pass4CodeGeneration.AsmCodegenAluState();
|
||||||
try {
|
try {
|
||||||
(new Pass4CodeGeneration(getProgram())).generateStatementAsm(asm, block, statement, aluState, false);
|
(new Pass4CodeGeneration(getProgram(), false)).generateStatementAsm(asm, block, statement, aluState, false);
|
||||||
} catch (AsmFragmentManager.UnknownFragmentException e) {
|
} catch (AsmFragmentManager.UnknownFragmentException e) {
|
||||||
unknownFragments.add(e.getFragmentSignature());
|
unknownFragments.add(e.getFragmentSignature());
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
|
Loading…
Reference in New Issue
Block a user