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