Skip to content

Commit 6c155f6

Browse files
committed
[VPlan] Implement printing VPIRMetadata.
Implement and use debug printing for VPIRMetadata.
1 parent 2fc42c7 commit 6c155f6

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
@@ -1020,6 +1020,11 @@ class VPIRMetadata {
10201020
find_if(Metadata, [Kind](const auto &P) { return P.first == Kind; });
10211021
return It != Metadata.end() ? It->second : nullptr;
10221022
}
1023+
1024+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1025+
/// Print metadata with node IDs.
1026+
void print(raw_ostream &O, const VPlan *Plan) const;
1027+
#endif
10231028
};
10241029

10251030
/// This is a concrete Recipe that models a single VPlan-level instruction.
@@ -4446,6 +4451,11 @@ class VPlan {
44464451
/// Return the VPIRBasicBlock wrapping the header of the scalar loop.
44474452
VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
44484453

4454+
/// Return the Module from the scalar header.
4455+
const Module &getModule() const {
4456+
return *ScalarHeader->getIRBasicBlock()->getModule();
4457+
}
4458+
44494459
/// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
44504460
/// the original scalar loop.
44514461
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
@@ -497,6 +497,11 @@ void VPRecipeBase::print(raw_ostream &O, const Twine &Indent,
497497
O << ", !dbg ";
498498
DL.print(O);
499499
}
500+
501+
if (auto *Metadata = dyn_cast<VPIRMetadata>(this)) {
502+
if (const VPBasicBlock *Parent = getParent())
503+
Metadata->print(O, Parent->getPlan());
504+
}
500505
}
501506
#endif
502507

@@ -1695,6 +1700,28 @@ void VPIRMetadata::intersect(const VPIRMetadata &Other) {
16951700
Metadata = std::move(MetadataIntersection);
16961701
}
16971702

1703+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1704+
void VPIRMetadata::print(raw_ostream &O, const VPlan *Plan) const {
1705+
if (Metadata.empty() || !Plan)
1706+
return;
1707+
1708+
const Module &M = Plan->getModule();
1709+
SmallVector<StringRef, 8> MDNames;
1710+
M.getContext().getMDKindNames(MDNames);
1711+
1712+
O << " (";
1713+
interleaveComma(Metadata, O, [&](const auto &KindNodePair) {
1714+
auto [Kind, Node] = KindNodePair;
1715+
assert(Kind != 0 && "Debug metadata should not be managed by VPIRMetadata");
1716+
assert(Kind < MDNames.size() && !MDNames[Kind].empty() &&
1717+
"Unexpected unnamed metadata kind");
1718+
O << "!" << MDNames[Kind] << " ";
1719+
Node->printAsOperand(O, &M);
1720+
});
1721+
O << ")";
1722+
}
1723+
#endif
1724+
16981725
void VPWidenCallRecipe::execute(VPTransformState &State) {
16991726
assert(State.VF.isVector() && "not widening");
17001727
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)