Search in sources :

Example 6 with SuperGraphEdge

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

the class MethodCacheAnalysis method findPersistenceSegmentCover.

/**
 * Find a segment cover (i.e., a set of segments covering all execution paths)
 *  where each segment in the set is persistent (a cache persistence region (CPR))
 *
 *  <h2>The simplest algorithm for a segment S (for acyclic callgraphs)</h2>
 *   <ul><li/>Check whether S itself is CPR; if so, return S
 *       <li/>Otherwise, create subsegments S' for each invoked method,
 *       <li/>and single node segments for each access
 *   </ul>
 * @param segment the parent segment
 * @param checks the strategy to use to determine whether a segment is a persistence region
 * @param avoidOverlap whether overlapping segments should be avoided
 * @param extraCostOut additional cost for edges which are considered as always-miss or not-cached
 * @return
 */
protected Collection<Segment> findPersistenceSegmentCover(Segment segment, EnumSet<PersistenceCheck> checks, boolean avoidOverlap, Map<SuperGraphEdge, Long> extraCostOut) {
    List<Segment> cover = new ArrayList<Segment>();
    /* We currently only support entries to one CFG */
    Set<ContextCFG> entryMethods = new HashSet<ContextCFG>();
    for (SuperGraphEdge entryEdge : segment.getEntryEdges()) {
        entryMethods.add(entryEdge.getTarget().getContextCFG());
    }
    if (entryMethods.size() != 1) {
        throw new AssertionError("findPersistenceSegmentCover: only supporting segments with unique entry method");
    }
    if (this.isPersistenceRegion(segment, checks)) {
        // System.err.println("Adding cover segment for: "+entryMethods);
        cover.add(segment);
    } else {
        for (Pair<SuperInvokeEdge, SuperReturnEdge> invocation : segment.getCallSitesFrom(entryMethods.iterator().next())) {
            ContextCFG callee = invocation.first().getCallee();
            // System.err.println("Recursively analyzing: "+callee);
            Segment subSegment = Segment.methodSegment(callee, segment.getSuperGraph());
            Collection<Segment> subRegions = findPersistenceSegmentCover(subSegment, checks, avoidOverlap, extraCostOut);
            cover.addAll(subRegions);
            SuperReturnEdge rEdge = invocation.second();
            MiscUtils.incrementBy(extraCostOut, rEdge, getMissCost(rEdge), 0);
        }
    }
    return cover;
}
Also used : ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) Segment(com.jopdesign.common.code.Segment) HashSet(java.util.HashSet) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Example 7 with SuperGraphEdge

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

the class ObjectCacheAnalysis method computeCacheCost.

/**
 * Compute object cache cost for the given persistence segment
 * @param segment the segment to consider
 * @param usedRefs DFA result: the set of objects a reference might point to during one execution
 *        of the segment
 * @param costModel The object cost model to use
 * @param usedSetOut <b>out</b> set of all symbolic objects names in the segment (pass in empty set)
 * @return the object cache cost for the specified segment
 * @throws InvalidFlowFactException
 * @throws LpSolveException
 */
private ObjectCacheCost computeCacheCost(Segment segment, LocalPointsToResult usedRefs, ObjectCacheCostModel costModel, HashSet<SymbolicAddress> usedSetOut) throws InvalidFlowFactException, LpSolveException {
    /* create an ILP graph for all reachable methods */
    String key = GlobalAnalysis.formatProblemName(KEY, segment.getEntryCFGs().toString());
    IPETSolver<SuperGraphEdge> ipetSolver = GlobalAnalysis.buildIpetProblem(project, key, segment, new IPETConfig(project.getConfig()));
    ObjectCacheIPETModel ocim = addObjectCacheCostEdges(segment, usedRefs, costModel, ipetSolver);
    /* solve */
    double lpCost;
    Map<SuperGraphEdge, Long> flowMap = new HashMap<SuperGraphEdge, Long>();
    lpCost = ipetSolver.solve(flowMap, true);
    long cost = (long) (lpCost + 0.5);
    return extractCost(segment, cost, flowMap, ocim.accessCostInfo, costModel, ocim.refMissEdges, ocim.blockMissEdges);
}
Also used : HashMap(java.util.HashMap) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) CallString(com.jopdesign.common.code.CallString) IPETConfig(com.jopdesign.wcet.ipet.IPETConfig)

Example 8 with SuperGraphEdge

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

the class ObjectCacheAnalysis method addObjectCacheCostEdges.

