Skip to content

Commit

Permalink
Add documentation for new backedge mass propagation in irregular loops.
Browse files Browse the repository at this point in the history
Tweak test cases and rename headerIndexFor -> getHeaderIndex.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239915 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dnovillo committed Jun 17, 2015
1 parent b306ae3 commit 5057ee8
Showing 4 changed files with 17 additions and 87 deletions.
13 changes: 12 additions & 1 deletion include/llvm/Analysis/BlockFrequencyInfoImpl.h
Original file line number Diff line number Diff line change
@@ -226,7 +226,7 @@ class BlockFrequencyInfoImplBase {
BlockNode getHeader() const { return Nodes[0]; }
bool isIrreducible() const { return NumHeaders > 1; }

HeaderMassList::difference_type headerIndexFor(const BlockNode &B) {
HeaderMassList::difference_type getHeaderIndex(const BlockNode &B) {
assert(isHeader(B) && "this is only valid on loop header blocks");
if (isIrreducible())
return std::lower_bound(Nodes.begin(), Nodes.begin() + NumHeaders, B) -
@@ -716,6 +716,17 @@ void IrreducibleGraph::addEdges(const BlockNode &Node,
/// - Distribute the mass accordingly, dithering to minimize mass loss,
/// as described in \a distributeMass().
///
/// In the case of irreducible loops, instead of a single loop header,
/// there will be several. The computation of backedge masses is similar
/// but instead of having a single backedge mass, there will be one
/// backedge per loop header. In these cases, each backedge will carry
/// a mass proportional to the edge weights along the corresponding
/// path.
///
/// At the end of propagation, the full mass assigned to the loop will be
/// distributed among the loop headers proportionally according to the
/// mass flowing through their backedges.
///
/// Finally, calculate the loop scale from the accumulated backedge mass.
///
/// 3. Distribute mass in the function (\a computeMassInFunction()).
5 changes: 2 additions & 3 deletions lib/Analysis/BlockFrequencyInfoImpl.cpp
Original file line number Diff line number Diff line change
@@ -414,8 +414,7 @@ void BlockFrequencyInfoImplBase::distributeMass(const BlockNode &Source,

// Check for a backedge.
if (W.Type == Weight::Backedge) {
auto ix = OuterLoop->headerIndexFor(W.TargetNode);
OuterLoop->BackedgeMass[ix] += Taken;
OuterLoop->BackedgeMass[OuterLoop->getHeaderIndex(W.TargetNode)] += Taken;
DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "back"));
continue;
}
@@ -741,7 +740,7 @@ void BlockFrequencyInfoImplBase::adjustLoopHeaderMass(LoopData &Loop) {
DEBUG(dbgs() << "adjust-loop-header-mass:\n");
for (uint32_t H = 0; H < Loop.NumHeaders; ++H) {
auto &HeaderNode = Loop.Nodes[H];
auto &BackedgeMass = Loop.BackedgeMass[Loop.headerIndexFor(HeaderNode)];
auto &BackedgeMass = Loop.BackedgeMass[Loop.getHeaderIndex(HeaderNode)];
DEBUG(dbgs() << " - Add back edge mass for node "
<< getBlockName(HeaderNode) << ": " << BackedgeMass << "\n");
Dist.addLocal(HeaderNode, BackedgeMass.getMass());
80 changes: 0 additions & 80 deletions test/Analysis/BlockFrequencyInfo/PR23525.ll

This file was deleted.

6 changes: 3 additions & 3 deletions test/Analysis/BlockFrequencyInfo/irreducible.ll
Original file line number Diff line number Diff line change
@@ -392,15 +392,15 @@ entry:
br i1 %x, label %left, label %right, !prof !21

left:
; CHECK-NEXT: left: float = 0.14{{[0-9]*}},
; CHECK-NEXT: left: float = 0.14
br i1 %x, label %top, label %bottom, !prof !22

right:
; CHECK-NEXT: right: float = 0.42{{[0-9]*}},
; CHECK-NEXT: right: float = 0.42
br i1 %x, label %top, label %bottom, !prof !22

top:
; CHECK-NEXT: top: float = 8.43{{[0-9]*}},
; CHECK-NEXT: top: float = 8.43
switch i2 %y, label %exit [ i2 0, label %left
i2 1, label %right
i2 2, label %bottom ], !prof !23

0 comments on commit 5057ee8

Please sign in to comment.