use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class MethodCacheAnalysis method getInvokeReturnMissCost.
/* utility functions */
/**
* Get the maximum method cache miss penalty for invoking {@code invoked} and returning to {@code invoker}.<br/>
* Also works with virtual invokes (taking the maximum cost)
* @param invokeSite the invoke site
* @param context call context
* @return miss penalty in cycles
*/
public long getInvokeReturnMissCost(InvokeSite invokeSite, CallString context) {
ControlFlowGraph invokerCfg = wcetTool.getFlowGraph(invokeSite.getInvoker());
long rMiss = methodCache.getMissPenaltyOnReturn(invokerCfg.getNumberOfWords(), invokeSite.getInvokeeRef().getDescriptor().getType());
long iMissMax = 0;
for (MethodInfo target : wcetTool.findImplementations(invokeSite.getInvoker(), invokeSite.getInstructionHandle(), context)) {
ControlFlowGraph invokedCfg = wcetTool.getFlowGraph(target);
long iMiss = methodCache.getMissPenaltyOnInvoke(invokedCfg.getNumberOfWords(), invokeSite.getInstructionHandle().getInstruction());
if (iMiss > iMissMax)
iMissMax = iMiss;
}
return iMissMax + rMiss;
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class GlobalAnalysis method getLoopBounds.
/**
* <p>Get all loop bounds for the given segment.</p>
* <p>For each loop bound B for loop H relative to marker M:</p>
* <p>sum(M) * B <= sum(continue-edges-of(H))</p>
*
* @param segment
* @return
* @throws InvalidFlowFactException
*/
private static Iterable<LinearConstraint<SuperGraphEdge>> getLoopBounds(WCETTool wcetTool, Segment segment) throws InvalidFlowFactException {
List<LinearConstraint<SuperGraphEdge>> constraints = new ArrayList<LinearConstraint<SuperGraphEdge>>();
// For all CFG instances
for (ContextCFG ccfg : segment.getCallGraphNodes()) {
ControlFlowGraph cfg = ccfg.getCfg();
// for all loops in the method
LoopColoring<CFGNode, ControlFlowGraph.CFGEdge> loops = cfg.getLoopColoring();
for (CFGNode hol : loops.getHeadOfLoops()) {
LoopBound loopBound = wcetTool.getLoopBound(hol, ccfg.getContext().getCallString());
if (loopBound == null) {
throw new AppInfoError("No loop bound record for head of loop: " + hol + " : " + cfg.buildLoopBoundMap());
}
addLoopConstraints(constraints, segment, ccfg, hol, loops, loopBound);
}
}
return constraints;
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class WCETTool method getFlowGraph.
/**
* Get the flowgraph of the given method.
* <p>
* A new callgraph is constructed when this method is called, changes to this graph are not
* automatically stored back to MethodCode. If you want to keep changes to the graph you need to keep a
* reference to this graph yourself.
* </p>
*
* @param mi the method to get the CFG for
* @return the CFG for the method.
*/
public ControlFlowGraph getFlowGraph(MethodInfo mi) {
if (!mi.hasCode()) {
throw new AssertionError("No CFG for MethodInfo " + mi);
}
ControlFlowGraph cfg;
try {
/* TODO We need to make sure that changes to the CFG are not compiled back automatically
* but CFG#compile() is not yet fully implemented anyways.
* We could add an option to MethodCode#getControlFlowGraph() to get a graph which will not be compiled back.
*
* We could also create a new graph instead, would allow us to create CFGs per callstring and be consistent
* with this.callgraph. But as long as neither this.callgraph and appInfo.callgraph are not modified
* after rebuildCallGraph() has been called, there is no difference.
*
* However, if we create a new graph we have to
* - keep the new graph, if we just recreate them modifications by analyses will be lost and some things
* like SuperGraph will break if we return new graphs every time.
* - provide a way to rebuild the CFGs if the code is modified, either by implementing WCETEventHandler.onMethodModified
* or by providing a dispose() method which must be called before the analysis starts after any code modifications.
* - when we do not use a CFG anymore (e.g. because we recreate it) we need to call CFG.dispose() so that it
* is not attached to the instruction handles anymore.
*/
//cfg = new ControlFlowGraph(mi, CallString.EMPTY, callGraph);
cfg = mi.getCode().getControlFlowGraph(false);
cfg.resolveVirtualInvokes();
cfg.insertReturnNodes();
cfg.insertContinueLoopNodes();
// cfg.insertSplitNodes();
// cfg.insertSummaryNodes();
} catch (BadGraphException e) {
// TODO handle this somehow??
throw new BadGraphError(e.getMessage(), e);
}
return cfg;
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class WCETTool method computeCyclomaticComplexity.
// public File getOutFile(String file) {
// return new File(projectConfig.getOutDir(), file);
// }
/* FIXME: Slow, caching is missing */
public int computeCyclomaticComplexity(MethodInfo m) {
ControlFlowGraph g = getFlowGraph(m);
int nLocal = g.vertexSet().size();
int eLocal = g.edgeSet().size();
int pLocal = g.buildLoopBoundMap().size();
int ccLocal = eLocal - nLocal + 2 * pLocal;
int ccGlobal = 0;
for (ExecutionContext n : this.getCallGraph().getReferencedMethods(m)) {
MethodInfo impl = n.getMethodInfo();
ccGlobal += 2 + computeCyclomaticComplexity(impl);
}
return ccLocal + ccGlobal;
}
use of com.jopdesign.common.code.ControlFlowGraph in project jop by jop-devel.
the class IPETUtils method buildLocalILPModel.
/**
* Create a max-cost maxflow problem for the given flow graph graph, based on a
* given node to cost mapping.
*
* @param wcetTool A reference to the WCETTool
* @param problemName a unique identifier for the problem (for reporting)
* @param cs context of the method invocation
* @param cfg the graph
* @param nodeWCET cost of nodes
* @return The max-cost maxflow problem
*/
public static IPETSolver buildLocalILPModel(WCETTool wcetTool, String problemName, CallString cs, ControlFlowGraph cfg, CostProvider<CFGNode> nodeWCET, IPETConfig ipetConfig) {
IPETSolver ipetSolver = new IPETSolver(problemName, ipetConfig);
IPETBuilder<CallString> builder = new IPETBuilder<CallString>(wcetTool, cs);
ipetSolver.addConstraints(IPETUtils.structuralFlowConstraintsRoot(cfg.getGraph(), builder));
ipetSolver.addConstraints(IPETUtils.loopBoundConstraints(cfg, builder));
ipetSolver.addConstraints(IPETUtils.infeasibleEdgeConstraints(cfg, builder));
for (CFGNode n : cfg.vertexSet()) {
long nodeCost = nodeWCET.getCost(n);
for (ControlFlowGraph.CFGEdge e : cfg.outgoingEdgesOf(n)) {
ipetSolver.addEdgeCost(builder.newEdge(e), nodeCost);
}
}
return ipetSolver;
}
Aggregations