Search in sources :

Example 6 with CFGNode

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

the class SuperGraph method outgoingEdgesOf.

/**
	 * The outgoing edges are generated as follows:
	 * <ul>
	 * <li/>invoke node: superedge invoking the callee
	 * <li/>exit node: superedge returning to the caller
	 * <li/>other: intraprocedural CFG edge
	 * </ul>
	 * @param node
	 * @return
	 */
public Iterable<SuperGraphEdge> outgoingEdgesOf(SuperGraphNode node) {
    CFGNode cfgNode = node.getCFGNode();
    if (cfgNode instanceof InvokeNode) {
        /* invoke node: outgoing SuperInvoke edges */
        final InvokeNode invNode = (InvokeNode) cfgNode;
        Set<SuperEdge> outgoingInvokeEdges = superGraph.outgoingEdgesOf(node.getContextCFG());
        return new Filter<SuperGraphEdge>() {

            @Override
            protected boolean include(SuperGraphEdge e) {
                if (!(e instanceof SuperInvokeEdge))
                    return false;
                SuperInvokeEdge invoke = (SuperInvokeEdge) e;
                return invoke.getInvokeNode().equals(invNode);
            }
        }.<SuperGraphEdge>filter(outgoingInvokeEdges);
    } else if (cfgNode instanceof VirtualNode && ((VirtualNode) cfgNode).getKind() == VirtualNodeKind.EXIT) {
        /* exit node: outgoing SuperReturn edges */
        Set<SuperEdge> outgoingReturnEdges = superGraph.outgoingEdgesOf(node.getContextCFG());
        return new Filter<SuperGraphEdge>() {

            @Override
            protected boolean include(SuperGraphEdge e) {
                return (e instanceof SuperReturnEdge);
            }
        }.<SuperGraphEdge>filter(outgoingReturnEdges);
    } else {
        /* standard edges: outgoing edges of cfg node */
        Set<CFGEdge> outgoingCFGEdges = node.getContextCFG().getCfg().outgoingEdgesOf(cfgNode);
        return liftCFGEdges(node.getContextCFG(), outgoingCFGEdges);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) Filter(com.jopdesign.common.misc.Filter) VirtualNode(com.jopdesign.common.code.ControlFlowGraph.VirtualNode) InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode)

Example 7 with CFGNode

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

the class TreeAnalysis method extractUBs.

private Map<CFGNode, Long> extractUBs(Map<CFGNode, LoopBound> loopBounds) {
    Map<CFGNode, Long> ubMap = new HashMap<CFGNode, Long>();
    for (Entry<CFGNode, LoopBound> entry : loopBounds.entrySet()) {
        MethodInfo mi = entry.getKey().getControlFlowGraph().getMethodInfo();
        ExecutionContext eCtx = new ExecutionContext(mi);
        ubMap.put(entry.getKey(), entry.getValue().getUpperBound(eCtx));
    }
    return ubMap;
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) HashMap(java.util.HashMap) LoopBound(com.jopdesign.common.code.LoopBound) MethodInfo(com.jopdesign.common.MethodInfo)

Example 8 with CFGNode

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

the class TreeAnalysis method computeProgress.

/* FIXME: filter leaf methods is really a ugly hack,
         * but needs some work to play nice with uppaal eliminate-leaf-methods optimizations
         */
public void computeProgress(MethodInfo targetMethod, CallString cs) {
    List<MethodInfo> reachable = project.getCallGraph().getReachableImplementations(targetMethod, cs);
    Collections.reverse(reachable);
    for (MethodInfo mi : reachable) {
        ControlFlowGraph cfg = project.getFlowGraph(mi);
        Map<CFGNode, Long> localProgress = new HashMap<CFGNode, Long>();
        ProgressVisitor progressVisitor = new ProgressVisitor(maxProgress);
        for (CFGNode n : cfg.vertexSet()) {
            localProgress.put(n, progressVisitor.getProgress(n));
        }
        ProgressMeasure<CFGNode, CFGEdge> pm = new ProgressMeasure<CFGNode, ControlFlowGraph.CFGEdge>(cfg.getGraph(), cfg.getLoopColoring(), extractUBs(cfg.buildLoopBoundMap()), localProgress);
        long progress = pm.getMaxProgress().get(cfg.getExit());
        /* FIXME: _UGLY_ hack */
        if (filterLeafMethods && cfg.isLeafMethod()) {
            maxProgress.put(mi, 0L);
        } else {
            maxProgress.put(mi, progress);
        }
        relativeProgress.put(mi, pm.computeRelativeProgress());
    }
    System.out.println("Progress Measure (max): " + maxProgress.get(targetMethod));
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) HashMap(java.util.HashMap) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo) ProgressMeasure(com.jopdesign.common.graphutils.ProgressMeasure) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 9 with CFGNode

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

the class ExecuteOnceAnalysis method analyze.

private void analyze() {
    inLoopSet = new HashMap<ExecutionContext, Set<MethodInfo>>();
    /* Top Down the Scope Graph */
    TopologicalOrderIterator<ExecutionContext, ContextEdge> iter = project.getCallGraph().topDownIterator();
    while (iter.hasNext()) {
        ExecutionContext scope = iter.next();
        scope = new ExecutionContext(scope.getMethodInfo());
        /* Remove call string */
        ControlFlowGraph cfg = project.getFlowGraph(scope.getMethodInfo());
        Set<MethodInfo> inLoop = new HashSet<MethodInfo>();
        for (CFGNode node : cfg.vertexSet()) {
            if (!(node instanceof ControlFlowGraph.InvokeNode))
                continue;
            ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
            if (!cfg.getLoopColoring().getLoopColor(node).isEmpty()) {
                for (MethodInfo impl : iNode.getImplementingMethods()) {
                    inLoop.add(impl);
                    inLoop.addAll(project.getCallGraph().getReachableImplementationsSet(impl));
                }
            }
        }
        inLoopSet.put(scope, inLoop);
    }
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) HashSet(java.util.HashSet) Set(java.util.Set) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) HashSet(java.util.HashSet)

Example 10 with CFGNode

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

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