/**
 * @param segment
 * @param usedRefs
 * @param costModel
 * @param ipetSolver
 * @return
 */
private ObjectCacheIPETModel addObjectCacheCostEdges(Segment segment, LocalPointsToResult usedRefs, ObjectCacheCostModel costModel, IPETSolver<SuperGraphEdge> ipetSolver) {
    final AccessCostInfo accessCostInfo = extractAccessesAndCosts(segment, usedRefs, costModel);
    ObjectCacheIPETModel model = new ObjectCacheIPETModel();
    model.accessCostInfo = accessCostInfo;
    /* cache cost edges (bypass/always miss) */
    model.staticCostEdges = addFixedCostEdges(segment.getEdges(), ipetSolver, new MiscUtils.F1<SuperGraphEdge, Long>() {

        @Override
        public Long apply(SuperGraphEdge v) {
            return accessCostInfo.getStaticCost(v.getTarget());
        }
    }, KEY + "_static", 0);
    /* cache cost edges (miss once) */
    /* for references */
    model.refMissEdges = addPersistenceSegmentConstraints(segment, accessCostInfo.getRefAccesses(segment), ipetSolver, MiscUtils.<SuperGraphEdge, Long>const1(costModel.getReplaceLineCost()), KEY + "_ref");
    /* and for blocks */
    model.blockMissEdges = addPersistenceSegmentConstraints(segment, accessCostInfo.getBlockAccesses(segment), ipetSolver, MiscUtils.<SuperGraphEdge, Long>const1(costModel.getLoadCacheBlockCost()), KEY + "_block");
    return model;
}
Also used : AccessCostInfo(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) F1(com.jopdesign.common.misc.MiscUtils.F1)

Example 9 with SuperGraphEdge

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

the class CachePersistenceAnalysis method fixedAdditionalCostEdge.

/**
 * Generate extra cost edge with fixed additional cost
 * @param accessEdge the corresponding flow edge (key-1)
 * @param key the access category (key-2)
 * @param tag the accessed tag    (key-3)
 * @param cost the extra cost when executing the edge
 * @param ipetSolver the ipet solver to operate on
 * @return
 */
protected SuperGraphEdge fixedAdditionalCostEdge(SuperGraphEdge accessEdge, Object key, Object tag, long cost, IPETSolver<SuperGraphEdge> ipetSolver) {
    SuperGraphEdge missEdge = SuperGraphExtraCostEdge.generateExtraCostEdge(accessEdge, key, tag);
    ipetSolver.addConstraint(IPETUtils.relativeBound(Iterators.singleton(missEdge), Iterators.singleton(accessEdge), 1));
    ipetSolver.addEdgeCost(missEdge, cost);
    return missEdge;
}
Also used : SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge)

Example 10 with SuperGraphEdge

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

the class CachePersistenceAnalysis method computeMissOnceCost.

/**
 * Analyze the cost for loading each distinct tag in the given segment at most once.
 * This can also be used to count the number of distinct tags (given each tag the cost of 1),
 * or the number of cache blocks for the variable block method cache (given each tag a cost
 * equal to the number of cache blocks it needs)
 * @param segment the segment to analyze
 * @param accessEdges cache access edges partitioned by tag
 * @param costModel
 * @param useILP use integer variables (more expensive, more accurate)
 * @param analysisKey
 * @param wcetTool
 * @return
 * @throws InvalidFlowFactException
 * @throws LpSolveException
 */
protected <T> long computeMissOnceCost(Segment segment, Iterable<Entry<T, List<SuperGraphEdge>>> partition, F1<SuperGraphEdge, Long> costModel, boolean useILP, String analysisKey, WCETTool wcetTool) throws InvalidFlowFactException, LpSolveException {
    IPETConfig ipetConfig = new IPETConfig(wcetTool.getConfig());
    String problemKey = GlobalAnalysis.formatProblemName(analysisKey, segment.getEntryCFGs().toString());
    /* create an global IPET problem for the supergraph */
    IPETSolver<SuperGraphEdge> ipetSolver = GlobalAnalysis.buildIpetProblem(wcetTool, problemKey, segment, ipetConfig);
    /* add persistence constraints */
    addPersistenceSegmentConstraints(segment, partition, ipetSolver, costModel, analysisKey);
    /* Solve */
    double lpCost = ipetSolver.solve(null, useILP);
    long maxCacheCost = (long) (lpCost + 0.5);
    return maxCacheCost;
}
Also used : SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) IPETConfig(com.jopdesign.wcet.ipet.IPETConfig)

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