Search in sources :

Example 1 with ContextEdge

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

the class WCETAnalysis method exploreCacheAnalysis.

/**
 * @param mca
 * @param iter
 * @throws InvalidFlowFactException
 */
@SuppressWarnings("unused")
private void exploreCacheAnalysis() throws InvalidFlowFactException {
    // Segment Cache Analysis: Experiments
    MethodCacheAnalysis mca = new MethodCacheAnalysis(wcetTool);
    /* iterate top down the scope graph (currently: the call graph) */
    TopologicalOrderIterator<ExecutionContext, ContextEdge> iter = wcetTool.getCallGraph().reverseTopologicalOrder();
    LpSolveWrapper.resetSolverTime();
    long blocks = 0;
    long start = System.nanoTime();
    while (iter.hasNext()) {
        ExecutionContext scope = iter.next();
        Segment segment = Segment.methodSegment(scope.getMethodInfo(), scope.getCallString(), wcetTool, wcetTool.getCallstringLength(), wcetTool);
        int availBlocks = wcetTool.getWCETProcessorModel().getMethodCache().getNumBlocks();
        long total, distinctApprox = -1, distinct = -1;
        blocks = total = mca.countDistinctBlocksUsed(segment);
        if (total > availBlocks || true) {
            try {
                blocks = distinctApprox = mca.countDistinctBlocksAccessed(segment, false);
                if (blocks > availBlocks && blocks < availBlocks * 2 || true) {
                    blocks = distinct = mca.countDistinctBlocksAccessed(segment, true);
                }
            } catch (LpSolveException e) {
                System.err.println((distinctApprox >= 0 ? "I" : "Relaxed ") + "LP Problem too difficult, giving up: " + e);
            }
        }
        System.out.println(String.format("block-count < %2d [%2d,%2d,%2d] for %-30s @ %s", blocks, total, distinctApprox, distinct, scope.getMethodInfo().getFQMethodName(), scope.getCallString().toStringVerbose(false)));
    }
    long stop = System.nanoTime();
    reportSpecial("block-count", WcetCost.totalCost(blocks), start, stop, LpSolveWrapper.getSolverTime());
    System.out.println("solver-time: " + LpSolveWrapper.getSolverTime());
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodCacheAnalysis(com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis) LpSolveException(lpsolve.LpSolveException) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) Segment(com.jopdesign.common.code.Segment)

Example 2 with ContextEdge

use of com.jopdesign.common.code.CallGraph.ContextEdge 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 3 with ContextEdge

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

the class ExecFrequencyAnalysis method updateExecCounts.

private void updateExecCounts(DirectedGraph<ExecutionContext, ContextEdge> dag) {
    // For now, we just require the graph to be a DAG.
    // TODO for all back-edges, we should find some max recursion count and update reachable nodes accordingly..
    // For now, we just assume we have no recursion (backedges are only due to insufficient callgraph thinning)
    // or simply ignore recursion (unsafe, of course..)
    // for the rest of the graph, we can now use a topological order
    TopologicalOrderIterator<ExecutionContext, ContextEdge> topOrder = new TopologicalOrderIterator<ExecutionContext, ContextEdge>(dag);
    while (topOrder.hasNext()) {
        ExecutionContext next = topOrder.next();
        if (logger.isTraceEnabled()) {
            logger.trace("Updating: " + next);
        }
        updateChilds(next);
    }
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) TopologicalOrderIterator(org.jgrapht.traverse.TopologicalOrderIterator) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge)

Example 4 with ContextEdge

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

the class MethodCacheAnalysis method updateNodes.

