[llvm] r229022 - AsmWriter/Bitcode: MDLocalVariable
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 17:39:44 PST 2015
Author: dexonsmith
Date: Thu Feb 12 19:39:44 2015
New Revision: 229022
URL: http://llvm.org/viewvc/llvm-project?rev=229022&view=rev
Log:
AsmWriter/Bitcode: MDLocalVariable
Added:
llvm/trunk/test/Assembler/invalid-mdlocalvariable-missing-name.ll
llvm/trunk/test/Assembler/mdlocalvariable.ll
Modified:
llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.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/lib/IR/DebugInfoMetadata.cpp
Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=229022&r1=229021&r2=229022&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Feb 12 19:39:44 2015
@@ -162,7 +162,8 @@ namespace bitc {
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_GLOBAL_VAR = 27 // [distinct, ...]
+ METADATA_GLOBAL_VAR = 27, // [distinct, ...]
+ METADATA_LOCAL_VAR = 28 // [distinct, ...]
};
// The constants block (CONSTANTS_BLOCK_ID) describes emission for each
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229022&r1=229021&r2=229022&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Feb 12 19:39:44 2015
@@ -3575,9 +3575,30 @@ bool LLParser::ParseMDGlobalVariable(MDN
return false;
}
+/// ParseMDLocalVariable:
+/// ::= !MDLocalVariable(tag: DW_TAG_arg_variable, scope: !0, name: "foo",
+/// file: !1, line: 7, type: !2, arg: 2, flags: 7,
+/// inlinedAt: !3)
bool LLParser::ParseMDLocalVariable(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ REQUIRED(tag, DwarfTagField, ); \
+ OPTIONAL(scope, MDField, ); \
+ OPTIONAL(name, MDStringField, ); \
+ OPTIONAL(file, MDField, ); \
+ OPTIONAL(line, LineField, ); \
+ OPTIONAL(type, MDField, ); \
+ OPTIONAL(arg, MDUnsignedField, (0, UINT8_MAX)); \
+ OPTIONAL(flags, MDUnsignedField, (0, UINT32_MAX)); \
+ OPTIONAL(inlinedAt, MDField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(
+ MDLocalVariable, (Context, tag.Val, scope.Val, name.Val, file.Val,
+ line.Val, type.Val, arg.Val, flags.Val, inlinedAt.Val));
+ return false;
}
+
bool LLParser::ParseMDExpression(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=229022&r1=229021&r2=229022&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Feb 12 19:39:44 2015
@@ -1539,6 +1539,19 @@ std::error_code BitcodeReader::ParseMeta
NextMDValueNo++);
break;
}
+ case bitc::METADATA_LOCAL_VAR: {
+ if (Record.size() != 10)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDLocalVariable, Record[0],
+ (Context, Record[1], getMDOrNull(Record[2]),
+ getMDString(Record[3]), getMDOrNull(Record[4]),
+ Record[5], getMDOrNull(Record[6]), Record[7],
+ Record[8], getMDOrNull(Record[9]))),
+ 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=229022&r1=229021&r2=229022&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Feb 12 19:39:44 2015
@@ -1072,11 +1072,26 @@ static void WriteMDGlobalVariable(const
Record.clear();
}
-static void WriteMDLocalVariable(const MDLocalVariable *,
- const ValueEnumerator &, BitstreamWriter &,
- SmallVectorImpl<uint64_t> &, unsigned) {
- llvm_unreachable("write not implemented");
+static void WriteMDLocalVariable(const MDLocalVariable *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->getScope()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
+ Record.push_back(VE.getMetadataOrNullID(N->getFile()));
+ Record.push_back(N->getLine());
+ Record.push_back(VE.getMetadataOrNullID(N->getType()));
+ Record.push_back(N->getArg());
+ Record.push_back(N->getFlags());
+ Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
+
+ Stream.EmitRecord(bitc::METADATA_LOCAL_VAR, Record, Abbrev);
+ Record.clear();
}
+
static void WriteMDExpression(const MDExpression *, 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=229022&r1=229021&r2=229022&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Feb 12 19:39:44 2015
@@ -1748,11 +1748,39 @@ static void writeMDGlobalVariable(raw_os
Out << ")";
}
-static void writeMDLocalVariable(raw_ostream &, const MDLocalVariable *,
- TypePrinting *, SlotTracker *,
- const Module *) {
- llvm_unreachable("write not implemented");
+static void writeMDLocalVariable(raw_ostream &Out, const MDLocalVariable *N,
+ TypePrinting *TypePrinter,
+ SlotTracker *Machine, const Module *Context) {
+ Out << "!MDLocalVariable(";
+ FieldSeparator FS;
+ writeTag(Out, FS, N);
+ Out << FS << "scope: ";
+ writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context);
+ Out << FS << "name: \"" << N->getName() << "\"";
+ 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);
+ }
+ if (N->getTag() == dwarf::DW_TAG_arg_variable || N->getArg())
+ Out << FS << "arg: " << N->getArg();
+ if (N->getFlags())
+ Out << FS << "flags: " << N->getFlags();
+ if (N->getInlinedAt()) {
+ Out << FS << "inlinedAt: ";
+ writeMetadataAsOperand(Out, N->getInlinedAt(), TypePrinter, Machine,
+ Context);
+ }
+ Out << ")";
}
+
static void writeMDExpression(raw_ostream &, const MDExpression *,
TypePrinting *, SlotTracker *, const Module *) {
llvm_unreachable("write not implemented");
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=229022&r1=229021&r2=229022&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Thu Feb 12 19:39:44 2015
@@ -336,6 +336,12 @@ MDLocalVariable *MDLocalVariable::getImp
LLVMContext &Context, unsigned Tag, Metadata *Scope, MDString *Name,
Metadata *File, unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags,
Metadata *InlinedAt, StorageType Storage, bool ShouldCreate) {
+ // Truncate Arg to 8 bits.
+ //
+ // FIXME: This is gross (and should be changed to an assert or removed), but
+ // it matches historical behaviour for now.
+ Arg &= (1u << 8) - 1;
+
assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(MDLocalVariable, (Tag, Scope, getString(Name), File,
Line, Type, Arg, Flags, InlinedAt));
Added: llvm/trunk/test/Assembler/invalid-mdlocalvariable-missing-name.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdlocalvariable-missing-name.ll?rev=229022&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdlocalvariable-missing-name.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdlocalvariable-missing-name.ll Thu Feb 12 19:39:44 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:29: error: missing required field 'tag'
+!0 = !MDLocalVariable(arg: 7)
Added: llvm/trunk/test/Assembler/mdlocalvariable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/mdlocalvariable.ll?rev=229022&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/mdlocalvariable.ll (added)
+++ llvm/trunk/test/Assembler/mdlocalvariable.ll Thu Feb 12 19:39:44 2015
@@ -0,0 +1,26 @@
+; 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, !7, !8}
+!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
+
+!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 = !MDLocalVariable(tag: DW_TAG_arg_variable, scope: !0, name: "foo", file: !1, line: 7, type: !3, arg: 3, flags: 8, inlinedAt: !4)
+; CHECK: !6 = !MDLocalVariable(tag: DW_TAG_auto_variable, scope: !0, name: "foo", file: !1, line: 7, type: !3, flags: 8, inlinedAt: !4)
+!5 = !MDLocalVariable(tag: DW_TAG_arg_variable, scope: !0, name: "foo",
+ file: !1, line: 7, type: !3, arg: 3,
+ flags: 8, inlinedAt: !4)
+!6 = !MDLocalVariable(tag: DW_TAG_auto_variable, scope: !0, name: "foo",
+ file: !1, line: 7, type: !3, flags: 8, inlinedAt: !4)
+
+; CHECK: !7 = !MDLocalVariable(tag: DW_TAG_arg_variable, scope: null, name: "", arg: 0)
+; CHECK: !8 = !MDLocalVariable(tag: DW_TAG_auto_variable, scope: null, name: "")
+!7 = !MDLocalVariable(tag: DW_TAG_arg_variable)
+!8 = !MDLocalVariable(tag: DW_TAG_auto_variable)
More information about the llvm-commits
mailing list