Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
IR: Drop scope from MDTemplateParameter
Browse files Browse the repository at this point in the history
Follow-up to r229740, which removed `DITemplate*::getContext()` after my
upgrade script revealed that scopes are always `nullptr` for template
parameters.  This is the other shoe: drop `scope:` from
`MDTemplateParameter` and its two subclasses.  (Note: a bitcode upgrade
would be pointless, since the hierarchy hasn't been moved into place.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229791 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Feb 19, 2015
1 parent a3fa104 commit eac950e
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 147 deletions.
72 changes: 29 additions & 43 deletions include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,6 @@ class MDNamespace : public MDScope {
};

/// \brief Base class for template parameters.
///
/// TODO: Remove the scope. It's always the compile unit, and never
/// referenced.
/// TODO: Remove File, Line and Column. They're always 0 and never
/// referenced.
class MDTemplateParameter : public DebugNode {
protected:
MDTemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
Expand All @@ -1169,11 +1164,10 @@ class MDTemplateParameter : public DebugNode {
~MDTemplateParameter() {}

public:
Metadata *getScope() const { return getOperand(0); }
StringRef getName() const { return getStringOperand(1); }
Metadata *getType() const { return getOperand(2); }
StringRef getName() const { return getStringOperand(0); }
Metadata *getType() const { return getOperand(1); }

MDString *getRawName() const { return getOperandAs<MDString>(1); }
MDString *getRawName() const { return getOperandAs<MDString>(0); }

static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDTemplateTypeParameterKind ||
Expand All @@ -1191,29 +1185,25 @@ class MDTemplateTypeParameter : public MDTemplateParameter {
dwarf::DW_TAG_template_type_parameter, Ops) {}
~MDTemplateTypeParameter() {}

static MDTemplateTypeParameter *getImpl(LLVMContext &Context, Metadata *Scope,
StringRef Name, Metadata *Type,
StorageType Storage,
static MDTemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
Metadata *Type, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name), Type,
Storage, ShouldCreate);
return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
ShouldCreate);
}
static MDTemplateTypeParameter *getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, Metadata *Type,
StorageType Storage,
static MDTemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
Metadata *Type, StorageType Storage,
bool ShouldCreate = true);

TempMDTemplateTypeParameter cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(), getType());
return getTemporary(getContext(), getName(), getType());
}

public:
DEFINE_MDNODE_GET(MDTemplateTypeParameter,
(Metadata * Scope, StringRef Name, Metadata *Type),
(Scope, Name, Type))
DEFINE_MDNODE_GET(MDTemplateTypeParameter,
(Metadata * Scope, MDString *Name, Metadata *Type),
(Scope, Name, Type))
DEFINE_MDNODE_GET(MDTemplateTypeParameter, (StringRef Name, Metadata *Type),
(Name, Type))
DEFINE_MDNODE_GET(MDTemplateTypeParameter, (MDString * Name, Metadata *Type),
(Name, Type))

TempMDTemplateTypeParameter clone() const { return cloneImpl(); }

Expand All @@ -1233,37 +1223,33 @@ class MDTemplateValueParameter : public MDTemplateParameter {
~MDTemplateValueParameter() {}

static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
Metadata *Scope, StringRef Name,
Metadata *Type, Metadata *Value,
StorageType Storage,
StringRef Name, Metadata *Type,
Metadata *Value, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
Type, Value, Storage, ShouldCreate);
return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
Value, Storage, ShouldCreate);
}
static MDTemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
Metadata *Scope, MDString *Name,
Metadata *Type, Metadata *Value,
StorageType Storage,
MDString *Name, Metadata *Type,
Metadata *Value, StorageType Storage,
bool ShouldCreate = true);

TempMDTemplateValueParameter cloneImpl() const {
return getTemporary(getContext(), getTag(), getScope(), getName(),
getType(), getValue());
return getTemporary(getContext(), getTag(), getName(), getType(),
getValue());
}

