Search in sources :

Example 1 with LinearConstraint

use of com.jopdesign.wcet.ipet.LinearConstraint 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) LinearConstraint(com.jopdesign.wcet.ipet.LinearConstraint) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) AppInfoError(com.jopdesign.common.misc.AppInfoError) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 2 with LinearConstraint

use of com.jopdesign.wcet.ipet.LinearConstraint in project jop by jop-devel.

the class GlobalAnalysis method addLoopConstraints.

/**
 * Add loop contraints
 * @param constraints the new constraints are added to this collection
 * @param segment
 * @param ccfg
 * @param headOfLoop
 * @param loops
 * @param loopBound
 * @throws InvalidFlowFactException
 */
private static void addLoopConstraints(List<LinearConstraint<SuperGraphEdge>> constraints, Segment segment, ContextCFG ccfg, CFGNode headOfLoop, LoopColoring<CFGNode, CFGEdge> loops, LoopBound loopBound) throws InvalidFlowFactException {
    /* marker loop constraints */
    for (Entry<SymbolicMarker, LoopBoundExpr> markerBound : loopBound.getLoopBounds()) {
        /* loop constraint */
        LinearConstraint<SuperGraphEdge> loopConstraint = new LinearConstraint<SuperGraphEdge>(ConstraintType.GreaterEqual);
        /* rhs = sum(continue-edges(loop)) */
        Iterable<SuperGraphEdge> continueEdges = segment.liftCFGEdges(ccfg, loops.getBackEdgesTo(headOfLoop));
        loopConstraint.addRHS(continueEdges);
        /* Multiplicities */
        ExecutionContext executionContext = new ExecutionContext(ccfg.getCfg().getMethodInfo(), ccfg.getCallString());
        long lhsMultiplicity = markerBound.getValue().upperBound(executionContext);
        SymbolicMarker marker = markerBound.getKey();
        if (marker.getMarkerType() == SymbolicMarkerType.OUTER_LOOP_MARKER) {
            CFGNode outerLoopHol;
            outerLoopHol = loops.getLoopAncestor(headOfLoop, marker.getOuterLoopDistance());
            if (outerLoopHol == null) {
                throw new InvalidFlowFactException("Bad outer loop annotation");
            }
            Iterable<SuperGraphEdge> exitEdges = segment.liftCFGEdges(ccfg, loops.getExitEdgesOf(outerLoopHol));
            for (SuperGraphEdge exitEdge : exitEdges) {
                loopConstraint.addLHS(exitEdge, lhsMultiplicity);
            }
        } else {
            assert (marker.getMarkerType() == SymbolicMarkerType.METHOD_MARKER);
            throw new AssertionError("ILPModelBuilder: method markers not yet supported, sorry");
        }
        constraints.add(loopConstraint);
    }
}
Also used : LoopBoundExpr(com.jopdesign.wcet.annotations.LoopBoundExpr) ExecutionContext(com.jopdesign.common.code.ExecutionContext) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) LinearConstraint(com.jopdesign.wcet.ipet.LinearConstraint) SymbolicMarker(com.jopdesign.common.code.SymbolicMarker)

Example 3 with LinearConstraint

use of com.jopdesign.wcet.ipet.LinearConstraint in project jop by jop-devel.

the class GlobalAnalysis method getInfeasibleEdgeConstraints.

/**
 * For each infeasible edge, assert that the edge has flow 0
 * @param wcetTool
 * @param segment
 * @return
 */
private static Iterable<LinearConstraint<SuperGraphEdge>> getInfeasibleEdgeConstraints(WCETTool wcetTool, Segment segment) {
    List<LinearConstraint<SuperGraphEdge>> constraints = new ArrayList<LinearConstraint<SuperGraphEdge>>();
    // -- edge = 0
    for (ContextCFG ccfg : segment.getCallGraphNodes()) {
        for (CFGEdge edge : wcetTool.getInfeasibleEdges(ccfg.getCfg(), ccfg.getCallString())) {
            LinearConstraint<SuperGraphEdge> infeasibleConstraint = new LinearConstraint<SuperGraphEdge>(ConstraintType.Equal);
            infeasibleConstraint.addLHS(segment.liftCFGEdges(ccfg, Iterators.singleton(edge)));
            infeasibleConstraint.addRHS(0);
            constraints.add(infeasibleConstraint);
        }
    }
    return constraints;
}
Also used : ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) LinearConstraint(com.jopdesign.wcet.ipet.LinearConstraint) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Aggregations

SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)3 LinearConstraint (com.jopdesign.wcet.ipet.LinearConstraint)3 CFGEdge (com.jopdesign.common.code.ControlFlowGraph.CFGEdge)2 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)2 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)2 ArrayList (java.util.ArrayList)2 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)1 ExecutionContext (com.jopdesign.common.code.ExecutionContext)1 LoopBound (com.jopdesign.common.code.LoopBound)1 SymbolicMarker (com.jopdesign.common.code.SymbolicMarker)1 AppInfoError (com.jopdesign.common.misc.AppInfoError)1 LoopBoundExpr (com.jopdesign.wcet.annotations.LoopBoundExpr)1