Skip to content

Commit 368bacd

Browse files
committed
[VPlan] Implement printing VPIRMetadata.
Implement and use debug printing for VPIRMetadata.
1 parent 90bbffe commit 368bacd

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,9 @@ class VPIRMetadata {
968968
/// Intersect this VPIRMetada object with \p MD, keeping only metadata
969969
/// nodes that are common to both.
970970
void intersect(const VPIRMetadata &MD);
971+
972+
/// Print metadata with node IDs.
973+
void print(raw_ostream &O, const Module &M) const;
971974
};
972975

973976
/// This is a concrete Recipe that models a single VPlan-level instruction.
@@ -4282,6 +4285,11 @@ class VPlan {
42824285
/// Return the VPIRBasicBlock wrapping the header of the scalar loop.
42834286
VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
42844287

4288+
/// Return the Module from the scalar header.
4289+
const Module &getModule() const {
4290+
return *ScalarHeader->getIRBasicBlock()->getModule();
4291+
}
4292+
42854293
/// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
42864294
/// the original scalar loop.
42874295
ArrayRef<VPIRBasicBlock *> getExitBlocks() const { return ExitBlocks; }

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
14431443

14441444
printFlags(O);
14451445
printOperands(O, SlotTracker);
1446+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
14461447

14471448
if (auto DL = getDebugLoc()) {
14481449
O << ", !dbg ";
@@ -1669,6 +1670,25 @@ void VPIRMetadata::intersect(const VPIRMetadata &Other) {
16691670
Metadata = std::move(MetadataIntersection);
16701671
}
16711672

1673+
void VPIRMetadata::print(raw_ostream &O, const Module &M) const {
1674+
if (Metadata.empty())
1675+
return;
1676+
1677+
SmallVector<StringRef, 8> MDNames;
1678+
M.getContext().getMDKindNames(MDNames);
1679+
1680+
O << " (";
1681+
interleaveComma(Metadata, O, [&](const auto &KindNodePair) {
1682+
auto [Kind, Node] = KindNodePair;
1683+
assert(Kind != 0 && "Debug metadata should not be managed by VPIRMetadata");
1684+
assert(Kind < MDNames.size() && !MDNames[Kind].empty() &&
1685+
"Unexpected unnamed metadata kind");
1686+
O << "!" << MDNames[Kind] << " ";
1687+
Node->printAsOperand(O, &M);
1688+
});
1689+
O << ")";
1690+
}
1691+
16721692
void VPWidenCallRecipe::execute(VPTransformState &State) {
16731693
assert(State.VF.isVector() && "not widening");
16741694
assert(Variant != nullptr && "Can't create vector function.");
@@ -1729,6 +1749,7 @@ void VPWidenCallRecipe::print(raw_ostream &O, const Twine &Indent,
17291749
Op->printAsOperand(O, SlotTracker);
17301750
});
17311751
O << ")";
1752+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
17321753

17331754
O << " (using library function";
17341755
if (Variant->hasName())
@@ -1863,6 +1884,7 @@ void VPWidenIntrinsicRecipe::print(raw_ostream &O, const Twine &Indent,
18631884
Op->printAsOperand(O, SlotTracker);
18641885
});
18651886
O << ")";
1887+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
18661888
}
18671889
#endif
18681890

@@ -2255,6 +2277,7 @@ void VPWidenRecipe::print(raw_ostream &O, const Twine &Indent,
22552277
O << " = " << Instruction::getOpcodeName(Opcode);
22562278
printFlags(O);
22572279
printOperands(O, SlotTracker);
2280+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
22582281
}
22592282
#endif
22602283

@@ -2336,6 +2359,7 @@ void VPWidenCastRecipe::print(raw_ostream &O, const Twine &Indent,
23362359
printFlags(O);
23372360
printOperands(O, SlotTracker);
23382361
O << " to " << *getResultType();
2362+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
23392363
}
23402364
#endif
23412365

