1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-24 04:31:02 +00:00

Implemented a less verbose statement print for uplift performance

This commit is contained in:
jespergravgaard 2017-11-09 23:28:21 +01:00
parent 88d765324a
commit 58500b39e0
22 changed files with 49 additions and 40 deletions

View File

@ -244,7 +244,7 @@ public class Compiler {
new Pass4RegistersFinalize(program).allocate(true);
// Initial Code generation
new Pass4CodeGeneration(program).generate();
new Pass4CodeGeneration(program, true).generate();
new Pass4AssertNoCpuClobber(program).check();
program.getLog().append("INITIAL ASM");
program.getLog().append(program.getAsm().toString());
@ -284,7 +284,7 @@ public class Compiler {
public void pass5GenerateAndOptimizeAsm(Program program) {
// Final ASM code generation before optimization
new Pass4CodeGeneration(program).generate();
new Pass4CodeGeneration(program, true).generate();
new Pass4AssertNoCpuClobber(program).check();
List<Pass5AsmOptimization> pass5Optimizations = new ArrayList<>();

View File

@ -136,7 +136,7 @@ public class ControlFlowBlock {
}
out.append("\n");
for (Statement statement : statements) {
out.append(" " + statement.toString(program) + "\n");
out.append(" " + statement.toString(program, true) + "\n");
}
if (defaultSuccessor != null) {
out.append(" to:");

View File

@ -74,5 +74,4 @@ public class LiveRangeEquivalenceClassSet {
}
}
}

View File

@ -21,7 +21,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
})
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. */
void setIndex(Integer idx);

View File

