blockfreq: Store the header with the members

<rdar://problem/14292693>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207182 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2014-04-25 04:38:09 +00:00
parent 7e26181f6b
commit 3df8534be1
2 changed files with 18 additions and 10 deletions

View File

@ -16,6 +16,7 @@
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/BasicBlock.h" #include "llvm/IR/BasicBlock.h"
#include "llvm/Support/BlockFrequency.h" #include "llvm/Support/BlockFrequency.h"
#include "llvm/Support/BranchProbability.h" #include "llvm/Support/BranchProbability.h"
@ -946,18 +947,25 @@ public:
typedef SmallVector<std::pair<BlockNode, BlockMass>, 4> ExitMap; typedef SmallVector<std::pair<BlockNode, BlockMass>, 4> ExitMap;
typedef SmallVector<BlockNode, 4> MemberList; typedef SmallVector<BlockNode, 4> MemberList;
LoopData *Parent; ///< The parent loop. LoopData *Parent; ///< The parent loop.
BlockNode Header; ///< Header.
bool IsPackaged; ///< Whether this has been packaged. bool IsPackaged; ///< Whether this has been packaged.
ExitMap Exits; ///< Successor edges (and weights). ExitMap Exits; ///< Successor edges (and weights).
MemberList Members; ///< Members of the loop. MemberList Nodes; ///< Header and the members of the loop.
BlockMass BackedgeMass; ///< Mass returned to loop header. BlockMass BackedgeMass; ///< Mass returned to loop header.
BlockMass Mass; BlockMass Mass;
Float Scale; Float Scale;
LoopData(LoopData *Parent, const BlockNode &Header) LoopData(LoopData *Parent, const BlockNode &Header)
: Parent(Parent), Header(Header), IsPackaged(false) {} : Parent(Parent), IsPackaged(false), Nodes(1, Header) {}
bool isHeader(const BlockNode &Node) const { return Node == Header; } bool isHeader(const BlockNode &Node) const { return Node == Nodes[0]; }
BlockNode getHeader() const { return Header; } BlockNode getHeader() const { return Nodes[0]; }
MemberList::const_iterator members_begin() const {
return Nodes.begin() + 1;
}
MemberList::const_iterator members_end() const { return Nodes.end(); }
iterator_range<MemberList::const_iterator> members() const {
return make_range(members_begin(), members_end());
}
}; };
/// \brief Index of loop information. /// \brief Index of loop information.
@ -1463,7 +1471,7 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
if (Working[Index].isLoopHeader()) { if (Working[Index].isLoopHeader()) {
LoopData *ContainingLoop = Working[Index].getContainingLoop(); LoopData *ContainingLoop = Working[Index].getContainingLoop();
if (ContainingLoop) if (ContainingLoop)
ContainingLoop->Members.push_back(Index); ContainingLoop->Nodes.push_back(Index);
continue; continue;
} }
@ -1478,7 +1486,7 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
assert(HeaderData.isLoopHeader()); assert(HeaderData.isLoopHeader());
Working[Index].Loop = HeaderData.Loop; Working[Index].Loop = HeaderData.Loop;
HeaderData.Loop->Members.push_back(Index); HeaderData.Loop->Nodes.push_back(Index);
DEBUG(dbgs() << " - loop = " << getBlockName(Header) DEBUG(dbgs() << " - loop = " << getBlockName(Header)
<< ": member = " << getBlockName(Index) << "\n"); << ": member = " << getBlockName(Index) << "\n");
} }
@ -1499,7 +1507,7 @@ void BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
Working[Loop.getHeader().Index].Mass = BlockMass::getFull(); Working[Loop.getHeader().Index].Mass = BlockMass::getFull();
propagateMassToSuccessors(&Loop, Loop.getHeader()); propagateMassToSuccessors(&Loop, Loop.getHeader());
for (const BlockNode &M : Loop.Members) for (const BlockNode &M : Loop.members())
propagateMassToSuccessors(&Loop, M); propagateMassToSuccessors(&Loop, M);
computeLoopScale(Loop); computeLoopScale(Loop);

View File

@ -746,7 +746,7 @@ void BlockFrequencyInfoImplBase::packageLoop(LoopData &Loop) {
DEBUG(dbgs() << "packaging-loop: " << getBlockName(Loop.getHeader()) << "\n"); DEBUG(dbgs() << "packaging-loop: " << getBlockName(Loop.getHeader()) << "\n");
Loop.IsPackaged = true; Loop.IsPackaged = true;
DEBUG(for (const BlockNode &M DEBUG(for (const BlockNode &M
: Loop.Members) { : Loop.members()) {
dbgs() << " - node: " << getBlockName(M.Index) << "\n"; dbgs() << " - node: " << getBlockName(M.Index) << "\n";
}); });
} }
@ -859,7 +859,7 @@ static void unwrapLoopPackage(BlockFrequencyInfoImplBase &BFI,
// Propagate the head scale through the loop. Since members are visited in // Propagate the head scale through the loop. Since members are visited in
// RPO, the head scale will be updated by the loop scale first, and then the // RPO, the head scale will be updated by the loop scale first, and then the
// final head scale will be used for updated the rest of the members. // final head scale will be used for updated the rest of the members.
for (const BlockNode &M : LoopPackage.Members) { for (const BlockNode &M : LoopPackage.members()) {
const FrequencyData &HeadData = BFI.Freqs[Head.Index]; const FrequencyData &HeadData = BFI.Freqs[Head.Index];
FrequencyData &Freqs = BFI.Freqs[M.Index]; FrequencyData &Freqs = BFI.Freqs[M.Index];
Float NewFreq = Freqs.Floating * HeadData.Floating; Float NewFreq = Freqs.Floating * HeadData.Floating;