From 44e80299e5182aa6015b3d342898e8600a763ae9 Mon Sep 17 00:00:00 2001 From: Eugene Zelenko Date: Tue, 27 Jun 2017 22:20:38 +0000 Subject: [PATCH] [Analysis] Revert r306472 changes in LoopInfo headers to fix broken builds. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306476 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/LoopInfo.h | 121 +++++++++++---------------- include/llvm/Analysis/LoopInfoImpl.h | 38 +++------ include/llvm/Analysis/LoopIterator.h | 30 ++----- 3 files changed, 69 insertions(+), 120 deletions(-) diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 19fc1460a8b..096df1e421a 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -39,39 +39,26 @@ #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; -template class DominatorTreeBase; -class Function; -class Loop; class LoopInfo; -template class LoopInfoBase; +class Loop; class MDNode; +class PHINode; class raw_ostream; -class Value; +template class DominatorTreeBase; +template class LoopInfoBase; +template class LoopBase; //===----------------------------------------------------------------------===// /// Instances of this class are used to represent loops that are detected in the @@ -79,8 +66,7 @@ class Value; /// template class LoopBase { - LoopT *ParentLoop = nullptr; - + LoopT *ParentLoop; // Loops contained entirely within this one. std::vector SubLoops; @@ -92,12 +78,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() = default; - LoopBase(const LoopBase &) = delete; - LoopBase &operator=(const LoopBase &) = delete; - + LoopBase() : ParentLoop(nullptr) {} ~LoopBase() { for (size_t i = 0, e = SubLoops.size(); i != e; ++i) delete SubLoops[i]; @@ -140,11 +126,9 @@ public: /// Return the loops contained entirely within this loop. const std::vector &getSubLoops() const { return SubLoops; } std::vector &getSubLoopsVector() { return SubLoops; } - - using iterator = typename std::vector::const_iterator; - using reverse_iterator = - typename std::vector::const_reverse_iterator; - + typedef typename std::vector::const_iterator iterator; + typedef typename std::vector::const_reverse_iterator + reverse_iterator; iterator begin() const { return SubLoops.begin(); } iterator end() const { return SubLoops.end(); } reverse_iterator rbegin() const { return SubLoops.rbegin(); } @@ -153,9 +137,7 @@ public: /// Get a list of the basic blocks which make up this loop. const std::vector &getBlocks() const { return Blocks; } - - using block_iterator = typename std::vector::const_iterator; - + typedef typename std::vector::const_iterator block_iterator; block_iterator block_begin() const { return Blocks.begin(); } block_iterator block_end() const { return Blocks.end(); } inline iterator_range blocks() const { @@ -191,8 +173,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; } @@ -201,7 +183,7 @@ public: unsigned NumBackEdges = 0; BlockT *H = getHeader(); - for (const auto Pred : children>(H)) + for (const auto Pred : children >(H)) if (contains(Pred)) ++NumBackEdges; @@ -234,7 +216,7 @@ public: BlockT *getExitBlock() const; /// Edge type. - using Edge = std::pair; + typedef std::pair Edge; /// Return all pairs of (_inside_block_,_outside_block_). void getExitEdges(SmallVectorImpl &ExitEdges) const; @@ -338,7 +320,7 @@ public: /// Blocks as appropriate. This does not update the mapping in the LoopInfo /// class. void removeBlockFromLoop(BlockT *BB) { - auto I = llvm::find(Blocks, BB); + auto I = find(Blocks, BB); assert(I != Blocks.end() && "N is not in this list!"); Blocks.erase(I); @@ -356,7 +338,6 @@ public: protected: friend class LoopInfoBase; - explicit LoopBase(BlockT *BB) : ParentLoop(nullptr) { Blocks.push_back(BB); DenseBlockSet.insert(BB); @@ -372,6 +353,7 @@ 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 { @@ -382,7 +364,7 @@ public: DebugLoc End; public: - LocRange() = default; + LocRange() {} LocRange(DebugLoc Start) : Start(std::move(Start)), End(std::move(Start)) {} LocRange(DebugLoc Start, DebugLoc End) : Start(std::move(Start)), End(std::move(End)) {} @@ -397,7 +379,7 @@ public: } }; - Loop() = default; + Loop() {} /// Return true if the specified value is loop invariant. bool isLoopInvariant(const Value *V) const; @@ -425,6 +407,7 @@ 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; @@ -434,6 +417,7 @@ public: /// /// The IndVarSimplify pass transforms loops to have a canonical induction /// variable. + /// PHINode *getCanonicalInductionVariable() const; /// Return true if the Loop is in LCSSA form. @@ -470,7 +454,6 @@ 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 @@ -516,7 +499,6 @@ public: private: friend class LoopInfoBase; - explicit Loop(BasicBlock *BB) : LoopBase(BB) {} }; @@ -527,17 +509,19 @@ 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() = default; + LoopInfoBase() { } + ~LoopInfoBase() { releaseMemory(); } LoopInfoBase(LoopInfoBase &&Arg) : BBMap(std::move(Arg.BBMap)), @@ -545,7 +529,6 @@ 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); @@ -556,10 +539,6 @@ public: return *this; } - LoopInfoBase(const LoopInfoBase &) = delete; - LoopInfoBase &operator=(const LoopInfoBase &) = delete; - ~LoopInfoBase() { releaseMemory(); } - void releaseMemory() { BBMap.clear(); @@ -573,10 +552,10 @@ public: /// iterator/begin/end - The interface to the top-level loops in the current /// function. - using iterator = typename std::vector::const_iterator; - using reverse_iterator = - typename std::vector::const_reverse_iterator; - + /// + typedef typename std::vector::const_iterator iterator; + typedef typename std::vector::const_reverse_iterator + reverse_iterator; iterator begin() const { return TopLevelLoops.begin(); } iterator end() const { return TopLevelLoops.end(); } reverse_iterator rbegin() const { return TopLevelLoops.rbegin(); } @@ -648,7 +627,7 @@ public: /// loop. void changeTopLevelLoop(LoopT *OldLoop, LoopT *NewLoop) { - auto I = llvm::find(TopLevelLoops, OldLoop); + auto I = find(TopLevelLoops, OldLoop); assert(I != TopLevelLoops.end() && "Old loop not at top level!"); *I = NewLoop; assert(!NewLoop->ParentLoop && !OldLoop->ParentLoop && @@ -696,24 +675,22 @@ public: extern template class LoopInfoBase; class LoopInfo : public LoopInfoBase { - friend class LoopBase; + typedef LoopInfoBase BaseT; - using BaseT = LoopInfoBase; + friend class LoopBase; + void operator=(const LoopInfo &) = delete; + LoopInfo(const LoopInfo &) = delete; public: - LoopInfo() = default; + LoopInfo() {} 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 &); @@ -821,8 +798,8 @@ public: // Allow clients to walk the list of nested loops... template <> struct GraphTraits { - using NodeRef = const Loop *; - using ChildIteratorType = LoopInfo::iterator; + typedef const Loop *NodeRef; + typedef LoopInfo::iterator ChildIteratorType; static NodeRef getEntryNode(const Loop *L) { return L; } static ChildIteratorType child_begin(NodeRef N) { return N->begin(); } @@ -830,8 +807,8 @@ template <> struct GraphTraits { }; template <> struct GraphTraits { - using NodeRef = Loop *; - using ChildIteratorType = LoopInfo::iterator; + typedef Loop *NodeRef; + typedef LoopInfo::iterator ChildIteratorType; static NodeRef getEntryNode(Loop *L) { return L; } static ChildIteratorType child_begin(NodeRef N) { return N->begin(); } @@ -841,11 +818,10 @@ template <> struct GraphTraits { /// \brief Analysis pass that exposes the \c LoopInfo for a function. class LoopAnalysis : public AnalysisInfoMixin { friend AnalysisInfoMixin; - static AnalysisKey Key; public: - using Result = LoopInfo; + typedef LoopInfo Result; LoopInfo run(Function &F, FunctionAnalysisManager &AM); }; @@ -856,7 +832,6 @@ class LoopPrinterPass : public PassInfoMixin { public: explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {} - PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; @@ -894,6 +869,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 namespace llvm +} // End llvm namespace -#endif // LLVM_ANALYSIS_LOOPINFO_H +#endif diff --git a/include/llvm/Analysis/LoopInfoImpl.h b/include/llvm/Analysis/LoopInfoImpl.h index 0e975af2798..372fc8b2174 100644 --- a/include/llvm/Analysis/LoopInfoImpl.h +++ b/include/llvm/Analysis/LoopInfoImpl.h @@ -15,23 +15,12 @@ #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/SmallPtrSet.h" -#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/SetVector.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 { @@ -119,8 +108,7 @@ BlockT *LoopBase::getLoopPreheader() const { return nullptr; // Make sure there is only one exit out of the preheader. - using BlockTraits = GraphTraits; - + typedef GraphTraits BlockTraits; typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out); ++SI; if (SI != BlockTraits::child_end(Out)) @@ -249,14 +237,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); }); @@ -356,7 +344,7 @@ template static void discoverAndMapSubloop(LoopT *L, ArrayRef Backedges, LoopInfoBase *LI, const DominatorTreeBase &DomTree) { - using InvBlockTraits = GraphTraits>; + typedef GraphTraits > InvBlockTraits; unsigned NumBlocks = 0; unsigned NumSubloops = 0; @@ -413,13 +401,13 @@ static void discoverAndMapSubloop(LoopT *L, ArrayRef Backedges, /// Populate all loop data in a stable order during a single forward DFS. template class PopulateLoopsDFS { - using BlockTraits = GraphTraits; - using SuccIterTy = typename BlockTraits::ChildIteratorType; + typedef GraphTraits BlockTraits; + typedef typename BlockTraits::ChildIteratorType SuccIterTy; LoopInfoBase *LI; - public: - PopulateLoopsDFS(LoopInfoBase *li) : LI(li) {} + PopulateLoopsDFS(LoopInfoBase *li): + LI(li) {} void traverse(BlockT *EntryBlock); @@ -669,6 +657,6 @@ void LoopInfoBase::verify( #endif } -} // end namespace llvm +} // End llvm namespace -#endif // LLVM_ANALYSIS_LOOPINFOIMPL_H +#endif diff --git a/include/llvm/Analysis/LoopIterator.h b/include/llvm/Analysis/LoopIterator.h index 1e03192b24d..461f7435182 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,23 +24,11 @@ #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 @@ -109,11 +97,11 @@ struct LoopBodyTraits { /// TODO: This could be generalized for any CFG region, or the entire CFG. class LoopBlocksDFS { public: - friend class LoopBlocksTraversal; - /// Postorder list iterators. - using POIterator = std::vector::const_iterator; - using RPOIterator = std::vector::const_reverse_iterator; + typedef std::vector::const_iterator POIterator; + typedef std::vector::const_reverse_iterator RPOIterator; + + friend class LoopBlocksTraversal; private: Loop *L; @@ -183,10 +171,8 @@ 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); @@ -196,7 +182,7 @@ public: class LoopBlocksTraversal { public: /// Graph traversal iterator. - using POTIterator = po_iterator; + typedef po_iterator POTIterator; private: LoopBlocksDFS &DFS; @@ -250,6 +236,6 @@ finishPostorder(BasicBlock *BB) { LBT.finishPostorder(BB); } -} // end namespace llvm +} // End namespace llvm -#endif // LLVM_ANALYSIS_LOOPITERATOR_H +#endif -- 2.50.1