private void updateNodes(SimpleDirectedGraph<ExecutionContext, ContextEdge> closure, Set<ExecutionContext> nodes, boolean reuseResults) {
    for (ExecutionContext node : nodes) {
        if (node.getMethodInfo().isNative())
            continue;
        // We could make this more memory efficient, because in many cases we do not need a
        // separate set for each node, but this would be more complicated to calculate
        Set<MethodInfo> reachable = new LinkedHashSet<MethodInfo>();
        reachable.add(node.getMethodInfo());
        // we only need to add all children to the set, no need to go down the graph
        for (ContextEdge edge : closure.outgoingEdgesOf(node)) {
            ExecutionContext target = edge.getTarget();
            if (target.getMethodInfo().isNative())
                continue;
            if (reuseResults && !nodes.contains(target)) {
                reachable.addAll(reachableMethods.get(target));
            } else {
                reachable.add(target.getMethodInfo());
            }
        }
        reachableMethods.put(node, reachable);
    }
    MethodCache cache = jcopter.getMethodCache();
    // now we can sum up the cache blocks for all nodes in the graph
    for (ExecutionContext node : nodes) {
        if (node.getMethodInfo().isNative())
            continue;
        Set<MethodInfo> reachable = reachableMethods.get(node);
        int blocks = 0;
        for (MethodInfo method : reachable) {
            int size = MiscUtils.bytesToWords(getMethodSize(method));
            blocks += cache.requiredNumberOfBlocks(size);
        }
        cacheBlocks.put(node, blocks);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodCache(com.jopdesign.wcet.jop.MethodCache) MethodInfo(com.jopdesign.common.MethodInfo) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge)

Example 5 with ContextEdge

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

the class RebateSelector method initialize.

@Override
public void initialize(GreedyConfig config, boolean dumpStats) {
    // calculate current global codesize
    globalCodesize = 0;
    if (usesCodeRemover) {
        for (MethodInfo method : AppInfo.getSingleton().getCallGraph().getMethodInfos()) {
            if (!method.hasCode())
                continue;
            globalCodesize += method.getCode().getNumberOfBytes();
        }
    } else {
        for (ClassInfo cls : AppInfo.getSingleton().getClassInfos()) {
            for (MethodInfo method : cls.getMethods()) {
                if (!method.hasCode())
                    continue;
                globalCodesize += method.getCode().getNumberOfBytes();
            }
        }
    }
    // we need a tie-breaker for the candidate selection, and to make the results deterministic
    // so we use a topological order of the (initial) callgraph
    DFSVisitor<ExecutionContext, ContextEdge> visitor = new EmptyDFSVisitor<ExecutionContext, ContextEdge>() {

        private int counter = 1;

        @Override
        public void postorder(ExecutionContext node) {
            depthMap.put(node.getMethodInfo(), counter++);
        }
    };
    DirectedGraph<ExecutionContext, ContextEdge> graph = analyses.getTargetCallGraph().getReversedGraph();
    DFSTraverser<ExecutionContext, ContextEdge> traverser = new DFSTraverser<ExecutionContext, ContextEdge>(visitor);
    traverser.traverse(graph);
    logger.info("Initial codesize: " + globalCodesize + " bytes");
    if (config.doDumpStats() && dumpStats) {
        try {
            File statsFile = config.getStatsFile();
            dump = new PrintWriter(statsFile);
            dump.print("total codesize, ");
            if (analyses.useWCAInvoker())
                dump.print("WCET, ");
            dump.println("candidate, ratio, gain, local gain, cache, local cache, delta codesize, frequency");
        } catch (FileNotFoundException e) {
            throw new AppInfoError("Could not initialize dump file", e);
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) EmptyDFSVisitor(com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) AppInfoError(com.jopdesign.common.misc.AppInfoError) DFSTraverser(com.jopdesign.common.graphutils.DFSTraverser) ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodInfo(com.jopdesign.common.MethodInfo) File(java.io.File) ClassInfo(com.jopdesign.common.ClassInfo) PrintWriter(java.io.PrintWriter)

Aggregations

ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)11 ExecutionContext (com.jopdesign.common.code.ExecutionContext)11 MethodInfo (com.jopdesign.common.MethodInfo)7 LinkedHashSet (java.util.LinkedHashSet)4 DFSTraverser (com.jopdesign.common.graphutils.DFSTraverser)3 EmptyDFSVisitor (com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor)3 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)2 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 TopologicalOrderIterator (org.jgrapht.traverse.TopologicalOrderIterator)2 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodCode (com.jopdesign.common.MethodCode)1 CallGraph (com.jopdesign.common.code.CallGraph)1 CallString (com.jopdesign.common.code.CallString)1 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)1 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 Segment (com.jopdesign.common.code.Segment)1 DFSEdgeType (com.jopdesign.common.graphutils.DFSTraverser.DFSEdgeType)1