Search in sources :

Example 1 with ControlFlowGraph

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

the class JavaOneProcessPerMethodTranslator method recordLoops.

private void recordLoops(MethodInfo mi, TemplateBuilder pb) {
    ControlFlowGraph cfg = project.getFlowGraph(mi);
    for (CFGNode hol : cfg.getLoopColoring().getHeadOfLoops()) {
        LoopBound bound = hol.getLoopBound();
        int nesting = cfg.getLoopColoring().getLoopColor(hol).size();
        pb.addLoop(hol, nesting, bound);
    }
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) LoopBound(com.jopdesign.common.code.LoopBound) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph)

Example 2 with ControlFlowGraph

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

the class JavaOneProcessPerSupergraphTranslator method computeMethodNestingDepths.

private void computeMethodNestingDepths() throws BadGraphException {
    this.methodMNDs = new HashMap<MethodInfo, Integer>();
    /* for super graph nodes in topological order */
    for (ContextCFG n : superGraph.topologicalOrderIterator().getTopologicalTraversal()) {
        MethodInfo methodInvoked = n.getCfg().getMethodInfo();
        int maxCaller = 0;
        for (Pair<SuperGraph.SuperInvokeEdge, SuperGraph.SuperReturnEdge> callSite : superGraph.getCallSitesInvoking(n)) {
            ControlFlowGraph.InvokeNode callSiteNode = callSite.first().getInvokeNode();
            ControlFlowGraph cfgInvoker = callSiteNode.invokerFlowGraph();
            int callerRootDepth = methodMNDs.get(cfgInvoker.getMethodInfo());
            int nestingDepth = cfgInvoker.getLoopColoring().getLoopColor(callSiteNode).size();
            maxCaller = Math.max(maxCaller, callerRootDepth + nestingDepth);
        }
        Integer oldValue = methodMNDs.get(methodInvoked);
        if (oldValue == null)
            oldValue = 0;
        methodMNDs.put(methodInvoked, Math.max(oldValue, maxCaller));
    }
    if (config.debug)
        MiscUtils.printMap(System.out, methodMNDs, 30, 0);
}
Also used : ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo)

Example 3 with ControlFlowGraph

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

the class JavaTranslator method translateMethod.

protected void translateMethod(TemplateBuilder tb, SubAutomaton methodAutomaton, int mId, MethodInfo mi, InvokeBuilder invokeBuilder) {
    /* get flow graph */
    ControlFlowGraph cfg = project.getFlowGraph(mi);
    MethodBuilder mBuilder = new MethodBuilder(this, tb, invokeBuilder, methodAutomaton, mId, cfg);
    mBuilder.build();
}
Also used : ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph)

Example 4 with ControlFlowGraph

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

the class WCAInvoker method updateWCEP.

private void updateWCEP() {
    if (!provideWCAExecCount)
        return;
    execCounts.clear();
    for (MethodInfo root : getWcaTargets()) {
        execCounts.put(root, 1L);
    }
    NodeVisitor<ExecutionContext> visitor = new NodeVisitor<ExecutionContext>() {

        @Override
        public boolean visitNode(ExecutionContext context) {
            MethodInfo method = context.getMethodInfo();
            MethodCode code = method.getCode();
            long ec = getExecCount(method);
            // skip methods which are not on the WCET path.. we can ship iterating over the childs too..
            if (ec == 0)
                return false;
            // iterate over all blocks in the CFG, find all invokes and add block execution counts to invokees
            ControlFlowGraph cfg = method.getCode().getControlFlowGraph(false);
            for (CFGNode node : cfg.getGraph().vertexSet()) {
                if (node instanceof InvokeNode) {
                    InvokeNode inv = (InvokeNode) node;
                    long ef = getExecFrequency(method, node);
                    for (MethodInfo invokee : inv.getImplementingMethods()) {
                        addExecCount(invokee, ec * ef);
                    }
                } else if (node instanceof BasicBlockNode) {
                    // check if we have a JVM invoke here (or an invoke not in a dedicated node..)
                    for (InstructionHandle ih : node.getBasicBlock().getInstructions()) {
                        if (!code.isInvokeSite(ih))
                            continue;
                        long ef = getExecFrequency(method, node);
                        for (MethodInfo invokee : method.getAppInfo().findImplementations(code.getInvokeSite(ih))) {
                            addExecCount(invokee, ec * ef);
                        }
                    }
                }
            }
            return true;
        }
    };
    TopologicalTraverser<ExecutionContext, ContextEdge> topOrder = new TopologicalTraverser<ExecutionContext, ContextEdge>(wcetTool.getCallGraph().getGraph(), visitor);
    topOrder.traverse();
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) BasicBlockNode(com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle) NodeVisitor(com.jopdesign.common.graphutils.NodeVisitor) ExecutionContext(com.jopdesign.common.code.ExecutionContext) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode) TopologicalTraverser(com.jopdesign.common.graphutils.TopologicalTraverser) MethodInfo(com.jopdesign.common.MethodInfo) MethodCode(com.jopdesign.common.MethodCode)

Example 5 with ControlFlowGraph

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

the class WCAInvoker method getExecFrequency.

@Override
public long getExecFrequency(MethodInfo method, InstructionHandle ih) {
    ControlFlowGraph cfg = method.getCode().getControlFlowGraph(false);
    BasicBlockNode block = cfg.getHandleNode(ih);
    return getExecFrequency(method, block);
}
Also used : BasicBlockNode(com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph)

Aggregations

ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)23 MethodInfo (com.jopdesign.common.MethodInfo)12 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)10 CFGEdge (com.jopdesign.common.code.ControlFlowGraph.CFGEdge)5 ExecutionContext (com.jopdesign.common.code.ExecutionContext)5 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)4 LoopBound (com.jopdesign.common.code.LoopBound)4 BadGraphError (com.jopdesign.common.misc.BadGraphError)3 BadGraphException (com.jopdesign.common.misc.BadGraphException)3 HashMap (java.util.HashMap)3 InstructionHandle (org.apache.bcel.generic.InstructionHandle)3 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)2 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)2 ProgressMeasure (com.jopdesign.common.graphutils.ProgressMeasure)2 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodCode (com.jopdesign.common.MethodCode)1 BasicBlock (com.jopdesign.common.code.BasicBlock)1 CallString (com.jopdesign.common.code.CallString)1 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)1