1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Refactored phi transitions and symbol infos to be calculated on demand.

This commit is contained in:
jespergravgaard 2019-08-02 00:43:47 +02:00
parent 1e03067814
commit 0a39633ed8
5 changed files with 31 additions and 33 deletions

View File

@ -441,7 +441,6 @@ public class Compiler {
program.clearCallGraph();
new PassNStatementInfos(program).execute();
program.clearVariableReferenceInfos();
new Pass3SymbolInfos(program).generateSymbolInfos();
new Pass3LiveRangesAnalysis(program).findLiveRanges();
new Pass3LiveRangesEffectiveAnalysis(program).findLiveRangesEffective();
pass2AssertSSA();
@ -485,7 +484,6 @@ public class Compiler {
new Pass4RegistersFinalize(program).allocate(true);
// Initial Code generation
new Pass4PhiTransitions(program).generate();
new Pass4CodeGeneration(program, false).generate();
new Pass4AssertNoCpuClobber(program).check();
getLog().append("\nINITIAL ASM");
@ -532,7 +530,7 @@ public class Compiler {
new Pass4AssertZeropageAllocation(program).check();
// Final ASM code generation before optimization
new Pass4PhiTransitions(program).generate();
program.clearPhiTransitions();
new Pass4CodeGeneration(program, false).generate();
new Pass4AssertNoCpuClobber(program).check();

View File

@ -6,9 +6,7 @@ import dk.camelot64.kickc.model.statements.StatementInfos;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.values.LabelRef;
import dk.camelot64.kickc.model.values.VariableRef;
import dk.camelot64.kickc.passes.PassNCalcCallGraph;
import dk.camelot64.kickc.passes.PassNCalcVariableReferenceInfos;
import dk.camelot64.kickc.passes.PassNDominatorsAnalysis;
import dk.camelot64.kickc.passes.*;
import java.nio.file.Path;
import java.util.ArrayList;
@ -65,9 +63,9 @@ public class Program {
private CallGraph callGraph;
/** Cached information about the variables referenced by blocks/statements. PASS 1-4 (CACHED ON-DEMAND) */
private VariableReferenceInfos variableReferenceInfos;
/** Information about dominators of all blocks. PASS 2U-4 (CACHED) */
/** Information about dominators of all blocks. PASS 2U-4 (CACHED ON-DEMAND) */
private DominatorsGraph dominators;
/** Cached information about symbols. Contains a symbol table cache for fast access. PASS 3-4 (CACHED) */
/** Cached information about symbols. Contains a symbol table cache for fast access. PASS 3-4 (CACHED ON-DEMAND) */
private SymbolInfos symbolInfos;
/** Cached phi transitions into each block. PASS 4 (CACHED) */
private Map<LabelRef, PhiTransitions> phiTransitions;
@ -170,14 +168,6 @@ public class Program {
this.structUnwinding = structUnwinding;
}
public Map<LabelRef, PhiTransitions> getPhiTransitions() {
return phiTransitions;
}
public void setPhiTransitions(Map<LabelRef, PhiTransitions> phiTransitions) {
this.phiTransitions = phiTransitions;
}
public List<Comment> getFileComments() {
return fileComments;
}
@ -279,6 +269,17 @@ public class Program {
this.dominators = null;
}
public Map<LabelRef, PhiTransitions> getPhiTransitions() {
if(phiTransitions==null)
this.phiTransitions = new PassNCalcPhiTransitions(this).calculate();
return phiTransitions;
}
public void clearPhiTransitions() {
this.phiTransitions = null;
}
public NaturalLoopSet getLoopSet() {
return loopSet;
}
@ -297,13 +298,11 @@ public class Program {
}
public SymbolInfos getSymbolInfos() {
if(symbolInfos==null)
this.symbolInfos = new PassNCalcSymbolInfos(this).calculate();
return symbolInfos;
}
public void setSymbolInfos(SymbolInfos symbolInfos) {
this.symbolInfos = symbolInfos;
}
public LiveRangeVariables getLiveRangeVariables() {
return liveRangeVariables;
}

View File

@ -8,7 +8,6 @@ import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.values.ScopeRef;
import dk.camelot64.kickc.model.values.VariableRef;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.symbols.Variable;
import java.util.*;
@ -110,7 +109,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base {
}
// Generate ASM
try {
new Pass4PhiTransitions(program).generate();
program.clearPhiTransitions();
new Pass4CodeGeneration(program, false).generate();
} catch(AsmFragmentTemplateSynthesizer.UnknownFragmentException e) {
unknownFragments.add(e.getFragmentSignature());

View File

@ -6,23 +6,25 @@ import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.values.LabelRef;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Generate phi-transitions for all phi-block transitions
*/
public class Pass4PhiTransitions extends Pass2Base {
public class PassNCalcPhiTransitions extends PassNCalcBase<Map<LabelRef, PhiTransitions>> {
public Pass4PhiTransitions(Program program) {
public PassNCalcPhiTransitions(Program program) {
super(program);
}
public void generate() {
@Override
public Map<LabelRef, PhiTransitions> calculate() {
LinkedHashMap<LabelRef, PhiTransitions> phiTransitions = new LinkedHashMap<>();
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
PhiTransitions blockTransitions = new PhiTransitions(getProgram(), block);
phiTransitions.put(block.getLabel(), blockTransitions);
}
getProgram().setPhiTransitions(phiTransitions);
return phiTransitions;
}

View File

@ -1,7 +1,8 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.SymbolInfos;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.symbols.Scope;
import dk.camelot64.kickc.model.symbols.Symbol;
@ -10,22 +11,22 @@ import dk.camelot64.kickc.model.values.SymbolRef;
import java.util.LinkedHashMap;
/** Create the symbol table cache */
public class Pass3SymbolInfos extends Pass2Base {
public class PassNCalcSymbolInfos extends PassNCalcBase<SymbolInfos> {
public Pass3SymbolInfos(Program program) {
public PassNCalcSymbolInfos(Program program) {
super(program);
}
/**
* Create map from statement index to block
*/
public void generateSymbolInfos() {
@Override
public SymbolInfos calculate() {
LinkedHashMap<SymbolRef, Symbol> symbolCache = new LinkedHashMap<>();
ProgramScope scope = getProgram().getScope();
generateCache(symbolCache, scope);
SymbolInfos symbolInfos = new SymbolInfos(symbolCache);
getProgram().setSymbolInfos(symbolInfos);
return symbolInfos;
}
private void generateCache(LinkedHashMap<SymbolRef, Symbol> symbolCache, Scope scope) {
@ -37,5 +38,4 @@ public class Pass3SymbolInfos extends Pass2Base {
}
}
}