blockfreq: Encapsulate LoopData::Header

<rdar://problem/14292693>

llvm-svn: 207181
This commit is contained in:
Duncan P. N. Exon Smith 2014-04-25 04:38:06 +00:00
parent d60094b215
commit 2a2a2175c7
2 changed files with 21 additions and 23 deletions

View File

@ -956,6 +956,8 @@ public:
LoopData(LoopData *Parent, const BlockNode &Header)
: Parent(Parent), Header(Header), IsPackaged(false) {}
bool isHeader(const BlockNode &Node) const { return Node == Header; }
BlockNode getHeader() const { return Header; }
};
/// \brief Index of loop information.
@ -966,7 +968,7 @@ public:
WorkingData(const BlockNode &Node) : Node(Node), Loop(nullptr) {}
bool isLoopHeader() const { return Loop && Loop->Header == Node; }
bool isLoopHeader() const { return Loop && Loop->isHeader(Node); }
bool hasLoopHeader() const { return isLoopHeader() ? Loop->Parent : Loop; }
LoopData *getContainingLoop() const {
@ -975,7 +977,7 @@ public:
BlockNode getContainingHeader() const {
auto *ContainingLoop = getContainingLoop();
if (ContainingLoop)
return ContainingLoop->Header;
return ContainingLoop->getHeader();
return BlockNode();
}
@ -1491,11 +1493,11 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::computeMassInLoops() {
template <class BT>
void BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
// Compute mass in loop.
DEBUG(dbgs() << "compute-mass-in-loop: " << getBlockName(Loop.Header)
DEBUG(dbgs() << "compute-mass-in-loop: " << getBlockName(Loop.getHeader())
<< "\n");
Working[Loop.Header.Index].Mass = BlockMass::getFull();
propagateMassToSuccessors(&Loop, Loop.Header);
Working[Loop.getHeader().Index].Mass = BlockMass::getFull();
propagateMassToSuccessors(&Loop, Loop.getHeader());
for (const BlockNode &M : Loop.Members)
propagateMassToSuccessors(&Loop, M);
@ -1528,10 +1530,8 @@ BlockFrequencyInfoImpl<BT>::propagateMassToSuccessors(LoopData *OuterLoop,
DEBUG(dbgs() << " - node: " << getBlockName(Node) << "\n");
// Calculate probability for successors.
Distribution Dist;
BlockNode LoopHead;
if (OuterLoop)
LoopHead = OuterLoop->Header;
if (Node != LoopHead && Working[Node.Index].isLoopHeader())
if (Working[Node.Index].isLoopHeader() &&
Working[Node.Index].Loop != OuterLoop)
addLoopSuccessorsToDist(OuterLoop, *Working[Node.Index].Loop, Dist);
else {
const BlockT *BB = getBlock(Node);

View File

@ -660,15 +660,15 @@ void BlockFrequencyInfoImplBase::addToDist(Distribution &Dist,
if (!Weight)
Weight = 1;
BlockNode LoopHead;
if (OuterLoop)
LoopHead = OuterLoop->Header;
auto isLoopHeader = [&OuterLoop](const BlockNode &Node) {
return OuterLoop && OuterLoop->isHeader(Node);
};
#ifndef NDEBUG
auto debugSuccessor = [&](const char *Type, const BlockNode &Resolved) {
dbgs() << " =>"
<< " [" << Type << "] weight = " << Weight;
if (Succ != LoopHead)
if (!isLoopHeader(Succ))
dbgs() << ", succ = " << getBlockName(Succ);
if (Resolved != Succ)
dbgs() << ", resolved = " << getBlockName(Resolved);
@ -677,15 +677,15 @@ void BlockFrequencyInfoImplBase::addToDist(Distribution &Dist,
(void)debugSuccessor;
#endif
if (Succ == LoopHead) {
if (isLoopHeader(Succ)) {
DEBUG(debugSuccessor("backedge", Succ));
Dist.addBackedge(LoopHead, Weight);
Dist.addBackedge(OuterLoop->getHeader(), Weight);
return;
}
BlockNode Resolved = getPackagedNode(*this, Succ);
assert(Resolved != LoopHead);
assert(!isLoopHeader(Resolved));
if (Working[Resolved.Index].getContainingHeader() != LoopHead) {
if (Working[Resolved.Index].getContainingLoop() != OuterLoop) {
DEBUG(debugSuccessor(" exit ", Resolved));
Dist.addExit(Resolved, Weight);
return;
@ -705,7 +705,7 @@ void BlockFrequencyInfoImplBase::addLoopSuccessorsToDist(
const LoopData *OuterLoop, LoopData &Loop, Distribution &Dist) {
// Copy the exit map into Dist.
for (const auto &I : Loop.Exits)
addToDist(Dist, OuterLoop, Loop.Header, I.first, I.second.getMass());
addToDist(Dist, OuterLoop, Loop.getHeader(), I.first, I.second.getMass());
// We don't need this map any more. Clear it to prevent quadratic memory
// usage in deeply nested loops with irreducible control flow.
@ -721,7 +721,8 @@ static Float getMaxLoopScale() { return Float(1, 12); }
/// \brief Compute the loop scale for a loop.
void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) {
// Compute loop scale.
DEBUG(dbgs() << "compute-loop-scale: " << getBlockName(Loop.Header) << "\n");
DEBUG(dbgs() << "compute-loop-scale: " << getBlockName(Loop.getHeader())
<< "\n");
// LoopScale == 1 / ExitMass
// ExitMass == HeadMass - BackedgeMass
@ -742,7 +743,7 @@ void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) {
/// \brief Package up a loop.
void BlockFrequencyInfoImplBase::packageLoop(LoopData &Loop) {
DEBUG(dbgs() << "packaging-loop: " << getBlockName(Loop.Header) << "\n");
DEBUG(dbgs() << "packaging-loop: " << getBlockName(Loop.getHeader()) << "\n");
Loop.IsPackaged = true;
DEBUG(for (const BlockNode &M
: Loop.Members) {
@ -774,9 +775,6 @@ void BlockFrequencyInfoImplBase::distributeMass(const BlockNode &Source,
(void)debugAssign;
#endif
BlockNode LoopHead;
if (OuterLoop)
LoopHead = OuterLoop->Header;
for (const Weight &W : Dist.Weights) {
// Check for a local edge (forward and non-exit).
if (W.Type == Weight::Local) {