[llvm] r229013 - AsmWriter/Bitcode: MDCompileUnit
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 17:25:11 PST 2015
Author: dexonsmith
Date: Thu Feb 12 19:25:10 2015
New Revision: 229013
URL: http://llvm.org/viewvc/llvm-project?rev=229013&view=rev
Log:
AsmWriter/Bitcode: MDCompileUnit
Added:
llvm/trunk/test/Assembler/invalid-mdcompileunit-language-bad.ll
llvm/trunk/test/Assembler/invalid-mdcompileunit-language-overflow.ll
llvm/trunk/test/Assembler/invalid-mdcompileunit-missing-language.ll
llvm/trunk/test/Assembler/mdcompileunit.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
Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=229013&r1=229012&r2=229013&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:25:10 2015
@@ -154,7 +154,8 @@ namespace bitc {
METADATA_FILE = 16, // [distinct, filename, directory]
METADATA_DERIVED_TYPE = 17, // [distinct, ...]
METADATA_COMPOSITE_TYPE= 18, // [distinct, ...]
- METADATA_SUBROUTINE_TYPE= 19 // [distinct, flags, types]
+ METADATA_SUBROUTINE_TYPE=19, // [distinct, flags, types]
+ METADATA_COMPILE_UNIT = 20 // [distinct, ...]
};
// 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=229013&r1=229012&r2=229013&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Thu Feb 12 19:25:10 2015
@@ -844,6 +844,12 @@ public:
Metadata *getGlobalVariables() const { return getOperand(7); }
Metadata *getImportedEntities() const { return getOperand(8); }
+ MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
+ MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
+ MDString *getRawSplitDebugFilename() const {
+ return getOperandAs<MDString>(3);
+ }
+
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDCompileUnitKind;
}
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229013&r1=229012&r2=229013&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:25:10 2015
@@ -3352,9 +3352,39 @@ bool LLParser::ParseMDFile(MDNode *&Resu
return false;
}
+/// ParseMDCompileUnit:
+/// ::= !MDCompileUnit(language: DW_LANG_C99, file: !0, producer: "clang",
+/// isOptimized: true, flags: "-O2", runtimeVersion: 1,
+/// splitDebugFilename: "abc.debug", emissionKind: 1,
+/// enums: !1, retainedTypes: !2, subprograms: !3,
+/// globals: !4, imports: !5)
bool LLParser::ParseMDCompileUnit(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ REQUIRED(language, DwarfLangField, ); \
+ REQUIRED(file, MDField, ); \
+ OPTIONAL(producer, MDStringField, ); \
+ OPTIONAL(isOptimized, MDBoolField, ); \
+ OPTIONAL(flags, MDStringField, ); \
+ OPTIONAL(runtimeVersion, MDUnsignedField, (0, UINT32_MAX)); \
+ OPTIONAL(splitDebugFilename, MDStringField, ); \
+ OPTIONAL(emissionKind, MDUnsignedField, (0, UINT32_MAX)); \
+ OPTIONAL(enums, MDField, ); \
+ OPTIONAL(retainedTypes, MDField, ); \
+ OPTIONAL(subprograms, MDField, ); \
+ OPTIONAL(globals, MDField, ); \
+ OPTIONAL(imports, MDField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(MDCompileUnit,
+ (Context, language.Val, file.Val, producer.Val,
+ isOptimized.Val, flags.Val, runtimeVersion.Val,
+ splitDebugFilename.Val, emissionKind.Val, enums.Val,
+ retainedTypes.Val, subprograms.Val, globals.Val,
+ imports.Val));
+ return false;
}
+
bool LLParser::ParseMDSubprogram(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=229013&r1=229012&r2=229013&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:25:10 2015
@@ -1437,6 +1437,21 @@ std::error_code BitcodeReader::ParseMeta
NextMDValueNo++);
break;
}
+ case bitc::METADATA_COMPILE_UNIT: {
+ if (Record.size() != 14)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(
+ MDCompileUnit, Record[0],
+ (Context, Record[1], getMD(Record[2]), getMDString(Record[3]),
+ Record[4], getMDString(Record[5]), Record[6],
+ getMDString(Record[7]), Record[8], getMDOrNull(Record[9]),
+ getMDOrNull(Record[10]), getMDOrNull(Record[11]),
+ getMDOrNull(Record[12]), getMDOrNull(Record[13]))),
+ 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=229013&r1=229012&r2=229013&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:25:10 2015
@@ -925,11 +925,30 @@ static void WriteMDFile(const MDFile *N,
Record.clear();
}
-static void WriteMDCompileUnit(const MDCompileUnit *, const ValueEnumerator &,
- BitstreamWriter &, SmallVectorImpl<uint64_t> &,
- unsigned) {
- llvm_unreachable("write not implemented");
+static void WriteMDCompileUnit(const MDCompileUnit *N,
+ const ValueEnumerator &VE,
+ BitstreamWriter &Stream,
+ SmallVectorImpl<uint64_t> &Record,
+ unsigned Abbrev) {
+ Record.push_back(N->isDistinct());
+ Record.push_back(N->getSourceLanguage());
+ Record.push_back(VE.getMetadataID(N->getFile()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
+ Record.push_back(N->isOptimized());
+ Record.push_back(VE.getMetadataOrNullID(N->getRawFlags()));
+ Record.push_back(N->getRuntimeVersion());
+ Record.push_back(VE.getMetadataOrNullID(N->getRawSplitDebugFilename()));
+ Record.push_back(N->getEmissionKind());
+ Record.push_back(VE.getMetadataOrNullID(N->getEnumTypes()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRetainedTypes()));
+ Record.push_back(VE.getMetadataOrNullID(N->getSubprograms()));
+ Record.push_back(VE.getMetadataOrNullID(N->getGlobalVariables()));
+ Record.push_back(VE.getMetadataOrNullID(N->getImportedEntities()));
+
+ Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
+ Record.clear();
}
+
static void WriteMDSubprogram(const MDSubprogram *, 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=229013&r1=229012&r2=229013&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:25:10 2015
@@ -1505,10 +1505,58 @@ static void writeMDFile(raw_ostream &Out
Out << ")";
}
-static void writeMDCompileUnit(raw_ostream &, const MDCompileUnit *,
- TypePrinting *, SlotTracker *, const Module *) {
- llvm_unreachable("write not implemented");
+static void writeMDCompileUnit(raw_ostream &Out, const MDCompileUnit *N,
+ TypePrinting *TypePrinter, SlotTracker *Machine,
+ const Module *Context) {
+ Out << "!MDCompileUnit(";
+ FieldSeparator FS;
+ Out << FS << "language: ";
+ if (const char *Lang = dwarf::LanguageString(N->getSourceLanguage()))
+ Out << Lang;
+ else
+ Out << N->getSourceLanguage();
+ if (N->getFile()) {
+ Out << FS << "file: ";
+ writeMetadataAsOperand(Out, N->getFile(), TypePrinter, Machine,
+ Context);
+ }
+ if (!N->getProducer().empty())
+ Out << FS << "producer: \"" << N->getProducer() << "\"";
+ Out << FS << "isOptimized: " << (N->isOptimized() ? "true" : "false");
+ if (!N->getFlags().empty())
+ Out << FS << "flags: \"" << N->getFlags() << "\"";
+ Out << FS << "runtimeVersion: " << N->getRuntimeVersion();
+ if (!N->getSplitDebugFilename().empty())
+ Out << FS << "splitDebugFilename: \"" << N->getSplitDebugFilename() << "\"";
+ Out << FS << "emissionKind: " << N->getEmissionKind();
+ if (N->getEnumTypes()) {
+ Out << FS << "enums: ";
+ writeMetadataAsOperand(Out, N->getEnumTypes(), TypePrinter, Machine,
+ Context);
+ }
+ if (N->getRetainedTypes()) {
+ Out << FS << "retainedTypes: ";
+ writeMetadataAsOperand(Out, N->getRetainedTypes(), TypePrinter, Machine,
+ Context);
+ }
+ if (N->getSubprograms()) {
+ Out << FS << "subprograms: ";
+ writeMetadataAsOperand(Out, N->getSubprograms(), TypePrinter, Machine,
+ Context);
+ }
+ if (N->getGlobalVariables()) {
+ Out << FS << "globals: ";
+ writeMetadataAsOperand(Out, N->getGlobalVariables(), TypePrinter, Machine,
+ Context);
+ }
+ if (N->getImportedEntities()) {
+ Out << FS << "imports: ";
+ writeMetadataAsOperand(Out, N->getImportedEntities(), TypePrinter, Machine,
+ Context);
+ }
+ Out << ")";
}
+
static void writeMDSubprogram(raw_ostream &, const MDSubprogram *,
TypePrinting *, SlotTracker *, const Module *) {
llvm_unreachable("write not implemented");
Added: llvm/trunk/test/Assembler/invalid-mdcompileunit-language-bad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdcompileunit-language-bad.ll?rev=229013&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdcompileunit-language-bad.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdcompileunit-language-bad.ll Thu Feb 12 19:25:10 2015
@@ -0,0 +1,5 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:31: error: invalid DWARF language 'DW_LANG_NoSuchLanguage'
+!0 = !MDCompileUnit(language: DW_LANG_NoSuchLanguage,
+ file: !MDFile(filename: "a", directory: "b"))
Added: llvm/trunk/test/Assembler/invalid-mdcompileunit-language-overflow.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdcompileunit-language-overflow.ll?rev=229013&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdcompileunit-language-overflow.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdcompileunit-language-overflow.ll Thu Feb 12 19:25:10 2015
@@ -0,0 +1,9 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK-NOT: error
+!0 = !MDCompileUnit(language: 65535,
+ file: !MDFile(filename: "a", directory: "b"))
+
+; CHECK: <stdin>:[[@LINE+1]]:31: error: value for 'language' too large, limit is 65535
+!1 = !MDCompileUnit(language: 65536,
+ file: !MDFile(filename: "a", directory: "b"))
Added: llvm/trunk/test/Assembler/invalid-mdcompileunit-missing-language.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdcompileunit-missing-language.ll?rev=229013&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdcompileunit-missing-language.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdcompileunit-missing-language.ll Thu Feb 12 19:25:10 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:65: error: missing required field 'language'
+!0 = !MDCompileUnit(file: !MDFile(filename: "a", directory: "b"))
Added: llvm/trunk/test/Assembler/mdcompileunit.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/mdcompileunit.ll?rev=229013&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/mdcompileunit.ll (added)
+++ llvm/trunk/test/Assembler/mdcompileunit.ll Thu Feb 12 19:25:10 2015
@@ -0,0 +1,31 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
+; RUN: verify-uselistorder %s
+
+; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !7, !8, !8}
+!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10}
+
+!0 = !{!"path/to/file", !"/path/to/dir"}
+!1 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
+!2 = distinct !{}
+!3 = distinct !{}
+!4 = distinct !{}
+!5 = distinct !{}
+!6 = distinct !{}
+
+; CHECK: !7 = !MDCompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 2, splitDebugFilename: "abc.debug", emissionKind: 3, enums: !2, retainedTypes: !3, subprograms: !4, globals: !5, imports: !6)
+!7 = !MDCompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
+ isOptimized: true, flags: "-O2", runtimeVersion: 2,
+ splitDebugFilename: "abc.debug", emissionKind: 3,
+ enums: !2, retainedTypes: !3, subprograms: !4,
+ globals: !5, imports: !6)
+!8 = !MDCompileUnit(language: 12, file: !1, producer: "clang",
+ isOptimized: true, flags: "-O2", runtimeVersion: 2,
+ splitDebugFilename: "abc.debug", emissionKind: 3,
+ enums: !2, retainedTypes: !3, subprograms: !4,
+ globals: !5, imports: !6)
+
+; CHECK: !8 = !MDCompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: 0)
+!9 = !MDCompileUnit(language: 12, file: !1, producer: "",
+ isOptimized: false, flags: "", runtimeVersion: 0,
+ splitDebugFilename: "", emissionKind: 0)
+!10 = !MDCompileUnit(language: 12, file: !1)
More information about the llvm-commits
mailing list