From: Eugene Zelenko Date: Tue, 27 Jun 2017 21:52:05 +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=01187b342a79e71ac9e335f9512ddcbc5a5971a9;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@306472 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 096df1e421a..19fc1460a8b 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -39,26 +39,39 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/GraphTraits.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" +#include "llvm/IR/DebugLoc.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/PassManager.h" +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" #include "llvm/Pass.h" +#include "llvm/Support/Casting.h" #include +#include +#include +#include +#include +#include namespace llvm { class DominatorTree; -class LoopInfo; +template class DominatorTreeBase; +class Function; class Loop; +class LoopInfo; +template class LoopInfoBase; class MDNode; -class PHINode; class raw_ostream; -template class DominatorTreeBase; -template class LoopInfoBase; -template class LoopBase; +class Value; //===----------------------------------------------------------------------===// /// Instances of this class are used to represent loops that are detected in the @@ -66,7 +79,8 @@ template class LoopBase; /// template class LoopBase { - LoopT *ParentLoop; + LoopT *ParentLoop = nullptr; + // Loops contained entirely within this one. std::vector SubLoops; @@ -78,12 +92,12 @@ class LoopBase { /// Indicator that this loop is no longer a valid loop. bool IsInvalid = false; - LoopBase(const LoopBase &) = delete; - const LoopBase& - operator=(const LoopBase &) = delete; public: /// This creates an empty loop. - LoopBase() : ParentLoop(nullptr) {} + LoopBase() = default; + LoopBase(const LoopBase &) = delete; + LoopBase &operator=(const LoopBase &) = delete; + ~LoopBase() { for (size_t i = 0, e = SubLoops.size(); i != e; ++i) delete SubLoops[i]; @@ -126,9 +140,11 @@ public: /// Return the loops contained entirely within this loop. const std::vector &getSubLoops() const { return SubLoops; } std::vector &getSubLoopsVector() { return SubLoops; } - typedef typename std::vector::const_iterator iterator; - typedef typename std::vector::const_reverse_iterator - reverse_iterator; + + using iterator = typename std::vector::const_iterator; + using reverse_iterator = + typename std::vector::const_reverse_iterator; + iterator begin() const { return SubLoops.begin(); } iterator end() const { return SubLoops.end(); } reverse_iterator rbegin() const { return SubLoops.rbegin(); } @@ -137,7 +153,9 @@ public: /// Get a list of the basic blocks which make up this loop. const std::vector &getBlocks() const { return Blocks; } - typedef typename std::vector::const_iterator block_iterator; + + using block_iterator = typename std::vector::const_iterator; + block_iterator block_begin() const { return Blocks.begin(); } block_iterator block_end() const { return Blocks.end(); } inline iterator_range blocks() const { @@ -173,8 +191,8 @@ public: assert(contains(BB) && "block does not belong to the loop"); BlockT *Header = getHeader(); - auto PredBegin = GraphTraits >::child_begin(Header); - auto PredEnd = GraphTraits >::child_end(Header); + auto PredBegin = GraphTraits>::child_begin(Header); + auto PredEnd = GraphTraits>::child_end(Header); return std::find(PredBegin, PredEnd, BB) != PredEnd; } @@ -183,7 +201,7 @@ public: unsigned NumBackEdges = 0; BlockT *H = getHeader(); - for (const auto Pred : children >(H)) + for (const auto Pred : children>(H)) if (contains(Pred)) ++NumBackEdges; @@ -216,7 +234,7 @@ public: BlockT *getExitBlock() const; /// Edge type. - typedef std::pair Edge; + using Edge = std::pair; /// Return all pairs of (_inside_block_,_outside_block_). void getExitEdges(SmallVectorImpl &ExitEdges) const; @@ -320,7 +338,7 @@ public: /// Blocks as appropriate. This does not update the mapping in the LoopInfo /// class. void removeBlockFromLoop(BlockT *BB) { - auto I = find(Blocks, BB); + auto I = llvm::find(Blocks, BB); assert(I != Blocks.end() && "N is not in this list!"); Blocks.erase(I); @@ -338,6 +356,7 @@ public: protected: friend class LoopInfoBase; + explicit LoopBase(BlockT *BB) : ParentLoop(nullptr) { Blocks.push_back(BB); DenseBlockSet.insert(BB); @@ -353,7 +372,6 @@ raw_ostream& operator<<(raw_ostream &OS, const LoopBase &Loop) { // Implementation in LoopInfoImpl.h extern template class LoopBase; - /// Represents a single loop in the control flow graph. Note that not all SCCs /// in the CFG are necessarily loops. class Loop : public LoopBase { @@ -364,7 +382,7 @@ public: DebugLoc End; public: - LocRange() {} + LocRange() = default; LocRange(DebugLoc Start) : Start(std::move(Start)), End(std::move(Start)) {} LocRange(DebugLoc Start, DebugLoc End) : Start(std::move(Start)), End(std::move(End)) {} @@ -379,7 +397,7 @@ public: } }; - Loop() {} + Loop() = default; /// Return true if the specified value is loop invariant. bool isLoopInvariant(const Value *V) const; @@ -407,7 +425,6 @@ public: /// /// If InsertPt is specified, it is the point to hoist instructions to. /// If null, the terminator of the loop preheader is used. - /// bool makeLoopInvariant(Instruction *I, bool &Changed, Instruction *InsertPt = nullptr) const; @@ -417,7 +434,6 @@ public: /// /// The IndVarSimplify pass transforms loops to have a canonical induction /// variable. - /// PHINode *getCanonicalInductionVariable() const; /// Return true if the Loop is in LCSSA form. @@ -454,6 +470,7 @@ public: /// contain llvm.loop or or if multiple latches contain different nodes then /// 0 is returned. MDNode *getLoopID() const; + /// Set the llvm.loop loop id metadata for this loop. /// /// The LoopID metadata node will be added to each terminator instruction in @@ -499,6 +516,7 @@ public: private: friend class LoopInfoBase; + explicit Loop(BasicBlock *BB) : LoopBase(BB) {} }; @@ -509,19 +527,17 @@ private: template class LoopInfoBase { + friend class LoopBase; + friend class LoopInfo; + // BBMap - Mapping of basic blocks to the inner most loop they occur in DenseMap BBMap; + std::vector TopLevelLoops; std::vector RemovedLoops; - friend class LoopBase; - friend class LoopInfo; - - void operator=(const LoopInfoBase &) = delete; - LoopInfoBase(const LoopInfoBase &) = delete; public: - LoopInfoBase() { } - ~LoopInfoBase() { releaseMemory(); } + LoopInfoBase() = default; LoopInfoBase(LoopInfoBase &&Arg) : BBMap(std::move(Arg.BBMap)), @@ -529,6 +545,7 @@ public: // We have to clear the arguments top level loops as we've taken ownership. Arg.TopLevelLoops.clear(); } + LoopInfoBase &operator=(LoopInfoBase &&RHS) { BBMap = std::move(RHS.BBMap); @@ -539,6 +556,10 @@ public: return *this; } + LoopInfoBase(const LoopInfoBase &) = delete; + LoopInfoBase &operator=(const LoopInfoBase &) = delete; + ~LoopInfoBase() { releaseMemory(); } + void releaseMemory() { BBMap.clear(); @@ -552,10 +573,10 @@ public: /// iterator/begin/end - The interface to the top-level loops in the current /// function. - /// - typedef typename std::vector::const_iterator iterator; - typedef typename std::vector::const_reverse_iterator - reverse_iterator; + using iterator = typename std::vector::const_iterator; + using reverse_iterator = + typename std::vector::const_reverse_iterator; + iterator begin() const { return TopLevelLoops.begin(); } iterator end() const { return TopLevelLoops.end(); } reverse_iterator rbegin() const { return TopLevelLoops.rbegin(); } @@ -627,7 +648,7 @@ public: /// loop. void changeTopLevelLoop(LoopT *OldLoop, LoopT *NewLoop) { - auto I = find(TopLevelLoops, OldLoop); + auto I = llvm::find(TopLevelLoops, OldLoop); assert(I != TopLevelLoops.end() && "Old loop not at top level!"); *I = NewLoop; assert(!NewLoop->ParentLoop && !OldLoop->ParentLoop && @@ -675,22 +696,24 @@ public: extern template class LoopInfoBase; class LoopInfo : public LoopInfoBase { - typedef LoopInfoBase BaseT; - friend class LoopBase; - void operator=(const LoopInfo &) = delete; - LoopInfo(const LoopInfo &) = delete; + using BaseT = LoopInfoBase; + public: - LoopInfo() {} + LoopInfo() = default; explicit LoopInfo(const DominatorTreeBase &DomTree); LoopInfo(LoopInfo &&Arg) : BaseT(std::move(static_cast(Arg))) {} + LoopInfo &operator=(LoopInfo &&RHS) { BaseT::operator=(std::move(static_cast(RHS))); return *this; } + LoopInfo(const LoopInfo &) = delete; + LoopInfo &operator=(const LoopInfo &) = delete; + /// Handle invalidation explicitly. bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &); @@ -798,8 +821,8 @@ public: // Allow clients to walk the list of nested loops... template <> struct GraphTraits { - typedef const Loop *NodeRef; - typedef LoopInfo::iterator ChildIteratorType; + using NodeRef = const Loop *; + using ChildIteratorType = LoopInfo::iterator; static NodeRef getEntryNode(const Loop *L) { return L; } static ChildIteratorType child_begin(NodeRef N) { return N->begin(); } @@ -807,8 +830,8 @@ template <> struct GraphTraits { }; template <> struct GraphTraits { - typedef Loop *NodeRef; - typedef LoopInfo::iterator ChildIteratorType; + using NodeRef = Loop *; + using ChildIteratorType = LoopInfo::iterator; static NodeRef getEntryNode(Loop *L) { return L; } static ChildIteratorType child_begin(NodeRef N) { return N->begin(); } @@ -818,10 +841,11 @@ template <> struct GraphTraits { /// \brief Analysis pass that exposes the \c LoopInfo for a function. class LoopAnalysis : public AnalysisInfoMixin { friend AnalysisInfoMixin; + static AnalysisKey Key; public: - typedef LoopInfo Result; + using Result = LoopInfo; LoopInfo run(Function &F, FunctionAnalysisManager &AM); }; @@ -832,6 +856,7 @@ class LoopPrinterPass : public PassInfoMixin { public: explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {} + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; @@ -869,6 +894,6 @@ public: /// Function to print a loop's contents as LLVM's text IR assembly. void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner = ""); -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_LOOPINFO_H diff --git a/include/llvm/Analysis/LoopInfoImpl.h b/include/llvm/Analysis/LoopInfoImpl.h index 372fc8b2174..0e975af2798 100644 --- a/include/llvm/Analysis/LoopInfoImpl.h +++ b/include/llvm/Analysis/LoopInfoImpl.h @@ -15,12 +15,23 @@ #ifndef LLVM_ANALYSIS_LOOPINFOIMPL_H #define LLVM_ANALYSIS_LOOPINFOIMPL_H +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/DepthFirstIterator.h" +#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/IR/Dominators.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include namespace llvm { @@ -108,7 +119,8 @@ BlockT *LoopBase::getLoopPreheader() const { return nullptr; // Make sure there is only one exit out of the preheader. - typedef GraphTraits BlockTraits; + using BlockTraits = GraphTraits; + typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out); ++SI; if (SI != BlockTraits::child_end(Out)) @@ -237,14 +249,14 @@ void LoopBase::verifyLoop() const { [&](BlockT *B){return contains(B);}) && "Loop block has no in-loop successors!"); - assert(std::any_of(GraphTraits >::child_begin(BB), - GraphTraits >::child_end(BB), + assert(std::any_of(GraphTraits>::child_begin(BB), + GraphTraits>::child_end(BB), [&](BlockT *B){return contains(B);}) && "Loop block has no in-loop predecessors!"); SmallVector OutsideLoopPreds; - std::for_each(GraphTraits >::child_begin(BB), - GraphTraits >::child_end(BB), + std::for_each(GraphTraits>::child_begin(BB), + GraphTraits>::child_end(BB), [&](BlockT *B){if (!contains(B)) OutsideLoopPreds.push_back(B); }); @@ -344,7 +356,7 @@ template static void discoverAndMapSubloop(LoopT *L, ArrayRef Backedges, LoopInfoBase *LI, const DominatorTreeBase &DomTree) { - typedef GraphTraits > InvBlockTraits; + using InvBlockTraits = GraphTraits>; unsigned NumBlocks = 0; unsigned NumSubloops = 0; @@ -401,13 +413,13 @@ static void discoverAndMapSubloop(LoopT *L, ArrayRef Backedges, /// Populate all loop data in a stable order during a single forward DFS. template class PopulateLoopsDFS { - typedef GraphTraits BlockTraits; - typedef typename BlockTraits::ChildIteratorType SuccIterTy; + using BlockTraits = GraphTraits; + using SuccIterTy = typename BlockTraits::ChildIteratorType; LoopInfoBase *LI; + public: - PopulateLoopsDFS(LoopInfoBase *li): - LI(li) {} + PopulateLoopsDFS(LoopInfoBase *li) : LI(li) {} void traverse(BlockT *EntryBlock); @@ -657,6 +669,6 @@ void LoopInfoBase::verify( #endif } -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_LOOPINFOIMPL_H diff --git a/include/llvm/Analysis/LoopIterator.h b/include/llvm/Analysis/LoopIterator.h index 461f7435182..1e03192b24d 100644 --- a/include/llvm/Analysis/LoopIterator.h +++ b/include/llvm/Analysis/LoopIterator.h @@ -1,4 +1,4 @@ -//===--------- LoopIterator.h - Iterate over loop blocks --------*- C++ -*-===// +//===- LoopIterator.h - Iterate over loop blocks ----------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -24,11 +24,23 @@ #ifndef LLVM_ANALYSIS_LOOPITERATOR_H #define LLVM_ANALYSIS_LOOPITERATOR_H +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/PostOrderIterator.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/iterator.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Analysis/LoopInfo.h" +#include "llvm/IR/CFG.h" +#include "llvm/Support/MathExtras.h" +#include +#include +#include +#include namespace llvm { +class BasicBlock; class LoopBlocksTraversal; // A traits type that is intended to be used in graph algorithms. The graph @@ -97,12 +109,12 @@ struct LoopBodyTraits { /// TODO: This could be generalized for any CFG region, or the entire CFG. class LoopBlocksDFS { public: - /// Postorder list iterators. - typedef std::vector::const_iterator POIterator; - typedef std::vector::const_reverse_iterator RPOIterator; - friend class LoopBlocksTraversal; + /// Postorder list iterators. + using POIterator = std::vector::const_iterator; + using RPOIterator = std::vector::const_reverse_iterator; + private: Loop *L; @@ -171,8 +183,10 @@ public: /// Specialize po_iterator_storage to record postorder numbers. template<> class po_iterator_storage { LoopBlocksTraversal &LBT; + public: po_iterator_storage(LoopBlocksTraversal &lbs) : LBT(lbs) {} + // These functions are defined below. bool insertEdge(Optional From, BasicBlock *To); void finishPostorder(BasicBlock *BB); @@ -182,7 +196,7 @@ public: class LoopBlocksTraversal { public: /// Graph traversal iterator. - typedef po_iterator POTIterator; + using POTIterator = po_iterator; private: LoopBlocksDFS &DFS; @@ -236,6 +250,6 @@ finishPostorder(BasicBlock *BB) { LBT.finishPostorder(BB); } -} // End namespace llvm +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_LOOPITERATOR_H diff --git a/include/llvm/Analysis/RegionInfo.h b/include/llvm/Analysis/RegionInfo.h index 16ee07fa317..2e34928b28a 100644 --- a/include/llvm/Analysis/RegionInfo.h +++ b/include/llvm/Analysis/RegionInfo.h @@ -37,18 +37,38 @@ #ifndef LLVM_ANALYSIS_REGIONINFO_H #define LLVM_ANALYSIS_REGIONINFO_H +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DepthFirstIterator.h" +#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/iterator_range.h" -#include "llvm/IR/CFG.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/PassManager.h" +#include "llvm/Pass.h" +#include "llvm/Support/raw_ostream.h" +#include +#include #include #include #include +#include +#include +#include namespace llvm { +class DominanceFrontier; +class DominatorTree; +class Loop; +class LoopInfo; +struct PostDominatorTree; +class Region; +template class RegionBase; +class RegionInfo; +template class RegionInfoBase; +class RegionNode; + // Class to be specialized for different users of RegionInfo // (i.e. BasicBlocks or MachineBasicBlocks). This is only to avoid needing to // pass around an unreasonable number of template parameters. @@ -59,37 +79,23 @@ struct RegionTraits { // RegionT // RegionNodeT // RegionInfoT - typedef typename FuncT_::UnknownRegionTypeError BrokenT; + using BrokenT = typename FuncT_::UnknownRegionTypeError; }; -class DominatorTree; -class DominanceFrontier; -class Loop; -class LoopInfo; -struct PostDominatorTree; -class raw_ostream; -class Region; -template -class RegionBase; -class RegionNode; -class RegionInfo; -template -class RegionInfoBase; - template <> struct RegionTraits { - typedef Function FuncT; - typedef BasicBlock BlockT; - typedef Region RegionT; - typedef RegionNode RegionNodeT; - typedef RegionInfo RegionInfoT; - typedef DominatorTree DomTreeT; - typedef DomTreeNode DomTreeNodeT; - typedef DominanceFrontier DomFrontierT; - typedef PostDominatorTree PostDomTreeT; - typedef Instruction InstT; - typedef Loop LoopT; - typedef LoopInfo LoopInfoT; + using FuncT = Function; + using BlockT = BasicBlock; + using RegionT = Region; + using RegionNodeT = RegionNode; + using RegionInfoT = RegionInfo; + using DomTreeT = DominatorTree; + using DomTreeNodeT = DomTreeNode; + using DomFrontierT = DominanceFrontier; + using PostDomTreeT = PostDominatorTree; + using InstT = Instruction; + using LoopT = Loop; + using LoopInfoT = LoopInfo; static unsigned getNumSuccessors(BasicBlock *BB) { return BB->getTerminator()->getNumSuccessors(); @@ -113,13 +119,10 @@ class RegionNodeBase { friend class RegionBase; public: - typedef typename Tr::BlockT BlockT; - typedef typename Tr::RegionT RegionT; + using BlockT = typename Tr::BlockT; + using RegionT = typename Tr::RegionT; private: - RegionNodeBase(const RegionNodeBase &) = delete; - const RegionNodeBase &operator=(const RegionNodeBase &) = delete; - /// This is the entry basic block that starts this region node. If this is a /// BasicBlock RegionNode, then entry is just the basic block, that this /// RegionNode represents. Otherwise it is the entry of this (Sub)RegionNode. @@ -150,6 +153,9 @@ protected: : entry(Entry, isSubRegion), parent(Parent) {} public: + RegionNodeBase(const RegionNodeBase &) = delete; + RegionNodeBase &operator=(const RegionNodeBase &) = delete; + /// @brief Get the parent Region of this RegionNode. /// /// The parent Region is the Region this RegionNode belongs to. If for @@ -247,24 +253,22 @@ public: /// tree, the second one creates a graphical representation using graphviz. template class RegionBase : public RegionNodeBase { - typedef typename Tr::FuncT FuncT; - typedef typename Tr::BlockT BlockT; - typedef typename Tr::RegionInfoT RegionInfoT; - typedef typename Tr::RegionT RegionT; - typedef typename Tr::RegionNodeT RegionNodeT; - typedef typename Tr::DomTreeT DomTreeT; - typedef typename Tr::LoopT LoopT; - typedef typename Tr::LoopInfoT LoopInfoT; - typedef typename Tr::InstT InstT; - - typedef GraphTraits BlockTraits; - typedef GraphTraits> InvBlockTraits; - typedef typename BlockTraits::ChildIteratorType SuccIterTy; - typedef typename InvBlockTraits::ChildIteratorType PredIterTy; - friend class RegionInfoBase; - RegionBase(const RegionBase &) = delete; - const RegionBase &operator=(const RegionBase &) = delete; + + using FuncT = typename Tr::FuncT; + using BlockT = typename Tr::BlockT; + using RegionInfoT = typename Tr::RegionInfoT; + using RegionT = typename Tr::RegionT; + using RegionNodeT = typename Tr::RegionNodeT; + using DomTreeT = typename Tr::DomTreeT; + using LoopT = typename Tr::LoopT; + using LoopInfoT = typename Tr::LoopInfoT; + using InstT = typename Tr::InstT; + + using BlockTraits = GraphTraits; + using InvBlockTraits = GraphTraits>; + using SuccIterTy = typename BlockTraits::ChildIteratorType; + using PredIterTy = typename InvBlockTraits::ChildIteratorType; // Information necessary to manage this Region. RegionInfoT *RI; @@ -274,12 +278,12 @@ class RegionBase : public RegionNodeBase { // (The entry BasicBlock is part of RegionNode) BlockT *exit; - typedef std::vector> RegionSet; + using RegionSet = std::vector>; // The subregions of this region. RegionSet children; - typedef std::map> BBNodeMapT; + using BBNodeMapT = std::map>; // Save the BasicBlock RegionNodes that are element of this Region. mutable BBNodeMapT BBNodeMap; @@ -308,6 +312,9 @@ public: RegionBase(BlockT *Entry, BlockT *Exit, RegionInfoT *RI, DomTreeT *DT, RegionT *Parent = nullptr); + RegionBase(const RegionBase &) = delete; + RegionBase &operator=(const RegionBase &) = delete; + /// Delete the Region and all its subregions. ~RegionBase(); @@ -543,8 +550,8 @@ public: /// /// These iterators iterator over all subregions of this Region. //@{ - typedef typename RegionSet::iterator iterator; - typedef typename RegionSet::const_iterator const_iterator; + using iterator = typename RegionSet::iterator; + using const_iterator = typename RegionSet::const_iterator; iterator begin() { return children.begin(); } iterator end() { return children.end(); } @@ -563,12 +570,13 @@ public: class block_iterator_wrapper : public df_iterator< typename std::conditional::type *> { - typedef df_iterator< - typename std::conditional::type *> super; + using super = + df_iterator< + typename std::conditional::type *>; public: - typedef block_iterator_wrapper Self; - typedef typename super::value_type value_type; + using Self = block_iterator_wrapper; + using value_type = typename super::value_type; // Construct the begin iterator. block_iterator_wrapper(value_type Entry, value_type Exit) @@ -592,8 +600,8 @@ public: } }; - typedef block_iterator_wrapper block_iterator; - typedef block_iterator_wrapper const_block_iterator; + using block_iterator = block_iterator_wrapper; + using const_block_iterator = block_iterator_wrapper; block_iterator block_begin() { return block_iterator(getEntry(), getExit()); } @@ -604,8 +612,8 @@ public: } const_block_iterator block_end() const { return const_block_iterator(); } - typedef iterator_range block_range; - typedef iterator_range const_block_range; + using block_range = iterator_range; + using const_block_range = iterator_range; /// @brief Returns a range view of the basic blocks in the region. inline block_range blocks() { @@ -626,14 +634,14 @@ public: /// are direct children of this Region. It does not iterate over any /// RegionNodes that are also element of a subregion of this Region. //@{ - typedef df_iterator, - false, GraphTraits> - element_iterator; + using element_iterator = + df_iterator, false, + GraphTraits>; - typedef df_iterator, false, - GraphTraits> - const_element_iterator; + using const_element_iterator = + df_iterator, false, + GraphTraits>; element_iterator element_begin(); element_iterator element_end(); @@ -661,29 +669,26 @@ inline raw_ostream &operator<<(raw_ostream &OS, const RegionNodeBase &Node); /// Tree. template class RegionInfoBase { - typedef typename Tr::BlockT BlockT; - typedef typename Tr::FuncT FuncT; - typedef typename Tr::RegionT RegionT; - typedef typename Tr::RegionInfoT RegionInfoT; - typedef typename Tr::DomTreeT DomTreeT; - typedef typename Tr::DomTreeNodeT DomTreeNodeT; - typedef typename Tr::PostDomTreeT PostDomTreeT; - typedef typename Tr::DomFrontierT DomFrontierT; - typedef GraphTraits BlockTraits; - typedef GraphTraits> InvBlockTraits; - typedef typename BlockTraits::ChildIteratorType SuccIterTy; - typedef typename InvBlockTraits::ChildIteratorType PredIterTy; - friend class RegionInfo; friend class MachineRegionInfo; - typedef DenseMap BBtoBBMap; - typedef DenseMap BBtoRegionMap; - RegionInfoBase(); - virtual ~RegionInfoBase(); + using BlockT = typename Tr::BlockT; + using FuncT = typename Tr::FuncT; + using RegionT = typename Tr::RegionT; + using RegionInfoT = typename Tr::RegionInfoT; + using DomTreeT = typename Tr::DomTreeT; + using DomTreeNodeT = typename Tr::DomTreeNodeT; + using PostDomTreeT = typename Tr::PostDomTreeT; + using DomFrontierT = typename Tr::DomFrontierT; + using BlockTraits = GraphTraits; + using InvBlockTraits = GraphTraits>; + using SuccIterTy = typename BlockTraits::ChildIteratorType; + using PredIterTy = typename InvBlockTraits::ChildIteratorType; + + using BBtoBBMap = DenseMap; + using BBtoRegionMap = DenseMap; - RegionInfoBase(const RegionInfoBase &) = delete; - const RegionInfoBase &operator=(const RegionInfoBase &) = delete; + RegionInfoBase(); RegionInfoBase(RegionInfoBase &&Arg) : DT(std::move(Arg.DT)), PDT(std::move(Arg.PDT)), DF(std::move(Arg.DF)), @@ -691,6 +696,7 @@ class RegionInfoBase { BBtoRegion(std::move(Arg.BBtoRegion)) { Arg.wipe(); } + RegionInfoBase &operator=(RegionInfoBase &&RHS) { DT = std::move(RHS.DT); PDT = std::move(RHS.PDT); @@ -701,12 +707,14 @@ class RegionInfoBase { return *this; } + virtual ~RegionInfoBase(); + DomTreeT *DT; PostDomTreeT *PDT; DomFrontierT *DF; /// The top level region. - RegionT *TopLevelRegion; + RegionT *TopLevelRegion = nullptr; /// Map every BB to the smallest region, that contains BB. BBtoRegionMap BBtoRegion; @@ -785,6 +793,9 @@ private: void calculate(FuncT &F); public: + RegionInfoBase(const RegionInfoBase &) = delete; + RegionInfoBase &operator=(const RegionInfoBase &) = delete; + static bool VerifyRegionInfo; static typename RegionT::PrintStyle printStyle; @@ -887,21 +898,22 @@ public: class RegionInfo : public RegionInfoBase> { public: - typedef RegionInfoBase> Base; + using Base = RegionInfoBase>; explicit RegionInfo(); - ~RegionInfo() override; - RegionInfo(RegionInfo &&Arg) : Base(std::move(static_cast(Arg))) { updateRegionTree(*this, TopLevelRegion); } + RegionInfo &operator=(RegionInfo &&RHS) { Base::operator=(std::move(static_cast(RHS))); updateRegionTree(*this, TopLevelRegion); return *this; } + ~RegionInfo() override; + /// Handle invalidation explicitly. bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &); @@ -931,8 +943,8 @@ class RegionInfoPass : public FunctionPass { public: static char ID; - explicit RegionInfoPass(); + explicit RegionInfoPass(); ~RegionInfoPass() override; RegionInfo &getRegionInfo() { return RI; } @@ -953,10 +965,11 @@ public: /// \brief Analysis pass that exposes the \c RegionInfo for a function. class RegionInfoAnalysis : public AnalysisInfoMixin { friend AnalysisInfoMixin; + static AnalysisKey Key; public: - typedef RegionInfo Result; + using Result = RegionInfo; RegionInfo run(Function &F, FunctionAnalysisManager &AM); }; @@ -967,6 +980,7 @@ class RegionInfoPrinterPass : public PassInfoMixin { public: explicit RegionInfoPrinterPass(raw_ostream &OS); + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; @@ -995,8 +1009,8 @@ RegionNodeBase>::getNodeAs() const { template inline raw_ostream &operator<<(raw_ostream &OS, const RegionNodeBase &Node) { - typedef typename Tr::BlockT BlockT; - typedef typename Tr::RegionT RegionT; + using BlockT = typename Tr::BlockT; + using RegionT = typename Tr::RegionT; if (Node.isSubRegion()) return OS << Node.template getNodeAs()->getNameStr(); @@ -1008,5 +1022,6 @@ extern template class RegionBase>; extern template class RegionNodeBase>; extern template class RegionInfoBase>; -} // End llvm namespace -#endif +} // end namespace llvm + +#endif // LLVM_ANALYSIS_REGIONINFO_H diff --git a/include/llvm/Analysis/RegionInfoImpl.h b/include/llvm/Analysis/RegionInfoImpl.h index a16c534484b..c0337b6daf3 100644 --- a/include/llvm/Analysis/RegionInfoImpl.h +++ b/include/llvm/Analysis/RegionInfoImpl.h @@ -12,7 +12,11 @@ #ifndef LLVM_ANALYSIS_REGIONINFOIMPL_H #define LLVM_ANALYSIS_REGIONINFOIMPL_H +#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/PostOrderIterator.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Analysis/DominanceFrontier.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/PostDominators.h" @@ -20,9 +24,15 @@ #include "llvm/Analysis/RegionIterator.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" #include +#include #include +#include #include +#include +#include +#include namespace llvm { @@ -303,7 +313,8 @@ RegionBase::element_end() const { template typename Tr::RegionT *RegionBase::getSubRegionNode(BlockT *BB) const { - typedef typename Tr::RegionT RegionT; + using RegionT = typename Tr::RegionT; + RegionT *R = RI->getRegionFor(BB); if (!R || R == this) @@ -330,7 +341,8 @@ typename Tr::RegionNodeT *RegionBase::getBBNode(BlockT *BB) const { if (at == BBNodeMap.end()) { auto Deconst = const_cast *>(this); typename BBNodeMapT::value_type V = { - BB, make_unique(static_cast(Deconst), BB)}; + BB, + llvm::make_unique(static_cast(Deconst), BB)}; at = BBNodeMap.insert(std::move(V)).first; } return at->second.get(); @@ -357,10 +369,10 @@ void RegionBase::transferChildrenTo(RegionT *To) { template void RegionBase::addSubRegion(RegionT *SubRegion, bool moveChildren) { assert(!SubRegion->parent && "SubRegion already has a parent!"); - assert(find_if(*this, - [&](const std::unique_ptr &R) { - return R.get() == SubRegion; - }) == children.end() && + assert(llvm::find_if(*this, + [&](const std::unique_ptr &R) { + return R.get() == SubRegion; + }) == children.end() && "Subregion already exists!"); SubRegion->parent = static_cast(this); @@ -402,7 +414,7 @@ typename Tr::RegionT *RegionBase::removeSubRegion(RegionT *Child) { assert(Child->parent == this && "Child is not a child of this region!"); Child->parent = nullptr; typename RegionSet::iterator I = - find_if(children, [&](const std::unique_ptr &R) { + llvm::find_if(children, [&](const std::unique_ptr &R) { return R.get() == Child; }); assert(I != children.end() && "Region does not exit. Unable to remove."); @@ -505,8 +517,7 @@ void RegionBase::clearNodeCache() { // template -RegionInfoBase::RegionInfoBase() - : TopLevelRegion(nullptr) {} +RegionInfoBase::RegionInfoBase() = default; template RegionInfoBase::~RegionInfoBase() { @@ -543,7 +554,8 @@ bool RegionInfoBase::isCommonDomFrontier(BlockT *BB, BlockT *entry, template bool RegionInfoBase::isRegion(BlockT *entry, BlockT *exit) const { assert(entry && exit && "entry and exit must not be null!"); - typedef typename DomFrontierT::DomSetType DST; + + using DST = typename DomFrontierT::DomSetType; DST *entrySuccs = &DF->find(entry)->second; @@ -689,7 +701,8 @@ void RegionInfoBase::findRegionsWithEntry(BlockT *entry, template void RegionInfoBase::scanForRegions(FuncT &F, BBtoBBMap *ShortCut) { - typedef typename std::add_pointer::type FuncPtrT; + using FuncPtrT = typename std::add_pointer::type; + BlockT *entry = GraphTraits::getEntryNode(&F); DomTreeNodeT *N = DT->getNode(entry); @@ -876,7 +889,7 @@ RegionInfoBase::getCommonRegion(SmallVectorImpl &BBs) const { template void RegionInfoBase::calculate(FuncT &F) { - typedef typename std::add_pointer::type FuncPtrT; + using FuncPtrT = typename std::add_pointer::type; // ShortCut a function where for every BB the exit of the largest region // starting with BB is stored. These regions can be threated as single BBS. @@ -892,4 +905,4 @@ void RegionInfoBase::calculate(FuncT &F) { } // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_REGIONINFOIMPL_H diff --git a/include/llvm/Analysis/RegionIterator.h b/include/llvm/Analysis/RegionIterator.h index de2f3bf3f12..fcb109cc550 100644 --- a/include/llvm/Analysis/RegionIterator.h +++ b/include/llvm/Analysis/RegionIterator.h @@ -8,17 +8,23 @@ //===----------------------------------------------------------------------===// // This file defines the iterators to iterate over the elements of a Region. //===----------------------------------------------------------------------===// + #ifndef LLVM_ANALYSIS_REGIONITERATOR_H #define LLVM_ANALYSIS_REGIONITERATOR_H +#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/PointerIntPair.h" -#include "llvm/ADT/SmallPtrSet.h" #include "llvm/Analysis/RegionInfo.h" #include "llvm/IR/CFG.h" -#include "llvm/Support/raw_ostream.h" +#include +#include +#include namespace llvm { + +class BasicBlock; + //===----------------------------------------------------------------------===// /// @brief Hierarchical RegionNode successor iterator. /// @@ -33,10 +39,9 @@ namespace llvm { template class RNSuccIterator : public std::iterator { - typedef std::iterator super; - - typedef GraphTraits BlockTraits; - typedef typename BlockTraits::ChildIteratorType SuccIterTy; + using super = std::iterator; + using BlockTraits = GraphTraits; + using SuccIterTy = typename BlockTraits::ChildIteratorType; // The iterator works in two modes, bb mode or region mode. enum ItMode { @@ -92,16 +97,15 @@ class RNSuccIterator inline bool isExit(BlockT* BB) const { return getNode()->getParent()->getExit() == BB; } -public: - typedef RNSuccIterator Self; - typedef typename super::value_type value_type; +public: + using Self = RNSuccIterator; + using value_type = typename super::value_type; /// @brief Create begin iterator of a RegionNode. inline RNSuccIterator(NodeRef node) : Node(node, node->isSubRegion() ? ItRgBegin : ItBB), BItor(BlockTraits::child_begin(node->getEntry())) { - // Skip the exit block if (!isRegionMode()) while (BlockTraits::child_end(node->getEntry()) != BItor && isExit(*BItor)) @@ -153,7 +157,6 @@ public: } }; - //===----------------------------------------------------------------------===// /// @brief Flat RegionNode iterator. /// @@ -163,16 +166,16 @@ public: template class RNSuccIterator, BlockT, RegionT> : public std::iterator { - typedef std::iterator super; - typedef GraphTraits BlockTraits; - typedef typename BlockTraits::ChildIteratorType SuccIterTy; + using super = std::iterator; + using BlockTraits = GraphTraits; + using SuccIterTy = typename BlockTraits::ChildIteratorType; NodeRef Node; SuccIterTy Itor; public: - typedef RNSuccIterator, BlockT, RegionT> Self; - typedef typename super::value_type value_type; + using Self = RNSuccIterator, BlockT, RegionT>; + using value_type = typename super::value_type; /// @brief Create the iterator from a RegionNode. /// @@ -255,8 +258,8 @@ inline RNSuccIterator succ_end(NodeRef Node) { #define RegionNodeGraphTraits(NodeT, BlockT, RegionT) \ template <> struct GraphTraits { \ - typedef NodeT *NodeRef; \ - typedef RNSuccIterator ChildIteratorType; \ + using NodeRef = NodeT *; \ + using ChildIteratorType = RNSuccIterator; \ static NodeRef getEntryNode(NodeRef N) { return N; } \ static inline ChildIteratorType child_begin(NodeRef N) { \ return RNSuccIterator(N); \ @@ -266,9 +269,9 @@ inline RNSuccIterator succ_end(NodeRef Node) { } \ }; \ template <> struct GraphTraits> { \ - typedef NodeT *NodeRef; \ - typedef RNSuccIterator, BlockT, RegionT> \ - ChildIteratorType; \ + using NodeRef = NodeT *; \ + using ChildIteratorType = \ + RNSuccIterator, BlockT, RegionT>; \ static NodeRef getEntryNode(NodeRef N) { return N; } \ static inline ChildIteratorType child_begin(NodeRef N) { \ return RNSuccIterator, BlockT, RegionT>(N); \ @@ -280,7 +283,7 @@ inline RNSuccIterator succ_end(NodeRef Node) { #define RegionGraphTraits(RegionT, NodeT) \ template <> struct GraphTraits : public GraphTraits { \ - typedef df_iterator nodes_iterator; \ + using nodes_iterator = df_iterator; \ static NodeRef getEntryNode(RegionT *R) { \ return R->getNode(R->getEntry()); \ } \ @@ -294,9 +297,9 @@ inline RNSuccIterator succ_end(NodeRef Node) { template <> \ struct GraphTraits> \ : public GraphTraits> { \ - typedef df_iterator, false, \ - GraphTraits>> \ - nodes_iterator; \ + using nodes_iterator = \ + df_iterator, false, \ + GraphTraits>>; \ static NodeRef getEntryNode(RegionT *R) { \ return R->getBBNode(R->getEntry()); \ } \ @@ -315,17 +318,19 @@ RegionGraphTraits(Region, RegionNode); RegionGraphTraits(const Region, const RegionNode); template <> struct GraphTraits - : public GraphTraits > { - typedef df_iterator, false, - GraphTraits>> - nodes_iterator; + : public GraphTraits> { + using nodes_iterator = + df_iterator, false, + GraphTraits>>; static NodeRef getEntryNode(RegionInfo *RI) { - return GraphTraits >::getEntryNode(RI->getTopLevelRegion()); + return GraphTraits>::getEntryNode(RI->getTopLevelRegion()); } + static nodes_iterator nodes_begin(RegionInfo* RI) { return nodes_iterator::begin(getEntryNode(RI)); } + static nodes_iterator nodes_end(RegionInfo *RI) { return nodes_iterator::end(getEntryNode(RI)); } @@ -333,21 +338,23 @@ template <> struct GraphTraits template <> struct GraphTraits : public GraphTraits { - typedef df_iterator, false, - GraphTraits>> - nodes_iterator; + using nodes_iterator = + df_iterator, false, + GraphTraits>>; static NodeRef getEntryNode(RegionInfoPass *RI) { return GraphTraits::getEntryNode(&RI->getRegionInfo()); } + static nodes_iterator nodes_begin(RegionInfoPass* RI) { return GraphTraits::nodes_begin(&RI->getRegionInfo()); } + static nodes_iterator nodes_end(RegionInfoPass *RI) { return GraphTraits::nodes_end(&RI->getRegionInfo()); } }; -} // End namespace llvm +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_REGIONITERATOR_H diff --git a/lib/Analysis/RegionInfo.cpp b/lib/Analysis/RegionInfo.cpp index 63ef8d28d44..90048732300 100644 --- a/lib/Analysis/RegionInfo.cpp +++ b/lib/Analysis/RegionInfo.cpp @@ -10,28 +10,29 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/RegionInfo.h" -#include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/Statistic.h" -#include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/RegionInfoImpl.h" -#include "llvm/Analysis/RegionIterator.h" -#include "llvm/IR/PassManager.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/ErrorHandling.h" #ifndef NDEBUG #include "llvm/Analysis/RegionPrinter.h" #endif +#include "llvm/Analysis/RegionInfoImpl.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/PassManager.h" +#include "llvm/Pass.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; #define DEBUG_TYPE "region" namespace llvm { + template class RegionBase>; template class RegionNodeBase>; template class RegionInfoBase>; -} + +} // end namespace llvm STATISTIC(numRegions, "The # of regions"); STATISTIC(numSimpleRegions, "The # of simple regions"); @@ -44,7 +45,6 @@ VerifyRegionInfoX( cl::location(RegionInfoBase>::VerifyRegionInfo), cl::desc("Verify region info (time consuming)")); - static cl::opt printStyleX("print-region-style", cl::location(RegionInfo::printStyle), cl::Hidden, @@ -56,7 +56,6 @@ static cl::opt printStyleX("print-region-style", clEnumValN(Region::PrintRN, "rn", "print regions in detail with element_iterator"))); - //===----------------------------------------------------------------------===// // Region implementation // @@ -68,20 +67,15 @@ Region::Region(BasicBlock *Entry, BasicBlock *Exit, } -Region::~Region() { } +Region::~Region() = default; //===----------------------------------------------------------------------===// // RegionInfo implementation // -RegionInfo::RegionInfo() : - RegionInfoBase>() { - -} +RegionInfo::RegionInfo() = default; -RegionInfo::~RegionInfo() { - -} +RegionInfo::~RegionInfo() = default; bool RegionInfo::invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &) { @@ -126,9 +120,7 @@ RegionInfoPass::RegionInfoPass() : FunctionPass(ID) { initializeRegionInfoPassPass(*PassRegistry::getPassRegistry()); } -RegionInfoPass::~RegionInfoPass() { - -} +RegionInfoPass::~RegionInfoPass() = default; bool RegionInfoPass::runOnFunction(Function &F) { releaseMemory(); @@ -181,10 +173,12 @@ INITIALIZE_PASS_END(RegionInfoPass, "regions", // the link time optimization. namespace llvm { + FunctionPass *createRegionInfoPass() { return new RegionInfoPass(); } -} + +} // end namespace llvm //===----------------------------------------------------------------------===// // RegionInfoAnalysis implementation