Search in sources :

Example 1 with Segment

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

the class MethodCacheAnalysis method addMissOnceConstraints.

/**
 * Add miss once constraints for all subsegments in the persistence cover of the given segment
 * @param segment
 * @param ipetSolver
 * @return
 */
@Override
public Set<SuperGraphEdge> addMissOnceConstraints(Segment segment, IPETSolver<SuperGraphEdge> ipetSolver) {
    Set<SuperGraphEdge> missEdges = new HashSet<SuperGraphEdge>();
    Map<SuperGraphEdge, Long> extraCost = new HashMap<SuperGraphEdge, Long>();
    Collection<Segment> cover = findPersistenceSegmentCover(segment, EnumSet.allOf(PersistenceCheck.class), false, extraCost);
    int segmentCounter = 0;
    for (Segment persistenceSegment : cover) {
        /* we need to distinguish edges which are shared between persistence segments */
        String key = KEY + "_" + (++segmentCounter);
        missEdges.addAll(addPersistenceSegmentConstraints(persistenceSegment, getCacheAccessesByTag(persistenceSegment).entrySet(), ipetSolver, EDGE_MISS_COST, key));
    }
    for (Entry<SuperGraphEdge, Long> entry : extraCost.entrySet()) {
        missEdges.add(fixedAdditionalCostEdge(entry.getKey(), KEY + "_am", 0, entry.getValue(), ipetSolver));
    }
    return missEdges;
}
Also used : HashMap(java.util.HashMap) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) CallString(com.jopdesign.common.code.CallString) Segment(com.jopdesign.common.code.Segment) HashSet(java.util.HashSet)

Example 2 with Segment

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

the class MethodCacheAnalysis method addMissOnceCost.

/**
 * Add miss once cost: for each method cache persistence segment, add maximum miss cost to the segment entries
 * @param segment
 * @param ipetSolver
 * @param peristenceChecks which checks to perform
 * @throws LpSolveException
 * @throws InvalidFlowFactException
 */
@Override
public Set<SuperGraphEdge> addMissOnceCost(Segment segment, IPETSolver<SuperGraphEdge> ipetSolver, EnumSet<PersistenceCheck> checks) throws InvalidFlowFactException, LpSolveException {
    Set<SuperGraphEdge> missEdges = new HashSet<SuperGraphEdge>();
    Map<SuperGraphEdge, Long> extraCost = new HashMap<SuperGraphEdge, Long>();
    Collection<Segment> cover = findPersistenceSegmentCover(segment, checks, true, extraCost);
    int tag = 0;
    for (Segment persistenceSegment : cover) {
        tag++;
        /* Collect all cache accesses */
        long cost = computeMissOnceCost(persistenceSegment, getCacheAccessesByTag(persistenceSegment).entrySet(), EDGE_MISS_COST, true, KEY + ".addMissOnceCost", wcetTool);
        F1<SuperGraphEdge, Long> costModel = MiscUtils.const1(cost);
        Set<SuperGraphEdge> costEdges = addFixedCostEdges(persistenceSegment.getEntryEdges(), ipetSolver, costModel, KEY + "_miss_once", tag);
        missEdges.addAll(costEdges);
    }
    for (Entry<SuperGraphEdge, Long> entry : extraCost.entrySet()) {
        missEdges.add(fixedAdditionalCostEdge(entry.getKey(), KEY + "_am", 0, entry.getValue(), ipetSolver));
    }
    return missEdges;
}
Also used : HashMap(java.util.HashMap) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) Segment(com.jopdesign.common.code.Segment) HashSet(java.util.HashSet)

Example 3 with Segment

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

the class MethodCacheAnalysis method isPersistenceRegion.

public boolean isPersistenceRegion(WCETTool wcetTool, MethodInfo m, CallString cs, EnumSet<PersistenceCheck> tests) {
    /* fast path for the optimizer (segments are still slow) */
    if (tests == EnumSet.of(PersistenceCheck.CountTotal)) {
        List<MethodInfo> methods = wcetTool.getCallGraph().getReachableImplementations(m, cs);
        long blocks = 0;
        for (MethodInfo reachable : methods) {
            blocks += methodCache.requiredNumberOfBlocks(reachable);
        }
        return methodCache.allFit(blocks);
    }
    Segment segment = Segment.methodSegment(m, cs, wcetTool, wcetTool.getCallstringLength(), wcetTool);
    return isPersistenceRegion(segment, tests);
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) Segment(com.jopdesign.common.code.Segment)

Example 4 with Segment

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

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

the class ObjectCacheAnalysis method getMaxCacheCost.

/**
 * Get maximum cost due to the object cache in the given scope.
 * Using special cost models such as COUNT_FIELD_TAGS and COUNT_REF_TAGS, this
 * method can be used to calculate different metrics as well.
 * <p> XXX: Use segment instead of scope </p>
 * @param scope
 * @param costModel The object cache cost model
 * @return
 * @throws InvalidFlowFactException
 * @throws LpSolveException
 */
public ObjectCacheCost getMaxCacheCost(ExecutionContext scope, ObjectCacheCostModel costModel) throws InvalidFlowFactException, LpSolveException {
    LocalPointsToResult usedRefs = getUsedRefs(scope);
    Segment segment = Segment.methodSegment(scope.getMethodInfo(), scope.getCallString(), project, project.getCallstringLength(), project);
    /* Compute worst-case cost */
    HashSet<SymbolicAddress> usedObjectsSet = new HashSet<SymbolicAddress>();
    return computeCacheCost(segment, usedRefs, costModel, usedObjectsSet);
}
Also used : SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) Segment(com.jopdesign.common.code.Segment) HashSet(java.util.HashSet)

Aggregations

Segment (com.jopdesign.common.code.Segment)13 HashSet (java.util.HashSet)8 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)7 SymbolicAddress (com.jopdesign.dfa.analyses.SymbolicAddress)4 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)3 CacheCostCalculationMethod (com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod)3 ArrayList (java.util.ArrayList)3 CallString (com.jopdesign.common.code.CallString)2 SuperGraphNode (com.jopdesign.common.code.SuperGraph.SuperGraphNode)2 SuperInvokeEdge (com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)2 SuperReturnEdge (com.jopdesign.common.code.SuperGraph.SuperReturnEdge)2 GlobalAnalysis (com.jopdesign.wcet.analysis.GlobalAnalysis)2 AccessCostInfo (com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo)2 HashMap (java.util.HashMap)2 MethodInfo (com.jopdesign.common.MethodInfo)1 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)1 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 ExecutionContext (com.jopdesign.common.code.ExecutionContext)1 MethodCacheAnalysis (com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis)1 ObjectCacheCost (com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost)1