Search in sources :

Example 11 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode 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 12 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class IPETUtils method loopBoundConstraints.

/**
     * Compute flow constraints: Loop Bound constraints (Control Flow Graph only)
     *
     * @param g   the flow graph
     * @param ctx the invocation context
     * @return A list of flow constraints
     */
public static <C extends CallStringProvider> List<LinearConstraint<IPETBuilder.ExecutionEdge>> loopBoundConstraints(ControlFlowGraph g, IPETBuilder<C> ctx) {
    List<LinearConstraint<IPETBuilder.ExecutionEdge>> constraints = new ArrayList<LinearConstraint<IPETBuilder.ExecutionEdge>>();
    // - for each loop with bound B
    // -- sum(exit_loop_edges) * B <= sum(continue_loop_edges)
    LoopColoring<CFGNode, ControlFlowGraph.CFGEdge> loops = g.getLoopColoring();
    for (CFGNode hol : loops.getHeadOfLoops()) {
        //LoopBound loopBound = g.getLoopBound(hol, ctx.getCallString());
        LoopBound loopBound = ctx.getWCETTool().getLoopBound(hol, ctx.getCallString());
        if (loopBound == null) {
            throw new AppInfoError("No loop bound record for head of loop: " + hol + " : " + g.buildLoopBoundMap());
        }
        for (LinearConstraint<IPETBuilder.ExecutionEdge> loopConstraint : constraintsForLoop(loops, hol, loopBound, ctx)) {
            constraints.add(loopConstraint);
        }
    }
    return constraints;
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) LoopBound(com.jopdesign.common.code.LoopBound) ArrayList(java.util.ArrayList) ExecutionEdge(com.jopdesign.wcet.ipet.IPETBuilder.ExecutionEdge) AppInfoError(com.jopdesign.common.misc.AppInfoError) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 13 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class IPETUtils method constraintsForLoop.

/**
     * Generate Loop Constraints
     */
public static <C extends CallStringProvider> List<LinearConstraint<IPETBuilder.ExecutionEdge>> constraintsForLoop(LoopColoring<CFGNode, ControlFlowGraph.CFGEdge> loops, CFGNode hol, LoopBound loopBound, IPETBuilder<C> ctx) {
    ExecutionContext eCtx = new ExecutionContext(hol.getControlFlowGraph().getMethodInfo(), ctx.getCallString());
    List<LinearConstraint<IPETBuilder.ExecutionEdge>> loopConstraints = new ArrayList<LinearConstraint<IPETBuilder.ExecutionEdge>>();
    /* marker loop constraints */
    for (Entry<SymbolicMarker, LoopBoundExpr> markerBound : loopBound.getLoopBounds()) {
        /* loop constraint */
        LinearConstraint<IPETBuilder.ExecutionEdge> loopConstraint = new LinearConstraint<IPETBuilder.ExecutionEdge>(ConstraintType.GreaterEqual);
        for (ControlFlowGraph.CFGEdge continueEdge : loops.getBackEdgesTo(hol)) {
            loopConstraint.addRHS(ctx.newEdge(continueEdge));
        }
        /* Multiplicities */
        long lhsMultiplicity = markerBound.getValue().upperBound(eCtx);
        SymbolicMarker marker = markerBound.getKey();
        if (marker.getMarkerType() == SymbolicMarkerType.OUTER_LOOP_MARKER) {
            CFGNode outerLoopHol;
            outerLoopHol = loops.getLoopAncestor(hol, marker.getOuterLoopDistance());
            if (outerLoopHol == null) {
                // FIXME: [annotations] This is a user error, not an assertion error
                throw new AssertionError("Invalid Loop Nest Level");
            }
            for (ControlFlowGraph.CFGEdge exitEdge : loops.getExitEdgesOf(outerLoopHol)) {
                loopConstraint.addLHS(ctx.newEdge(exitEdge), lhsMultiplicity);
            }
        } else {
            assert (marker.getMarkerType() == SymbolicMarkerType.METHOD_MARKER);
            throw new AssertionError("ILPModelBuilder: method markers not yet supported, sorry");
        }
        loopConstraints.add(loopConstraint);
    }
    return loopConstraints;
}
Also used : LoopBoundExpr(com.jopdesign.wcet.annotations.LoopBoundExpr) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) ArrayList(java.util.ArrayList) ExecutionContext(com.jopdesign.common.code.ExecutionContext) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) ExecutionEdge(com.jopdesign.wcet.ipet.IPETBuilder.ExecutionEdge) SymbolicMarker(com.jopdesign.common.code.SymbolicMarker)

Example 14 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode 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)

Example 15 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class SuperGraph method addEdge.

private void addEdge(ControlFlowGraph.InvokeNode invokeNode, ContextCFG invoker, ContextCFG invoked) {
    SuperInvokeEdge iEdge = new SuperInvokeEdge(invokeNode, invoker, invoked);
    superGraph.addEdge(invoker, invoked, iEdge);
    CFGEdge returnEdge;
    Set<CFGEdge> outEdges = invoker.getCfg().outgoingEdgesOf(invokeNode);
    if (outEdges.size() != 1) {
        throw new AssertionError("SuperGraph: Outdegree of invoker node != 1 (Missing return node?)");
    } else {
        returnEdge = outEdges.iterator().next();
    }
    CFGNode returnNode = invoker.getCfg().getEdgeTarget(returnEdge);
    if (invoker.getCfg().incomingEdgesOf(returnNode).size() != 1) {
        throw new AssertionError("SuperGraph: Indegree of return node != 1 (Missing return node?)");
    }
    SuperReturnEdge rEdge = new SuperReturnEdge(invokeNode, returnNode, invoker, invoked);
    superGraph.addEdge(invoked, invoker, rEdge);
    superEdgePairs.put(iEdge, rEdge);
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Aggregations

CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)28 MethodInfo (com.jopdesign.common.MethodInfo)13 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)13 CFGEdge (com.jopdesign.common.code.ControlFlowGraph.CFGEdge)10 LoopBound (com.jopdesign.common.code.LoopBound)7 ExecutionContext (com.jopdesign.common.code.ExecutionContext)6 HashMap (java.util.HashMap)6 InstructionHandle (org.apache.bcel.generic.InstructionHandle)6 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)5 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)4 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 BasicBlock (com.jopdesign.common.code.BasicBlock)3 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 ClassInfo (com.jopdesign.common.ClassInfo)2 MethodCode (com.jopdesign.common.MethodCode)2 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)2