public:
DEFINE_MDNODE_GET(MDTemplateValueParameter,
(unsigned Tag, Metadata *Scope, StringRef Name,
Metadata *Type, Metadata *Value),
(Tag, Scope, Name, Type, Value))
DEFINE_MDNODE_GET(MDTemplateValueParameter,
(unsigned Tag, Metadata *Scope, MDString *Name,
Metadata *Type, Metadata *Value),
(Tag, Scope, Name, Type, Value))
DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, StringRef Name,
Metadata *Type, Metadata *Value),
(Tag, Name, Type, Value))
DEFINE_MDNODE_GET(MDTemplateValueParameter, (unsigned Tag, MDString *Name,
Metadata *Type, Metadata *Value),
(Tag, Name, Type, Value))

TempMDTemplateValueParameter clone() const { return cloneImpl(); }

Metadata *getValue() const { return getOperand(3); }
Metadata *getValue() const { return getOperand(2); }

static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDTemplateValueParameterKind;
Expand Down
16 changes: 6 additions & 10 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3515,37 +3515,33 @@ bool LLParser::ParseMDNamespace(MDNode *&Result, bool IsDistinct) {
}

/// ParseMDTemplateTypeParameter:
/// ::= !MDTemplateTypeParameter(scope: !0, name: "Ty", type: !1)
/// ::= !MDTemplateTypeParameter(name: "Ty", type: !1)
bool LLParser::ParseMDTemplateTypeParameter(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(scope, MDField, ); \
OPTIONAL(name, MDStringField, ); \
REQUIRED(type, MDField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS

Result = GET_OR_DISTINCT(MDTemplateTypeParameter,
(Context, scope.Val, name.Val, type.Val));
Result =
GET_OR_DISTINCT(MDTemplateTypeParameter, (Context, name.Val, type.Val));
return false;
}

/// ParseMDTemplateValueParameter:
/// ::= !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter,
/// scope: !0, name: "V", type: !1,
/// value: i32 7)
/// name: "V", type: !1, value: i32 7)
bool LLParser::ParseMDTemplateValueParameter(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(tag, DwarfTagField, ); \
REQUIRED(scope, MDField, ); \
OPTIONAL(name, MDStringField, ); \
REQUIRED(type, MDField, ); \
REQUIRED(value, MDField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS

Result = GET_OR_DISTINCT(
MDTemplateValueParameter,
(Context, tag.Val, scope.Val, name.Val, type.Val, value.Val));
Result = GET_OR_DISTINCT(MDTemplateValueParameter,
(Context, tag.Val, name.Val, type.Val, value.Val));
return false;
}

Expand Down
19 changes: 9 additions & 10 deletions lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,25 +1515,24 @@ std::error_code BitcodeReader::ParseMetadata() {
break;
}
case bitc::METADATA_TEMPLATE_TYPE: {
if (Record.size() != 4)
if (Record.size() != 3)
return Error("Invalid record");

MDValueList.AssignValue(
GET_OR_DISTINCT(MDTemplateTypeParameter, Record[0],
(Context, getMDOrNull(Record[1]),
getMDString(Record[2]), getMDOrNull(Record[3]))),
NextMDValueNo++);
MDValueList.AssignValue(GET_OR_DISTINCT(MDTemplateTypeParameter,
Record[0],
(Context, getMDString(Record[1]),
getMDOrNull(Record[2]))),
NextMDValueNo++);
break;
}
case bitc::METADATA_TEMPLATE_VALUE: {
if (Record.size() != 6)
if (Record.size() != 5)
return Error("Invalid record");

MDValueList.AssignValue(
GET_OR_DISTINCT(MDTemplateValueParameter, Record[0],
(Context, Record[1], getMDOrNull(Record[2]),
getMDString(Record[3]), getMDOrNull(Record[4]),
getMDOrNull(Record[5]))),
(Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), getMDOrNull(Record[4]))),
NextMDValueNo++);
break;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ static void WriteMDTemplateTypeParameter(const MDTemplateTypeParameter *N,
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->getType()));

