Search in sources :

Example 11 with SuperGraphEdge

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

the class CachePersistenceAnalysis method addPersistenceSegmentConstraints.

/**
 * Add constraints for a persistence segment
 * @param <T> cache tag type
 * @param <C> access edge collection type
 * @param persistenceSegment
 * @param partition
 * @param ipetSolver
 * @param costModel
 * @param analysisKey
 * @return
 */
protected <T, C extends Iterable<SuperGraphEdge>> Set<SuperGraphEdge> addPersistenceSegmentConstraints(Segment persistenceSegment, Iterable<Entry<T, C>> partition, IPETSolver<SuperGraphEdge> ipetSolver, F1<SuperGraphEdge, Long> costModel, Object analysisKey) {
    HashSet<SuperGraphEdge> missEdges = new HashSet<SuperGraphEdge>();
    for (Entry<T, C> accessed : partition) {
        List<SuperGraphEdge> missOnceEdges = new ArrayList<SuperGraphEdge>();
        for (SuperGraphEdge accessEdge : accessed.getValue()) {
            long cost = costModel.apply(accessEdge);
            SuperGraphEdge missEdge = SuperGraphExtraCostEdge.generateExtraCostEdge(accessEdge, analysisKey, accessed.getKey());
            ipetSolver.addConstraint(IPETUtils.relativeBound(Iterators.singleton(missEdge), Iterators.singleton(accessEdge), 1));
            ipetSolver.addEdgeCost(missEdge, cost);
            missOnceEdges.add(missEdge);
        }
        ipetSolver.addConstraint(IPETUtils.relativeBound(missOnceEdges, persistenceSegment.getEntryEdges(), 1));
        missEdges.addAll(missOnceEdges);
    }
    return missEdges;
}
Also used : SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 12 with SuperGraphEdge

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

the class GlobalAnalysis method getLoopBounds.

/**
 * <p>Get all loop bounds for the given segment.</p>
 * <p>For each loop bound B for loop H relative to marker M:</p>
 * <p>sum(M) * B &lt;= sum(continue-edges-of(H))</p>
 *
 * @param segment
 * @return
 * @throws InvalidFlowFactException
 */
private static Iterable<LinearConstraint<SuperGraphEdge>> getLoopBounds(WCETTool wcetTool, Segment segment) throws InvalidFlowFactException {
    List<LinearConstraint<SuperGraphEdge>> constraints = new ArrayList<LinearConstraint<SuperGraphEdge>>();
    // For all CFG instances
    for (ContextCFG ccfg : segment.getCallGraphNodes()) {
        ControlFlowGraph cfg = ccfg.getCfg();
        // for all loops in the method
        LoopColoring<CFGNode, ControlFlowGraph.CFGEdge> loops = cfg.getLoopColoring();
        for (CFGNode hol : loops.getHeadOfLoops()) {
            LoopBound loopBound = wcetTool.getLoopBound(hol, ccfg.getContext().getCallString());
            if (loopBound == null) {
                throw new AppInfoError("No loop bound record for head of loop: " + hol + " : " + cfg.buildLoopBoundMap());
            }
            addLoopConstraints(constraints, segment, ccfg, hol, loops, loopBound);
        }
    }
    return constraints;
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) LoopBound(com.jopdesign.common.code.LoopBound) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) LinearConstraint(com.jopdesign.wcet.ipet.LinearConstraint) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) AppInfoError(com.jopdesign.common.misc.AppInfoError) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 13 with SuperGraphEdge

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

the class GlobalAnalysis method exportCostProfile.

/**
 * @param flowMap
 * @param costMissEdges
 * @param ipetSolver
 * @param problemId
 */
private WcetCost exportCostProfile(Map<SuperGraphEdge, Long> flowMap, HashMap<String, Set<SuperGraphEdge>> costMissEdges, IPETSolver<SuperGraphEdge> ipetSolver, String problemId) {
    File profileFile = new File(project.getOutDir("profiles"), problemId + ".txt");
    WcetCost cost = new WcetCost();
    HashMap<SuperGraphEdge, Long> costProfile = new HashMap<SuperGraphEdge, Long>();
    HashMap<SuperGraphEdge, Long> cacheCostProfile = new HashMap<SuperGraphEdge, Long>();
    /* extra cost lookup map */
    HashMap<SuperGraphEdge, String> extraCostKeys = new HashMap<SuperGraphEdge, String>();
    for (Entry<String, Set<SuperGraphEdge>> cacheEntry : costMissEdges.entrySet()) {
        String key = cacheEntry.getKey();
        for (SuperGraphEdge costEdge : cacheEntry.getValue()) {
            extraCostKeys.put(costEdge, key);
        }
    }
    for (Entry<SuperGraphEdge, Long> flowEntry : flowMap.entrySet()) {
        SuperGraphEdge edge = flowEntry.getKey();
        long edgeCost = ipetSolver.getEdgeCost(edge);
        long flowCost = edgeCost * flowEntry.getValue();
        if (extraCostKeys.containsKey(edge)) {
            cost.addCacheCost(extraCostKeys.get(edge), flowCost);
            MiscUtils.incrementBy(cacheCostProfile, edge, flowCost, 0);
        } else {
            cost.addLocalCost(flowCost);
        }
        MiscUtils.incrementBy(costProfile, edge, flowCost, 0);
    }
    /* export profile */
    try {
        ArrayList<Entry<SuperGraphEdge, Long>> profile = new ArrayList<Entry<SuperGraphEdge, Long>>(costProfile.entrySet());
        Collections.sort(profile, new Comparator<Entry<SuperGraphEdge, Long>>() {

            @Override
            public int compare(Entry<SuperGraphEdge, Long> o1, Entry<SuperGraphEdge, Long> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }
        });
        FileWriter fw = new FileWriter(profileFile);
        fw.append("Profile\n");
        fw.append(problemId + "\n");
        fw.append("------------------------------------------------------\n");
        long totalCost = cost.getCost();
        for (Entry<SuperGraphEdge, Long> entry : profile) {
            Long flowCost = entry.getValue();
            double contribution = (100.0 * flowCost) / totalCost;
            fw.append(String.format("  %-50s %8d %.2f%%", entry.getKey(), flowCost, contribution));
            if (cacheCostProfile.containsKey(entry.getKey())) {
                fw.append(String.format(" cache{%d}", cacheCostProfile.get(entry.getKey())));
            }
            fw.append(String.format(" flow{%d}", flowMap.get(entry.getKey())));
            fw.append('\n');
        }
        fw.close();
    } catch (IOException ex) {
        WCETTool.logger.error("Generating profile file failed: " + ex);
    }
    return cost;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Entry(java.util.Map.Entry) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) File(java.io.File)

