[llvm] r207177 - blockfreq: Use a std::list for Loops

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Apr 24 21:30:06 PDT 2014


Author: dexonsmith
Date: Thu Apr 24 23:30:06 2014
New Revision: 207177

URL: http://llvm.org/viewvc/llvm-project?rev=207177&view=rev
Log:
blockfreq: Use a std::list for Loops

As pointed out by David Blaikie in code review, a `std::list<T>` is
simpler than a `std::vector<std::unique_ptr<T>>`.  Another option is a
`std::deque<T>` (which allocates in chunks), but I'd like to leave open
the option of inserting in the middle of the sequence for handling
irreducible control flow on the fly.

<rdar://problem/14292693>

Modified:
    llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h
    llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp

Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h?rev=207177&r1=207176&r2=207177&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h (original)
+++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h Thu Apr 24 23:30:06 2014
@@ -23,6 +23,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include <string>
 #include <vector>
+#include <list>
 
 #define DEBUG_TYPE "block-freq"
 
@@ -1051,7 +1052,7 @@ public:
   std::vector<WorkingData> Working;
 
   /// \brief Indexed information about loops.
-  std::vector<std::unique_ptr<LoopData>> Loops;
+  std::list<LoopData> Loops;
 
   /// \brief Add all edges out of a packaged loop to the distribution.
   ///
@@ -1438,8 +1439,8 @@ template <class BT> void BlockFrequencyI
     BlockNode Header = getNode(Loop->getHeader());
     assert(Header.isValid());
 
-    Loops.emplace_back(new LoopData(Header));
-    Working[Header.Index].Loop = Loops.back().get();
+    Loops.emplace_back(Header);
+    Working[Header.Index].Loop = &Loops.back();
     DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n");
   }
 
@@ -1471,7 +1472,7 @@ template <class BT> void BlockFrequencyI
 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(Loops.rbegin(), Loops.rend()))
-    computeMassInLoop(L->Header);
+    computeMassInLoop(L.Header);
 }
 
 template <class BT>

Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp?rev=207177&r1=207176&r2=207177&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp Thu Apr 24 23:30:06 2014
@@ -602,7 +602,7 @@ void BlockFrequencyInfoImplBase::clear()
   // does not actually clear heap storage.
   std::vector<FrequencyData>().swap(Freqs);
   std::vector<WorkingData>().swap(Working);
-  std::vector<std::unique_ptr<LoopData>>().swap(Loops);
+  Loops.clear();
 }
 
 /// \brief Clear all memory not needed downstream.





More information about the llvm-commits mailing list