1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[DebugInfoMetadata] Added DIFlags interface in DIBasicType.

Flags in DIBasicType will be used to pass attributes used in
DW_TAG_base_type, such as DW_AT_endianity.

Patch by Chirag Patel!

Differential Revision: https://reviews.llvm.org/D49610

llvm-svn: 339714
This commit is contained in:
Adrian Prantl 2018-08-14 19:35:34 +00:00
parent 1d69232f55
commit d46169a911
16 changed files with 94 additions and 44 deletions

View File

@ -20,7 +20,8 @@
defined HANDLE_DW_LNCT || defined HANDLE_DW_MACRO || \
defined HANDLE_DW_RLE || defined HANDLE_DW_CFA || \
defined HANDLE_DW_APPLE_PROPERTY || defined HANDLE_DW_UT || \
defined HANDLE_DWARF_SECTION || defined HANDLE_DW_IDX)
defined HANDLE_DWARF_SECTION || defined HANDLE_DW_IDX || \
defined HANDLE_DW_END)
#error "Missing macro definition of HANDLE_DW*"
#endif
@ -100,6 +101,10 @@
#define HANDLE_DW_IDX(ID, NAME)
#endif
#ifndef HANDLE_DW_END
#define HANDLE_DW_END(ID, NAME)
#endif
HANDLE_DW_TAG(0x0000, null, 2, DWARF)
HANDLE_DW_TAG(0x0001, array_type, 2, DWARF)
HANDLE_DW_TAG(0x0002, class_type, 2, DWARF)
@ -690,6 +695,11 @@ HANDLE_DW_ATE(0x10, UTF, 4, DWARF)
HANDLE_DW_ATE(0x11, UCS, 5, DWARF)
HANDLE_DW_ATE(0x12, ASCII, 5, DWARF)
// DWARF attribute endianity
HANDLE_DW_END(0x00, default)
HANDLE_DW_END(0x01, big)
HANDLE_DW_END(0x02, little)
// DWARF virtuality codes.
HANDLE_DW_VIRTUALITY(0x00, none)
HANDLE_DW_VIRTUALITY(0x01, virtual)
@ -909,3 +919,4 @@ HANDLE_DW_IDX(0x05, type_hash)
#undef HANDLE_DW_UT
#undef HANDLE_DWARF_SECTION
#undef HANDLE_DW_IDX
#undef HANDLE_DW_END

View File

@ -150,9 +150,8 @@ enum DecimalSignEncoding {
enum EndianityEncoding {
// Endianity attribute values
DW_END_default = 0x00,
DW_END_big = 0x01,
DW_END_little = 0x02,
#define HANDLE_DW_END(ID, NAME) DW_END_##NAME = ID,
#include "llvm/BinaryFormat/Dwarf.def"
DW_END_lo_user = 0x40,
DW_END_hi_user = 0xff
};

View File

@ -188,9 +188,11 @@ namespace llvm {
/// type.
/// \param Name Type name.
/// \param SizeInBits Size of the type.
/// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
/// \param Encoding DWARF encoding code, e.g., dwarf::DW_ATE_float.
/// \param Flags Optional DWARF attributes, e.g., DW_AT_endianity.
DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
unsigned Encoding);
unsigned Encoding,
DINode::DIFlags Flags = DINode::FlagZero);
/// Create debugging information entry for a qualified
/// type, e.g. 'const int'.

View File

@ -48,6 +48,8 @@ HANDLE_DI_FLAG((1 << 23), TypePassByReference)
HANDLE_DI_FLAG((1 << 24), FixedEnum)
HANDLE_DI_FLAG((1 << 25), Thunk)
HANDLE_DI_FLAG((1 << 26), Trivial)
HANDLE_DI_FLAG((1 << 27), BigEndian)
HANDLE_DI_FLAG((1 << 28), LittleEndian)
// To avoid needing a dedicated value for IndirectVirtualBase, we use
// the bitwise or of Virtual and FwdDecl, which does not otherwise
@ -57,7 +59,7 @@ HANDLE_DI_FLAG((1 << 2) | (1 << 5), IndirectVirtualBase)
#ifdef DI_FLAG_LARGEST_NEEDED
// intended to be used with ADT/BitmaskEnum.h
// NOTE: always must be equal to largest flag, check this when adding new flag
HANDLE_DI_FLAG((1 << 26), Largest)
HANDLE_DI_FLAG((1 << 28), Largest)
#undef DI_FLAG_LARGEST_NEEDED
#endif

View File

