use of com.jopdesign.common.code.CallGraph.ContextEdge in project jop by jop-devel.
the class WCETAnalysis method exploreCacheAnalysis.
/**
* @param mca
* @param iter
* @throws InvalidFlowFactException
*/
@SuppressWarnings("unused")
private void exploreCacheAnalysis() throws InvalidFlowFactException {
// Segment Cache Analysis: Experiments
MethodCacheAnalysis mca = new MethodCacheAnalysis(wcetTool);
/* iterate top down the scope graph (currently: the call graph) */
TopologicalOrderIterator<ExecutionContext, ContextEdge> iter = wcetTool.getCallGraph().reverseTopologicalOrder();
LpSolveWrapper.resetSolverTime();
long blocks = 0;
long start = System.nanoTime();
while (iter.hasNext()) {
ExecutionContext scope = iter.next();
Segment segment = Segment.methodSegment(scope.getMethodInfo(), scope.getCallString(), wcetTool, wcetTool.getCallstringLength(), wcetTool);
int availBlocks = wcetTool.getWCETProcessorModel().getMethodCache().getNumBlocks();
long total, distinctApprox = -1, distinct = -1;
blocks = total = mca.countDistinctBlocksUsed(segment);
if (total > availBlocks || true) {
try {
blocks = distinctApprox = mca.countDistinctBlocksAccessed(segment, false);
if (blocks > availBlocks && blocks < availBlocks * 2 || true) {
blocks = distinct = mca.countDistinctBlocksAccessed(segment, true);
}
} catch (LpSolveException e) {
System.err.println((distinctApprox >= 0 ? "I" : "Relaxed ") + "LP Problem too difficult, giving up: " + e);
}
}
System.out.println(String.format("block-count < %2d [%2d,%2d,%2d] for %-30s @ %s", blocks, total, distinctApprox, distinct, scope.getMethodInfo().getFQMethodName(), scope.getCallString().toStringVerbose(false)));
}
long stop = System.nanoTime();
reportSpecial("block-count", WcetCost.totalCost(blocks), start, stop, LpSolveWrapper.getSolverTime());
System.out.println("solver-time: " + LpSolveWrapper.getSolverTime());
}
use of com.jopdesign.common.code.CallGraph.ContextEdge in project jop by jop-devel.
the class ExecuteOnceAnalysis method analyze.
private void analyze() {
inLoopSet = new HashMap<ExecutionContext, Set<MethodInfo>>();
/* Top Down the Scope Graph */
TopologicalOrderIterator<ExecutionContext, ContextEdge> iter = project.getCallGraph().topDownIterator();
while (iter.hasNext()) {
ExecutionContext scope = iter.next();
scope = new ExecutionContext(scope.getMethodInfo());
/* Remove call string */
ControlFlowGraph cfg = project.getFlowGraph(scope.getMethodInfo());
Set<MethodInfo> inLoop = new HashSet<MethodInfo>();
for (CFGNode node : cfg.vertexSet()) {
if (!(node instanceof ControlFlowGraph.InvokeNode))
continue;
ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
if (!cfg.getLoopColoring().getLoopColor(node).isEmpty()) {
for (MethodInfo impl : iNode.getImplementingMethods()) {
inLoop.add(impl);
inLoop.addAll(project.getCallGraph().getReachableImplementationsSet(impl));
}
}
}
inLoopSet.put(scope, inLoop);
}
}
use of com.jopdesign.common.code.CallGraph.ContextEdge in project jop by jop-devel.
the class ExecFrequencyAnalysis method updateExecCounts.
private void updateExecCounts(DirectedGraph<ExecutionContext, ContextEdge> dag) {
// For now, we just require the graph to be a DAG.
// TODO for all back-edges, we should find some max recursion count and update reachable nodes accordingly..
// For now, we just assume we have no recursion (backedges are only due to insufficient callgraph thinning)
// or simply ignore recursion (unsafe, of course..)
// for the rest of the graph, we can now use a topological order
TopologicalOrderIterator<ExecutionContext, ContextEdge> topOrder = new TopologicalOrderIterator<ExecutionContext, ContextEdge>(dag);
while (topOrder.hasNext()) {
ExecutionContext next = topOrder.next();
if (logger.isTraceEnabled()) {
logger.trace("Updating: " + next);
}
updateChilds(next);
}
}
use of com.jopdesign.common.code.CallGraph.ContextEdge in project jop by jop-devel.
the class MethodCacheAnalysis method updateNodes.
private void updateNodes(SimpleDirectedGraph<ExecutionContext, ContextEdge> closure, Set<ExecutionContext> nodes, boolean reuseResults) {
for (ExecutionContext node : nodes) {
if (node.getMethodInfo().isNative())
continue;
// We could make this more memory efficient, because in many cases we do not need a
// separate set for each node, but this would be more complicated to calculate
Set<MethodInfo> reachable = new LinkedHashSet<MethodInfo>();
reachable.add(node.getMethodInfo());
// we only need to add all children to the set, no need to go down the graph
for (ContextEdge edge : closure.outgoingEdgesOf(node)) {
ExecutionContext target = edge.getTarget();
if (target.getMethodInfo().isNative())
continue;
if (reuseResults && !nodes.contains(target)) {
reachable.addAll(reachableMethods.get(target));
} else {
reachable.add(target.getMethodInfo());
}
}
reachableMethods.put(node, reachable);
}
MethodCache cache = jcopter.getMethodCache();
// now we can sum up the cache blocks for all nodes in the graph
for (ExecutionContext node : nodes) {
if (node.getMethodInfo().isNative())
continue;
Set<MethodInfo> reachable = reachableMethods.get(node);
int blocks = 0;
for (MethodInfo method : reachable) {
int size = MiscUtils.bytesToWords(getMethodSize(method));
blocks += cache.requiredNumberOfBlocks(size);
}
cacheBlocks.put(node, blocks);
}
}
use of com.jopdesign.common.code.CallGraph.ContextEdge in project jop by jop-devel.
the class RebateSelector method initialize.
@Override
public void initialize(GreedyConfig config, boolean dumpStats) {
// calculate current global codesize
globalCodesize = 0;
if (usesCodeRemover) {
for (MethodInfo method : AppInfo.getSingleton().getCallGraph().getMethodInfos()) {
if (!method.hasCode())
continue;
globalCodesize += method.getCode().getNumberOfBytes();
}
} else {
for (ClassInfo cls : AppInfo.getSingleton().getClassInfos()) {
for (MethodInfo method : cls.getMethods()) {
if (!method.hasCode())
continue;
globalCodesize += method.getCode().getNumberOfBytes();
}
}
}
// we need a tie-breaker for the candidate selection, and to make the results deterministic
// so we use a topological order of the (initial) callgraph
DFSVisitor<ExecutionContext, ContextEdge> visitor = new EmptyDFSVisitor<ExecutionContext, ContextEdge>() {
private int counter = 1;
@Override
public void postorder(ExecutionContext node) {
depthMap.put(node.getMethodInfo(), counter++);
}
};
DirectedGraph<ExecutionContext, ContextEdge> graph = analyses.getTargetCallGraph().getReversedGraph();
DFSTraverser<ExecutionContext, ContextEdge> traverser = new DFSTraverser<ExecutionContext, ContextEdge>(visitor);
traverser.traverse(graph);
logger.info("Initial codesize: " + globalCodesize + " bytes");
if (config.doDumpStats() && dumpStats) {
try {
File statsFile = config.getStatsFile();
dump = new PrintWriter(statsFile);
dump.print("total codesize, ");
if (analyses.useWCAInvoker())
dump.print("WCET, ");
dump.println("candidate, ratio, gain, local gain, cache, local cache, delta codesize, frequency");
} catch (FileNotFoundException e) {
throw new AppInfoError("Could not initialize dump file", e);
}
}
}
Aggregations