AsmWriter/Bitcode: MDLocalVariable

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229022 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-02-13 01:39:44 +00:00
parent f594c2a210
commit a342d827bd
8 changed files with 124 additions and 10 deletions

View File

@ -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

View File

@ -3575,9 +3575,30 @@ bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) {
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");
}

View File

@ -1539,6 +1539,19 @@ std::error_code BitcodeReader::ParseMetadata() {
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);

View File

@ -1072,11 +1072,26 @@ static void WriteMDGlobalVariable(const MDGlobalVariable *N,
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) {

View File

@ -1748,11 +1748,39 @@ static void writeMDGlobalVariable(raw_ostream &Out, const MDGlobalVariable *N,
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");

View File

@ -336,6 +336,12 @@ MDLocalVariable *MDLocalVariable::getImpl(
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));

View File

@ -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)

View File

@ -0,0 +1,26 @@
; 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, !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)