use of com.jopdesign.jcopter.analysis.AnalysisManager in project jop by jop-devel.
the class GreedyOptimizer method optimize.
public void optimize() {
List<MethodInfo> rootMethods = config.getTargetMethods();
// initialization
resetCounters();
boolean useWCAProvider = config.useWCA() && config.useWCAExecCount();
GreedyOrder order = config.getOrder();
if (order != GreedyOrder.WCAFirst) {
// updated as well.
if (!config.getTargetMethodSet().equals(config.getWCATargetSet())) {
logger.warn("Using the WCA for exec frequencies is currently only supported if order is WCAFirst " + "or if the target method is the WCA target method");
useWCAProvider = false;
}
}
AnalysisManager analyses = initializeAnalyses(config.useWCEP() || useWCAProvider);
for (CodeOptimizer opt : optimizers) {
opt.initialize(analyses, rootMethods);
}
CandidateSelector selector;
if (config.useWCA()) {
GainCalculator gc = new GainCalculator(analyses);
if (config.useWCEP()) {
logger.info("Using WCEP driven selector");
selector = new WCEPRebateSelector(analyses, gc, config.getMaxCodesize());
} else {
logger.info("Using WCA driven selector");
selector = new WCETRebateSelector(analyses, gc, config.getMaxCodesize());
}
} else {
logger.info("WCA is disabled, not using WCA for optimization.");
selector = new ACETRebateSelector(analyses, new GainCalculator(analyses), config.getMaxCodesize());
}
selector.initialize(config, true);
ExecFrequencyProvider ecp = useWCAProvider ? analyses.getWCAInvoker() : analyses.getExecFrequencyAnalysis();
if (config.useLocalExecCount()) {
ecp = new LocalExecFrequencyProvider(ecp);
}
// dump initial callgraph
logger.info("Initial number of methods in target callgraph: " + analyses.getTargetCallGraph().getMethodInfos().size());
analyses.getTargetCallGraph().dumpCallgraph(jcopter.getJConfig().getConfig(), "greedy-target", config.getTargetCallgraphDumpType(), true);
if (order == GreedyOrder.Global || (order == GreedyOrder.WCAFirst && !config.useWCA())) {
optimizeMethods(analyses, ecp, selector, analyses.getTargetCallGraph().getMethodInfos());
} else if (order == GreedyOrder.Targets) {
for (MethodInfo target : config.getTargetMethods()) {
optimizeMethods(analyses, ecp, selector, analyses.getTargetCallGraph().getReachableImplementationsSet(target));
}
} else if (order == GreedyOrder.WCAFirst) {
logger.info("Optimizing WCA target");
Set<MethodInfo> wcaMethods = analyses.getWCAMethods();
optimizeMethods(analyses, ecp, selector, wcaMethods);
selector.printStatistics();
// We do not want to include the wca methods in the second pass because inlining there could have negative
// effects on the WCET path due to the cache
Set<MethodInfo> others = new LinkedHashSet<MethodInfo>(analyses.getTargetCallGraph().getMethodInfos());
others.removeAll(wcaMethods);
logger.info("Optimizing non-WCA code");
//analyses.dumpTargetCallgraph("acet", true);
selector = new ACETRebateSelector(analyses, new GainCalculator(analyses), config.getMaxCodesize());
selector.initialize(config, false);
ecp = analyses.getExecFrequencyAnalysis();
if (config.useLocalExecCount()) {
ecp = new LocalExecFrequencyProvider(ecp);
}
optimizeMethods(analyses, ecp, selector, others);
} else if (order == GreedyOrder.TopDown || order == GreedyOrder.BottomUp) {
if (config.useWCA() && !analyses.hasWCATargetsOnly()) {
// TODO iterate over WCA and then non-wca graph or something in this case..
throw new AppInfoError("Order " + order + " currently only works with WCA if the target method is the WCA target");
}
TopologicalOrderIterator<MethodNode, InvokeEdge> topOrder = new TopologicalOrderIterator<MethodNode, InvokeEdge>(analyses.getTargetCallGraph().getAcyclicMergedGraph(order == GreedyOrder.BottomUp));
while (topOrder.hasNext()) {
MethodNode node = topOrder.next();
optimizeMethods(analyses, ecp, selector, Collections.singleton(node.getMethodInfo()));
}
} else {
throw new AppInfoError("Order " + order + " not yet implemented.");
}
// dump final callgraph
analyses.getTargetCallGraph().dumpCallgraph(jcopter.getJConfig().getConfig(), "greedy-target-opt", config.getTargetCallgraphDumpType(), true);
selector.printStatistics();
printStatistics();
}
use of com.jopdesign.jcopter.analysis.AnalysisManager in project jop by jop-devel.
the class GreedyOptimizer method initializeAnalyses.
private AnalysisManager initializeAnalyses(boolean updateWCEP) {
AnalysisManager analyses = new AnalysisManager(jcopter);
analyses.initAnalyses(config.getTargetMethodSet(), config.getCacheAnalysisType(), config.getCacheApproximation(), config.useMethodCacheStrategy(), config.useWCA() ? config.getWCATargetSet() : null, updateWCEP);
logger.info("Callgraph nodes: " + analyses.getTargetCallGraph().getNodes().size());
return analyses;
}
Aggregations