@ -713,6 +713,8 @@ public:
bool isTypePassByReference() const {
return getFlags() & FlagTypePassByReference;
}
bool isBigEndian() const { return getFlags() & FlagBigEndian; }
bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
static bool classof(const Metadata *MD) {
switch (MD->getMetadataID()) {
@ -739,40 +741,43 @@ class DIBasicType : public DIType {
DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
ArrayRef<Metadata *> Ops)
DIFlags Flags, ArrayRef<Metadata *> Ops)
: DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
FlagZero, Ops),
Flags, Ops),
Encoding(Encoding) {}
~DIBasicType() = default;
static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
StringRef Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding,
StorageType Storage, bool ShouldCreate = true) {
DIFlags Flags, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
SizeInBits, AlignInBits, Encoding, Flags, Storage,
ShouldCreate);
}
static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
MDString *Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding,
StorageType Storage, bool ShouldCreate = true);
DIFlags Flags, StorageType Storage,
bool ShouldCreate = true);
TempDIBasicType cloneImpl() const {
return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
getAlignInBits(), getEncoding());
getAlignInBits(), getEncoding(), getFlags());
}
public:
DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
(Tag, Name, 0, 0, 0))
(Tag, Name, 0, 0, 0, FlagZero))
DEFINE_MDNODE_GET(DIBasicType,
(unsigned Tag, StringRef Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding),
(Tag, Name, SizeInBits, AlignInBits, Encoding))
uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
DEFINE_MDNODE_GET(DIBasicType,
(unsigned Tag, MDString *Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding),
(Tag, Name, SizeInBits, AlignInBits, Encoding))
uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
TempDIBasicType clone() const { return cloneImpl(); }

View File

@ -4281,19 +4281,21 @@ bool LLParser::ParseDIEnumerator(MDNode *&Result, bool IsDistinct) {
}
/// ParseDIBasicType:
/// ::= !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32)
/// ::= !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32,
/// encoding: DW_ATE_encoding, flags: 0)
bool LLParser::ParseDIBasicType(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \
OPTIONAL(name, MDStringField, ); \
OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
OPTIONAL(encoding, DwarfAttEncodingField, );
OPTIONAL(encoding, DwarfAttEncodingField, ); \
OPTIONAL(flags, DIFlagField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS
Result = GET_OR_DISTINCT(DIBasicType, (Context, tag.Val, name.Val, size.Val,
align.Val, encoding.Val));
align.Val, encoding.Val, flags.Val));
return false;
}

View File

@ -1211,14 +1211,17 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_BASIC_TYPE: {
if (Record.size() != 6)
if (Record.size() < 6 || Record.size() > 7)
return error("Invalid record");
IsDistinct = Record[0];
DINode::DIFlags Flags = (Record.size() > 6) ?
static_cast<DINode::DIFlags>(Record[6]) : DINode::FlagZero;
MetadataList.assignValue(
GET_OR_DISTINCT(DIBasicType,
(Context, Record[1], getMDString(Record[2]), Record[3],
Record[4], Record[5])),
Record[4], Record[5], Flags)),
NextMetadataNo);
NextMetadataNo++;
break;

View File

