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>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207177 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2014-04-25 04:30:06 +00:00
parent 573faecacf
commit 6f1f9f4c7f
2 changed files with 6 additions and 5 deletions

View File

@ -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 BlockFrequencyInfoImpl<BT>::initializeLoops() {
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 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(Loops.rbegin(), Loops.rend()))
computeMassInLoop(L->Header);
computeMassInLoop(L.Header);
}
template <class BT>

View File

@ -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.