use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class DetailedMethodReport method generateGraph.
private File generateGraph(MethodInfo method, String key, Map<CFGNode, ?> nodeAnnotations, Map<ControlFlowGraph.CFGEdge, ?> edgeAnnotations) throws IOException {
File cgdot = config.getOutFile(method, key + ".dot");
File cgimg = config.getOutFile(method, key + ".png");
ControlFlowGraph flowGraph = project.getFlowGraph(method);
if (nodeAnnotations != null || edgeAnnotations != null) {
flowGraph.exportDOT(cgdot, nodeAnnotations, edgeAnnotations);
} else {
flowGraph.exportDOT(cgdot, new WCETNodeLabeller(project), null);
}
project.getReport().recordDot(cgdot, cgimg);
return cgimg;
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class MethodCode method getControlFlowGraph.
/**
* Get the control flow graph associated with this method code or create a new one.
* <p>
* By default, changes to the returned CFG are compiled back before the InstructionList of this method is accessed.
* If you want a CFG where changes to it are not compiled back automatically, use {@code new ControlFlowGraph(MethodInfo)}
* instead. Also if you want to construct a CFG for a specific context or with a different implementation finder,
* you need to construct a callgraph yourself, keep a reference to it as long as you want to keep modifications to the
* graph and you need ensure that changes to a graph invalidate other graphs of the same method yourself, if required.
* </p>
* @param clean if true, compile and recreate the graph if {@link ControlFlowGraph#isClean()} returns false.
* @return the CFG for this method.
*/
public ControlFlowGraph getControlFlowGraph(boolean clean) {
if (cfg != null && clean && !cfg.isClean()) {
cfg.compile();
cfg = null;
}
if (this.cfg == null) {
try {
cfg = new ControlFlowGraph(this.getMethodInfo());
// TODO we do this for now by default for the 'main' CFG on creation
cfg.registerHandleNodes();
for (AppEventHandler ah : AppInfo.getSingleton().getEventHandlers()) {
ah.onCreateMethodControlFlowGraph(cfg, clean);
}
} catch (BadGraphException e) {
throw new BadGraphError("Unable to create CFG for " + methodInfo, e);
}
}
return cfg;
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class RecursiveWcetAnalysis method computeSolution.
public LocalWCETSolution computeSolution(MethodInfo m, Context ctx) {
/* just compute the solution using cached results, and also place the result into the cache,
but always return the complete solution. Also, no reports are generated here..
*/
// TODO return type could be made more generic and this method could be moved to RecursiveAnalysis
CacheKey key = new CacheKey(m, ctx);
/* compute solution */
ControlFlowGraph cfg = getWCETTool().getFlowGraph(m);
LocalWCETSolution sol = runWCETComputation(key.toString(), cfg, ctx);
sol.checkConsistency();
recordCost(key, sol.getCost());
/* Logging */
logger.debug("WCET for " + key + ": " + sol.getCost());
return sol;
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class MethodCacheAnalysis method getMissCost.
/**
* Get miss cost for an edge accessing the method cache
* @param accessEdge either a SuperInvoke or SuperReturn edge, or an entry edge of the segment analyzed
* @return maximum miss penalty (in cycles)
*/
private long getMissCost(SuperGraphEdge accessEdge) {
SuperGraphNode accessed = accessEdge.getTarget();
ControlFlowGraph cfg = accessed.getCfg();
if (accessEdge instanceof SuperReturnEdge) {
/* return edge: return cost */
Type returnType = accessEdge.getSource().getCfg().getMethodInfo().getType();
return methodCache.getMissPenaltyOnReturn(cfg.getNumberOfWords(), returnType);
} else if (accessEdge instanceof SuperInvokeEdge) {
InstructionHandle invokeIns = ((SuperInvokeEdge) accessEdge).getInvokeNode().getInvokeSite().getInstructionHandle();
return methodCache.getMissPenaltyOnInvoke(cfg.getNumberOfWords(), invokeIns.getInstruction());
} else {
/* entry edge of the segment: can be invoke or return cost */
return methodCache.getMissPenalty(cfg.getNumberOfWords(), false);
}
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class JavaOneProcessPerSupergraphTranslator method recordLoops.
// Global maximal nesting depth is given by the equation
// node.gmnd = node.method.gmnd + (node.loop ? node.loop.nestingDepth : 0)
// method.gmnd = max { cs.method.gmnd + cs.gmnd | cs <- method.callsites }
// Example:
// main() { for() for() X: f(); }
// f() { for() for(HOL) }
// nesting depth of HOL is 2
// gmnd of f is gmnd of X = 2 + gmnd of main = 2
// gmnd of HOL is 4
private void recordLoops(TemplateBuilder tBuilder) {
try {
computeMethodNestingDepths();
} catch (BadGraphException e) {
throw new BadGraphError(e);
}
for (MethodInfo m : methodInfos) {
ControlFlowGraph cfg = project.getFlowGraph(m);
for (Entry<CFGNode, LoopBound> entry : cfg.buildLoopBoundMap().entrySet()) {
CFGNode hol = entry.getKey();
LoopBound lb = entry.getValue();
int nesting = cfg.getLoopColoring().getLoopColor(hol).size();
int gmnd = nesting + methodMNDs.get(m);
tBuilder.addLoop(hol, gmnd, lb);
}
}
if (config.debug)
tBuilder.dumpLoops();
}
Aggregations