Search in sources :

Example 16 with ControlFlowGraph

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;
}
Also used : ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) File(java.io.File)

Example 17 with ControlFlowGraph

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;
}
Also used : BadGraphException(com.jopdesign.common.misc.BadGraphException) BadGraphError(com.jopdesign.common.misc.BadGraphError) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph)

Example 18 with ControlFlowGraph

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;
}
Also used : ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph)

Example 19 with ControlFlowGraph

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);
    }
}
Also used : Type(org.apache.bcel.generic.Type) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) InstructionHandle(org.apache.bcel.generic.InstructionHandle) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Example 20 with ControlFlowGraph

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();
}
Also used : BadGraphException(com.jopdesign.common.misc.BadGraphException) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) BadGraphError(com.jopdesign.common.misc.BadGraphError) LoopBound(com.jopdesign.common.code.LoopBound) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo)

Aggregations

ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)23 MethodInfo (com.jopdesign.common.MethodInfo)12 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)10 CFGEdge (com.jopdesign.common.code.ControlFlowGraph.CFGEdge)5 ExecutionContext (com.jopdesign.common.code.ExecutionContext)5 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)4 LoopBound (com.jopdesign.common.code.LoopBound)4 BadGraphError (com.jopdesign.common.misc.BadGraphError)3 BadGraphException (com.jopdesign.common.misc.BadGraphException)3 HashMap (java.util.HashMap)3 InstructionHandle (org.apache.bcel.generic.InstructionHandle)3 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)2 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)2 ProgressMeasure (com.jopdesign.common.graphutils.ProgressMeasure)2 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodCode (com.jopdesign.common.MethodCode)1 BasicBlock (com.jopdesign.common.code.BasicBlock)1 CallString (com.jopdesign.common.code.CallString)1 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)1