summaryrefslogtreecommitdiff
path: root/include/llvm/Analysis/CallGraph.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Analysis/CallGraph.h')
-rw-r--r--include/llvm/Analysis/CallGraph.h94
1 files changed, 53 insertions, 41 deletions
diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h
index 01469a25c96c..c5687def3ebe 100644
--- a/include/llvm/Analysis/CallGraph.h
+++ b/include/llvm/Analysis/CallGraph.h
@@ -54,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 Module;
class CallGraphNode;
+class Module;
+class raw_ostream;
/// \brief The basic data container for the call graph of a \c Module of IR.
///
@@ -70,8 +74,8 @@ class CallGraphNode;
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;
@@ -103,8 +107,8 @@ public:
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; }
@@ -162,20 +166,23 @@ class CallGraphNode {
public:
/// \brief A pair of the calling instruction (a call or invoke)
/// and the call graph node being called.
- typedef std::pair<WeakTrackingVH, 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; }
@@ -268,10 +275,7 @@ private:
/// \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; }
@@ -287,11 +291,12 @@ private:
/// 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.
///
@@ -305,6 +310,7 @@ class CallGraphPrinterPass : public PassInfoMixin<CallGraphPrinterPass> {
public:
explicit CallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
@@ -329,8 +335,8 @@ public:
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(); }
@@ -399,40 +405,38 @@ public:
// 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);
}
@@ -440,21 +444,25 @@ template <> struct GraphTraits<const CallGraphNode *> {
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);
}
@@ -463,26 +471,30 @@ struct GraphTraits<CallGraph *> : public GraphTraits<CallGraphNode *> {
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