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