@ -1486,6 +1486,7 @@ void ModuleBitcodeWriter::writeDIBasicType(const DIBasicType *N,
Record.push_back(N->getSizeInBits());
Record.push_back(N->getAlignInBits());
Record.push_back(N->getEncoding());
Record.push_back(N->getFlags());
Stream.EmitRecord(bitc::METADATA_BASIC_TYPE, Record, Abbrev);
Record.clear();

View File

@ -859,6 +859,11 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {
uint64_t Size = BTy->getSizeInBits() >> 3;
addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
if (BTy->isBigEndian())
addUInt(Buffer, dwarf::DW_AT_endianity, None, dwarf::DW_END_big);
else if (BTy->isLittleEndian())
addUInt(Buffer, dwarf::DW_AT_endianity, None, dwarf::DW_END_little);
}
void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {

View File

@ -1787,6 +1787,7 @@ static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N,
Printer.printInt("align", N->getAlignInBits());
Printer.printDwarfEnum("encoding", N->getEncoding(),
dwarf::AttributeEncodingString);
Printer.printDIFlags("flags", N->getFlags());
Out << ")";
}

View File

@ -256,10 +256,11 @@ DIBasicType *DIBuilder::createNullPtrType() {
}
DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
unsigned Encoding) {
unsigned Encoding,
DINode::DIFlags Flags) {
assert(!Name.empty() && "Unable to create type without name");
return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
0, Encoding);
0, Encoding, Flags);
}
DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {

View File

@ -274,13 +274,14 @@ DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
MDString *Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding,
StorageType Storage, bool ShouldCreate) {
DIFlags Flags, StorageType Storage,
bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(DIBasicType,
(Tag, Name, SizeInBits, AlignInBits, Encoding));
(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
Metadata *Ops[] = {nullptr, nullptr, Name};
DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
Ops);
DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,
Flags), Ops);
}
Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {

View File

@ -376,20 +376,22 @@ template <> struct MDNodeKeyImpl<DIBasicType> {
uint64_t SizeInBits;
uint32_t AlignInBits;
unsigned Encoding;
unsigned Flags;
MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding)
uint32_t AlignInBits, unsigned Encoding, unsigned Flags)
: Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
Encoding(Encoding) {}
Encoding(Encoding), Flags(Flags) {}
MDNodeKeyImpl(const DIBasicType *N)
: Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {}
bool isKeyOf(const DIBasicType *RHS) const {
return Tag == RHS->getTag() && Name == RHS->getRawName() &&
SizeInBits == RHS->getSizeInBits() &&
AlignInBits == RHS->getAlignInBits() &&
Encoding == RHS->getEncoding();
Encoding == RHS->getEncoding() &&
Flags == RHS->getFlags();
}
unsigned getHashValue() const {

View File

@ -886,6 +886,8 @@ void Verifier::visitDIBasicType(const DIBasicType &N) {
AssertDI(N.getTag() == dwarf::DW_TAG_base_type ||
N.getTag() == dwarf::DW_TAG_unspecified_type,
"invalid tag", &N);
AssertDI(!(N.isBigEndian() && N.isLittleEndian()) ,
"has conflicting flags", &N);
}
void Verifier::visitDIDerivedType(const DIDerivedType &N) {

View File

@ -1,8 +1,8 @@
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
; RUN: verify-uselistorder %s
; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}
!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37, !38, !39, !40}
; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37, !38, !39}
!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37, !38, !39, !40, !41, !42}
; CHECK: !0 = !DISubrange(count: 3)
; CHECK-NEXT: !1 = !DISubrange(count: 3, lowerBound: 4)
@ -94,3 +94,8 @@
; CHECK-NEXT: !37 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_MD5, checksum: "3a420e2646916a475e68de8d48f779f5", source: "int source() { }\0A")
!39 = !DIFile(filename: "file", directory: "dir", source: "int source() { }\0A")
!40 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_MD5, checksum: "3a420e2646916a475e68de8d48f779f5", source: "int source() { }\0A")
; CHECK-NEXT: !38 = !DIBasicType(name: "u64.be", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagBigEndian)
; CHECK-NEXT: !39 = !DIBasicType(name: "u64.le", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagLittleEndian)
!41 = !DIBasicType(name: "u64.be", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagBigEndian)
!42 = !DIBasicType(name: "u64.le", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagLittleEndian)

View File

@ -997,26 +997,33 @@ typedef MetadataTest DIBasicTypeTest;
TEST_F(DIBasicTypeTest, get) {
auto *N =
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7);
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7,
DINode::FlagZero);
EXPECT_EQ(dwarf::DW_TAG_base_type, N->getTag());
EXPECT_EQ("special", N->getName());
EXPECT_EQ(33u, N->getSizeInBits());
EXPECT_EQ(26u, N->getAlignInBits());
EXPECT_EQ(7u, N->getEncoding());
EXPECT_EQ(0u, N->getLine());
EXPECT_EQ(DINode::FlagZero, N->getFlags());
EXPECT_EQ(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 7));
26, 7, DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type,
"special", 33, 26, 7));
"special", 33, 26, 7, DINode::FlagZero));
EXPECT_NE(N,
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7));
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7,
DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32,
26, 7));
26, 7, DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
25, 7));
25, 7, DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 6));
26, 6, DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 7, DINode::FlagBigEndian));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 7, DINode::FlagLittleEndian));
TempDIBasicType Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
@ -1024,7 +1031,7 @@ TEST_F(DIBasicTypeTest, get) {
TEST_F(DIBasicTypeTest, getWithLargeValues) {
auto *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special",
UINT64_MAX, UINT32_MAX - 1, 7);
UINT64_MAX, UINT32_MAX - 1, 7, DINode::FlagZero);
EXPECT_EQ(UINT64_MAX, N->getSizeInBits());
EXPECT_EQ(UINT32_MAX - 1, N->getAlignInBits());
}
@ -1038,6 +1045,7 @@ TEST_F(DIBasicTypeTest, getUnspecified) {
EXPECT_EQ(0u, N->getAlignInBits());
EXPECT_EQ(0u, N->getEncoding());
EXPECT_EQ(0u, N->getLine());
EXPECT_EQ(DINode::FlagZero, N->getFlags());
}
typedef MetadataTest DITypeTest;
@ -1045,7 +1053,7 @@ typedef MetadataTest DITypeTest;
TEST_F(DITypeTest, clone) {
// Check that DIType has a specialized clone that returns TempDIType.
DIType *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32,
dwarf::DW_ATE_signed);
dwarf::DW_ATE_signed, DINode::FlagZero);
TempDIType Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));