blockfreq: Use pointers to loops instead of an index

Store pointers directly to loops inside the nodes.  This could have been
done without changing the type stored in `std::vector<>`.  However,
rather than computing the number of loops before constructing them
(which `LoopInfo` doesn't provide directly), I've switched to a
`vector<unique_ptr<LoopData>>`.

This adds some heap overhead, but the number of loops is typically
small.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206857 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2014-04-22 03:31:37 +00:00
parent 153a265d01
commit 92897fda32
2 changed files with 20 additions and 18 deletions

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<LoopData>().swap(PackagedLoops);
std::vector<std::unique_ptr<LoopData>>().swap(PackagedLoops);
}
/// \brief Clear all memory not needed downstream.
@ -646,7 +646,7 @@ static BlockMass &getPackageMass(BlockFrequencyInfoImplBase &BFI,
const BlockNode &Node) {
assert(Node.isValid());
assert(!BFI.Working[Node.Index].IsPackaged);
if (!BFI.Working[Node.Index].IsAPackage)
if (!BFI.Working[Node.Index].isAPackage())
return BFI.Working[Node.Index].Mass;
return BFI.getLoopPackage(Node).Mass;
@ -744,8 +744,9 @@ void BlockFrequencyInfoImplBase::computeLoopScale(const BlockNode &LoopHead) {
/// \brief Package up a loop.
void BlockFrequencyInfoImplBase::packageLoop(const BlockNode &LoopHead) {
DEBUG(dbgs() << "packaging-loop: " << getBlockName(LoopHead) << "\n");
Working[LoopHead.Index].IsAPackage = true;
for (const BlockNode &M : getLoopPackage(LoopHead).Members) {
auto &PackagedLoop = getLoopPackage(LoopHead);
PackagedLoop.IsPackaged = true;
for (const BlockNode &M : PackagedLoop.Members) {
DEBUG(dbgs() << " - node: " << getBlockName(M.Index) << "\n");
Working[M.Index].IsPackaged = true;
}