llvm.org GIT mirror llvm / 517aac8
CallGraph: Remove almost-unused field 'Root'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302852 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
2 changed file(s) with 5 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
4040 /// of all of the caller-callee relationships, which is useful for
4141 /// transformations.
4242 ///
43 /// The CallGraph class also attempts to figure out what the root of the
44 /// CallGraph is, which it currently does by looking for a function named
45 /// 'main'. If no function named 'main' is found, the external node is used as
46 /// the entry node, reflecting the fact that any function without internal
47 /// linkage could be called into (which is common for libraries).
48 ///
4943 //===----------------------------------------------------------------------===//
5044
5145 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
8175 /// \brief A map from \c Function* to \c CallGraphNode*.
8276 FunctionMapTy FunctionMap;
8377
84 /// \brief Root is root of the call graph, or the external node if a 'main'
85 /// function couldn't be found.
86 CallGraphNode *Root;
87
8878 /// \brief This node has edges to all external functions and those internal
8979 /// functions that have their address taken.
9080 CallGraphNode *ExternalCallingNode;
2020 //
2121
2222 CallGraph::CallGraph(Module &M)
23 : M(M), Root(nullptr), ExternalCallingNode(getOrInsertFunction(nullptr)),
23 : M(M), ExternalCallingNode(getOrInsertFunction(nullptr)),
2424 CallsExternalNode(llvm::make_unique(nullptr)) {
2525 // Add every function to the call graph.
2626 for (Function &F : M)
2727 addToCallGraph(&F);
28
29 // If we didn't find a main function, use the external call graph node
30 if (!Root)
31 Root = ExternalCallingNode;
3228 }
3329
3430 CallGraph::CallGraph(CallGraph &&Arg)
35 : M(Arg.M), FunctionMap(std::move(Arg.FunctionMap)), Root(Arg.Root),
31 : M(Arg.M), FunctionMap(std::move(Arg.FunctionMap)),
3632 ExternalCallingNode(Arg.ExternalCallingNode),
3733 CallsExternalNode(std::move(Arg.CallsExternalNode)) {
3834 Arg.FunctionMap.clear();
39 Arg.Root = nullptr;
4035 Arg.ExternalCallingNode = nullptr;
4136 }
4237
5651 void CallGraph::addToCallGraph(Function *F) {
5752 CallGraphNode *Node = getOrInsertFunction(F);
5853
59 // If this function has external linkage, anything could call it.
60 if (!F->hasLocalLinkage()) {
61 ExternalCallingNode->addCalledFunction(CallSite(), Node);
62
63 // Found the entry point?
64 if (F->getName() == "main") {
65 if (Root) // Found multiple external mains? Don't pick one.
66 Root = ExternalCallingNode;
67 else
68 Root = Node; // Found a main, keep track of it!
69 }
70 }
71
72 // If this function has its address taken, anything could call it.
73 if (F->hasAddressTaken())
54 // If this function has external linkage or has its address taken, anything
55 // could call it.
56 if (!F->hasLocalLinkage() || F->hasAddressTaken())
7457 ExternalCallingNode->addCalledFunction(CallSite(), Node);
7558
7659 // If this function is not defined in this translation unit, it could call
9578 }
9679
9780 void CallGraph::print(raw_ostream &OS) const {
98 OS << "CallGraph Root is: ";
99 if (Function *F = Root->getFunction())
100 OS << F->getName() << "\n";
101 else {
102 OS << "<>\n";
103 }
104
10581 // Print in a deterministic order by sorting CallGraphNodes by name. We do
10682 // this here to avoid slowing down the non-printing fast path.
10783