Rename LoopInfo::Analyze() to LoopInfo::analyze() and turn its parameter type to...
authorCong Hou <congh@google.com>
Thu, 16 Jul 2015 18:23:57 +0000 (18:23 +0000)
committerCong Hou <congh@google.com>
Thu, 16 Jul 2015 18:23:57 +0000 (18:23 +0000)
The benefit of turning the parameter of LoopInfo::analyze() to const& is that it now can accept a rvalue.

http://reviews.llvm.org/D11250

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242426 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopInfo.h
include/llvm/Analysis/LoopInfoImpl.h
include/llvm/CodeGen/MachineDominators.h
include/llvm/IR/Dominators.h
lib/Analysis/LoopInfo.cpp
lib/CodeGen/MachineLoopInfo.cpp

index 3ec83f2c21fdf1a52e77af0fd62cf0e32b2d5014..292a8b2b6d26f6c3ff120534b76a1ef999ce55de 100644 (file)
@@ -622,7 +622,7 @@ public:
   }
 
   /// Create the loop forest using a stable algorithm.
-  void Analyze(DominatorTreeBase<BlockT> &DomTree);
+  void analyze(const DominatorTreeBase<BlockT> &DomTree);
 
   // Debugging
   void print(raw_ostream &OS) const;
index f5cc856f624769aad68b6593b395e5ff66967bbc..dcd9a0f4cbcf2bfd763a235557263994c3d31c44 100644 (file)
@@ -345,7 +345,7 @@ void LoopBase<BlockT, LoopT>::print(raw_ostream &OS, unsigned Depth) const {
 template<class BlockT, class LoopT>
 static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT*> Backedges,
                                   LoopInfoBase<BlockT, LoopT> *LI,
-                                  DominatorTreeBase<BlockT> &DomTree) {
+                                  const DominatorTreeBase<BlockT> &DomTree) {
   typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
 
   unsigned NumBlocks = 0;
@@ -468,10 +468,10 @@ void PopulateLoopsDFS<BlockT, LoopT>::insertIntoLoop(BlockT *Block) {
 /// insertions per block.
 template<class BlockT, class LoopT>
 void LoopInfoBase<BlockT, LoopT>::
-Analyze(DominatorTreeBase<BlockT> &DomTree) {
+analyze(const DominatorTreeBase<BlockT> &DomTree) {
 
   // Postorder traversal of the dominator tree.
-  DomTreeNodeBase<BlockT>* DomRoot = DomTree.getRootNode();
+  const DomTreeNodeBase<BlockT> *DomRoot = DomTree.getRootNode();
   for (auto DomNode : post_order(DomRoot)) {
 
     BlockT *Header = DomNode->getBlock();
index 735dd069cf7f53d7c819233e168cbebddc7ca089..0ac8a5d0e2a4dafb24147a53a991c3528a6c9385 100644 (file)
@@ -263,6 +263,21 @@ template <> struct GraphTraits<MachineDomTreeNode *> {
   }
 };
 
+template <> struct GraphTraits<const MachineDomTreeNode *> {
+  typedef const MachineDomTreeNode NodeType;
+  typedef NodeType::const_iterator ChildIteratorType;
+
+  static NodeType *getEntryNode(NodeType *N) {
+    return N;
+  }
+  static inline ChildIteratorType child_begin(NodeType* N) {
+    return N->begin();
+  }
+  static inline ChildIteratorType child_end(NodeType* N) {
+    return N->end();
+  }
+};
+
 template <> struct GraphTraits<MachineDominatorTree*>
   : public GraphTraits<MachineDomTreeNode *> {
   static NodeType *getEntryNode(MachineDominatorTree *DT) {
index 27d989b0344c323ac8f744a694aeb5c522d69fe8..8080ae7c1224eb8e860083cc92c97ad169633304 100644 (file)
@@ -147,6 +147,31 @@ template <> struct GraphTraits<DomTreeNode*> {
   }
 };
 
+template <> struct GraphTraits<const DomTreeNode *> {
+  typedef const DomTreeNode NodeType;
+  typedef NodeType::const_iterator ChildIteratorType;
+
+  static NodeType *getEntryNode(NodeType *N) {
+    return N;
+  }
+  static inline ChildIteratorType child_begin(NodeType *N) {
+    return N->begin();
+  }
+  static inline ChildIteratorType child_end(NodeType *N) {
+    return N->end();
+  }
+
+  typedef df_iterator<const DomTreeNode *> nodes_iterator;
+
+  static nodes_iterator nodes_begin(const DomTreeNode *N) {
+    return df_begin(getEntryNode(N));
+  }
+
+  static nodes_iterator nodes_end(const DomTreeNode *N) {
+    return df_end(getEntryNode(N));
+  }
+};
+
 template <> struct GraphTraits<DominatorTree*>
   : public GraphTraits<DomTreeNode*> {
   static NodeType *getEntryNode(DominatorTree *DT) {
index 6b6faf8a66c3c6295b70b197b241da6bd77edbd1..7ca811067d41400ecc3051505feb09521403638b 100644 (file)
@@ -675,7 +675,7 @@ LoopInfo LoopAnalysis::run(Function &F, AnalysisManager<Function> *AM) {
   // objects. I don't want to add that kind of complexity until the scope of
   // the problem is better understood.
   LoopInfo LI;
-  LI.Analyze(AM->getResult<DominatorTreeAnalysis>(F));
+  LI.analyze(AM->getResult<DominatorTreeAnalysis>(F));
   return LI;
 }
 
@@ -698,7 +698,7 @@ INITIALIZE_PASS_END(LoopInfoWrapperPass, "loops", "Natural Loop Information",
 
 bool LoopInfoWrapperPass::runOnFunction(Function &) {
   releaseMemory();
-  LI.Analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
+  LI.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
   return false;
 }
 
index ce6abdd870b3e87a1d5e6491efc6edc492c1db19..e19e6e30a01c3828e1386bfb56ac9ebe98656a1f 100644 (file)
@@ -37,7 +37,7 @@ char &llvm::MachineLoopInfoID = MachineLoopInfo::ID;
 
 bool MachineLoopInfo::runOnMachineFunction(MachineFunction &) {
   releaseMemory();
-  LI.Analyze(getAnalysis<MachineDominatorTree>().getBase());
+  LI.analyze(getAnalysis<MachineDominatorTree>().getBase());
   return false;
 }