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>

llvm-svn: 207177
This commit is contained in:
Duncan P. N. Exon Smith 2014-04-25 04:30:06 +00:00
parent e6cb63e471
commit fc7dc93031
2 changed files with 6 additions and 5 deletions

View File

@ -23,6 +23,7 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include <list>
#define DEBUG_TYPE "block-freq" #define DEBUG_TYPE "block-freq"
@ -1051,7 +1052,7 @@ public:
std::vector<WorkingData> Working; std::vector<WorkingData> Working;
/// \brief Indexed information about loops. /// \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. /// \brief Add all edges out of a packaged loop to the distribution.
/// ///
@ -1438,8 +1439,8 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
BlockNode Header = getNode(Loop->getHeader()); BlockNode Header = getNode(Loop->getHeader());
assert(Header.isValid()); assert(Header.isValid());
Loops.emplace_back(new LoopData(Header)); Loops.emplace_back(Header);
Working[Header.Index].Loop = Loops.back().get(); Working[Header.Index].Loop = &Loops.back();
DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n"); DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n");
} }
@ -1471,7 +1472,7 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
template <class BT> void BlockFrequencyInfoImpl<BT>::computeMassInLoops() { template <class BT> void BlockFrequencyInfoImpl<BT>::computeMassInLoops() {
// Visit loops with the deepest first, and the top-level loops last. // Visit loops with the deepest first, and the top-level loops last.
for (const auto &L : make_range(Loops.rbegin(), Loops.rend())) for (const auto &L : make_range(Loops.rbegin(), Loops.rend()))
computeMassInLoop(L->Header); computeMassInLoop(L.Header);
} }
template <class BT> template <class BT>

View File

@ -602,7 +602,7 @@ void BlockFrequencyInfoImplBase::clear() {
// does not actually clear heap storage. // does not actually clear heap storage.
std::vector<FrequencyData>().swap(Freqs); std::vector<FrequencyData>().swap(Freqs);
std::vector<WorkingData>().swap(Working); std::vector<WorkingData>().swap(Working);
std::vector<std::unique_ptr<LoopData>>().swap(Loops); Loops.clear();
} }
/// \brief Clear all memory not needed downstream. /// \brief Clear all memory not needed downstream.