@@ -3617,6 +3641,7 @@ void VPWidenLoadRecipe::print(raw_ostream &O, const Twine &Indent,
36173641
printAsOperand(O, SlotTracker);
36183642
O << " = load ";
36193643
printOperands(O, SlotTracker);
3644+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
36203645
}
36213646
#endif
36223647

@@ -3738,6 +3763,7 @@ void VPWidenStoreRecipe::print(raw_ostream &O, const Twine &Indent,
37383763
VPSlotTracker &SlotTracker) const {
37393764
O << Indent << "WIDEN store ";
37403765
printOperands(O, SlotTracker);
3766+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
37413767
}
37423768
#endif
37433769

llvm/test/Transforms/LoopVectorize/vplan-printing-metadata.ll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ define void @test_widen_metadata(ptr noalias %A, ptr noalias %B, i32 %n) {
77
; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
88
; CHECK: <x1> vector loop: {
99
; CHECK: vector.body:
10-
; CHECK: WIDEN ir<%lv> = load vp<{{.*}}>
11-
; CHECK: WIDEN-CAST ir<%conv> = sitofp ir<%lv> to float
12-
; CHECK: WIDEN ir<%mul> = fmul ir<%conv>, ir<2.000000e+00>
10+
; CHECK: WIDEN ir<%lv> = load vp<{{.*}}> (!tbaa !{{[0-9]+}})
11+
; CHECK: WIDEN-CAST ir<%conv> = sitofp ir<%lv> to float (!fpmath !{{[0-9]+}})
12+
; CHECK: WIDEN ir<%mul> = fmul ir<%conv>, ir<2.000000e+00> (!fpmath !{{[0-9]+}})
1313
; CHECK: WIDEN-CAST ir<%conv.back> = fptosi ir<%mul> to i32
14-
; CHECK: WIDEN store vp<{{.*}}>, ir<%conv.back>
14+
; CHECK: WIDEN store vp<{{.*}}>, ir<%conv.back> (!tbaa !{{[0-9]+}})
1515
;
1616
entry:
1717
br label %loop
@@ -40,9 +40,9 @@ define void @test_intrinsic_with_metadata(ptr noalias %A, ptr noalias %B, i32 %n
4040
; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
4141
; CHECK: <x1> vector loop: {
4242
; CHECK: vector.body:
43-
; CHECK: WIDEN ir<%lv> = load vp<{{.*}}>
44-
; CHECK: WIDEN-INTRINSIC ir<%sqrt> = call llvm.sqrt(ir<%lv>)
45-
; CHECK: WIDEN store vp<{{.*}}>, ir<%sqrt>
43+
; CHECK: WIDEN ir<%lv> = load vp<{{.*}}> (!tbaa !{{[0-9]+}})
44+
; CHECK: WIDEN-INTRINSIC ir<%sqrt> = call llvm.sqrt(ir<%lv>) (!fpmath !{{[0-9]+}})
45+
; CHECK: WIDEN store vp<{{.*}}>, ir<%sqrt> (!tbaa !{{[0-9]+}})
4646
;
4747
entry:
4848
br label %loop
@@ -67,11 +67,11 @@ define void @test_widen_with_multiple_metadata(ptr noalias %A, ptr noalias %B, i
6767
; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
6868
; CHECK: <x1> vector loop: {
6969
; CHECK: vector.body:
70-
; CHECK: WIDEN ir<%lv> = load vp<{{.*}}>
70+
; CHECK: WIDEN ir<%lv> = load vp<{{.*}}> (!tbaa !{{[0-9]+}})
7171
; CHECK: WIDEN-CAST ir<%conv> = sitofp ir<%lv> to float
7272
; CHECK: WIDEN ir<%mul> = fmul ir<%conv>, ir<2.000000e+00>
7373
; CHECK: WIDEN-CAST ir<%conv.back> = fptosi ir<%mul> to i32
74-
; CHECK: WIDEN store vp<{{.*}}>, ir<%conv.back>
74+
; CHECK: WIDEN store vp<{{.*}}>, ir<%conv.back> (!tbaa !{{[0-9]+}})
7575
;
7676
entry:
7777
br label %loop

0 commit comments

Comments
 (0)