mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-22 20:26:31 +00:00
AsmWriter: Split out code for printing Metadata attachments, NFC
Refactor the code for printing `Instruction` metadata attachments so it can be reused for `Function`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235772 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7a301c1b8c
commit
61317d57df
@ -1987,6 +1987,10 @@ public:
|
||||
private:
|
||||
void init();
|
||||
|
||||
/// \brief Print out metadata attachments.
|
||||
void printMetadataAttachments(
|
||||
const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs);
|
||||
|
||||
// printInfoComment - Print a little comment after the instruction indicating
|
||||
// which slot it occupies.
|
||||
void printInfoComment(const Value &V);
|
||||
@ -2952,24 +2956,31 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
|
||||
// Print Metadata info.
|
||||
SmallVector<std::pair<unsigned, MDNode *>, 4> InstMD;
|
||||
I.getAllMetadata(InstMD);
|
||||
if (!InstMD.empty()) {
|
||||
SmallVector<StringRef, 8> MDNames;
|
||||
I.getType()->getContext().getMDKindNames(MDNames);
|
||||
for (unsigned i = 0, e = InstMD.size(); i != e; ++i) {
|
||||
unsigned Kind = InstMD[i].first;
|
||||
if (Kind < MDNames.size()) {
|
||||
Out << ", !" << MDNames[Kind];
|
||||
} else {
|
||||
Out << ", !<unknown kind #" << Kind << ">";
|
||||
}
|
||||
Out << ' ';
|
||||
WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine,
|
||||
TheModule);
|
||||
}
|
||||
}
|
||||
printMetadataAttachments(InstMD);
|
||||
|
||||
// Print a nice comment.
|
||||
printInfoComment(I);
|
||||
}
|
||||
|
||||
void AssemblyWriter::printMetadataAttachments(
|
||||
const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) {
|
||||
if (MDs.empty())
|
||||
return;
|
||||
|
||||
SmallVector<StringRef, 8> MDNames;
|
||||
TheModule->getMDKindNames(MDNames);
|
||||
for (const auto &I : MDs) {
|
||||
unsigned Kind = I.first;
|
||||
if (Kind < MDNames.size()) {
|
||||
Out << ", !" << MDNames[Kind];
|
||||
} else {
|
||||
Out << ", !<unknown kind #" << Kind << ">";
|
||||
}
|
||||
Out << ' ';
|
||||
WriteAsOperandInternal(Out, I.second, &TypePrinter, &Machine, TheModule);
|
||||
}
|
||||
}
|
||||
|
||||
void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) {
|
||||
Out << '!' << Slot << " = ";
|
||||
printMDNodeBody(Node);
|
||||
|
Loading…
x
Reference in New Issue
Block a user