Expand All @@ -1042,7 +1041,6 @@ static void WriteMDTemplateValueParameter(const MDTemplateValueParameter *N,
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->getType()));
Record.push_back(VE.getMetadataOrNullID(N->getValue()));
Expand Down
4 changes: 0 additions & 4 deletions lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,8 +1685,6 @@ static void writeMDTemplateTypeParameter(raw_ostream &Out,
const Module *Context) {
Out << "!MDTemplateTypeParameter(";
FieldSeparator FS;
Out << FS << "scope: ";
writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context);
Out << FS << "name: \"" << N->getName() << "\"";
Out << FS << "type: ";
writeMetadataAsOperand(Out, N->getType(), TypePrinter, Machine, Context);
Expand All @@ -1701,8 +1699,6 @@ static void writeMDTemplateValueParameter(raw_ostream &Out,
Out << "!MDTemplateValueParameter(";
FieldSeparator FS;
writeTag(Out, FS, N);
Out << FS << "scope: ";
writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context);
Out << FS << "name: \"" << N->getName() << "\"";
Out << FS << "type: ";
writeMetadataAsOperand(Out, N->getType(), TypePrinter, Machine, Context);
Expand Down
22 changes: 11 additions & 11 deletions lib/IR/DebugInfoMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,24 +298,24 @@ MDNamespace *MDNamespace::getImpl(LLVMContext &Context, Metadata *Scope,
DEFINE_GETIMPL_STORE(MDNamespace, (Line), Ops);
}

MDTemplateTypeParameter *
MDTemplateTypeParameter::getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, Metadata *Type,
StorageType Storage, bool ShouldCreate) {
MDTemplateTypeParameter *MDTemplateTypeParameter::getImpl(LLVMContext &Context,
MDString *Name,
Metadata *Type,
StorageType Storage,
bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(MDTemplateTypeParameter,
(Scope, getString(Name), Type));
Metadata *Ops[] = {Scope, Name, Type};
DEFINE_GETIMPL_LOOKUP(MDTemplateTypeParameter, (getString(Name), Type));
Metadata *Ops[] = {Name, Type};
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(MDTemplateTypeParameter, Ops);
}

MDTemplateValueParameter *MDTemplateValueParameter::getImpl(
LLVMContext &Context, unsigned Tag, Metadata *Scope, MDString *Name,
Metadata *Type, Metadata *Value, StorageType Storage, bool ShouldCreate) {
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
Metadata *Value, StorageType Storage, bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(MDTemplateValueParameter,
(Tag, Scope, getString(Name), Type, Value));
Metadata *Ops[] = {Scope, Name, Type, Value};
(Tag, getString(Name), Type, Value));
Metadata *Ops[] = {Name, Type, Value};
DEFINE_GETIMPL_STORE(MDTemplateValueParameter, (Tag), Ops);
}

Expand Down
30 changes: 11 additions & 19 deletions lib/IR/LLVMContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,44 +646,36 @@ template <> struct MDNodeKeyImpl<MDNamespace> {
};

template <> struct MDNodeKeyImpl<MDTemplateTypeParameter> {
Metadata *Scope;
StringRef Name;
Metadata *Type;

MDNodeKeyImpl(Metadata *Scope, StringRef Name, Metadata *Type)
: Scope(Scope), Name(Name), Type(Type) {}
MDNodeKeyImpl(StringRef Name, Metadata *Type) : Name(Name), Type(Type) {}
MDNodeKeyImpl(const MDTemplateTypeParameter *N)
: Scope(N->getScope()), Name(N->getName()), Type(N->getType()) {}
: Name(N->getName()), Type(N->getType()) {}

bool isKeyOf(const MDTemplateTypeParameter *RHS) const {
return Scope == RHS->getScope() && Name == RHS->getName() &&
Type == RHS->getType();
return Name == RHS->getName() && Type == RHS->getType();
}
unsigned getHashValue() const { return hash_combine(Scope, Name, Type); }
unsigned getHashValue() const { return hash_combine(Name, Type); }
};

