Search in sources :

Example 11 with ControlFlowGraph

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

Example 12 with ControlFlowGraph

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 &lt;= 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;
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) LoopBound(com.jopdesign.common.code.LoopBound) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) LinearConstraint(com.jopdesign.wcet.ipet.LinearConstraint) AppInfoError(com.jopdesign.common.misc.AppInfoError) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 13 with ControlFlowGraph

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

Example 14 with ControlFlowGraph

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

Example 15 with ControlFlowGraph

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

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