[llvm] r229005 - AsmWriter/Bitcode: MDBasicType

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Feb 12 18:47:40 PST 2015


> On 2015-Feb-12, at 18:34, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> 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:58 2015
> New Revision: 229005
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=229005&view=rev
> Log:
> AsmWriter/Bitcode: MDBasicType
> 
> Added:
>     llvm/trunk/test/Assembler/invalid-mdbasictype-missing-tag.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=229005&r1=229004&r2=229005&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
> +++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:14:58 2015
> @@ -149,7 +149,8 @@ namespace bitc {
>      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_ENUMERATOR    = 14   // [distinct, value, name?]
> +    METADATA_ENUMERATOR    = 14,  // [distinct, value, name?]
> +    METADATA_BASIC_TYPE    = 15   // [distinct, tag, name, size, align, enc]
> 
> Looks like the last field ended up being called 'encoding', not 'enc'.

I was just looking for 80-columns here.  'encoding' didn't fit.

Do you find this useful, even?  I wonder if I should just remove
these comments.  It's duplicated from the actual code in `BitcodeWriter`,
and I figure it's liable to get stale.

>  
>    };
> 
>    // 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=229005&r1=229004&r2=229005&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
> +++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Thu Feb 12 19:14:58 2015
> @@ -381,6 +381,8 @@ public:
>    Metadata *getScope() const { return getOperand(1); }
>    StringRef getName() const { return getStringOperand(2); }
> 
> +  MDString *getRawName() const { return getOperandAs<MDString>(2); }
> +
>    static bool classof(const Metadata *MD) {
>      switch (MD->getMetadataID()) {
>      default:
> 
> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229005&r1=229004&r2=229005&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:14:58 2015
> @@ -3194,9 +3194,23 @@ bool LLParser::ParseMDEnumerator(MDNode
>    return false;
>  }
> 
> +/// ParseMDBasicType:
> +///   ::= !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32)
>  bool LLParser::ParseMDBasicType(MDNode *&Result, bool IsDistinct) {
> -  return TokError("unimplemented parser");
> +#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
> +  REQUIRED(tag, DwarfTagField, );                                              \
> +  OPTIONAL(name, MDStringField, );                                             \
> +  OPTIONAL(size, MDUnsignedField, (0, UINT32_MAX));                            \
> +  OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));                           \
> +  OPTIONAL(encoding, MDUnsignedField, (0, UINT32_MAX));
> +  PARSE_MD_FIELDS();
> +#undef VISIT_MD_FIELDS
> +
> +  Result = GET_OR_DISTINCT(MDBasicType, (Context, tag.Val, name.Val, size.Val,
> +                                         align.Val, encoding.Val));
> +  return false;
>  }
> +
>  bool LLParser::ParseMDDerivedType(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=229005&r1=229004&r2=229005&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:14:58 2015
> @@ -1371,6 +1371,17 @@ std::error_code BitcodeReader::ParseMeta
>                                NextMDValueNo++);
>        break;
>      }
> +    case bitc::METADATA_BASIC_TYPE: {
> +      if (Record.size() != 6)
> +        return Error("Invalid record");
> +
> +      MDValueList.AssignValue(
> +          GET_OR_DISTINCT(MDBasicType, Record[0],
> +                          (Context, Record[1], getMDString(Record[2]),
> +                           Record[3], Record[4], Record[5])),
> +          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=229005&r1=229004&r2=229005&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:14:58 2015
> @@ -838,11 +838,21 @@ static void WriteMDEnumerator(const MDEn
>    Record.clear();
>  }
> 
> -static void WriteMDBasicType(const MDBasicType *, const ValueEnumerator &,
> -                             BitstreamWriter &, SmallVectorImpl<uint64_t> &,
> -                             unsigned) {
> -  llvm_unreachable("write not implemented");
> +static void WriteMDBasicType(const MDBasicType *N, const ValueEnumerator &VE,
> +                             BitstreamWriter &Stream,
> +                             SmallVectorImpl<uint64_t> &Record,
> +                             unsigned Abbrev) {
> +  Record.push_back(N->isDistinct());
> +  Record.push_back(N->getTag());
> +  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
> +  Record.push_back(N->getSizeInBits());
> +  Record.push_back(N->getAlignInBits());
> +  Record.push_back(N->getEncoding());
> +
> +  Stream.EmitRecord(bitc::METADATA_BASIC_TYPE, Record, Abbrev);
> +  Record.clear();
>  }
> +
>  static void WriteMDDerivedType(const MDDerivedType *, 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=229005&r1=229004&r2=229005&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:14:58 2015
> @@ -1366,10 +1366,22 @@ static void writeMDEnumerator(raw_ostrea
>    Out << ")";
>  }
> 
> -static void writeMDBasicType(raw_ostream &, const MDBasicType *, TypePrinting *,
> -                             SlotTracker *, const Module *) {
> -  llvm_unreachable("write not implemented");
> +static void writeMDBasicType(raw_ostream &Out, const MDBasicType *N,
> +                             TypePrinting *, SlotTracker *, const Module *) {
> +  Out << "!MDBasicType(";
> +  FieldSeparator FS;
> +  writeTag(Out, FS, N);
> +  if (!N->getName().empty())
> +    Out << FS << "name: \"" << N->getName() << "\"";
> +  if (N->getSizeInBits())
> +    Out << FS << "size: " << N->getSizeInBits();
> +  if (N->getAlignInBits())
> +    Out << FS << "align: " << N->getAlignInBits();
> +  if (N->getEncoding())
> +    Out << FS << "encoding: " << N->getEncoding();
> +  Out << ")";
>  }
> +
>  static void writeMDDerivedType(raw_ostream &, const MDDerivedType *,
>                                 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=229005&r1=229004&r2=229005&view=diff
> ==============================================================================
> --- llvm/trunk/test/Assembler/debug-info.ll (original)
> +++ llvm/trunk/test/Assembler/debug-info.ll Thu Feb 12 19:14:58 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, !3, !4, !5}
> -!named = !{!0, !1, !2, !3, !4, !5, !6}
> +; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8}
> +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10}
> 
>  ; CHECK:      !0 = !MDSubrange(count: 3)
>  ; CHECK-NEXT: !1 = !MDSubrange(count: 3, lowerBound: 4)
> @@ -19,3 +19,11 @@
>  !4 = !MDEnumerator(value: 7, name: "seven")
>  !5 = !MDEnumerator(value: -8, name: "negeight")
>  !6 = !MDEnumerator(value: 0, name: "")
> +
> +; CHECK-NEXT: !6 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: 3)
> +; CHECK-NEXT: !7 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
> +; CHECK-NEXT: !8 = !MDBasicType(tag: DW_TAG_base_type)
> +!7 = !MDBasicType(tag: DW_TAG_base_type, name: "name", size: 1, align: 2, encoding: 3)
> +!8 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
> +!9 = !MDBasicType(tag: DW_TAG_base_type)
> +!10 = !MDBasicType(tag: DW_TAG_base_type, name: "", size: 0, align: 0, encoding: 0)
> 
> Added: llvm/trunk/test/Assembler/invalid-mdbasictype-missing-tag.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdbasictype-missing-tag.ll?rev=229005&view=auto
> ==============================================================================
> --- llvm/trunk/test/Assembler/invalid-mdbasictype-missing-tag.ll (added)
> +++ llvm/trunk/test/Assembler/invalid-mdbasictype-missing-tag.ll Thu Feb 12 19:14:58 2015
> @@ -0,0 +1,4 @@
> +; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
> +
> +; CHECK: [[@LINE+1]]:31: error: missing required field 'tag'
> +!0 = !MDBasicType(name: "name")
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list