From: Eugene Zelenko Date: Mon, 24 Jul 2017 23:16:33 +0000 (+0000) Subject: [Analysis] Fix some Clang-tidy modernize-use-using and Include What You Use warnings... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4114bcf1b9c263703174eeba25c06c2763ea2447;p=llvm [Analysis] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308936 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/AliasSetTracker.h b/include/llvm/Analysis/AliasSetTracker.h index daafd2fabe7..7da3ebabb8a 100644 --- a/include/llvm/Analysis/AliasSetTracker.h +++ b/include/llvm/Analysis/AliasSetTracker.h @@ -18,36 +18,46 @@ #define LLVM_ANALYSIS_ALIASSETTRACKER_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/ilist.h" #include "llvm/ADT/ilist_node.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/ValueHandle.h" +#include "llvm/Support/Casting.h" +#include +#include +#include +#include #include namespace llvm { +class AliasSetTracker; +class BasicBlock; class LoadInst; +class MemSetInst; +class MemTransferInst; +class raw_ostream; class StoreInst; class VAArgInst; -class MemSetInst; -class AliasSetTracker; -class AliasSet; +class Value; class AliasSet : public ilist_node { friend class AliasSetTracker; class PointerRec { Value *Val; // The pointer this record corresponds to. - PointerRec **PrevInList, *NextInList; - AliasSet *AS; - uint64_t Size; + PointerRec **PrevInList = nullptr; + PointerRec *NextInList = nullptr; + AliasSet *AS = nullptr; + uint64_t Size = 0; AAMDNodes AAInfo; public: PointerRec(Value *V) - : Val(V), PrevInList(nullptr), NextInList(nullptr), AS(nullptr), Size(0), - AAInfo(DenseMapInfo::getEmptyKey()) {} + : Val(V), AAInfo(DenseMapInfo::getEmptyKey()) {} Value *getValue() const { return Val; } @@ -121,9 +131,10 @@ class AliasSet : public ilist_node { }; // Doubly linked list of nodes. - PointerRec *PtrList, **PtrListEnd; + PointerRec *PtrList = nullptr; + PointerRec **PtrListEnd; // Forwarding pointer. - AliasSet *Forward; + AliasSet *Forward = nullptr; /// All instructions without a specific address in this alias set. /// In rare cases this vector can have a null'ed out WeakVH @@ -167,7 +178,7 @@ class AliasSet : public ilist_node { /// True if this alias set contains volatile loads or stores. unsigned Volatile : 1; - unsigned SetSize; + unsigned SetSize = 0; void addRef() { ++RefCount; } @@ -183,6 +194,9 @@ class AliasSet : public ilist_node { } public: + AliasSet(const AliasSet &) = delete; + AliasSet &operator=(const AliasSet &) = delete; + /// Accessors... bool isRef() const { return Access & RefAccess; } bool isMod() const { return Access & ModAccess; } @@ -249,12 +263,8 @@ public: private: // Can only be created by AliasSetTracker. AliasSet() - : PtrList(nullptr), PtrListEnd(&PtrList), Forward(nullptr), RefCount(0), - AliasAny(false), Access(NoAccess), Alias(SetMustAlias), - Volatile(false), SetSize(0) {} - - AliasSet(const AliasSet &AS) = delete; - void operator=(const AliasSet &AS) = delete; + : PtrListEnd(&PtrList), RefCount(0), AliasAny(false), Access(NoAccess), + Alias(SetMustAlias), Volatile(false) {} PointerRec *getSomePointer() const { return PtrList; @@ -281,6 +291,7 @@ private: const AAMDNodes &AAInfo, bool KnownMustAlias = false); void addUnknownInst(Instruction *I, AliasAnalysis &AA); + void removeUnknownInst(AliasSetTracker &AST, Instruction *I) { bool WasEmpty = UnknownInsts.empty(); for (size_t i = 0, e = UnknownInsts.size(); i != e; ++i) @@ -292,6 +303,7 @@ private: if (!WasEmpty && UnknownInsts.empty()) dropRef(AST); } + void setVolatile() { Volatile = true; } public: @@ -312,11 +324,13 @@ class AliasSetTracker { /// Value is deleted. class ASTCallbackVH final : public CallbackVH { AliasSetTracker *AST; + void deleted() override; void allUsesReplacedWith(Value *) override; public: ASTCallbackVH(Value *V, AliasSetTracker *AST = nullptr); + ASTCallbackVH &operator=(Value *V); }; /// Traits to tell DenseMap that tell us how to compare and hash the value @@ -326,9 +340,8 @@ class AliasSetTracker { AliasAnalysis &AA; ilist AliasSets; - typedef DenseMap - PointerMapType; + using PointerMapType = DenseMap; // Map from pointers to their node PointerMapType PointerMap; @@ -336,8 +349,7 @@ class AliasSetTracker { public: /// Create an empty collection of AliasSets, and use the specified alias /// analysis object to disambiguate load and store addresses. - explicit AliasSetTracker(AliasAnalysis &aa) - : AA(aa), TotalMayAliasSetSize(0), AliasAnyAS(nullptr) {} + explicit AliasSetTracker(AliasAnalysis &aa) : AA(aa) {} ~AliasSetTracker() { clear(); } /// These methods are used to add different types of instructions to the alias @@ -401,8 +413,8 @@ public: /// tracker already knows about a value, it will ignore the request. void copyValue(Value *From, Value *To); - typedef ilist::iterator iterator; - typedef ilist::const_iterator const_iterator; + using iterator = ilist::iterator; + using const_iterator = ilist::const_iterator; const_iterator begin() const { return AliasSets.begin(); } const_iterator end() const { return AliasSets.end(); } @@ -417,11 +429,11 @@ private: friend class AliasSet; // The total number of pointers contained in all "may" alias sets. - unsigned TotalMayAliasSetSize; + unsigned TotalMayAliasSetSize = 0; // A non-null value signifies this AST is saturated. A saturated AST lumps // all pointers into a single "May" set. - AliasSet *AliasAnyAS; + AliasSet *AliasAnyAS = nullptr; void removeAliasSet(AliasSet *AS); @@ -451,6 +463,6 @@ inline raw_ostream& operator<<(raw_ostream &OS, const AliasSetTracker &AST) { return OS; } -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_ALIASSETTRACKER_H diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h index 01469a25c96..c5687def3eb 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 #include +#include +#include +#include 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> - FunctionMapTy; + using FunctionMapTy = + std::map>; /// \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 CallRecord; + using CallRecord = std::pair; public: - typedef std::vector CalledFunctionsVector; + using CalledFunctionsVector = std::vector; /// \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::iterator iterator; - typedef std::vector::const_iterator const_iterator; + using iterator = std::vector::iterator; + using const_iterator = std::vector::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 { friend AnalysisInfoMixin; + 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 { 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 { - 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 - ChildIteratorType; + using ChildIteratorType = + mapped_iterator; 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 { - 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 - ChildIteratorType; + using ChildIteratorType = + mapped_iterator; 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 { template <> struct GraphTraits : public GraphTraits { + using PairTy = + std::pair>; + static NodeRef getEntryNode(CallGraph *CGN) { return CGN->getExternalCallingNode(); // Start at the external node! } - typedef std::pair> - 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 - nodes_iterator; + using nodes_iterator = + mapped_iterator; + 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 : public GraphTraits { template <> struct GraphTraits : public GraphTraits< const CallGraphNode *> { + using PairTy = + std::pair>; + static NodeRef getEntryNode(const CallGraph *CGN) { return CGN->getExternalCallingNode(); // Start at the external node! } - typedef std::pair> - 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 - nodes_iterator; + using nodes_iterator = + mapped_iterator; + 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 diff --git a/include/llvm/Analysis/DominanceFrontier.h b/include/llvm/Analysis/DominanceFrontier.h index b566aeaf1fd..4f29743636f 100644 --- a/include/llvm/Analysis/DominanceFrontier.h +++ b/include/llvm/Analysis/DominanceFrontier.h @@ -18,37 +18,44 @@ #ifndef LLVM_ANALYSIS_DOMINANCEFRONTIER_H #define LLVM_ANALYSIS_DOMINANCEFRONTIER_H -#include "llvm/IR/Dominators.h" +#include "llvm/ADT/GraphTraits.h" #include "llvm/IR/PassManager.h" +#include "llvm/Pass.h" +#include "llvm/Support/GenericDomTree.h" +#include #include #include +#include +#include namespace llvm { +class Function; +class raw_ostream; + //===----------------------------------------------------------------------===// /// DominanceFrontierBase - Common base class for computing forward and inverse /// dominance frontiers for a function. /// template class DominanceFrontierBase { - public: - typedef std::set DomSetType; // Dom set for a bb - typedef std::map DomSetMapType; // Dom set map +public: + using DomSetType = std::set; // Dom set for a bb + using DomSetMapType = std::map; // Dom set map protected: - typedef GraphTraits BlockTraits; + using BlockTraits = GraphTraits; DomSetMapType Frontiers; std::vector Roots; static constexpr bool IsPostDominators = IsPostDom; - public: - DominanceFrontierBase() {} +public: + DominanceFrontierBase() = default; /// getRoots - Return the root blocks of the current CFG. This may include /// multiple blocks if we are computing post dominators. For forward /// dominators, this will always be a single block (the entry node). - /// inline const std::vector &getRoots() const { return Roots; } @@ -59,7 +66,6 @@ protected: } /// isPostDominator - Returns true if analysis based of postdoms - /// bool isPostDominator() const { return IsPostDominators; } @@ -69,8 +75,9 @@ protected: } // Accessor interface: - typedef typename DomSetMapType::iterator iterator; - typedef typename DomSetMapType::const_iterator const_iterator; + using iterator = typename DomSetMapType::iterator; + using const_iterator = typename DomSetMapType::const_iterator; + iterator begin() { return Frontiers.begin(); } const_iterator begin() const { return Frontiers.begin(); } iterator end() { return Frontiers.end(); } @@ -115,19 +122,19 @@ protected: template class ForwardDominanceFrontierBase : public DominanceFrontierBase { - private: - typedef GraphTraits BlockTraits; +private: + using BlockTraits = GraphTraits; public: - typedef DomTreeBase DomTreeT; - typedef DomTreeNodeBase DomTreeNodeT; - typedef typename DominanceFrontierBase::DomSetType DomSetType; - - void analyze(DomTreeT &DT) { - this->Roots = DT.getRoots(); - assert(this->Roots.size() == 1 && - "Only one entry block for forward domfronts!"); - calculate(DT, DT[this->Roots[0]]); + using DomTreeT = DomTreeBase; + using DomTreeNodeT = DomTreeNodeBase; + using DomSetType = typename DominanceFrontierBase::DomSetType; + + void analyze(DomTreeT &DT) { + this->Roots = DT.getRoots(); + assert(this->Roots.size() == 1 && + "Only one entry block for forward domfronts!"); + calculate(DT, DT[this->Roots[0]]); } const DomSetType &calculate(const DomTreeT &DT, const DomTreeNodeT *Node); @@ -135,20 +142,21 @@ public: class DominanceFrontier : public ForwardDominanceFrontierBase { public: - typedef DomTreeBase DomTreeT; - typedef DomTreeNodeBase DomTreeNodeT; - typedef DominanceFrontierBase::DomSetType DomSetType; - typedef DominanceFrontierBase::iterator iterator; - typedef DominanceFrontierBase::const_iterator - const_iterator; - - /// Handle invalidation explicitly. - bool invalidate(Function &F, const PreservedAnalyses &PA, - FunctionAnalysisManager::Invalidator &); + using DomTreeT = DomTreeBase; + using DomTreeNodeT = DomTreeNodeBase; + using DomSetType = DominanceFrontierBase::DomSetType; + using iterator = DominanceFrontierBase::iterator; + using const_iterator = + DominanceFrontierBase::const_iterator; + + /// Handle invalidation explicitly. + bool invalidate(Function &F, const PreservedAnalyses &PA, + FunctionAnalysisManager::Invalidator &); }; class DominanceFrontierWrapperPass : public FunctionPass { DominanceFrontier DF; + public: static char ID; // Pass ID, replacement for typeid @@ -176,11 +184,12 @@ extern template class ForwardDominanceFrontierBase; class DominanceFrontierAnalysis : public AnalysisInfoMixin { friend AnalysisInfoMixin; + static AnalysisKey Key; public: - /// \brief Provide the result typedef for this analysis pass. - typedef DominanceFrontier Result; + /// \brief Provide the result type for this analysis pass. + using Result = DominanceFrontier; /// \brief Run the analysis pass over a function and produce a dominator tree. DominanceFrontier run(Function &F, FunctionAnalysisManager &AM); @@ -193,9 +202,10 @@ class DominanceFrontierPrinterPass public: explicit DominanceFrontierPrinterPass(raw_ostream &OS); + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_DOMINANCEFRONTIER_H diff --git a/include/llvm/Analysis/DominanceFrontierImpl.h b/include/llvm/Analysis/DominanceFrontierImpl.h index 5093b975e70..dffb2e02b62 100644 --- a/include/llvm/Analysis/DominanceFrontierImpl.h +++ b/include/llvm/Analysis/DominanceFrontierImpl.h @@ -18,21 +18,28 @@ #ifndef LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H #define LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H +#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Analysis/DominanceFrontier.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GenericDomTree.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include namespace llvm { template class DFCalculateWorkObject { public: - typedef DomTreeNodeBase DomTreeNodeT; + using DomTreeNodeT = DomTreeNodeBase; DFCalculateWorkObject(BlockT *B, BlockT *P, const DomTreeNodeT *N, const DomTreeNodeT *PN) : currentBB(B), parentBB(P), Node(N), parentNode(PN) {} + BlockT *currentBB; BlockT *parentBB; const DomTreeNodeT *Node; @@ -219,6 +226,6 @@ ForwardDominanceFrontierBase::calculate(const DomTreeT &DT, return *Result; } -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H diff --git a/include/llvm/Analysis/Interval.h b/include/llvm/Analysis/Interval.h index a63a004043c..f3714dddedd 100644 --- a/include/llvm/Analysis/Interval.h +++ b/include/llvm/Analysis/Interval.h @@ -39,10 +39,11 @@ class Interval { /// interval. Also, any loops in this interval must go through the HeaderNode. /// BasicBlock *HeaderNode; + public: - typedef std::vector::iterator succ_iterator; - typedef std::vector::iterator pred_iterator; - typedef std::vector::iterator node_iterator; + using succ_iterator = std::vector::iterator; + using pred_iterator = std::vector::iterator; + using node_iterator = std::vector::iterator; inline Interval(BasicBlock *Header) : HeaderNode(Header) { Nodes.push_back(Header); @@ -51,18 +52,15 @@ public: inline BasicBlock *getHeaderNode() const { return HeaderNode; } /// Nodes - The basic blocks in this interval. - /// std::vector Nodes; /// Successors - List of BasicBlocks that are reachable directly from nodes in /// this interval, but are not in the interval themselves. /// These nodes necessarily must be header nodes for other intervals. - /// std::vector Successors; /// Predecessors - List of BasicBlocks that have this Interval's header block /// as one of their successors. - /// std::vector Predecessors; /// contains - Find out if a basic block is in this interval @@ -88,7 +86,6 @@ public: /// Equality operator. It is only valid to compare two intervals from the /// same partition, because of this, all we have to check is the header node /// for equality. - /// inline bool operator==(const Interval &I) const { return HeaderNode == I.HeaderNode; } @@ -121,8 +118,8 @@ inline Interval::pred_iterator pred_end(Interval *I) { } template <> struct GraphTraits { - typedef Interval *NodeRef; - typedef Interval::succ_iterator ChildIteratorType; + using NodeRef = Interval *; + using ChildIteratorType = Interval::succ_iterator; static NodeRef getEntryNode(Interval *I) { return I; } @@ -131,14 +128,15 @@ template <> struct GraphTraits { static ChildIteratorType child_end(NodeRef N) { return succ_end(N); } }; -template <> struct GraphTraits > { - typedef Interval *NodeRef; - typedef Interval::pred_iterator ChildIteratorType; +template <> struct GraphTraits> { + using NodeRef = Interval *; + using ChildIteratorType = Interval::pred_iterator; + static NodeRef getEntryNode(Inverse G) { return G.Graph; } static ChildIteratorType child_begin(NodeRef N) { return pred_begin(N); } static ChildIteratorType child_end(NodeRef N) { return pred_end(N); } }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_INTERVAL_H diff --git a/include/llvm/Analysis/IntervalIterator.h b/include/llvm/Analysis/IntervalIterator.h index 655ce2dab41..6ffcae592e9 100644 --- a/include/llvm/Analysis/IntervalIterator.h +++ b/include/llvm/Analysis/IntervalIterator.h @@ -33,26 +33,32 @@ #ifndef LLVM_ANALYSIS_INTERVALITERATOR_H #define LLVM_ANALYSIS_INTERVALITERATOR_H +#include "llvm/ADT/GraphTraits.h" +#include "llvm/Analysis/Interval.h" #include "llvm/Analysis/IntervalPartition.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Function.h" +#include "llvm/Support/ErrorHandling.h" #include +#include +#include #include +#include #include namespace llvm { +class BasicBlock; + // getNodeHeader - Given a source graph node and the source graph, return the // BasicBlock that is the header node. This is the opposite of // getSourceGraphNode. -// inline BasicBlock *getNodeHeader(BasicBlock *BB) { return BB; } inline BasicBlock *getNodeHeader(Interval *I) { return I->getHeaderNode(); } // getSourceGraphNode - Given a BasicBlock and the source graph, return the // source graph node that corresponds to the BasicBlock. This is the opposite // of getNodeHeader. -// inline BasicBlock *getSourceGraphNode(Function *, BasicBlock *BB) { return BB; } @@ -64,7 +70,6 @@ inline Interval *getSourceGraphNode(IntervalPartition *IP, BasicBlock *BB) { // with the task of adding a node to the new interval, depending on the // type of the source node. In the case of a CFG source graph (BasicBlock // case), the BasicBlock itself is added to the interval. -// inline void addNodeToInterval(Interval *Int, BasicBlock *BB) { Int->Nodes.push_back(BB); } @@ -75,28 +80,25 @@ inline void addNodeToInterval(Interval *Int, BasicBlock *BB) { // case), the BasicBlock itself is added to the interval. In the case of // an IntervalPartition source graph (Interval case), all of the member // BasicBlocks are added to the interval. -// inline void addNodeToInterval(Interval *Int, Interval *I) { // Add all of the nodes in I as new nodes in Int. Int->Nodes.insert(Int->Nodes.end(), I->Nodes.begin(), I->Nodes.end()); } - - - - -template, - class IGT = GraphTraits > > +template, + class IGT = GraphTraits>> class IntervalIterator { - std::vector > IntStack; - std::set Visited; + std::vector> IntStack; + std::set Visited; OrigContainer_t *OrigContainer; bool IOwnMem; // If True, delete intervals when done with them // See file header for conditions of use + public: - typedef std::forward_iterator_tag iterator_category; + using iterator_category = std::forward_iterator_tag; + + IntervalIterator() = default; // End iterator, empty stack - IntervalIterator() {} // End iterator, empty stack IntervalIterator(Function *M, bool OwnMemory) : IOwnMem(OwnMemory) { OrigContainer = M; if (!ProcessInterval(&M->front())) { @@ -157,6 +159,7 @@ public: return *this; } + IntervalIterator operator++(int) { // Postincrement IntervalIterator tmp = *this; ++*this; @@ -171,7 +174,6 @@ private: // // This method is templated because it may operate on two different source // graphs: a basic block graph, or a preexisting interval graph. - // bool ProcessInterval(NodeTy *Node) { BasicBlock *Header = getNodeHeader(Node); if (!Visited.insert(Header).second) @@ -196,7 +198,6 @@ private: // // This method is templated because it may operate on two different source // graphs: a basic block graph, or a preexisting interval graph. - // void ProcessNode(Interval *Int, NodeTy *Node) { assert(Int && "Null interval == bad!"); assert(Node && "Null Node == bad!"); @@ -241,10 +242,9 @@ private: } }; -typedef IntervalIterator function_interval_iterator; -typedef IntervalIterator - interval_part_interval_iterator; - +using function_interval_iterator = IntervalIterator; +using interval_part_interval_iterator = + IntervalIterator; inline function_interval_iterator intervals_begin(Function *F, bool DeleteInts = true) { @@ -263,6 +263,6 @@ inline interval_part_interval_iterator intervals_end(IntervalPartition &IP) { return interval_part_interval_iterator(); } -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_INTERVALITERATOR_H diff --git a/include/llvm/Analysis/IntervalPartition.h b/include/llvm/Analysis/IntervalPartition.h index 274be2bdcfa..50335165711 100644 --- a/include/llvm/Analysis/IntervalPartition.h +++ b/include/llvm/Analysis/IntervalPartition.h @@ -23,12 +23,15 @@ #ifndef LLVM_ANALYSIS_INTERVALPARTITION_H #define LLVM_ANALYSIS_INTERVALPARTITION_H -#include "llvm/Analysis/Interval.h" #include "llvm/Pass.h" #include +#include namespace llvm { +class BasicBlock; +class Interval; + //===----------------------------------------------------------------------===// // // IntervalPartition - This class builds and holds an "interval partition" for @@ -38,17 +41,17 @@ namespace llvm { // nodes following it. // class IntervalPartition : public FunctionPass { - typedef std::map IntervalMapTy; + using IntervalMapTy = std::map; IntervalMapTy IntervalMap; - typedef std::vector IntervalListTy; - Interval *RootInterval; - std::vector Intervals; + using IntervalListTy = std::vector; + Interval *RootInterval = nullptr; + std::vector Intervals; public: static char ID; // Pass identification, replacement for typeid - IntervalPartition() : FunctionPass(ID), RootInterval(nullptr) { + IntervalPartition() : FunctionPass(ID) { initializeIntervalPartitionPass(*PassRegistry::getPassRegistry()); } @@ -58,7 +61,6 @@ public: // IntervalPartition ctor - Build a reduced interval partition from an // existing interval graph. This takes an additional boolean parameter to // distinguish it from a copy constructor. Always pass in false for now. - // IntervalPartition(IntervalPartition &I, bool); // print - Show contents in human readable format... @@ -95,17 +97,15 @@ private: // addIntervalToPartition - Add an interval to the internal list of intervals, // and then add mappings from all of the basic blocks in the interval to the // interval itself (in the IntervalMap). - // void addIntervalToPartition(Interval *I); // updatePredecessors - Interval generation only sets the successor fields of // the interval data structures. After interval generation is complete, // run through all of the intervals and propagate successor info as // predecessor info. - // void updatePredecessors(Interval *Int); }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_INTERVALPARTITION_H diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp index 4dfa25490d0..025e8119deb 100644 --- a/lib/Analysis/AliasSetTracker.cpp +++ b/lib/Analysis/AliasSetTracker.cpp @@ -13,17 +13,29 @@ #include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/MemoryLocation.h" +#include "llvm/IR/CallSite.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/Function.h" #include "llvm/IR/InstIterator.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" -#include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" +#include "llvm/Support/AtomicOrdering.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include + using namespace llvm; static cl::opt @@ -106,7 +118,6 @@ void AliasSetTracker::removeAliasSet(AliasSet *AS) { TotalMayAliasSetSize -= AS->size(); AliasSets.erase(AS); - } void AliasSet::removeFromTracker(AliasSetTracker &AST) { @@ -580,7 +591,6 @@ AliasSet &AliasSetTracker::mergeAllAliasSets() { AliasSet &AliasSetTracker::addPointer(Value *P, uint64_t Size, const AAMDNodes &AAInfo, AliasSet::AccessLattice E) { - AliasSet &AS = getAliasSetForPointer(P, Size, AAInfo); AS.Access |= E; @@ -611,7 +621,6 @@ void AliasSet::print(raw_ostream &OS) const { if (Forward) OS << " forwarding to " << (void*)Forward; - if (!empty()) { OS << "Pointers: "; for (iterator I = begin(), E = end(); I != E; ++I) { @@ -671,10 +680,13 @@ AliasSetTracker::ASTCallbackVH::operator=(Value *V) { //===----------------------------------------------------------------------===// namespace { + class AliasSetPrinter : public FunctionPass { AliasSetTracker *Tracker; + public: static char ID; // Pass identification, replacement for typeid + AliasSetPrinter() : FunctionPass(ID) { initializeAliasSetPrinterPass(*PassRegistry::getPassRegistry()); } @@ -695,9 +707,11 @@ namespace { return false; } }; -} + +} // end anonymous namespace char AliasSetPrinter::ID = 0; + INITIALIZE_PASS_BEGIN(AliasSetPrinter, "print-alias-sets", "Alias Set Printer", false, true) INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp index ff5242f69a1..ac3ea2b73fe 100644 --- a/lib/Analysis/CallGraph.cpp +++ b/lib/Analysis/CallGraph.cpp @@ -8,12 +8,20 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/CallGraph.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/IR/CallSite.h" -#include "llvm/IR/Instructions.h" -#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Intrinsics.h" +#include "llvm/IR/PassManager.h" +#include "llvm/Pass.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include +#include + using namespace llvm; //===----------------------------------------------------------------------===// @@ -125,7 +133,6 @@ Function *CallGraph::removeFunctionFromModule(CallGraphNode *CGN) { /// This does not rescan the body of the function, so it is suitable when /// splicing the body of the old function to the new while also updating all /// callers from old to new. -/// void CallGraph::spliceFunction(const Function *From, const Function *To) { assert(FunctionMap.count(From) && "No CallGraphNode for function!"); assert(!FunctionMap.count(To) && @@ -256,7 +263,7 @@ CallGraphWrapperPass::CallGraphWrapperPass() : ModulePass(ID) { initializeCallGraphWrapperPassPass(*PassRegistry::getPassRegistry()); } -CallGraphWrapperPass::~CallGraphWrapperPass() {} +CallGraphWrapperPass::~CallGraphWrapperPass() = default; void CallGraphWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); @@ -291,8 +298,10 @@ void CallGraphWrapperPass::dump() const { print(dbgs(), nullptr); } #endif namespace { + struct CallGraphPrinterLegacyPass : public ModulePass { static char ID; // Pass ID, replacement for typeid + CallGraphPrinterLegacyPass() : ModulePass(ID) { initializeCallGraphPrinterLegacyPassPass(*PassRegistry::getPassRegistry()); } @@ -301,12 +310,14 @@ struct CallGraphPrinterLegacyPass : public ModulePass { AU.setPreservesAll(); AU.addRequiredTransitive(); } + bool runOnModule(Module &M) override { getAnalysis().print(errs(), &M); return false; } }; -} + +} // end anonymous namespace char CallGraphPrinterLegacyPass::ID = 0; diff --git a/lib/Analysis/DominanceFrontier.cpp b/lib/Analysis/DominanceFrontier.cpp index c08c6cfe0c3..bb8caf4a517 100644 --- a/lib/Analysis/DominanceFrontier.cpp +++ b/lib/Analysis/DominanceFrontier.cpp @@ -9,15 +9,23 @@ #include "llvm/Analysis/DominanceFrontier.h" #include "llvm/Analysis/DominanceFrontierImpl.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" +#include "llvm/Pass.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; namespace llvm { + template class DominanceFrontierBase; template class DominanceFrontierBase; template class ForwardDominanceFrontierBase; -} + +} // end namespace llvm char DominanceFrontierWrapperPass::ID = 0; @@ -27,7 +35,7 @@ INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier", "Dominance Frontier Construction", true, true) - DominanceFrontierWrapperPass::DominanceFrontierWrapperPass() +DominanceFrontierWrapperPass::DominanceFrontierWrapperPass() : FunctionPass(ID), DF() { initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry()); } diff --git a/lib/Analysis/Interval.cpp b/lib/Analysis/Interval.cpp index 6c10d73bcb4..6d5de22cb93 100644 --- a/lib/Analysis/Interval.cpp +++ b/lib/Analysis/Interval.cpp @@ -16,7 +16,6 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" #include "llvm/Support/raw_ostream.h" -#include using namespace llvm; @@ -25,7 +24,6 @@ using namespace llvm; //===----------------------------------------------------------------------===// // isLoop - Find out if there is a back edge in this interval... -// bool Interval::isLoop() const { // There is a loop in this interval iff one of the predecessors of the header // node lives in the interval. @@ -36,7 +34,6 @@ bool Interval::isLoop() const { return false; } - void Interval::print(raw_ostream &OS) const { OS << "-------------------------------------------------------------\n" << "Interval Contents:\n"; diff --git a/lib/Analysis/IntervalPartition.cpp b/lib/Analysis/IntervalPartition.cpp index a4e56e0694b..c777d91b67c 100644 --- a/lib/Analysis/IntervalPartition.cpp +++ b/lib/Analysis/IntervalPartition.cpp @@ -12,10 +12,17 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/IntervalPartition.h" +#include "llvm/Analysis/Interval.h" #include "llvm/Analysis/IntervalIterator.h" +#include "llvm/Pass.h" +#include +#include + using namespace llvm; char IntervalPartition::ID = 0; + INITIALIZE_PASS(IntervalPartition, "intervals", "Interval Partition Construction", true, true) @@ -40,7 +47,6 @@ void IntervalPartition::print(raw_ostream &O, const Module*) const { // addIntervalToPartition - Add an interval to the internal list of intervals, // and then add mappings from all of the basic blocks in the interval to the // interval itself (in the IntervalMap). -// void IntervalPartition::addIntervalToPartition(Interval *I) { Intervals.push_back(I); @@ -54,7 +60,6 @@ void IntervalPartition::addIntervalToPartition(Interval *I) { // the interval data structures. After interval generation is complete, // run through all of the intervals and propagate successor info as // predecessor info. -// void IntervalPartition::updatePredecessors(Interval *Int) { BasicBlock *Header = Int->getHeaderNode(); for (BasicBlock *Successor : Int->Successors) @@ -63,7 +68,6 @@ void IntervalPartition::updatePredecessors(Interval *Int) { // IntervalPartition ctor - Build the first level interval partition for the // specified function... -// bool IntervalPartition::runOnFunction(Function &F) { // Pass false to intervals_begin because we take ownership of it's memory function_interval_iterator I = intervals_begin(&F, false); @@ -84,11 +88,9 @@ bool IntervalPartition::runOnFunction(Function &F) { return false; } - // IntervalPartition ctor - Build a reduced interval partition from an // existing interval graph. This takes an additional boolean parameter to // distinguish it from a copy constructor. Always pass in false for now. -// IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) : FunctionPass(ID) { assert(IP.getRootInterval() && "Cannot operate on empty IntervalPartitions!"); @@ -110,4 +112,3 @@ IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) for (unsigned i = 0, e = Intervals.size(); i != e; ++i) updatePredecessors(Intervals[i]); } -