mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-08 14:37:40 +00:00
Improving implementation.
This commit is contained in:
parent
c0b0f063cc
commit
0e58165f3a
src/main/java/dk/camelot64/kickc
@ -149,23 +149,25 @@ public class CallGraph {
|
||||
/**
|
||||
* Get all calls of a specific procedure
|
||||
*
|
||||
* @param label The label of the procedure
|
||||
* @param procedureRef The procedure
|
||||
* @return All calls
|
||||
*/
|
||||
public Collection<CallBlock.Call> getRecursiveCallers(ProcedureRef procedureRef) {
|
||||
final LinkedList<CallBlock.Call> callers = new LinkedList<>();
|
||||
Deque<ProcedureRef> todo = new LinkedList<>();
|
||||
Deque<ScopeRef> todo = new LinkedList<>();
|
||||
todo.add(procedureRef);
|
||||
Collection<ProcedureRef> visited = new LinkedList<>();
|
||||
Collection<ScopeRef> visited = new LinkedList<>();
|
||||
while(!todo.isEmpty()) {
|
||||
final ProcedureRef procRef = todo.pop();
|
||||
final ScopeRef procRef = todo.pop();
|
||||
if(visited.contains(procRef))
|
||||
continue;
|
||||
visited.add(procRef);
|
||||
final Collection<CallBlock.Call> procCallers = getCallers(procRef);
|
||||
callers.addAll(procCallers);
|
||||
for(CallBlock.Call caller : procCallers) {
|
||||
todo.add(caller.getProcedure());
|
||||
if(procRef instanceof ProcedureRef) {
|
||||
final Collection<CallBlock.Call> procCallers = getCallers((ProcedureRef) procRef);
|
||||
callers.addAll(procCallers);
|
||||
for(CallBlock.Call procCaller : procCallers) {
|
||||
todo.add(procCaller.getCallStatementScope());
|
||||
}
|
||||
}
|
||||
}
|
||||
return callers;
|
||||
@ -245,7 +247,7 @@ public class CallGraph {
|
||||
}
|
||||
|
||||
public void addCall(ProcedureRef procedureLabel, StatementCalling call) {
|
||||
this.calls.add(new Call(procedureLabel, call));
|
||||
this.calls.add(new Call(procedureLabel, call, scopeLabel));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,14 +308,20 @@ public class CallGraph {
|
||||
*/
|
||||
private Integer callStatementIdx;
|
||||
|
||||
/**
|
||||
* The calling procedure (which contains the call statement).
|
||||
*/
|
||||
private ScopeRef callStatementScope;
|
||||
|
||||
/**
|
||||
* The called procedure (which is itself also a Scope).
|
||||
*/
|
||||
private ProcedureRef procedure;
|
||||
|
||||
Call(ProcedureRef procedure, StatementCalling call) {
|
||||
Call(ProcedureRef procedure, StatementCalling call, ScopeRef callStatementScope) {
|
||||
this.callStatementIdx = call.getIndex();
|
||||
this.procedure = procedure;
|
||||
this.callStatementScope = callStatementScope;
|
||||
}
|
||||
|
||||
public ProcedureRef getProcedure() {
|
||||
@ -324,6 +332,10 @@ public class CallGraph {
|
||||
return callStatementIdx;
|
||||
}
|
||||
|
||||
public ScopeRef getCallStatementScope() {
|
||||
return callStatementScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
@ -10,9 +10,9 @@ import java.util.*;
|
||||
/**
|
||||
* Use the call graph to coalesce memory registers.
|
||||
* For each live range equivalence class:
|
||||
* - Look up through the call graph and avoid all variables declared in the scopes there
|
||||
* - Go through already handled live range equivalence classes and if any exist with no scope overlap with the call graph - try to coalesce
|
||||
* - Add to the list of already handled live range equivalence classes
|
||||
* - Look up through the call graph and avoid all variables declared in the scopes there
|
||||
* - Go through already handled live range equivalence classes and if any exist with no scope overlap with the call graph - try to coalesce
|
||||
* - Add to the list of already handled live range equivalence classes
|
||||
*/
|
||||
public class Pass4MemoryCoalesceCallGraph extends Pass2Base {
|
||||
|
||||
@ -130,8 +130,11 @@ public class Pass4MemoryCoalesceCallGraph extends Pass2Base {
|
||||
List<VariableRef> variables = equivalenceClass.getVariables();
|
||||
for(VariableRef varRef : variables) {
|
||||
ScopeRef scopeRef = new ScopeRef(varRef.getScopeNames());
|
||||
//if(!ScopeRef.ROOT.equals(scopeRef)) {
|
||||
// scopeRef = new ProcedureRef(varRef.getScopeNames());
|
||||
//}
|
||||
if(!ecScopes.contains(scopeRef))
|
||||
ecScopes.add(scopeRef);
|
||||
ecScopes.add(scopeRef);
|
||||
}
|
||||
return ecScopes;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user