mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 16:17:17 +00:00
blockfreq: Encapsulate LoopData::Header
<rdar://problem/14292693> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207181 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -956,6 +956,8 @@ public:
|
|||||||
|
|
||||||
LoopData(LoopData *Parent, const BlockNode &Header)
|
LoopData(LoopData *Parent, const BlockNode &Header)
|
||||||
: Parent(Parent), Header(Header), IsPackaged(false) {}
|
: 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.
|
/// \brief Index of loop information.
|
||||||
@@ -966,7 +968,7 @@ public:
|
|||||||
|
|
||||||
WorkingData(const BlockNode &Node) : Node(Node), Loop(nullptr) {}
|
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; }
|
bool hasLoopHeader() const { return isLoopHeader() ? Loop->Parent : Loop; }
|
||||||
|
|
||||||
LoopData *getContainingLoop() const {
|
LoopData *getContainingLoop() const {
|
||||||
@@ -975,7 +977,7 @@ public:
|
|||||||
BlockNode getContainingHeader() const {
|
BlockNode getContainingHeader() const {
|
||||||
auto *ContainingLoop = getContainingLoop();
|
auto *ContainingLoop = getContainingLoop();
|
||||||
if (ContainingLoop)
|
if (ContainingLoop)
|
||||||
return ContainingLoop->Header;
|
return ContainingLoop->getHeader();
|
||||||
return BlockNode();
|
return BlockNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1491,11 +1493,11 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::computeMassInLoops() {
|
|||||||
template <class BT>
|
template <class BT>
|
||||||
void BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
|
void BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
|
||||||
// Compute mass in loop.
|
// Compute mass in loop.
|
||||||
DEBUG(dbgs() << "compute-mass-in-loop: " << getBlockName(Loop.Header)
|
DEBUG(dbgs() << "compute-mass-in-loop: " << getBlockName(Loop.getHeader())
|
||||||
<< "\n");
|
<< "\n");
|
||||||
|
|
||||||
Working[Loop.Header.Index].Mass = BlockMass::getFull();
|
Working[Loop.getHeader().Index].Mass = BlockMass::getFull();
|
||||||
propagateMassToSuccessors(&Loop, Loop.Header);
|
propagateMassToSuccessors(&Loop, Loop.getHeader());
|
||||||
|
|
||||||
for (const BlockNode &M : Loop.Members)
|
for (const BlockNode &M : Loop.Members)
|
||||||
propagateMassToSuccessors(&Loop, M);
|
propagateMassToSuccessors(&Loop, M);
|
||||||
@@ -1528,10 +1530,8 @@ BlockFrequencyInfoImpl<BT>::propagateMassToSuccessors(LoopData *OuterLoop,
|
|||||||
DEBUG(dbgs() << " - node: " << getBlockName(Node) << "\n");
|
DEBUG(dbgs() << " - node: " << getBlockName(Node) << "\n");
|
||||||
// Calculate probability for successors.
|
// Calculate probability for successors.
|
||||||
Distribution Dist;
|
Distribution Dist;
|
||||||
BlockNode LoopHead;
|
if (Working[Node.Index].isLoopHeader() &&
|
||||||
if (OuterLoop)
|
Working[Node.Index].Loop != OuterLoop)
|
||||||
LoopHead = OuterLoop->Header;
|
|
||||||
if (Node != LoopHead && Working[Node.Index].isLoopHeader())
|
|
||||||
addLoopSuccessorsToDist(OuterLoop, *Working[Node.Index].Loop, Dist);
|
addLoopSuccessorsToDist(OuterLoop, *Working[Node.Index].Loop, Dist);
|
||||||
else {
|
else {
|
||||||
const BlockT *BB = getBlock(Node);
|
const BlockT *BB = getBlock(Node);
|
||||||
|
@@ -660,15 +660,15 @@ void BlockFrequencyInfoImplBase::addToDist(Distribution &Dist,
|
|||||||
if (!Weight)
|
if (!Weight)
|
||||||
Weight = 1;
|
Weight = 1;
|
||||||
|
|
||||||
BlockNode LoopHead;
|
auto isLoopHeader = [&OuterLoop](const BlockNode &Node) {
|
||||||
if (OuterLoop)
|
return OuterLoop && OuterLoop->isHeader(Node);
|
||||||
LoopHead = OuterLoop->Header;
|
};
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto debugSuccessor = [&](const char *Type, const BlockNode &Resolved) {
|
auto debugSuccessor = [&](const char *Type, const BlockNode &Resolved) {
|
||||||
dbgs() << " =>"
|
dbgs() << " =>"
|
||||||
<< " [" << Type << "] weight = " << Weight;
|
<< " [" << Type << "] weight = " << Weight;
|
||||||
if (Succ != LoopHead)
|
if (!isLoopHeader(Succ))
|
||||||
dbgs() << ", succ = " << getBlockName(Succ);
|
dbgs() << ", succ = " << getBlockName(Succ);
|
||||||
if (Resolved != Succ)
|
if (Resolved != Succ)
|
||||||
dbgs() << ", resolved = " << getBlockName(Resolved);
|
dbgs() << ", resolved = " << getBlockName(Resolved);
|
||||||
@@ -677,15 +677,15 @@ void BlockFrequencyInfoImplBase::addToDist(Distribution &Dist,
|
|||||||
(void)debugSuccessor;
|
(void)debugSuccessor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Succ == LoopHead) {
|
if (isLoopHeader(Succ)) {
|
||||||
DEBUG(debugSuccessor("backedge", Succ));
|
DEBUG(debugSuccessor("backedge", Succ));
|
||||||
Dist.addBackedge(LoopHead, Weight);
|
Dist.addBackedge(OuterLoop->getHeader(), Weight);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BlockNode Resolved = getPackagedNode(*this, Succ);
|
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));
|
DEBUG(debugSuccessor(" exit ", Resolved));
|
||||||
Dist.addExit(Resolved, Weight);
|
Dist.addExit(Resolved, Weight);
|
||||||
return;
|
return;
|
||||||
@@ -705,7 +705,7 @@ void BlockFrequencyInfoImplBase::addLoopSuccessorsToDist(
|
|||||||
const LoopData *OuterLoop, LoopData &Loop, Distribution &Dist) {
|
const LoopData *OuterLoop, LoopData &Loop, Distribution &Dist) {
|
||||||
// Copy the exit map into Dist.
|
// Copy the exit map into Dist.
|
||||||
for (const auto &I : Loop.Exits)
|
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
|
// We don't need this map any more. Clear it to prevent quadratic memory
|
||||||
// usage in deeply nested loops with irreducible control flow.
|
// 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.
|
/// \brief Compute the loop scale for a loop.
|
||||||
void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) {
|
void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) {
|
||||||
// Compute loop scale.
|
// Compute loop scale.
|
||||||
DEBUG(dbgs() << "compute-loop-scale: " << getBlockName(Loop.Header) << "\n");
|
DEBUG(dbgs() << "compute-loop-scale: " << getBlockName(Loop.getHeader())
|
||||||
|
<< "\n");
|
||||||
|
|
||||||
// LoopScale == 1 / ExitMass
|
// LoopScale == 1 / ExitMass
|
||||||
// ExitMass == HeadMass - BackedgeMass
|
// ExitMass == HeadMass - BackedgeMass
|
||||||
@@ -742,7 +743,7 @@ void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) {
|
|||||||
|
|
||||||
/// \brief Package up a loop.
|
/// \brief Package up a loop.
|
||||||
void BlockFrequencyInfoImplBase::packageLoop(LoopData &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;
|
Loop.IsPackaged = true;
|
||||||
DEBUG(for (const BlockNode &M
|
DEBUG(for (const BlockNode &M
|
||||||
: Loop.Members) {
|
: Loop.Members) {
|
||||||
@@ -774,9 +775,6 @@ void BlockFrequencyInfoImplBase::distributeMass(const BlockNode &Source,
|
|||||||
(void)debugAssign;
|
(void)debugAssign;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BlockNode LoopHead;
|
|
||||||
if (OuterLoop)
|
|
||||||
LoopHead = OuterLoop->Header;
|
|
||||||
for (const Weight &W : Dist.Weights) {
|
for (const Weight &W : Dist.Weights) {
|
||||||
// Check for a local edge (forward and non-exit).
|
// Check for a local edge (forward and non-exit).
|
||||||
if (W.Type == Weight::Local) {
|
if (W.Type == Weight::Local) {
|
||||||
|
Reference in New Issue
Block a user