Skip to content

Commit bcd6751

Browse files
committed
[VPlan] Implement printing VPIRMetadata.
Implement and use debug printing for VPIRMetadata.
1 parent 5ba0b91 commit bcd6751

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
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.
@@ -4268,6 +4271,11 @@ class VPlan {
42684271
/// Return the VPIRBasicBlock wrapping the header of the scalar loop.
42694272
VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
42704273

4274+
/// Return the Module from the scalar header.
4275+
const Module &getModule() const {
4276+
return *ScalarHeader->getIRBasicBlock()->getModule();
4277+
}
4278+
42714279
/// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
42724280
/// the original scalar loop.
42734281
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

@@ -3618,6 +3642,7 @@ void VPWidenLoadRecipe::print(raw_ostream &O, const Twine &Indent,
36183642
printAsOperand(O, SlotTracker);
36193643
O << " = load ";
36203644
printOperands(O, SlotTracker);
3645+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
36213646
}
36223647
#endif
36233648

@@ -3739,6 +3764,7 @@ void VPWidenStoreRecipe::print(raw_ostream &O, const Twine &Indent,
37393764
VPSlotTracker &SlotTracker) const {
37403765
O << Indent << "WIDEN store ";
37413766
printOperands(O, SlotTracker);
3767+
VPIRMetadata::print(O, getParent()->getPlan()->getModule());
37423768
}
37433769
#endif
37443770

0 commit comments

Comments
 (0)