Skip to content

Commit d06d43a

Browse files
committed
[VPlan] Add printPhiOperands to VPPhiAccessors, use for wide phis.
(NFC modulo debug output changes) Add generic helper to print phi operands (incoming values) together with their incoming blocks. As more and more transforms are added, keeping the incoming blocks of phis becomes more important. Print incoming blocks via VPPhiAcessors, to make debugging easier.
1 parent a861f50 commit d06d43a

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,11 @@ class VPPhiAccessors {
12011201

12021202
/// Returns the number of incoming values, also number of incoming blocks.
12031203
unsigned getNumIncoming() const { return getAsRecipe()->getNumOperands(); }
1204+
1205+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1206+
/// Print the recipe.
1207+
void printPhiOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const;
1208+
#endif
12041209
};
12051210

12061211
/// An overlay for VPIRInstructions wrapping PHI nodes enabling convenient use

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,20 @@ void VPIRPhi::execute(VPTransformState &State) {
11971197
State.Builder.SetInsertPoint(Phi->getParent(), std::next(Phi->getIterator()));
11981198
}
11991199

1200+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1201+
void VPPhiAccessors::printPhiOperands(raw_ostream &O,
1202+
VPSlotTracker &SlotTracker) const {
1203+
interleaveComma(enumerate(getAsRecipe()->operands()), O,
1204+
[this, &O, &SlotTracker](auto Op) {
1205+
O << "[ ";
1206+
Op.value()->printAsOperand(O, SlotTracker);
1207+
O << ", ";
1208+
getIncomingBlock(Op.index())->printAsOperand(O);
1209+
O << " ]";
1210+
});
1211+
}
1212+
#endif
1213+
12001214
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
12011215
void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
12021216
VPSlotTracker &SlotTracker) const {
@@ -3809,7 +3823,7 @@ void VPWidenPHIRecipe::print(raw_ostream &O, const Twine &Indent,
38093823

38103824
printAsOperand(O, SlotTracker);
38113825
O << " = phi ";
3812-
printOperands(O, SlotTracker);
3826+
printPhiOperands(O, SlotTracker);
38133827
}
38143828
#endif
38153829

llvm/test/Transforms/LoopVectorize/vplan-printing-outer-loop.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ define void @foo(i64 %n) {
1313
; CHECK-NEXT: Successor(s): outer.header
1414
; CHECK-EMPTY:
1515
; CHECK-NEXT: outer.header:
16-
; CHECK-NEXT: WIDEN-PHI ir<%outer.iv> = phi ir<%outer.iv.next>, ir<0>
16+
; CHECK-NEXT: WIDEN-PHI ir<%outer.iv> = phi [ ir<%outer.iv.next>, outer.latch ], [ ir<0>, ir-bb<entry> ]
1717
; CHECK-NEXT: EMIT ir<%gep.1> = getelementptr ir<@arr2>, ir<0>, ir<%outer.iv>
1818
; CHECK-NEXT: EMIT store ir<%outer.iv>, ir<%gep.1>
1919
; CHECK-NEXT: EMIT ir<%add> = add ir<%outer.iv>, ir<%n>
2020
; CHECK-NEXT: Successor(s): inner
2121
; CHECK-EMPTY:
2222
; CHECK-NEXT: inner:
23-
; CHECK-NEXT: WIDEN-PHI ir<%inner.iv> = phi ir<%inner.iv.next>, ir<0>
23+
; CHECK-NEXT: WIDEN-PHI ir<%inner.iv> = phi [ ir<%inner.iv.next>, inner ], [ ir<0>, outer.header ]
2424
; CHECK-NEXT: EMIT ir<%gep.2> = getelementptr ir<@arr>, ir<0>, ir<%inner.iv>, ir<%outer.iv>
2525
; CHECK-NEXT: EMIT store ir<%add>, ir<%gep.2>
2626
; CHECK-NEXT: EMIT ir<%inner.iv.next> = add ir<%inner.iv>, ir<1>

llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ compound=true
122122
N2 [label =
123123
"vector.body:\l" +
124124
" EMIT vp\<%2\> = CANONICAL-INDUCTION ir\<0\>, vp\<%index.next\>\l" +
125-
" WIDEN-PHI ir\<%indvars.iv\> = phi ir\<0\>, ir\<%indvars.iv.next\>\l" +
125+
" WIDEN-PHI ir\<%indvars.iv\> = phi [ ir\<0\>, vector.ph ], [ ir\<%indvars.iv.next\>, vector.body ]\l" +
126126
" EMIT ir\<%arr.idx\> = getelementptr ir\<%A\>, ir\<%indvars.iv\>\l" +
127127
" EMIT ir\<%l1\> = load ir\<%arr.idx\>\l" +
128128
" EMIT ir\<%res\> = add ir\<%l1\>, ir\<10\>\l" +
@@ -291,7 +291,7 @@ compound=true
291291
N2 [label =
292292
"vector.body:\l" +
293293
" EMIT vp\<%2\> = CANONICAL-INDUCTION ir\<0\>, vp\<%index.next\>\l" +
294-
" WIDEN-PHI ir\<%iv\> = phi ir\<0\>, ir\<%iv.next\>\l" +
294+
" WIDEN-PHI ir\<%iv\> = phi [ ir\<0\>, vector.ph ], [ ir\<%iv.next\>, loop.latch ]\l" +
295295
" EMIT ir\<%arr.idx\> = getelementptr ir\<%A\>, ir\<%iv\>\l" +
296296
" EMIT ir\<%l1\> = load ir\<%arr.idx\>\l" +
297297
" EMIT ir\<%c\> = icmp ir\<%l1\>, ir\<0\>\l" +

0 commit comments

Comments
 (0)