[llvm] r229020 - AsmWriter/Bitcode: MDGlobalVariable
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 17:35:41 PST 2015
Author: dexonsmith
Date: Thu Feb 12 19:35:40 2015
New Revision: 229020
URL: http://llvm.org/viewvc/llvm-project?rev=229020&view=rev
Log:
AsmWriter/Bitcode: MDGlobalVariable
Added:
llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll
llvm/trunk/test/Assembler/mdglobalvariable.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=229020&r1=229019&r2=229020&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:35:40 2015
@@ -161,7 +161,8 @@ namespace bitc {
METADATA_LEXICAL_BLOCK_FILE=23,//[distinct, scope, file, discriminator]
METADATA_NAMESPACE = 24, // [distinct, scope, file, name, line]
METADATA_TEMPLATE_TYPE = 25, // [distinct, scope, name, type, ...]
- METADATA_TEMPLATE_VALUE= 26 // [distinct, scope, name, type, value, ...]
+ METADATA_TEMPLATE_VALUE= 26, // [distinct, scope, name, type, value, ...]
+ METADATA_GLOBAL_VAR = 27 // [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=229020&r1=229019&r2=229020&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Thu Feb 12 19:35:40 2015
@@ -1243,6 +1243,8 @@ public:
Metadata *getFile() const { return getOperand(2); }
Metadata *getType() const { return getOperand(3); }
+ MDString *getRawName() const { return getOperandAs<MDString>(1); }
+
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDLocalVariableKind ||
MD->getMetadataID() == MDGlobalVariableKind;
@@ -1315,6 +1317,8 @@ public:
Metadata *getVariable() const { return getOperand(6); }
Metadata *getStaticDataMemberDeclaration() const { return getOperand(7); }
+ MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
+
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDGlobalVariableKind;
}
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229020&r1=229019&r2=229020&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:35:40 2015
@@ -3548,9 +3548,33 @@ bool LLParser::ParseMDTemplateValueParam
return false;
}
+/// ParseMDGlobalVariable:
+/// ::= !MDGlobalVariable(scope: !0, name: "foo", linkageName: "foo",
+/// file: !1, line: 7, type: !2, isLocal: false,
+/// isDefinition: true, variable: i32* @foo,
+/// declaration: !3)
bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ OPTIONAL(scope, MDField, ); \
+ REQUIRED(name, MDStringField, ); \
+ OPTIONAL(linkageName, MDStringField, ); \
+ OPTIONAL(file, MDField, ); \
+ OPTIONAL(line, LineField, ); \
+ OPTIONAL(type, MDField, ); \
+ OPTIONAL(isLocal, MDBoolField, ); \
+ OPTIONAL(isDefinition, MDBoolField, (true)); \
+ OPTIONAL(variable, MDConstant, ); \
+ OPTIONAL(declaration, MDField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(MDGlobalVariable,
+ (Context, scope.Val, name.Val, linkageName.Val,
+ file.Val, line.Val, type.Val, isLocal.Val,
+ isDefinition.Val, variable.Val, declaration.Val));
+ return false;
}
+
bool LLParser::ParseMDLocalVariable(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=229020&r1=229019&r2=229020&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:35:40 2015
@@ -1525,6 +1525,20 @@ std::error_code BitcodeReader::ParseMeta
NextMDValueNo++);
break;
}
+ case bitc::METADATA_GLOBAL_VAR: {
+ if (Record.size() != 11)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDGlobalVariable, Record[0],
+ (Context, getMDOrNull(Record[1]),
+ getMDString(Record[2]), getMDString(Record[3]),
+ getMDOrNull(Record[4]), Record[5],
+ getMDOrNull(Record[6]), Record[7], Record[8],
+ getMDOrNull(Record[9]), getMDOrNull(Record[10]))),
+ 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=229020&r1=229019&r2=229020&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:35:40 2015
@@ -1051,11 +1051,27 @@ static void WriteMDTemplateValueParamete
Record.clear();
}
-static void WriteMDGlobalVariable(const MDGlobalVariable *,
- const ValueEnumerator &, BitstreamWriter &,
- SmallVectorImpl<uint64_t> &, unsigned) {
- llvm_unreachable("write not implemented");
+static void WriteMDGlobalVariable(const MDGlobalVariable *N,
+ const ValueEnumerator &VE,
+ BitstreamWriter &Stream,
+ SmallVectorImpl<uint64_t> &Record,
+ unsigned Abbrev) {
+ Record.push_back(N->isDistinct());
+ Record.push_back(VE.getMetadataOrNullID(N->getScope()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
+ Record.push_back(VE.getMetadataOrNullID(N->getFile()));
+ Record.push_back(N->getLine());
+ Record.push_back(VE.getMetadataOrNullID(N->getType()));
+ Record.push_back(N->isLocalToUnit());
+ Record.push_back(N->isDefinition());
+ Record.push_back(VE.getMetadataOrNullID(N->getVariable()));
+ Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration()));
+
+ Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR, Record, Abbrev);
+ Record.clear();
}
+
static void WriteMDLocalVariable(const MDLocalVariable *,
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=229020&r1=229019&r2=229020&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:35:40 2015
@@ -1711,11 +1711,43 @@ static void writeMDTemplateValueParamete
Out << ")";
}
-static void writeMDGlobalVariable(raw_ostream &, const MDGlobalVariable *,
- TypePrinting *, SlotTracker *,
- const Module *) {
- llvm_unreachable("write not implemented");
+static void writeMDGlobalVariable(raw_ostream &Out, const MDGlobalVariable *N,
+ TypePrinting *TypePrinter,
+ SlotTracker *Machine, const Module *Context) {
+ Out << "!MDGlobalVariable(";
+ FieldSeparator FS;
+ Out << FS << "scope: ";
+ writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context);
+ Out << FS << "name: \"" << N->getName() << "\"";
+ if (!N->getLinkageName().empty())
+ Out << FS << "linkageName: \"" << N->getLinkageName() << "\"";
+ if (N->getFile()) {
+ Out << FS << "file: ";
+ writeMetadataAsOperand(Out, N->getFile(), TypePrinter, Machine,
+ Context);
+ }
+ if (N->getLine())
+ Out << FS << "line: " << N->getLine();
+ if (N->getType()) {
+ Out << FS << "type: ";
+ writeMetadataAsOperand(Out, N->getType(), TypePrinter, Machine,
+ Context);
+ }
+ Out << FS << "isLocal: " << (N->isLocalToUnit() ? "true" : "false");
+ Out << FS << "isDefinition: " << (N->isDefinition() ? "true" : "false");
+ if (N->getVariable()) {
+ Out << FS << "variable: ";
+ writeMetadataAsOperand(Out, N->getVariable(), TypePrinter, Machine,
+ Context);
+ }
+ if (N->getStaticDataMemberDeclaration()) {
+ Out << FS << "declaration: ";
+ writeMetadataAsOperand(Out, N->getStaticDataMemberDeclaration(),
+ TypePrinter, Machine, Context);
+ }
+ Out << ")";
}
+
static void writeMDLocalVariable(raw_ostream &, const MDLocalVariable *,
TypePrinting *, SlotTracker *,
const Module *) {
Added: llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll?rev=229020&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll Thu Feb 12 19:35:40 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:42: error: missing required field 'name'
+!0 = !MDGlobalVariable(linkageName: "foo")
Added: llvm/trunk/test/Assembler/mdglobalvariable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/mdglobalvariable.ll?rev=229020&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/mdglobalvariable.ll (added)
+++ llvm/trunk/test/Assembler/mdglobalvariable.ll Thu Feb 12 19:35:40 2015
@@ -0,0 +1,22 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
+; RUN: verify-uselistorder %s
+
+ at foo = global i32 0
+
+; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6}
+!named = !{!0, !1, !2, !3, !4, !5, !6}
+
+!0 = distinct !{}
+!1 = !{!"path/to/file", !"/path/to/dir"}
+!2 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
+!3 = distinct !{}
+!4 = distinct !{}
+
+; CHECK: !5 = !MDGlobalVariable(scope: !0, name: "foo", linkageName: "foo", file: !1, line: 7, type: !3, isLocal: true, isDefinition: false, variable: i32* @foo, declaration: !4)
+!5 = !MDGlobalVariable(scope: !0, name: "foo", linkageName: "foo",
+ file: !1, line: 7, type: !3, isLocal: true,
+ isDefinition: false, variable: i32* @foo,
+ declaration: !4)
+
+; CHECK: !6 = !MDGlobalVariable(scope: null, name: "bar", isLocal: false, isDefinition: true)
+!6 = !MDGlobalVariable(name: "bar")
More information about the llvm-commits
mailing list