diff include/llvm/Analysis/CallGraph.h @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents 1172e4bd9c6f
children
line wrap: on
line diff
--- a/include/llvm/Analysis/CallGraph.h	Fri Nov 25 19:14:25 2016 +0900
+++ b/include/llvm/Analysis/CallGraph.h	Fri Oct 27 17:07:41 2017 +0900
@@ -41,12 +41,6 @@
 /// of all of the caller-callee relationships, which is useful for
 /// transformations.
 ///
-/// The CallGraph class also attempts to figure out what the root of the
-/// CallGraph is, which it currently does by looking for a function named
-/// 'main'. If no function named 'main' is found, the external node is used as
-/// the entry node, reflecting the fact that any function without internal
-/// linkage could be called into (which is common for libraries).
-///
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
@@ -60,13 +54,17 @@
 #include "llvm/IR/PassManager.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
+#include <cassert>
 #include <map>
+#include <memory>
+#include <utility>
+#include <vector>
 
 namespace llvm {
 
-class Function;
+class CallGraphNode;
 class Module;
-class CallGraphNode;
+class raw_ostream;
 
 /// \brief The basic data container for the call graph of a \c Module of IR.
 ///
@@ -76,16 +74,12 @@
 class CallGraph {
   Module &M;
 
-  typedef std::map<const Function *, std::unique_ptr<CallGraphNode>>
-      FunctionMapTy;
+  using FunctionMapTy =
+      std::map<const Function *, std::unique_ptr<CallGraphNode>>;
 
   /// \brief A map from \c Function* to \c CallGraphNode*.
   FunctionMapTy FunctionMap;
 
-  /// \brief Root is root of the call graph, or the external node if a 'main'
-  /// function couldn't be found.
-  CallGraphNode *Root;
-
   /// \brief This node has edges to all external functions and those internal
   /// functions that have their address taken.
   CallGraphNode *ExternalCallingNode;
@@ -113,8 +107,8 @@
   void print(raw_ostream &OS) const;
   void dump() const;
 
-  typedef FunctionMapTy::iterator iterator;
-  typedef FunctionMapTy::const_iterator const_iterator;
+  using iterator = FunctionMapTy::iterator;
+  using const_iterator = FunctionMapTy::const_iterator;
 
   /// \brief Returns the module the call graph corresponds to.
   Module &getModule() const { return M; }
@@ -172,20 +166,23 @@
 public:
   /// \brief A pair of the calling instruction (a call or invoke)
   /// and the call graph node being called.
-  typedef std::pair<WeakVH, CallGraphNode *> CallRecord;
+  using CallRecord = std::pair<WeakTrackingVH, CallGraphNode *>;
 
 public:
-  typedef std::vector<CallRecord> CalledFunctionsVector;
+  using CalledFunctionsVector = std::vector<CallRecord>;
 
   /// \brief Creates a node for the specified function.
-  inline CallGraphNode(Function *F) : F(F), NumReferences(0) {}
+  inline CallGraphNode(Function *F) : F(F) {}
+
+  CallGraphNode(const CallGraphNode &) = delete;
+  CallGraphNode &operator=(const CallGraphNode &) = delete;
 
   ~CallGraphNode() {
     assert(NumReferences == 0 && "Node deleted while references remain");
   }
 
-  typedef std::vector<CallRecord>::iterator iterator;
-  typedef std::vector<CallRecord>::const_iterator const_iterator;
+  using iterator = std::vector<CallRecord>::iterator;
+  using const_iterator = std::vector<CallRecord>::const_iterator;
 
   /// \brief Returns the function that this call graph node represents.
   Function *getFunction() const { return F; }
@@ -272,16 +269,13 @@
 private:
   friend class CallGraph;
 
-  AssertingVH<Function> F;
+  Function *F;
 
   std::vector<CallRecord> CalledFunctions;
 
   /// \brief The number of times that this CallGraphNode occurs in the
   /// CalledFunctions array of this or other CallGraphNodes.
-  unsigned NumReferences;
-
-  CallGraphNode(const CallGraphNode &) = delete;
-  void operator=(const CallGraphNode &) = delete;
+  unsigned NumReferences = 0;
 
   void DropRef() { --NumReferences; }
   void AddRef() { ++NumReferences; }
@@ -297,11 +291,12 @@
 /// resulting data.
 class CallGraphAnalysis : public AnalysisInfoMixin<CallGraphAnalysis> {
   friend AnalysisInfoMixin<CallGraphAnalysis>;
+
   static AnalysisKey Key;
 
 public:
-  /// \brief A formulaic typedef to inform clients of the result type.
-  typedef CallGraph Result;
+  /// \brief A formulaic type to inform clients of the result type.
+  using Result = CallGraph;
 
   /// \brief Compute the \c CallGraph for the module \c M.
   ///
@@ -315,6 +310,7 @@
 
 public:
   explicit CallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
+
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
 };
 
@@ -339,8 +335,8 @@
   const CallGraph &getCallGraph() const { return *G; }
   CallGraph &getCallGraph() { return *G; }
 
-  typedef CallGraph::iterator iterator;
-  typedef CallGraph::const_iterator const_iterator;
+  using iterator = CallGraph::iterator;
+  using const_iterator = CallGraph::const_iterator;
 
   /// \brief Returns the module the call graph corresponds to.
   Module &getModule() const { return G->getModule(); }
@@ -409,40 +405,38 @@
 // Provide graph traits for tranversing call graphs using standard graph
 // traversals.
 template <> struct GraphTraits<CallGraphNode *> {
-  typedef CallGraphNode *NodeRef;
-
-  typedef CallGraphNode::CallRecord CGNPairTy;
+  using NodeRef = CallGraphNode *;
+  using CGNPairTy = CallGraphNode::CallRecord;
 
   static NodeRef getEntryNode(CallGraphNode *CGN) { return CGN; }
-
   static CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
 
-  typedef mapped_iterator<CallGraphNode::iterator, decltype(&CGNGetValue)>
-      ChildIteratorType;
+  using ChildIteratorType =
+      mapped_iterator<CallGraphNode::iterator, decltype(&CGNGetValue)>;
 
   static ChildIteratorType child_begin(NodeRef N) {
     return ChildIteratorType(N->begin(), &CGNGetValue);
   }
+
   static ChildIteratorType child_end(NodeRef N) {
     return ChildIteratorType(N->end(), &CGNGetValue);
   }
 };
 
 template <> struct GraphTraits<const CallGraphNode *> {
-  typedef const CallGraphNode *NodeRef;
-
-  typedef CallGraphNode::CallRecord CGNPairTy;
+  using NodeRef = const CallGraphNode *;
+  using CGNPairTy = CallGraphNode::CallRecord;
 
   static NodeRef getEntryNode(const CallGraphNode *CGN) { return CGN; }
-
   static const CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
 
-  typedef mapped_iterator<CallGraphNode::const_iterator, decltype(&CGNGetValue)>
-      ChildIteratorType;
+  using ChildIteratorType =
+      mapped_iterator<CallGraphNode::const_iterator, decltype(&CGNGetValue)>;
 
   static ChildIteratorType child_begin(NodeRef N) {
     return ChildIteratorType(N->begin(), &CGNGetValue);
   }
+
   static ChildIteratorType child_end(NodeRef N) {
     return ChildIteratorType(N->end(), &CGNGetValue);
   }
@@ -450,21 +444,25 @@
 
 template <>
 struct GraphTraits<CallGraph *> : public GraphTraits<CallGraphNode *> {
+  using PairTy =
+      std::pair<const Function *const, std::unique_ptr<CallGraphNode>>;
+
   static NodeRef getEntryNode(CallGraph *CGN) {
     return CGN->getExternalCallingNode(); // Start at the external node!
   }
-  typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
-      PairTy;
+
   static CallGraphNode *CGGetValuePtr(const PairTy &P) {
     return P.second.get();
   }
 
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
-  typedef mapped_iterator<CallGraph::iterator, decltype(&CGGetValuePtr)>
-      nodes_iterator;
+  using nodes_iterator =
+      mapped_iterator<CallGraph::iterator, decltype(&CGGetValuePtr)>;
+
   static nodes_iterator nodes_begin(CallGraph *CG) {
     return nodes_iterator(CG->begin(), &CGGetValuePtr);
   }
+
   static nodes_iterator nodes_end(CallGraph *CG) {
     return nodes_iterator(CG->end(), &CGGetValuePtr);
   }
@@ -473,26 +471,30 @@
 template <>
 struct GraphTraits<const CallGraph *> : public GraphTraits<
                                             const CallGraphNode *> {
+  using PairTy =
+      std::pair<const Function *const, std::unique_ptr<CallGraphNode>>;
+
   static NodeRef getEntryNode(const CallGraph *CGN) {
     return CGN->getExternalCallingNode(); // Start at the external node!
   }
-  typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
-      PairTy;
+
   static const CallGraphNode *CGGetValuePtr(const PairTy &P) {
     return P.second.get();
   }
 
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
-  typedef mapped_iterator<CallGraph::const_iterator, decltype(&CGGetValuePtr)>
-      nodes_iterator;
+  using nodes_iterator =
+      mapped_iterator<CallGraph::const_iterator, decltype(&CGGetValuePtr)>;
+
   static nodes_iterator nodes_begin(const CallGraph *CG) {
     return nodes_iterator(CG->begin(), &CGGetValuePtr);
   }
+
   static nodes_iterator nodes_end(const CallGraph *CG) {
     return nodes_iterator(CG->end(), &CGGetValuePtr);
   }
 };
 
-} // End llvm namespace
+} // end namespace llvm
 
-#endif
+#endif // LLVM_ANALYSIS_CALLGRAPH_H