diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-24 20:59:52 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-24 20:59:52 +0000 |
| commit | 86979275aadee2516f42916155f804ce81ad2431 (patch) | |
| tree | cfaaf376c0be04784b2dfd4b4f7a8cde25202050 /llvm/lib | |
| parent | 86ac630585e8bd92739d6ef5edca664387efc27e (diff) | |
| download | bcm5719-llvm-86979275aadee2516f42916155f804ce81ad2431.tar.gz bcm5719-llvm-86979275aadee2516f42916155f804ce81ad2431.zip | |
AsmWriter: Split out code for printing Metadata attachments, NFC
Refactor the code for printing `Instruction` metadata attachments so it
can be reused for `Function`.
llvm-svn: 235772
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index fe6770ea5c6..7d0422d8c0a 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -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,22 +2956,29 @@ 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); } - printInfoComment(I); } void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) { |