@ -14,7 +14,7 @@ public class StatementAsm extends StatementBase {
}
@Override
public String toString(Program program) {
public String toString(Program program, boolean aliveInfo) {
return "asm { "+asmLines.getText()+" }";
}

View File

@ -90,18 +90,18 @@ public class StatementAssignment extends StatementBase implements StatementLValu
@Override
public String toString() {
return toString(null);
return toString(null, true);
}
@Override
public String toString(Program program) {
public String toString(Program program, boolean aliveInfo) {
return
super.idxString() +
lValue.toString(program) + "" +
(rValue1==null?"":rValue1.toString(program)+" ") +
(operator==null?"":operator+" ") +
rValue2.toString(program) +
super.aliveString(program);
(aliveInfo?super.aliveString(program):"");
}
@Override

View File

@ -41,7 +41,7 @@ public abstract class StatementBase implements Statement {
@Override
public String toString() {
return toString(null);
return toString(null, true);
}
public String aliveString(Program program) {

View File

@ -97,7 +97,7 @@ public class StatementCall extends StatementBase implements StatementLValue {
}
@Override
public String toString(Program program) {
public String toString(Program program, boolean aliveInfo) {
StringBuilder res = new StringBuilder();
res.append(super.idxString());
if (lValue != null) {
@ -118,7 +118,9 @@ public class StatementCall extends StatementBase implements StatementLValue {
if (parametersByAssignment) {
res.append("param-assignment");
}
res.append(super.aliveString(program));
if(aliveInfo) {
res.append(super.aliveString(program));
}
return res.toString();
}

View File

@ -82,7 +82,7 @@ public class StatementConditionalJump extends StatementBase {
}
@Override
public String toString(Program program) {
public String toString(Program program, boolean aliveInfo) {
StringBuilder out = new StringBuilder();
out.append(super.idxString());
out.append("if(");
@ -93,7 +93,9 @@ public class StatementConditionalJump extends StatementBase {
out.append(rValue2.toString(program));
out.append(") goto ");
out.append(destination.getFullName());
out.append(super.aliveString(program));
if(aliveInfo) {
out.append(super.aliveString(program));
}
return out.toString();
}

View File

@ -24,8 +24,8 @@ public class StatementJump extends StatementBase {
}
@Override
public String toString(Program program) {
return super.idxString() + "goto " + destination.getFullName()+ super.aliveString(program);
public String toString(Program program, boolean aliveInfo) {
return super.idxString() + "goto " + destination.getFullName()+ (aliveInfo?super.aliveString(program):"");
}
}

View File

@ -17,8 +17,8 @@ public class StatementLabel extends StatementBase {
}
@Override
public String toString(Program program) {
return super.idxString() + label.getFullName() + ":"+super.aliveString(program);
public String toString(Program program, boolean aliveInfo) {
return super.idxString() + label.getFullName() + ":"+(aliveInfo?super.aliveString(program):"");
}
}

View File

@ -63,14 +63,16 @@ public class StatementPhiBlock extends StatementBase {
}
@Override
public String toString(Program program) {
public String toString(Program program, boolean aliveInfo) {
StringBuilder s = new StringBuilder();
List<PhiVariable> variables = new ArrayList<>(phiVariables);
Collections.reverse(variables);
if(phiVariables.size()==0) {
s.append(super.idxString());
s.append("phi()");
s.append(super.aliveString(program));
if(aliveInfo) {
s.append(super.aliveString(program));
}
s.append("\n ");
}
for (PhiVariable phiVariable : variables) {
@ -85,7 +87,9 @@ public class StatementPhiBlock extends StatementBase {
s.append(rValue==null?"null":rValue.toString(program));
}
s.append(" )");
s.append(super.aliveString(program));
if(aliveInfo) {
s.append(super.aliveString(program));
}
s.append("\n ");
}
if(s.length()>0) {

View File

@ -30,8 +30,8 @@ public class StatementProcedureBegin extends StatementBase {
}
@Override
public String toString(Program program) {
return super.idxString() + "proc " + procedure.toString(program) + super.aliveString(program);
public String toString(Program program, boolean aliveInfo) {
return super.idxString() + "proc " + procedure.toString(program) + (aliveInfo?super.aliveString(program):"");
}
}

View File

@ -17,7 +17,7 @@ public class StatementProcedureEnd extends StatementBase {
}
@Override
public String toString(Program program) {
return super.idxString() + "endproc // " + procedure.getFullName() + "()"+super.aliveString(program);
public String toString(Program program, boolean aliveInfo) {
return super.idxString() + "endproc // " + procedure.getFullName() + "()"+(aliveInfo?super.aliveString(program):"");
}
}

View File

@ -35,8 +35,8 @@ public class StatementReturn extends StatementBase {
}
@Override
public String toString(Program program) {
return super.idxString() + "return " + (value == null ? "" : value.toString(program)) + super.aliveString(program);
public String toString(Program program, boolean aliveInfo) {
return super.idxString() + "return " + (value == null ? "" : value.toString(program)) + (aliveInfo?super.aliveString(program):"");
}
@Override

View File

@ -26,7 +26,7 @@ public class StatementSequence {
if(!(statement instanceof StatementLabel) && !(statement instanceof StatementProcedureBegin) && !(statement instanceof StatementProcedureEnd)) {
out.append(" ");
}
out.append(statement.toString(program)+"\n");
out.append(statement.toString(program, true)+"\n");
}
return out.toString();
}

View File

@ -622,7 +622,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
for (PrePostModifier mod : modifiers) {
Statement stmt = new StatementAssignment((LValue) mod.child, mod.operator, mod.child);
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));
}
}

View File

@ -55,7 +55,7 @@ public class Pass2ConditionalJumpSimplification extends Pass2SsaOptimization {
conditionalJump.setOperator(conditionAssignment.getOperator());
conditionalJump.setrValue2(conditionAssignment.getrValue2());
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;
default:
}

View File

@ -98,7 +98,7 @@ public class Pass2UnaryNotSimplification extends Pass2SsaOptimization {
assignment.setrValue1(tempAssignment.getrValue1());
assignment.setOperator(newOperator==null?null:Operator.getBinary(newOperator));
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));
}

View File

@ -5,8 +5,6 @@ import dk.camelot64.kickc.fragment.AsmFragment;
import dk.camelot64.kickc.fragment.AsmFragmentManager;
import dk.camelot64.kickc.fragment.AsmFragmentSignature;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.parser.KickCParser;
import org.antlr.v4.runtime.CharStreams;
import java.util.*;
@ -17,8 +15,12 @@ public class Pass4CodeGeneration {
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.verboseAliveInfo = verboseAliveInfo;
}
ControlFlowGraph getGraph() {
@ -193,7 +195,7 @@ public class Pass4CodeGeneration {
*/
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 (aluState.hasAluAssignment()) {

View File

@ -127,7 +127,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base {
}
// Generate ASM
try {
new Pass4CodeGeneration(program).generate();
new Pass4CodeGeneration(program, false).generate();
} catch (AsmFragmentManager.UnknownFragmentException e) {
unknownFragments.add(e.getFragmentSignature());
if (program.getLog().isVerboseUplift()) {
@ -240,7 +240,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base {
if(overlap) {
if (program.getLog().isVerboseUplift()) {
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());
}
return true;

View File

@ -69,7 +69,7 @@ public class Pass4RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
continue;
} else {
StringBuilder msg = new StringBuilder();
msg.append("Statement ").append(statement.toString(getProgram()));
msg.append("Statement ").append(statement.toString(getProgram(), true));
msg.append(" always clobbers ");
for (Registers.Register register : alwaysClobbered) {
msg.append(register).append(" ");
@ -132,10 +132,10 @@ public class Pass4RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
combination.allocate(getProgram().getScope());
// Generate ASM
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();
try {
(new Pass4CodeGeneration(getProgram())).generateStatementAsm(asm, block, statement, aluState, false);
(new Pass4CodeGeneration(getProgram(), false)).generateStatementAsm(asm, block, statement, aluState, false);
} catch (AsmFragmentManager.UnknownFragmentException e) {
unknownFragments.add(e.getFragmentSignature());
StringBuilder msg = new StringBuilder();