template <> struct MDNodeKeyImpl<MDTemplateValueParameter> {
unsigned Tag;
Metadata *Scope;
StringRef Name;
Metadata *Type;
Metadata *Value;

MDNodeKeyImpl(unsigned Tag, Metadata *Scope, StringRef Name, Metadata *Type,
Metadata *Value)
: Tag(Tag), Scope(Scope), Name(Name), Type(Type), Value(Value) {}
MDNodeKeyImpl(unsigned Tag, StringRef Name, Metadata *Type, Metadata *Value)
: Tag(Tag), Name(Name), Type(Type), Value(Value) {}
MDNodeKeyImpl(const MDTemplateValueParameter *N)
: Tag(N->getTag()), Scope(N->getScope()), Name(N->getName()),
Type(N->getType()), Value(N->getValue()) {}
: Tag(N->getTag()), Name(N->getName()), Type(N->getType()),
Value(N->getValue()) {}

bool isKeyOf(const MDTemplateValueParameter *RHS) const {
return Tag == RHS->getTag() && Scope == RHS->getScope() &&
Name == RHS->getName() && Type == RHS->getType() &&
Value == RHS->getValue();
}
unsigned getHashValue() const {
return hash_combine(Tag, Scope, Name, Type, Value);
return Tag == RHS->getTag() && Name == RHS->getName() &&
Type == RHS->getType() && Value == RHS->getValue();
}
unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
};

template <> struct MDNodeKeyImpl<MDGlobalVariable> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s

; CHECK: [[@LINE+1]]:41: error: missing required field 'type'
!0 = !MDTemplateTypeParameter(scope: !{})
; CHECK: [[@LINE+1]]:44: error: missing required field 'type'
!0 = !MDTemplateTypeParameter(name: "param")

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s

; CHECK: [[@LINE+1]]:67: error: missing required field 'tag'
!0 = !MDTemplateValueParameter(scope: !{}, type: !{}, value: i32 7)
; CHECK: [[@LINE+1]]:55: error: missing required field 'tag'
!0 = !MDTemplateValueParameter(type: !{}, value: i32 7)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s

; CHECK: [[@LINE+2]]:56: error: missing required field 'type'
; CHECK: [[@LINE+2]]:44: error: missing required field 'type'
!0 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter,
scope: !{}, value: i32 7)
value: i32 7)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s

; CHECK: [[@LINE+2]]:53: error: missing required field 'value'
; CHECK: [[@LINE+2]]:41: error: missing required field 'value'
!0 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter,
scope: !{}, type: !{})
type: !{})
20 changes: 10 additions & 10 deletions test/Assembler/mdtemplateparameter.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
!1 = distinct !{}
; CHECK: !1 = distinct !{}

; CHECK-NEXT: !2 = !MDTemplateTypeParameter(scope: !0, name: "Ty", type: !1)
; CHECK-NEXT: !3 = !MDTemplateTypeParameter(scope: !0, name: "", type: !1)
!2 = !MDTemplateTypeParameter(scope: !0, name: "Ty", type: !1)
!3 = !MDTemplateTypeParameter(scope: !0, type: !1)
!4 = !MDTemplateTypeParameter(scope: !0, name: "", type: !1)
; CHECK-NEXT: !2 = !MDTemplateTypeParameter(name: "Ty", type: !1)
; CHECK-NEXT: !3 = !MDTemplateTypeParameter(name: "", type: !1)
!2 = !MDTemplateTypeParameter(name: "Ty", type: !1)
!3 = !MDTemplateTypeParameter(type: !1)
!4 = !MDTemplateTypeParameter(name: "", type: !1)

; CHECK-NEXT: !4 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter, scope: !0, name: "V", type: !1, value: i32 7)
; CHECK-NEXT: !5 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter, scope: !0, name: "", type: !1, value: i32 7)
; CHECK-NEXT: !4 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter, name: "V", type: !1, value: i32 7)
; CHECK-NEXT: !5 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter, name: "", type: !1, value: i32 7)
!5 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter,
scope: !0, name: "V", type: !1, value: i32 7)
name: "V", type: !1, value: i32 7)
!6 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter,
scope: !0, type: !1, value: i32 7)
type: !1, value: i32 7)
!7 = !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter,
scope: !0, name: "", type: !1, value: i32 7)
name: "", type: !1, value: i32 7)
Loading

0 comments on commit eac950e

Please sign in to comment.