Search in sources :

Example 1 with DefaultCallgraphBuilder

use of com.jopdesign.common.code.DefaultCallgraphBuilder in project jop by jop-devel.

the class PhaseExecutor method buildCallGraph.

public void buildCallGraph(boolean useDFA) {
    if (useDFA) {
        // build the callgraph using DFA results
        DFACallgraphBuilder builder = new DFACallgraphBuilder(jcopter.getDfaTool(), appInfo.getCallstringLength());
        builder.setSkipNatives(true);
        appInfo.buildCallGraph(builder);
    } else {
        DefaultCallgraphBuilder builder = new DefaultCallgraphBuilder();
        builder.setSkipNatives(true);
        // rebuild without using the existing callgraph, because the callstrings are not updated by SimpleInliner
        builder.setUseCallgraph(false);
        appInfo.buildCallGraph(builder);
        // reduce the callgraph old-school
        reduceCallGraph();
    }
}
Also used : DFACallgraphBuilder(com.jopdesign.dfa.framework.DFACallgraphBuilder) DefaultCallgraphBuilder(com.jopdesign.common.code.DefaultCallgraphBuilder)

Example 2 with DefaultCallgraphBuilder

use of com.jopdesign.common.code.DefaultCallgraphBuilder in project jop by jop-devel.

the class AppInfo method buildCallGraph.

/**
     * Build a new default callgraph using the current roots as roots for the callgraph, if the default
     * callgraph has not yet been created.
     * @param rebuild if true, rebuild the graph if it already exists. All manual changes and optimizations
     *                of the graph will be lost.
     * @return the default callgraph
     */
public CallGraph buildCallGraph(boolean rebuild) {
    if (rebuild) {
        // we set the callgraph null first, so that rebuilding it does not use the old graph
        callGraph = null;
    }
    if (callGraph == null) {
        CallgraphBuilder builder = new DefaultCallgraphBuilder(getCallstringLength());
        buildCallGraph(builder);
    }
    return callGraph;
}
Also used : DefaultCallgraphBuilder(com.jopdesign.common.code.DefaultCallgraphBuilder) DefaultCallgraphBuilder(com.jopdesign.common.code.DefaultCallgraphBuilder) CallgraphBuilder(com.jopdesign.common.code.CallGraph.CallgraphBuilder)

Example 3 with DefaultCallgraphBuilder

use of com.jopdesign.common.code.DefaultCallgraphBuilder 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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BadConfigurationError(com.jopdesign.common.config.Config.BadConfigurationError) DefaultCallgraphBuilder(com.jopdesign.common.code.DefaultCallgraphBuilder) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) MethodInfo(com.jopdesign.common.MethodInfo)

Example 4 with DefaultCallgraphBuilder

use of com.jopdesign.common.code.DefaultCallgraphBuilder in project jop by jop-devel.

the class WCETTool method initialize.

public void initialize(boolean loadLinkInfo, boolean initDFA) throws BadConfigurationException {
    if (projectConfig.saveResults()) {
        this.resultRecord = projectConfig.getResultFile();
        if (!projectConfig.appendResults()) {
            // TODO remove existing file if we do not append?
            //resultRecord.delete();
            recordMetric("problem", this.getProjectName());
            if (projectConfig.addPerformanceResults()) {
                recordMetric("date", new Date());
            }
        }
    }
    if (loadLinkInfo) {
        linkerInfo = new LinkerInfo(this);
        try {
            linkerInfo.loadLinkInfo();
        } catch (IOException e) {
            throw new BadConfigurationException("Could not load link infos", e);
        } catch (ClassNotFoundException e) {
            throw new BadConfigurationException("Could not load link infos", e);
        }
    }
    /* run dataflow analysis */
    if (doDataflowAnalysis() && initDFA) {
        topLevelLogger.info("Starting DFA analysis");
        dataflowAnalysis();
        topLevelLogger.info("DFA analysis finished");
    }
    if (!appInfo.hasCallGraph()) {
        DefaultCallgraphBuilder callGraphBuilder;
        /* build callgraph for the whole program */
        if (doDataflowAnalysis()) {
            // build the callgraph using DFA results
            callGraphBuilder = new DFACallgraphBuilder(getDfaTool(), appInfo.getCallstringLength());
        } else {
            callGraphBuilder = new DefaultCallgraphBuilder();
        }
        // we do not want natives in the callgraph
        callGraphBuilder.setSkipNatives(true);
        appInfo.buildCallGraph(callGraphBuilder);
    }
    /* build callgraph for target method */
    rebuildCallGraph();
    if (projectConfig.doPreprocess()) {
        WCETPreprocess.preprocess(appInfo);
    }
    dumpCallGraph("callgraph");
}
Also used : DFACallgraphBuilder(com.jopdesign.dfa.framework.DFACallgraphBuilder) DefaultCallgraphBuilder(com.jopdesign.common.code.DefaultCallgraphBuilder) LinkerInfo(com.jopdesign.wcet.jop.LinkerInfo) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) IOException(java.io.IOException) Date(java.util.Date)

Example 5 with DefaultCallgraphBuilder

use of com.jopdesign.common.code.DefaultCallgraphBuilder in project jop by jop-devel.

the class WCETTool method rebuildCallGraph.

/**
     * Rebuild the WCET callgraph, starting at the target method.
     * The new callgraph will be based on (but not backed by) the AppInfo callgraph, if available.
     *
     * @return the new callgraph.
     */
public CallGraph rebuildCallGraph() {
    /* This would be the ideal solution, but this way the root
    	 * does NOT have an empty callstring
    	 */
    // callGraph = appInfo.getCallGraph().getSubGraph(projectConfig.getTargetMethodInfo());
    /* Instead, we create a new "subgraph" based on the appInfo callgraph (which has been created using
         * DFA results if available in initialize() or by some other tool), where the target method has an empty
         * callstring, using the callstring length configured for the WCET tool (which is currently the same
         * as the global setting).
         */
    DefaultCallgraphBuilder callGraphBuilder = new CFGCallgraphBuilder(getCallstringLength());
    // we do not want natives in the callgraph
    callGraphBuilder.setSkipNatives(true);
    callGraph = CallGraph.buildCallGraph(getTargetMethod(), callGraphBuilder);
    try {
        callGraph.checkAcyclicity();
    } catch (AppInfoException e) {
        throw new AssertionError(e);
    }
    return callGraph;
}
Also used : CFGCallgraphBuilder(com.jopdesign.common.code.CFGCallgraphBuilder) DefaultCallgraphBuilder(com.jopdesign.common.code.DefaultCallgraphBuilder) AppInfoException(com.jopdesign.common.misc.AppInfoException)

Aggregations

DefaultCallgraphBuilder (com.jopdesign.common.code.DefaultCallgraphBuilder)5 BadConfigurationException (com.jopdesign.common.config.Config.BadConfigurationException)2 DFACallgraphBuilder (com.jopdesign.dfa.framework.DFACallgraphBuilder)2 MethodInfo (com.jopdesign.common.MethodInfo)1 CFGCallgraphBuilder (com.jopdesign.common.code.CFGCallgraphBuilder)1 CallgraphBuilder (com.jopdesign.common.code.CallGraph.CallgraphBuilder)1 BadConfigurationError (com.jopdesign.common.config.Config.BadConfigurationError)1 AppInfoException (com.jopdesign.common.misc.AppInfoException)1 LinkerInfo (com.jopdesign.wcet.jop.LinkerInfo)1 IOException (java.io.IOException)1 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1