[llvm] r207181 - blockfreq: Encapsulate LoopData::Header
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Apr 24 21:38:07 PDT 2014
Author: dexonsmith
Date: Thu Apr 24 23:38:06 2014
New Revision: 207181
URL: http://llvm.org/viewvc/llvm-project?rev=207181&view=rev
Log:
blockfreq: Encapsulate LoopData::Header
<rdar://problem/14292693>
Modified:
llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h
llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp
Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h?rev=207181&r1=207180&r2=207181&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h (original)
+++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h Thu Apr 24 23:38:06 2014
@@ -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 BlockFrequencyI
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>::propagateMas
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);
Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp?rev=207181&r1=207180&r2=207181&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp Thu Apr 24 23:38:06 2014
@@ -660,15 +660,15 @@ void BlockFrequencyInfoImplBase::addToDi
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::addToDi
(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::addLoop
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
/// \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::compute
/// \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::distrib
(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) {
More information about the llvm-commits
mailing list