Example 14 with SuperGraphEdge

use of com.jopdesign.common.code.SuperGraph.SuperGraphEdge 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) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) LinearConstraint(com.jopdesign.wcet.ipet.LinearConstraint) SymbolicMarker(com.jopdesign.common.code.SymbolicMarker)

Example 15 with SuperGraphEdge

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

the class GlobalAnalysis method buildIpetProblem.

/**
 * Create an interprocedural max-cost max-flow problem for the given segment<br/>
 * Notes:<ul>
 * <li/> super graph edges always have the callstring of the invoking method
 * </ul>
 *
 * @param wcetTool    A reference to the WCETTool
 * @param problemName A unique identifier for the problem (for reporting)
 * @param segment     The segment to build the ILP for
 * @param ipetConfig  Cost of nodes (or {@code null} if no cost is associated with nodes)
 * @return The max-cost maxflow problem
 * @throws InvalidFlowFactException
 */
public static IPETSolver<SuperGraphEdge> buildIpetProblem(WCETTool wcetTool, String problemName, Segment segment, IPETConfig ipetConfig) throws InvalidFlowFactException {
    IPETSolver<SuperGraphEdge> ipetSolver = new IPETSolver<SuperGraphEdge>(problemName, ipetConfig);
    /* DEBUGGING: Render segment */
    // try {
    // segment.exportDOT(wcetTool.getProjectConfig().getOutFile(problemName+".dot"));
    // } catch (IOException e) {
    // e.printStackTrace();
    // }
    /* In- and Outflow */
    ipetSolver.addConstraint(IPETUtils.constantFlow(segment.getEntryEdges(), 1));
    ipetSolver.addConstraint(IPETUtils.constantFlow(segment.getExitEdges(), 1));
    /* Structural flow constraints */
    for (SuperGraphNode node : segment.getNodes()) {
        ipetSolver.addConstraint(IPETUtils.flowPreservation(segment.incomingEdgesOf(node), segment.outgoingEdgesOf(node)));
    }
    /* Supergraph constraints */
    for (Pair<SuperInvokeEdge, SuperReturnEdge> superEdgePair : segment.getCallSites()) {
        Iterable<SuperGraphEdge> es1 = Iterators.<SuperGraphEdge>singleton(superEdgePair.first());
        Iterable<SuperGraphEdge> es2 = Iterators.<SuperGraphEdge>singleton(superEdgePair.second());
        ipetSolver.addConstraint(IPETUtils.flowPreservation(es1, es2));
    }
    /* Program Flow Constraints */
    for (LinearConstraint<SuperGraphEdge> flowFact : getFlowFacts(wcetTool, segment)) {
        ipetSolver.addConstraint(flowFact);
    }
    return ipetSolver;
}
Also used : SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) IPETSolver(com.jopdesign.wcet.ipet.IPETSolver) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Aggregations

SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)25 HashSet (java.util.HashSet)12 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)9 SuperGraphNode (com.jopdesign.common.code.SuperGraph.SuperGraphNode)8 ArrayList (java.util.ArrayList)8 Segment (com.jopdesign.common.code.Segment)7 HashMap (java.util.HashMap)7 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)5 SuperInvokeEdge (com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)5 CallString (com.jopdesign.common.code.CallString)4 SuperReturnEdge (com.jopdesign.common.code.SuperGraph.SuperReturnEdge)4 CFGEdge (com.jopdesign.common.code.ControlFlowGraph.CFGEdge)3 AccessCostInfo (com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo)3 LinearConstraint (com.jopdesign.wcet.ipet.LinearConstraint)3 InstructionHandle (org.apache.bcel.generic.InstructionHandle)3 SymbolicAddress (com.jopdesign.dfa.analyses.SymbolicAddress)2 IPETConfig (com.jopdesign.wcet.ipet.IPETConfig)2 ObjectCacheCost (com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2