AsmWriter/Bitcode: MDSubroutineType
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:22:59 +0000 (01:22 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Feb 2015 01:22:59 +0000 (01:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229011 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/LLVMBitCodes.h
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/IR/AsmWriter.cpp
test/Assembler/debug-info.ll
test/Assembler/invalid-mdsubroutinetype-missing-types.ll [new file with mode: 0644]

index c221ad2dc9083dc194a3e02ac086e3a987ee047b..84991585c67b07fc79db6c4f3c29df55f4fd468d 100644 (file)
@@ -153,7 +153,8 @@ namespace bitc {
     METADATA_BASIC_TYPE    = 15,  // [distinct, tag, name, size, align, enc]
     METADATA_FILE          = 16,  // [distinct, filename, directory]
     METADATA_DERIVED_TYPE  = 17,  // [distinct, ...]
-    METADATA_COMPOSITE_TYPE= 18   // [distinct, ...]
+    METADATA_COMPOSITE_TYPE= 18,  // [distinct, ...]
+    METADATA_SUBROUTINE_TYPE= 19  // [distinct, flags, types]
   };
 
   // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
index 33f395a1f5a5c9df722f4f3c5977ef18338e9369..24442ef127bda5ad7378bef7d39afe818be3bd74 100644 (file)
@@ -3329,7 +3329,14 @@ bool LLParser::ParseMDCompositeType(MDNode *&Result, bool IsDistinct) {
 }
 
 bool LLParser::ParseMDSubroutineType(MDNode *&Result, bool IsDistinct) {
-  return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
+  OPTIONAL(flags, MDUnsignedField, (0, UINT32_MAX));                           \
+  REQUIRED(types, MDField, );
+  PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+  Result = GET_OR_DISTINCT(MDSubroutineType, (Context, flags.Val, types.Val));
+  return false;
 }
 
 /// ParseMDFileType:
index 6c38e0d85b483ffe18f3b537320203eaef88076b..5fc758a93cc99cffa4a2775d87d8e7edc5a171a1 100644 (file)
@@ -1417,6 +1417,16 @@ std::error_code BitcodeReader::ParseMetadata() {
           NextMDValueNo++);
       break;
     }
+    case bitc::METADATA_SUBROUTINE_TYPE: {
+      if (Record.size() != 3)
+        return Error("Invalid record");
+
+      MDValueList.AssignValue(
+          GET_OR_DISTINCT(MDSubroutineType, Record[0],
+                          (Context, Record[1], getMDOrNull(Record[2]))),
+          NextMDValueNo++);
+      break;
+    }
     case bitc::METADATA_FILE: {
       if (Record.size() != 3)
         return Error("Invalid record");
index 0c1b1e127b92c698e91c01062fa8a97f3eb558bd..6f275ab796209427000ff14f62aa407e4a57f8ed 100644 (file)
@@ -901,10 +901,17 @@ static void WriteMDCompositeType(const MDCompositeType *N,
   Record.clear();
 }
 
-static void WriteMDSubroutineType(const MDSubroutineType *,
-                                  const ValueEnumerator &, BitstreamWriter &,
-                                  SmallVectorImpl<uint64_t> &, unsigned) {
-  llvm_unreachable("write not implemented");
+static void WriteMDSubroutineType(const MDSubroutineType *N,
+                                  const ValueEnumerator &VE,
+                                  BitstreamWriter &Stream,
+                                  SmallVectorImpl<uint64_t> &Record,
+                                  unsigned Abbrev) {
+  Record.push_back(N->isDistinct());
+  Record.push_back(N->getFlags());
+  Record.push_back(VE.getMetadataOrNullID(N->getTypeArray()));
+
+  Stream.EmitRecord(bitc::METADATA_SUBROUTINE_TYPE, Record, Abbrev);
+  Record.clear();
 }
 
 static void WriteMDFile(const MDFile *N, const ValueEnumerator &VE,
index 0a585a097e2ede33bdd3391a86fc1df078e9e3f6..b2205a198664e595d6ed1ad024d1711b1b53ab5c 100644 (file)
@@ -1484,10 +1484,16 @@ static void writeMDCompositeType(raw_ostream &Out, const MDCompositeType *N,
   Out << ")";
 }
 
-static void writeMDSubroutineType(raw_ostream &, const MDSubroutineType *,
-                                  TypePrinting *, SlotTracker *,
-                                  const Module *) {
-  llvm_unreachable("write not implemented");
+static void writeMDSubroutineType(raw_ostream &Out, const MDSubroutineType *N,
+                                  TypePrinting *TypePrinter,
+                                  SlotTracker *Machine, const Module *Context) {
+  Out << "!MDSubroutineType(";
+  FieldSeparator FS;
+  if (N->getFlags())
+    Out << FS << "flags: " << N->getFlags();
+  Out << FS << "types: ";
+  writeMetadataAsOperand(Out, N->getTypeArray(), TypePrinter, Machine, Context);
+  Out << ")";
 }
 
 static void writeMDFile(raw_ostream &Out, const MDFile *N, TypePrinting *,
index 0b8ada7a2318fc0942fec34229f1614431f65d3c..4d508e1bf00b62db2cd9cd72cd91b03f03708d21 100644 (file)
@@ -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, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24}
-!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26}
+; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !27}
+!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30}
 
 ; CHECK:      !0 = !MDSubrange(count: 3)
 ; CHECK-NEXT: !1 = !MDSubrange(count: 3, lowerBound: 4)
 !24 = !MDDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !7, size: 32, align: 32, extraData: !17)
 !25 = !MDCompositeType(tag: DW_TAG_structure_type)
 !26 = !MDCompositeType(tag: DW_TAG_structure_type, runtimeLang: 6)
+
+; !25 = !{!7, !7}
+; !26 = !MDSubroutineType(flags: 7, types: !25)
+; !27 = !MDSubroutineType(types: !25)
+!27 = !{!7, !7}
+!28 = !MDSubroutineType(flags: 7, types: !27)
+!29 = !MDSubroutineType(flags: 0, types: !27)
+!30 = !MDSubroutineType(types: !27)
diff --git a/test/Assembler/invalid-mdsubroutinetype-missing-types.ll b/test/Assembler/invalid-mdsubroutinetype-missing-types.ll
new file mode 100644 (file)
index 0000000..6c976ed
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: [[@LINE+1]]:33: error: missing required field 'types'
+!29 = !MDSubroutineType(flags: 7)