Skip to content

Commit 279213b

Browse files
committed
[VPlan] Implement printing VPIRMetadata.
Implement and use debug printing for VPIRMetadata.
1 parent f7ed15b commit 279213b

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.
@@ -4444,6 +4449,11 @@ class VPlan {
44444449
/// Return the VPIRBasicBlock wrapping the header of the scalar loop.
44454450
VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
44464451

4452+
/// Return the Module from the scalar header.
4453+
const Module &getModule() const {
4454+
return *ScalarHeader->getIRBasicBlock()->getModule();
4455+
}
4456+
44474457
/// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
44484458
/// the original scalar loop.
44494459
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
@@ -507,6 +507,11 @@ void VPRecipeBase::print(raw_ostream &O, const Twine &Indent,
507507
O << ", !dbg ";
508508
DL.print(O);
509509
}
510+
511+
if (auto *Metadata = dyn_cast<VPIRMetadata>(this)) {
512+
if (const VPBasicBlock *Parent = getParent())
513+
Metadata->print(O, Parent->getPlan());
514+
}
510515
}
511516
#endif
512517

@@ -1706,6 +1711,28 @@ void VPIRMetadata::intersect(const VPIRMetadata &Other) {
17061711
Metadata = std::move(MetadataIntersection);
17071712
}
17081713

1714+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1715+
void VPIRMetadata::print(raw_ostream &O, const VPlan *Plan) const {
1716+
if (Metadata.empty() || !Plan)
1717+
return;
1718+
1719+
const Module &M = Plan->getModule();
1720+
SmallVector<StringRef, 8> MDNames;
1721+
M.getContext().getMDKindNames(MDNames);
1722+
1723+
O << " (";
1724+
interleaveComma(Metadata, O, [&](const auto &KindNodePair) {
1725+
auto [Kind, Node] = KindNodePair;
1726+
assert(Kind != 0 && "Debug metadata should not be managed by VPIRMetadata");
1727+
assert(Kind < MDNames.size() && !MDNames[Kind].empty() &&
1728+
"Unexpected unnamed metadata kind");
1729+
O << "!" << MDNames[Kind] << " ";
1730+
Node->printAsOperand(O, &M);
1731+
});
1732+
O << ")";
1733+
}
1734+
#endif
1735+
17091736
void VPWidenCallRecipe::execute(VPTransformState &State) {
17101737
assert(State.VF.isVector() && "not widening");
17111738
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)