blockfreq: Stop using range-based for to traverse Loops
[oota-llvm.git] / include / llvm / Analysis / BlockFrequencyInfoImpl.h
index ca98a2e1d2214c1e9be99b0d66dd90adf8cb9cd2..78f7e8414254dcc39afaf0aed0dd3df9dc0c1f64 100644 (file)
@@ -23,6 +23,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include <string>
 #include <vector>
+#include <list>
 
 #define DEBUG_TYPE "block-freq"
 
@@ -958,16 +959,25 @@ public:
   /// \brief Index of loop information.
   struct WorkingData {
     LoopData *Loop;           ///< The loop this block is the header of.
-    BlockNode ContainingLoop; ///< The block whose loop this block is inside.
-    bool IsPackaged;          ///< Has ContainingLoop been packaged up?
+    LoopData *ContainingLoop; ///< The block whose loop this block is inside.
     BlockMass Mass;           ///< Mass distribution from the entry block.
 
-    WorkingData() : Loop(nullptr), IsPackaged(false) {}
+    WorkingData() : Loop(nullptr), ContainingLoop(nullptr) {}
 
-    bool hasLoopHeader() const { return ContainingLoop.isValid(); }
+    bool hasLoopHeader() const { return ContainingLoop; }
     bool isLoopHeader() const { return Loop; }
 
-    /// \brief Has this block's loop been packaged up?
+    BlockNode getContainingHeader() const {
+      if (ContainingLoop)
+        return ContainingLoop->Header;
+      return BlockNode();
+    }
+
+    /// \brief Has ContainingLoop been packaged up?
+    bool isPackaged() const {
+      return ContainingLoop && ContainingLoop->IsPackaged;
+    }
+    /// \brief Has Loop been packaged up?
     bool isAPackage() const { return Loop && Loop->IsPackaged; }
   };
 
@@ -1041,8 +1051,8 @@ public:
   /// \brief Loop data: see initializeLoops().
   std::vector<WorkingData> Working;
 
-  /// \brief Indexed information about packaged loops.
-  std::vector<std::unique_ptr<LoopData>> PackagedLoops;
+  /// \brief Indexed information about loops.
+  std::list<LoopData> Loops;
 
   /// \brief Add all edges out of a packaged loop to the distribution.
   ///
@@ -1070,7 +1080,7 @@ public:
   /// \brief Distribute mass according to a distribution.
   ///
   /// Distributes the mass in Source according to Dist.  If LoopHead.isValid(),
-  /// backedges and exits are stored in its entry in PackagedLoops.
+  /// backedges and exits are stored in its entry in Loops.
   ///
   /// Mass is distributed in parallel from two copies of the source mass.
   ///
@@ -1429,8 +1439,8 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
     BlockNode Header = getNode(Loop->getHeader());
     assert(Header.isValid());
 
-    PackagedLoops.emplace_back(new LoopData(Header));
-    Working[Header.Index].Loop = PackagedLoops.back().get();
+    Loops.emplace_back(Header);
+    Working[Header.Index].Loop = &Loops.back();
     DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n");
   }
 
@@ -1452,7 +1462,7 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
     const auto &HeaderData = Working[Header.Index];
     assert(HeaderData.isLoopHeader());
 
-    Working[Index].ContainingLoop = Header;
+    Working[Index].ContainingLoop = HeaderData.Loop;
     HeaderData.Loop->Members.push_back(Index);
     DEBUG(dbgs() << " - loop = " << getBlockName(Header)
                  << ": member = " << getBlockName(Index) << "\n");
@@ -1461,7 +1471,7 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
 
 template <class BT> void BlockFrequencyInfoImpl<BT>::computeMassInLoops() {
   // Visit loops with the deepest first, and the top-level loops last.
-  for (const auto &L : make_range(PackagedLoops.rbegin(), PackagedLoops.rend()))
+  for (auto L = Loops.rbegin(), E = Loops.rend(); L != E; ++L)
     computeMassInLoop(L->Header);
 }