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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations