Search in sources :

Example 16 with ExecutionContext

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

the class ObjectCacheAnalysis method contextForSegment.

/**
	 * XXX: temporary helper to bridge gap between two representations (segment and scope)
	 * @param segment
	 * @return the corresponding execution context
	 * @throws RuntimeException if the conversion is impossible
	 */
private ExecutionContext contextForSegment(Segment segment) {
    ContextCFG entry;
    Set<ContextCFG> entries = segment.getEntryCFGs();
    if (entries.size() != 1) {
        throw new RuntimeException("contextForSegment(): Currently we only support a single entry method");
    }
    entry = entries.iterator().next();
    return new ExecutionContext(entry.getCfg().getMethodInfo(), entry.getCallString());
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG)

Example 17 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext 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) LinearConstraint(com.jopdesign.wcet.ipet.LinearConstraint) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SymbolicMarker(com.jopdesign.common.code.SymbolicMarker)

Example 18 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext 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 19 with ExecutionContext

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

the class WCETTool method getLoopBound.

// TODO move somewhere else?
public LoopBound getLoopBound(CFGNode node, CallString cs) {
    LoopBound globalBound = node.getLoopBound();
    ExecutionContext eCtx = new ExecutionContext(node.getControlFlowGraph().getMethodInfo(), cs);
    if (node.getBasicBlock() != null) {
        return this.getEventHandler().dfaLoopBound(node.getBasicBlock(), eCtx, globalBound);
    } else {
        return globalBound;
    }
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) LoopBound(com.jopdesign.common.code.LoopBound)

Example 20 with ExecutionContext

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

Aggregations

ExecutionContext (com.jopdesign.common.code.ExecutionContext)34 MethodInfo (com.jopdesign.common.MethodInfo)15 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)11 LinkedHashSet (java.util.LinkedHashSet)10 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)6 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)6 Set (java.util.Set)4 MethodCode (com.jopdesign.common.MethodCode)3 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)3 LoopBound (com.jopdesign.common.code.LoopBound)3 DFSTraverser (com.jopdesign.common.graphutils.DFSTraverser)3 EmptyDFSVisitor (com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor)3 AppInfoError (com.jopdesign.common.misc.AppInfoError)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 InstructionHandle (org.apache.bcel.generic.InstructionHandle)3 ClassInfo (com.jopdesign.common.ClassInfo)2 BasicBlock (com.jopdesign.common.code.BasicBlock)2 CallGraph (com.jopdesign.common.code.CallGraph)2 InvokeSite (com.jopdesign.common.code.InvokeSite)2