From 61317d57df145c9392951c124876c7a58e66c1d1 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 24 Apr 2015 20:59:52 +0000 Subject: [PATCH] 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 --- lib/IR/AsmWriter.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index fe6770ea5c6..7d0422d8c0a 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1987,6 +1987,10 @@ public: private: void init(); + /// \brief Print out metadata attachments. + void printMetadataAttachments( + const SmallVectorImpl> &MDs); + // printInfoComment - Print a little comment after the instruction indicating // which slot it occupies. void printInfoComment(const Value &V); @@ -2952,22 +2956,29 @@ void AssemblyWriter::printInstruction(const Instruction &I) { // Print Metadata info. SmallVector, 4> InstMD; I.getAllMetadata(InstMD); - if (!InstMD.empty()) { - SmallVector 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 << ", !"; - } - Out << ' '; - WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine, - TheModule); + printMetadataAttachments(InstMD); + + // Print a nice comment. + printInfoComment(I); +} + +void AssemblyWriter::printMetadataAttachments( + const SmallVectorImpl> &MDs) { + if (MDs.empty()) + return; + + SmallVector MDNames; + TheModule->getMDKindNames(MDNames); + for (const auto &I : MDs) { + unsigned Kind = I.first; + if (Kind < MDNames.size()) { + Out << ", !" << MDNames[Kind]; + } else { + Out << ", !"; } + Out << ' '; + WriteAsOperandInternal(Out, I.second, &TypePrinter, &Machine, TheModule); } - printInfoComment(I); } void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) { -- 2.34.1