Skip to content

Commit 96de4eb

Browse files
committed
[VPlan] Implement printing VPIRMetadata.
Implement and use debug printing for VPIRMetadata. !fixup address comments, thanks!
1 parent 7aa511d commit 96de4eb

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,11 @@ class VPIRMetadata {
983983
/// Intersect this VPIRMetada object with \p MD, keeping only metadata
984984
/// nodes that are common to both.
985985
void intersect(const VPIRMetadata &MD);
986+
987+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
988+
/// Print metadata with node IDs.
989+
void print(raw_ostream &O, const VPlan *Plan) const;
990+
#endif
986991
};
987992

988993
/// This is a concrete Recipe that models a single VPlan-level instruction.
@@ -4406,6 +4411,11 @@ class VPlan {
44064411
/// Return the VPIRBasicBlock wrapping the header of the scalar loop.
44074412
VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
44084413

4414+
/// Return the Module from the scalar header.
4415+
const Module &getModule() const {
4416+
return *ScalarHeader->getIRBasicBlock()->getModule();
4417+
}
4418+
44094419
/// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
44104420
/// the original scalar loop.
44114421
ArrayRef<VPIRBasicBlock *> getExitBlocks() const { return ExitBlocks; }

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ void VPSingleDefRecipe::dump() const { VPDef::dump(); }
489489
void VPRecipeBase::print(raw_ostream &O, const Twine &Indent,
490490
VPSlotTracker &SlotTracker) const {
491491
printRecipe(O, Indent, SlotTracker);
492+
493+
if (auto *Metadata = dyn_cast<VPIRMetadata>(this)) {
494+
if (const VPBasicBlock *Parent = getParent())
495+
Metadata->print(O, Parent->getPlan());
496+
}
492497
}
493498
#endif
494499

@@ -1703,6 +1708,28 @@ void VPIRMetadata::intersect(const VPIRMetadata &Other) {
17031708
Metadata = std::move(MetadataIntersection);
17041709
}
17051710

1711+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1712+
void VPIRMetadata::print(raw_ostream &O, const VPlan *Plan) const {
1713+
if (Metadata.empty() || !Plan)
1714+
return;
1715+
1716+
const Module &M = Plan->getModule();
1717+
SmallVector<StringRef, 8> MDNames;
1718+
M.getContext().getMDKindNames(MDNames);
1719+
1720+
O << " (";
1721+
interleaveComma(Metadata, O, [&](const auto &KindNodePair) {
1722+
auto [Kind, Node] = KindNodePair;
1723+
assert(Kind != 0 && "Debug metadata should not be managed by VPIRMetadata");
1724+
assert(Kind < MDNames.size() && !MDNames[Kind].empty() &&
1725+
"Unexpected unnamed metadata kind");
1726+
O << "!" << MDNames[Kind] << " ";
1727+
Node->printAsOperand(O, &M);
1728+
});
1729+
O << ")";
1730+
}
1731+
#endif
1732+
17061733
void VPWidenCallRecipe::execute(VPTransformState &State) {
17071734
assert(State.VF.isVector() && "not widening");
17081735
assert(Variant != nullptr && "Can't create vector function.");

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)