Search in sources :

Example 1 with CFGEdge

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

the class IPETUtils method infeasibleEdgeConstraints.

/**
 * Compute flow constraints: Infeasible edge constraints
 *
 * @param g   the flow graph
 * @param ctx the invocation context
 * @return A list of flow constraints
 */
public static <C extends CallStringProvider> List<LinearConstraint<ExecutionEdge>> infeasibleEdgeConstraints(ControlFlowGraph g, IPETBuilder<C> ctx) {
    List<LinearConstraint<ExecutionEdge>> constraints = new ArrayList<LinearConstraint<ExecutionEdge>>();
    // -- edge = 0
    for (CFGEdge edge : ctx.getWCETTool().getInfeasibleEdges(g, ctx.getCallString())) {
        LinearConstraint<ExecutionEdge> infeasibleConstraint = new LinearConstraint<ExecutionEdge>(ConstraintType.Equal);
        infeasibleConstraint.addLHS(ctx.newEdge(edge));
        infeasibleConstraint.addRHS(0);
        constraints.add(infeasibleConstraint);
    }
    return constraints;
}
Also used : ArrayList(java.util.ArrayList) ExecutionEdge(com.jopdesign.wcet.ipet.IPETBuilder.ExecutionEdge) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 2 with CFGEdge

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

the class Segment method synchronizedSegment.

/**
 * Create an interprocedural segment for a synchronized block. Currently we do
 * not split basic blocks here, so either you are happy with basic block granularity,
 * or you split the basic block while loading.
 * @param targetBlock The block containing the monitorenter instruction
 * @param monitorEnter The monitor enter instruction
 * @param callString   The context for the method
 * @param cfgProvider A control flow graph provider
 * @param callStringLength Length of the callstrings
 * @param infeasibles Information about infeasible edges (null if no information available)
 *
 * @return a segment representing executions of the synchronized block
 */
public static Segment synchronizedSegment(ContextCFG ccfg, CFGNode entryNode, InstructionHandle monitorEnter, CFGProvider cfgProvider, int callStringLength, InfeasibleEdgeProvider infeasibles) {
    if (infeasibles == null) {
        infeasibles = InfeasibleEdgeProvider.NO_INFEASIBLES;
    }
    ControlFlowGraph cfg = ccfg.getCfg();
    SuperGraph superGraph = new SuperGraph(cfgProvider, cfg, ccfg.getCallString(), callStringLength, infeasibles);
    ContextCFG rootMethod = superGraph.getRootNode();
    /* lift entry edges */
    Set<SuperGraphEdge> entryEdges = Iterators.addAll(new HashSet<SuperGraphEdge>(), superGraph.liftCFGEdges(rootMethod, cfg.incomingEdgesOf(entryNode)));
    /* find exit blocks (might also be in the same block) */
    /* monitorenter followed bei monitorexit in same block => segment only contains this block */
    Set<CFGEdge> monitorExitEdges = new HashSet<CFGEdge>();
    CFGNode currentNode = entryNode;
    int currentNestingLevel = 1;
    Iterator<InstructionHandle> insIter = currentNode.getBasicBlock().getInstructions().iterator();
    while (insIter.hasNext()) {
        if (insIter.next() == monitorEnter)
            break;
    }
    Stack<Pair<CFGNode, Integer>> todo = new Stack<Pair<CFGNode, Integer>>();
    Set<CFGNode> visited = new HashSet<CFGNode>();
    do {
        boolean isExit = false;
        while (insIter.hasNext()) {
            InstructionHandle ih = insIter.next();
            if (ih.getInstruction() instanceof MONITOREXIT) {
                /* blocks outgoing edges terminate segment */
                currentNestingLevel--;
                if (currentNestingLevel == 0) {
                    isExit = true;
                    // If monitorexit is not implemented in Java, the outgoing edges of the
                    // basic block that contains monitorexit end the synchronized block.
                    // In order to avoid imprecision, it is advisable that monitorexit is the
                    // last statement in the basic block.
                    // We also handle the case when monitorexit is implemented in Java. In this case,
                    // currentNode will be a SpecialInvokeNode, urrentNode's only
                    // successor will be the corresponding ReturnNode, and the outgoing edges of
                    // the ReturnNode are the exit edges for the synchronized segment.
                    CFGNode onlySuccessor = Iterators.fromSingleton(cfg.getSuccessors(currentNode));
                    if (onlySuccessor != null && onlySuccessor instanceof ControlFlowGraph.ReturnNode) {
                        Iterators.addAll(monitorExitEdges, cfg.outgoingEdgesOf(onlySuccessor));
                    } else {
                        Iterators.addAll(monitorExitEdges, cfg.outgoingEdgesOf(currentNode));
                    }
                    break;
                }
            } else if (ih.getInstruction() instanceof MONITORENTER) {
                currentNestingLevel++;
            }
        }
        if (!isExit) {
            for (CFGNode node : cfg.getSuccessors(currentNode)) {
                todo.add(new Pair<CFGNode, Integer>(node, currentNestingLevel));
            }
        }
        currentNode = null;
        while (!todo.isEmpty()) {
            Pair<CFGNode, Integer> nextPair = todo.pop();
            CFGNode nextNode = nextPair.first();
            if (!visited.contains(nextNode)) {
                visited.add(nextNode);
                if (cfg.outgoingEdgesOf(nextNode).isEmpty()) {
                    throw new AssertionError("Found monitor-exit free path from monitorenter to the end of a function. In: " + cfg);
                } else if (nextNode.getBasicBlock() == null) {
                    for (CFGNode node : cfg.getSuccessors(nextNode)) {
                        todo.add(new Pair<CFGNode, Integer>(node, nextPair.second()));
                    }
                } else {
                    currentNode = nextNode;
                    currentNestingLevel = nextPair.second();
                    insIter = currentNode.getBasicBlock().getInstructions().iterator();
                    break;
                }
            }
        }
    } while (currentNode != null);
    Set<SuperGraphEdge> exitEdges = Iterators.addAll(new HashSet<SuperGraphEdge>(), superGraph.liftCFGEdges(rootMethod, monitorExitEdges));
    return new Segment(superGraph, entryEdges, exitEdges);
}
Also used : MONITORENTER(org.apache.bcel.generic.MONITORENTER) InstructionHandle(org.apache.bcel.generic.InstructionHandle) MONITOREXIT(org.apache.bcel.generic.MONITOREXIT) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge) HashSet(java.util.HashSet) Pair(com.jopdesign.common.graphutils.Pair) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) Stack(java.util.Stack) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge)

