[llvm] r229004 - AsmWriter/Bitcode: MDEnumerator
David Blaikie
dblaikie at gmail.com
Thu Feb 12 18:33:29 PST 2015
On Thu, Feb 12, 2015 at 5:14 PM, Duncan P. N. Exon Smith <
dexonsmith at apple.com> wrote:
> Author: dexonsmith
> Date: Thu Feb 12 19:14:11 2015
> New Revision: 229004
>
> URL: http://llvm.org/viewvc/llvm-project?rev=229004&view=rev
> Log:
> AsmWriter/Bitcode: MDEnumerator
>
> Added:
> llvm/trunk/test/Assembler/invalid-mdenumerator-missing-name.ll
> llvm/trunk/test/Assembler/invalid-mdenumerator-missing-value.ll
> Modified:
> llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
> llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
> llvm/trunk/lib/AsmParser/LLParser.cpp
> llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
> llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
> llvm/trunk/lib/IR/AsmWriter.cpp
> llvm/trunk/test/Assembler/debug-info.ll
>
> Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=229004&r1=229003&r2=229004&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
> +++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:14:11 2015
> @@ -148,7 +148,8 @@ namespace bitc {
> METADATA_NAMED_NODE = 10, // NAMED_NODE: [n x mdnodes]
> METADATA_ATTACHMENT = 11, // [m x [value, [n x [id, mdnode]]]
> METADATA_GENERIC_DEBUG = 12, // [distinct, tag, vers, header, n x md
> num]
> - METADATA_SUBRANGE = 13 // [distinct, count, lo]
> + METADATA_SUBRANGE = 13, // [distinct, count, lo]
> + METADATA_ENUMERATOR = 14 // [distinct, value, name?]
>
Test cases seem to indicate that name is mandatory? (I assume the '?' was
meant to indicate optionality)
Also - do all our compilers already support the extra ',' at the end of
lists like this? They /might/ in which case you can use that to avoid
having to touch the previous line when you add a new entry.
> };
>
> // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
>
> Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=229004&r1=229003&r2=229004&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
> +++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Thu Feb 12 19:14:11 2015
> @@ -309,6 +309,8 @@ public:
> int64_t getValue() const { return Value; }
> StringRef getName() const { return getStringOperand(0); }
>
> + MDString *getRawName() const { return getOperandAs<MDString>(0); }
> +
> static bool classof(const Metadata *MD) {
> return MD->getMetadataID() == MDEnumeratorKind;
> }
>
> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229004&r1=229003&r2=229004&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:14:11 2015
> @@ -3181,9 +3181,19 @@ bool LLParser::ParseMDSubrange(MDNode *&
> return false;
> }
>
> +/// ParseMDEnumerator:
> +/// ::= !MDEnumerator(value: 30, name: "SomeKind")
> bool LLParser::ParseMDEnumerator(MDNode *&Result, bool IsDistinct) {
> - return TokError("unimplemented parser");
> +#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)
> \
> + REQUIRED(value, MDSignedField, );
> \
> + REQUIRED(name, MDStringField, );
> + PARSE_MD_FIELDS();
> +#undef VISIT_MD_FIELDS
> +
> + Result = GET_OR_DISTINCT(MDEnumerator, (Context, value.Val, name.Val));
> + return false;
> }
> +
> bool LLParser::ParseMDBasicType(MDNode *&Result, bool IsDistinct) {
> return TokError("unimplemented parser");
> }
>
> Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=229004&r1=229003&r2=229004&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:14:11
> 2015
> @@ -1361,6 +1361,16 @@ std::error_code BitcodeReader::ParseMeta
> NextMDValueNo++);
> break;
> }
> + case bitc::METADATA_ENUMERATOR: {
> + if (Record.size() != 3)
> + return Error("Invalid record");
> +
> + MDValueList.AssignValue(GET_OR_DISTINCT(MDEnumerator, Record[0],
> + (Context,
> unrotateSign(Record[1]),
> + getMDString(Record[2]))),
> + NextMDValueNo++);
> + break;
> + }
> case bitc::METADATA_STRING: {
> std::string String(Record.begin(), Record.end());
> llvm::UpgradeMDStringConstant(String);
>
> Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=229004&r1=229003&r2=229004&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:14:11
> 2015
> @@ -826,11 +826,18 @@ static void WriteMDSubrange(const MDSubr
> Record.clear();
> }
>
> -static void WriteMDEnumerator(const MDEnumerator *, const ValueEnumerator
> &,
> - BitstreamWriter &,
> SmallVectorImpl<uint64_t> &,
> - unsigned) {
> - llvm_unreachable("write not implemented");
> +static void WriteMDEnumerator(const MDEnumerator *N, const
> ValueEnumerator &VE,
> + BitstreamWriter &Stream,
> + SmallVectorImpl<uint64_t> &Record,
> + unsigned Abbrev) {
> + Record.push_back(N->isDistinct());
> + Record.push_back(rotateSign(N->getValue()));
> + Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
> +
> + Stream.EmitRecord(bitc::METADATA_ENUMERATOR, Record, Abbrev);
> + Record.clear();
> }
> +
> static void WriteMDBasicType(const MDBasicType *, const ValueEnumerator &,
> BitstreamWriter &, SmallVectorImpl<uint64_t>
> &,
> unsigned) {
>
> Modified: llvm/trunk/lib/IR/AsmWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=229004&r1=229003&r2=229004&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:14:11 2015
> @@ -1357,10 +1357,15 @@ static void writeMDSubrange(raw_ostream
> Out << ")";
> }
>
> -static void writeMDEnumerator(raw_ostream &, const MDEnumerator *,
> +static void writeMDEnumerator(raw_ostream &Out, const MDEnumerator *N,
> TypePrinting *, SlotTracker *, const Module
> *) {
> - llvm_unreachable("write not implemented");
> + Out << "!MDEnumerator(";
> + FieldSeparator FS;
> + Out << FS << "value: " << N->getValue();
> + Out << FS << "name: \"" << N->getName() << "\"";
> + Out << ")";
> }
> +
> static void writeMDBasicType(raw_ostream &, const MDBasicType *,
> TypePrinting *,
> SlotTracker *, const Module *) {
> llvm_unreachable("write not implemented");
>
> Modified: llvm/trunk/test/Assembler/debug-info.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/debug-info.ll?rev=229004&r1=229003&r2=229004&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Assembler/debug-info.ll (original)
> +++ llvm/trunk/test/Assembler/debug-info.ll Thu Feb 12 19:14:11 2015
> @@ -1,8 +1,8 @@
> ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
> ; RUN: verify-uselistorder %s
>
> -; CHECK: !named = !{!0, !0, !1, !2}
> -!named = !{!0, !1, !2, !3}
> +; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5}
> +!named = !{!0, !1, !2, !3, !4, !5, !6}
>
> ; CHECK: !0 = !MDSubrange(count: 3)
> ; CHECK-NEXT: !1 = !MDSubrange(count: 3, lowerBound: 4)
> @@ -12,3 +12,10 @@
>
> !2 = !MDSubrange(count: 3, lowerBound: 4)
> !3 = !MDSubrange(count: 3, lowerBound: -5)
> +
> +; CHECK-NEXT: !3 = !MDEnumerator(value: 7, name: "seven")
> +; CHECK-NEXT: !4 = !MDEnumerator(value: -8, name: "negeight")
> +; CHECK-NEXT: !5 = !MDEnumerator(value: 0, name: "")
> +!4 = !MDEnumerator(value: 7, name: "seven")
> +!5 = !MDEnumerator(value: -8, name: "negeight")
> +!6 = !MDEnumerator(value: 0, name: "")
>
> Added: llvm/trunk/test/Assembler/invalid-mdenumerator-missing-name.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdenumerator-missing-name.ll?rev=229004&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/Assembler/invalid-mdenumerator-missing-name.ll (added)
> +++ llvm/trunk/test/Assembler/invalid-mdenumerator-missing-name.ll Thu Feb
> 12 19:14:11 2015
> @@ -0,0 +1,4 @@
> +; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
> +
> +; CHECK: [[@LINE+1]]:28: error: missing required field 'name'
> +!0 = !MDEnumerator(value: 7)
>
> Added: llvm/trunk/test/Assembler/invalid-mdenumerator-missing-value.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdenumerator-missing-value.ll?rev=229004&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/Assembler/invalid-mdenumerator-missing-value.ll (added)
> +++ llvm/trunk/test/Assembler/invalid-mdenumerator-missing-value.ll Thu
> Feb 12 19:14:11 2015
> @@ -0,0 +1,4 @@
> +; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
> +
> +; CHECK: [[@LINE+1]]:32: error: missing required field 'value'
> +!0 = !MDEnumerator(name: "name")
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150212/23c1dbcd/attachment.html>
More information about the llvm-commits
mailing list