Search in sources :

Example 6 with CFGEdge

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

Example 7 with CFGEdge

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

the class SuperGraph method createSuperGraph.

private void createSuperGraph() {
    Stack<ContextCFG> todo = new Stack<ContextCFG>();
    todo.push(rootNode);
    superGraph.addVertex(rootNode);
    while (!todo.empty()) {
        ContextCFG current = todo.pop();
        if (!current.getCfg().areVirtualInvokesResolved()) {
            throw new AssertionError("Virtual dispatch nodes not yet supported for supergraph (file a bug)");
        }
        ControlFlowGraph currentCFG = current.getCfg();
        CallString currentCS = current.getCallString();
        Collection<CFGEdge> infeasibleEdges = infeasibleEdgeProvider.getInfeasibleEdges(currentCFG, currentCS);
        for (CFGNode node : current.getCfg().vertexSet()) {
            if (node instanceof ControlFlowGraph.InvokeNode) {
                /* skip node if all incoming edges are infeasible in the current call context */
                boolean infeasible = true;
                for (CFGEdge e : current.getCfg().incomingEdgesOf(node)) {
                    if (!infeasibleEdges.contains(e)) {
                        infeasible = false;
                    }
                }
                if (infeasible)
                    continue;
                ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
                Set<MethodInfo> impls = iNode.getImplementingMethods();
                if (impls.size() == 0) {
                    throw new AssertionError("No implementations for iNode available");
                } else if (impls.size() != 1) {
                    throw new AssertionError("Unresolved virtual Dispatch for " + iNode + ": " + impls);
                }
                for (MethodInfo impl : impls) {
                    ControlFlowGraph invokedCFG = cfgProvider.getFlowGraph(impl);
                    CallString invokedCS = currentCS.push(iNode, callstringLength);
                    /* skip node if receiver is infeasible in current call context */
                    if (infeasibleEdgeProvider.isInfeasibleReceiver(impl, invokedCS)) {
                        Logger.getLogger(this.getClass()).info("createSuperGraph(): infeasible receiver " + impl);
                        continue;
                    }
                    ContextCFG invoked = new ContextCFG(invokedCFG, invokedCS);
                    if (!superGraph.containsVertex(invoked)) {
                        superGraph.addVertex(invoked);
                        todo.push(invoked);
                    }
                    addEdge(iNode, current, invoked);
                }
            }
        }
    }
}
Also used : InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) Stack(java.util.Stack) InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode) MethodInfo(com.jopdesign.common.MethodInfo) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 8 with CFGEdge

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

the class WCETTool method dfaInfeasibleEdge.

/**
     * Get infeasible edges for certain basic block call string
     * @param cfg the CFG containing the block
     * @param block get infeasible outgoing edges for the block
     * @param cs the callstring
     * @return The infeasible edges for this basic block
     */
private List<CFGEdge> dfaInfeasibleEdge(ControlFlowGraph cfg, BasicBlock block, CallString cs) {
    List<CFGEdge> retval = new LinkedList<CFGEdge>();
    if (getDfaLoopBounds() != null) {
        LoopBounds lbs = getDfaLoopBounds();
        Set<FlowEdge> edges = lbs.getInfeasibleEdges(block.getLastInstruction(), cs);
        for (FlowEdge e : edges) {
            BasicBlockNode head = cfg.getHandleNode(e.getHead());
            BasicBlockNode tail = cfg.getHandleNode(e.getTail());
            CFGEdge edge = cfg.getEdge(tail, head);
            if (edge != null) {
                retval.add(edge);
            } else {
            // edge does was removed from the CFG
            // logger.warn("The infeasible edge between "+head+" and "+tail+" does not exist");                	
            }
        }
    }
    return retval;
}
Also used : FlowEdge(com.jopdesign.dfa.framework.FlowEdge) LoopBounds(com.jopdesign.dfa.analyses.LoopBounds) BasicBlockNode(com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode) LinkedList(java.util.LinkedList) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 9 with CFGEdge

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

Aggregations

CFGEdge (com.jopdesign.common.code.ControlFlowGraph.CFGEdge)9 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)5 MethodInfo (com.jopdesign.common.MethodInfo)3 ArrayList (java.util.ArrayList)3 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)2 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)2 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)2 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)2 Stack (java.util.Stack)2 BasicBlock (com.jopdesign.common.code.BasicBlock)1 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 LoopBound (com.jopdesign.common.code.LoopBound)1 Pair (com.jopdesign.common.graphutils.Pair)1 ProgressMeasure (com.jopdesign.common.graphutils.ProgressMeasure)1 LoopBounds (com.jopdesign.dfa.analyses.LoopBounds)1 FlowEdge (com.jopdesign.dfa.framework.FlowEdge)1 ExecutionEdge (com.jopdesign.wcet.ipet.IPETBuilder.ExecutionEdge)1 LinearConstraint (com.jopdesign.wcet.ipet.LinearConstraint)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1