summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-13 01:35:40 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-13 01:35:40 +0000
commitc8f810a017b7ae75760c36dcd5b669d831bf900f (patch)
treeff66edc5388c059bfc9312dcc36b5b7ce2b378dc /llvm
parent2847f3805ebeeb7787323b2b3a6aafa44022a908 (diff)
downloadbcm5719-llvm-c8f810a017b7ae75760c36dcd5b669d831bf900f.tar.gz
bcm5719-llvm-c8f810a017b7ae75760c36dcd5b669d831bf900f.zip
AsmWriter/Bitcode: MDGlobalVariable
llvm-svn: 229020
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Bitcode/LLVMBitCodes.h3
-rw-r--r--llvm/include/llvm/IR/DebugInfoMetadata.h4
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp26
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp14
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp24
-rw-r--r--llvm/lib/IR/AsmWriter.cpp40
-rw-r--r--llvm/test/Assembler/invalid-mdglobalvariable-missing-name.ll4
-rw-r--r--llvm/test/Assembler/mdglobalvariable.ll22
8 files changed, 127 insertions, 10 deletions
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 64d4bf98a5f..492d7c588b3 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -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
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 071f2706eb8..c9b0da9a26d 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -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;
}
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 59e3c0ec8cf..9c557258a4a 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3548,9 +3548,33 @@ bool LLParser::ParseMDTemplateValueParameter(MDNode *&Result, bool IsDistinct) {
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");
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 9731e8c0e03..56855ebb81b 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1525,6 +1525,20 @@ std::error_code BitcodeReader::ParseMetadata() {
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);
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index b1b61e717e6..a86e26cc362 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1051,11 +1051,27 @@ static void WriteMDTemplateValueParameter(const MDTemplateValueParameter *N,
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) {
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 4e7bc8ded0c..b00d52ca744 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1711,11 +1711,43 @@ static void writeMDTemplateValueParameter(raw_ostream &Out,
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 *) {
diff --git a/llvm/test/Assembler/invalid-mdglobalvariable-missing-name.ll b/llvm/test/Assembler/invalid-mdglobalvariable-missing-name.ll
new file mode 100644
index 00000000000..bc0f72434a5
--- /dev/null
+++ b/llvm/test/Assembler/invalid-mdglobalvariable-missing-name.ll
@@ -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")
diff --git a/llvm/test/Assembler/mdglobalvariable.ll b/llvm/test/Assembler/mdglobalvariable.ll
new file mode 100644
index 00000000000..f52eaa710ed
--- /dev/null
+++ b/llvm/test/Assembler/mdglobalvariable.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
+; RUN: verify-uselistorder %s
+
+@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")
OpenPOWER on IntegriCloud