Example 3 with CFGEdge

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

the class ExecFrequencyAnalysis method getExecFrequency.

public long getExecFrequency(ExecutionContext context, InstructionHandle ih) {
    MethodInfo method = context.getMethodInfo();
    // By loading the CFG, loopbounds are attached to the blocks if the WCA tool is loaded
    ControlFlowGraph cfg = method.getCode().getControlFlowGraph(false);
    LoopColoring<CFGNode, CFGEdge> lc = cfg.getLoopColoring();
    BasicBlockNode node = cfg.getHandleNode(ih, true);
    if (node == null) {
        // THIS IS UNSAFE! but what can you do ...
        return 1;
    }
    long ef = 1;
    for (CFGNode hol : lc.getLoopColor(node)) {
        LoopBound lb = hol.getLoopBound();
        if (lb != null) {
            if (lb.isDefaultBound() && !analyses.isWCAMethod(method)) {
                ef *= DEFAULT_ACET_LOOP_BOUND;
            } else {
                ef *= lb.getUpperBound(context);
            }
        } else {
            ef *= DEFAULT_ACET_LOOP_BOUND;
        }
    }
    return ef;
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) BasicBlockNode(com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode) LoopBound(com.jopdesign.common.code.LoopBound) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 4 with CFGEdge

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

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

the class WCETTool method getInfeasibleEdges.

/**
 * Get infeasible edges for certain call string
 *
 * @param cfg the controlflowgraph of the method
 * @param cs the callstring of the method
 * @return The infeasible edges
 */
public List<CFGEdge> getInfeasibleEdges(ControlFlowGraph cfg, CallString cs) {
    List<CFGEdge> edges = new ArrayList<CFGEdge>();
    for (BasicBlock b : cfg.getBlocks()) {
        List<CFGEdge> edge = dfaInfeasibleEdge(cfg, b, cs);
        edges.addAll(edge);
    }
    return edges;
}
Also used : ArrayList(java.util.ArrayList) BasicBlock(com.jopdesign.common.code.BasicBlock) 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