use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class WCAInvoker method runAnalysis.
// /////////////////////////////////////////////////////////////////////////////
// Private methods
// /////////////////////////////////////////////////////////////////////////////
private Set<MethodInfo> runAnalysis(DirectedGraph<ExecutionContext, ContextEdge> reversed) {
// Phew. The WCA only runs on acyclic callgraphs, we can therefore assume the
// reversed graph to be a DAG
TopologicalOrderIterator<ExecutionContext, ContextEdge> topOrder = new TopologicalOrderIterator<ExecutionContext, ContextEdge>(reversed);
Set<MethodInfo> changed = new LinkedHashSet<MethodInfo>();
while (topOrder.hasNext()) {
ExecutionContext node = topOrder.next();
// At times like this I really wish Java would have type aliases ..
RecursiveWcetAnalysis<AnalysisContextLocal>.LocalWCETSolution sol = recursiveAnalysis.computeSolution(node.getMethodInfo(), new AnalysisContextLocal(cacheApproximation, node.getCallString()));
wcaNodeFlow.put(node, sol.getNodeFlowVirtual());
// TODO some logging would be nice, keep target-method WCET for comparison of speedup
if (node.getMethodInfo().equals(wcetTool.getTargetMethod())) {
lastWCET = sol.getCost().getCost();
logger.info("WCET: " + lastWCET);
}
changed.add(node.getMethodInfo());
}
return changed;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class InlineOptimizer method findCandidates.
@Override
public Collection<Candidate> findCandidates(MethodInfo method, AnalysisManager analyses, StacksizeAnalysis stacksize, int maxLocals, InstructionHandle start, InstructionHandle end) {
List<Candidate> candidates = new LinkedList<Candidate>();
MethodCode code = method.getCode();
InstructionHandle next = end.getNext();
for (InstructionHandle ih = start; ih != next; ih = ih.getNext()) {
if (code.isInvokeSite(ih)) {
InvokeSite site = code.getInvokeSite(ih);
// since we update the appInfo callgraph, the callstring only contains the invokesite and no
// inlined methods
CallString cs = new CallString(site);
countInvokeSites++;
MethodInfo invokee = helper.devirtualize(cs);
if (invokee == null)
continue;
countDevirtualized++;
// for the initial check and the DFA lookup we need the old callstring
cs = getInlineCallString(code, ih).push(site);
Candidate candidate = checkInvoke(code, cs, site, invokee, maxLocals);
if (candidate == null) {
continue;
}
// initial check for locals and stack, calculate gain and codesize
if (!candidate.recalculate(analyses, stacksize)) {
continue;
}
candidates.add(candidate);
}
}
return candidates;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class InlineHelper method devirtualize.
/**
* Devirtualize an invocation.
* <p>
* Since this uses the callgraph if available, the callstring must match the state of the callgraph,
* i.e. if an invocation in the callstring has been inlined and the callgraph has been updated to reflect
* the new invoke, the inlined invocation must be removed from the callstring too.
* Contrariwise, if an invoke has been inlined but the callgraph has not yet been updated, the callstring
* must also contain the inlined invoke. Also the callstring does not need to start at the method to optimize.
* This is different from what {@link #canInline(CallString, InvokeSite, MethodInfo)} expects.
* </p>
*
* @see #canInline(CallString, InvokeSite, MethodInfo)
* @param invokers the callstring of the invocation to devirtualize. The last entry must be the invoke site to
* devirtualize. The first first entry does not need to be the method into which inlining
* is performed.
* @return the method info to call if unique, else null.
*/
public MethodInfo devirtualize(CallString invokers) {
AppInfo appInfo = AppInfo.getSingleton();
Set<MethodInfo> methods = appInfo.findImplementations(invokers);
if (methods.size() == 1) {
return methods.iterator().next();
} else {
return null;
}
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class AnalysisManager method initAnalyses.
/**
* Quick'n'dirty initialization of all analyses.
* If the analyses get more options or get more complex in the future, this will need some work.
*
* @param targets the root methods to use for all analyses and the callgraph.
* @param cacheAnalysisType cache analysis type
* @param wcaRoots if not null, initialize the WCA invoker with these roots.
* @param updateWCEP if true, let the wcaInvoker provide a global WCET path and keep it up-to-date
*/
public void initAnalyses(Set<MethodInfo> targets, AnalysisType cacheAnalysisType, CacheCostCalculationMethod cacheApproximation, boolean useMethodCacheStrategy, Set<MethodInfo> wcaRoots, boolean updateWCEP) {
logger.info("Initializing analyses..");
Set<MethodInfo> allTargets = new LinkedHashSet<MethodInfo>(targets);
if (wcaRoots != null) {
// Just make sure the WCA callgraph is contained in the target graph..
allTargets.addAll(wcaRoots);
wcaInvoker = new WCAInvoker(this, wcaRoots, cacheApproximation);
wcaInvoker.setProvideWCAExecCount(updateWCEP);
try {
// need to initialize the WCA Tool before the other analyses since we need the WCA callgraph
wcaInvoker.initTool();
} catch (BadConfigurationException e) {
// TODO or maybe just throw the exception up a few levels more?
throw new BadConfigurationError(e.getMessage(), e);
}
}
if (wcaRoots != null && wcaRoots.equals(allTargets) && wcaInvoker.getWCACallGraphs().size() == 1) {
targetCallGraph = wcaInvoker.getWCACallGraphs().iterator().next();
} else {
logger.info("Initializing Target Callgraph");
targetCallGraph = CallGraph.buildCallGraph(allTargets, new DefaultCallgraphBuilder(AppInfo.getSingleton().getCallstringLength()));
}
// TODO we might want to classify methods depending on whether they are reachable from the wcaRoots
// for all non-wca-methods we might want to use different initial analysis data, e.g.
// if we use the WCA, we might want to use the IPET WCA to initialize the execCountAnalysis for
// wca-methods
// We can do this as first step (after the callgraph has been created) since it does not use the ExecFrequencyAnalysis
logger.info("Initializing MethodCacheAnalysis");
methodCacheAnalysis = new MethodCacheAnalysis(jcopter, cacheAnalysisType, targetCallGraph);
methodCacheAnalysis.initialize();
if (wcaRoots != null) {
logger.info("Initializing WCAInvoker");
wcaInvoker.initAnalysis(useMethodCacheStrategy);
}
// TODO in fact, we might not even need this if we only use the wcaInvoker as provider or some other provider
logger.info("Initializing ExecFrequencyAnalysis");
execFreqAnalysis = new ExecFrequencyAnalysis(this, targetCallGraph);
execFreqAnalysis.initialize();
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class AbstractOptimizer method visitClass.
@Override
public final boolean visitClass(ClassInfo classInfo) {
if (appInfo.isHwObject(classInfo)) {
// Do not optimize Hardware Objects, leave them alone!
return false;
}
Collection<MethodInfo> methods = classInfo.getMethods();
if (iterateSorted) {
// little hack to make the DFA cache hack more deterministic
TreeMap<String, MethodInfo> temp = new TreeMap<String, MethodInfo>();
for (MethodInfo method : methods) {
temp.put(method.getMethodSignature(), method);
}
methods = temp.values();
}
for (MethodInfo method : methods) {
if (method.hasCode()) {
optimizeMethod(method);
}
}
return true;
}
Aggregations