1 //===- CompleteBottomUp.cpp - Complete Bottom-Up Data Structure Graphs ----===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is the exact same as the bottom-up graphs, but we use take a completed
11 // call graph and inline all indirect callees into their callers graphs, making
12 // the result more useful for things like pool allocation.
14 //===----------------------------------------------------------------------===//
16 #include "llvm/Analysis/DataStructure.h"
17 #include "llvm/Module.h"
18 #include "llvm/Analysis/DSGraph.h"
22 RegisterAnalysis<CompleteBUDataStructures>
23 X("cbudatastructure", "'Complete' Bottom-up Data Structure Analysis");
28 // run - Calculate the bottom up data structure graphs for each function in the
31 bool CompleteBUDataStructures::run(Module &M) {
32 BUDataStructures &BU = getAnalysis<BUDataStructures>();
33 GlobalsGraph = new DSGraph(BU.getGlobalsGraph());
34 GlobalsGraph->setPrintAuxCalls();
36 // Our call graph is the same as the BU data structures call graph
37 ActualCallees = BU.getActualCallees();
39 #if 1 // REMOVE ME EVENTUALLY
40 // FIXME: TEMPORARY (remove once finalization of indirect call sites in the
41 // globals graph has been implemented in the BU pass)
42 TDDataStructures &TD = getAnalysis<TDDataStructures>();
44 // The call graph extractable from the TD pass is _much more complete_ and
45 // trustable than that generated by the BU pass so far. Until this is fixed,
46 // we hack it like this:
47 for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) {
48 if (MI->isExternal()) continue;
49 const std::vector<DSCallSite> &CSs = TD.getDSGraph(*MI).getFunctionCalls();
51 for (unsigned CSi = 0, e = CSs.size(); CSi != e; ++CSi) {
52 if (CSs[CSi].isIndirectCall()) {
53 Instruction *TheCall = CSs[CSi].getCallSite().getInstruction();
55 const std::vector<GlobalValue*> &Callees =
56 CSs[CSi].getCalleeNode()->getGlobals();
57 for (unsigned i = 0, e = Callees.size(); i != e; ++i)
58 if (Function *F = dyn_cast<Function>(Callees[i]))
59 ActualCallees.insert(std::make_pair(TheCall, F));
65 // Start by copying all of the BU data structures graphs over, verbatim.
66 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
67 if (!I->isExternal()) {
68 DSInfo[I] = new DSGraph(BU.getDSGraph(*I));
69 DSInfo[I]->setGlobalsGraph(GlobalsGraph);
70 DSInfo[I]->setPrintAuxCalls();