2015-05-27 18:44:32 +00:00
|
|
|
//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the debug info Metadata classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "LLVMContextImpl.h"
|
|
|
|
#include "MetadataImpl.h"
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
|
|
|
|
unsigned Column, ArrayRef<Metadata *> MDs)
|
|
|
|
: MDNode(C, DILocationKind, Storage, MDs) {
|
|
|
|
assert((MDs.size() == 1 || MDs.size() == 2) &&
|
|
|
|
"Expected a scope and optional inlined-at");
|
|
|
|
|
|
|
|
// Set line and column.
|
|
|
|
assert(Column < (1u << 16) && "Expected 16-bit column");
|
|
|
|
|
|
|
|
SubclassData32 = Line;
|
|
|
|
SubclassData16 = Column;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adjustColumn(unsigned &Column) {
|
|
|
|
// Set to unknown on overflow. We only have 16 bits to play with here.
|
|
|
|
if (Column >= (1u << 16))
|
|
|
|
Column = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
|
|
|
|
unsigned Column, Metadata *Scope,
|
|
|
|
Metadata *InlinedAt, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
// Fixup column.
|
|
|
|
adjustColumn(Column);
|
|
|
|
|
|
|
|
if (Storage == Uniqued) {
|
|
|
|
if (auto *N =
|
|
|
|
getUniqued(Context.pImpl->DILocations,
|
|
|
|
DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
|
|
|
|
return N;
|
|
|
|
if (!ShouldCreate)
|
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<Metadata *, 2> Ops;
|
|
|
|
Ops.push_back(Scope);
|
|
|
|
if (InlinedAt)
|
|
|
|
Ops.push_back(InlinedAt);
|
|
|
|
return storeImpl(new (Ops.size())
|
|
|
|
DILocation(Context, Storage, Line, Column, Ops),
|
|
|
|
Storage, Context.pImpl->DILocations);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned DINode::getFlag(StringRef Flag) {
|
|
|
|
return StringSwitch<unsigned>(Flag)
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
.Default(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *DINode::getFlagString(unsigned Flag) {
|
|
|
|
switch (Flag) {
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
|
|
|
case Flag##NAME: \
|
|
|
|
return "DIFlag" #NAME;
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned DINode::splitFlags(unsigned Flags,
|
|
|
|
SmallVectorImpl<unsigned> &SplitFlags) {
|
2016-07-23 20:41:05 +00:00
|
|
|
// Accessibility and member pointer flags need to be specially handled, since
|
|
|
|
// they're packed together.
|
2015-05-27 18:44:32 +00:00
|
|
|
if (unsigned A = Flags & FlagAccessibility) {
|
|
|
|
if (A == FlagPrivate)
|
|
|
|
SplitFlags.push_back(FlagPrivate);
|
|
|
|
else if (A == FlagProtected)
|
|
|
|
SplitFlags.push_back(FlagProtected);
|
|
|
|
else
|
|
|
|
SplitFlags.push_back(FlagPublic);
|
|
|
|
Flags &= ~A;
|
|
|
|
}
|
2016-07-23 20:41:05 +00:00
|
|
|
if (unsigned R = Flags & FlagPtrToMemberRep) {
|
|
|
|
if (R == FlagSingleInheritance)
|
|
|
|
SplitFlags.push_back(FlagSingleInheritance);
|
|
|
|
else if (R == FlagMultipleInheritance)
|
|
|
|
SplitFlags.push_back(FlagMultipleInheritance);
|
|
|
|
else
|
|
|
|
SplitFlags.push_back(FlagVirtualInheritance);
|
|
|
|
Flags &= ~R;
|
|
|
|
}
|
2015-05-27 18:44:32 +00:00
|
|
|
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
|
|
|
if (unsigned Bit = Flags & ID) { \
|
|
|
|
SplitFlags.push_back(Bit); \
|
|
|
|
Flags &= ~Bit; \
|
|
|
|
}
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
|
|
|
|
return Flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIScopeRef DIScope::getScope() const {
|
|
|
|
if (auto *T = dyn_cast<DIType>(this))
|
|
|
|
return T->getScope();
|
|
|
|
|
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(this))
|
|
|
|
return SP->getScope();
|
|
|
|
|
|
|
|
if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
|
2016-07-23 20:41:05 +00:00
|
|
|
return LB->getScope();
|
2015-05-27 18:44:32 +00:00
|
|
|
|
|
|
|
if (auto *NS = dyn_cast<DINamespace>(this))
|
2016-07-23 20:41:05 +00:00
|
|
|
return NS->getScope();
|
2015-05-27 18:44:32 +00:00
|
|
|
|
2015-07-05 14:21:36 +00:00
|
|
|
if (auto *M = dyn_cast<DIModule>(this))
|
2016-07-23 20:41:05 +00:00
|
|
|
return M->getScope();
|
2015-07-05 14:21:36 +00:00
|
|
|
|
2015-05-27 18:44:32 +00:00
|
|
|
assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
|
|
|
|
"Unhandled type of scope.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef DIScope::getName() const {
|
|
|
|
if (auto *T = dyn_cast<DIType>(this))
|
|
|
|
return T->getName();
|
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(this))
|
|
|
|
return SP->getName();
|
|
|
|
if (auto *NS = dyn_cast<DINamespace>(this))
|
|
|
|
return NS->getName();
|
2015-07-05 14:21:36 +00:00
|
|
|
if (auto *M = dyn_cast<DIModule>(this))
|
|
|
|
return M->getName();
|
2015-05-27 18:44:32 +00:00
|
|
|
assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
|
|
|
|
isa<DICompileUnit>(this)) &&
|
|
|
|
"Unhandled type of scope.");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
static bool isCanonical(const MDString *S) {
|
|
|
|
return !S || !S->getString().empty();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
|
|
|
|
MDString *Header,
|
|
|
|
ArrayRef<Metadata *> DwarfOps,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
unsigned Hash = 0;
|
|
|
|
if (Storage == Uniqued) {
|
2016-07-23 20:41:05 +00:00
|
|
|
GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
|
2015-05-27 18:44:32 +00:00
|
|
|
if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
|
|
|
|
return N;
|
|
|
|
if (!ShouldCreate)
|
|
|
|
return nullptr;
|
|
|
|
Hash = Key.getHash();
|
|
|
|
} else {
|
|
|
|
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use a nullptr for empty headers.
|
|
|
|
assert(isCanonical(Header) && "Expected canonical MDString");
|
|
|
|
Metadata *PreOps[] = {Header};
|
|
|
|
return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
|
|
|
|
Context, Storage, Hash, Tag, PreOps, DwarfOps),
|
|
|
|
Storage, Context.pImpl->GenericDINodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericDINode::recalculateHash() {
|
|
|
|
setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
|
|
|
|
#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
|
|
|
|
#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
|
|
|
|
do { \
|
|
|
|
if (Storage == Uniqued) { \
|
|
|
|
if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
|
|
|
|
CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
|
|
|
|
return N; \
|
|
|
|
if (!ShouldCreate) \
|
|
|
|
return nullptr; \
|
|
|
|
} else { \
|
|
|
|
assert(ShouldCreate && \
|
|
|
|
"Expected non-uniqued nodes to always be created"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
|
2016-07-23 20:41:05 +00:00
|
|
|
return storeImpl(new (array_lengthof(OPS)) \
|
2015-05-27 18:44:32 +00:00
|
|
|
CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
|
|
|
|
Storage, Context.pImpl->CLASS##s)
|
|
|
|
#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
|
|
|
|
return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
|
|
|
|
Storage, Context.pImpl->CLASS##s)
|
|
|
|
#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
|
2016-07-23 20:41:05 +00:00
|
|
|
return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
|
2015-05-27 18:44:32 +00:00
|
|
|
Storage, Context.pImpl->CLASS##s)
|
|
|
|
|
|
|
|
DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo));
|
|
|
|
DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo));
|
|
|
|
}
|
|
|
|
|
|
|
|
DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
|
|
|
|
MDString *Name, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, Name));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {Name};
|
|
|
|
DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
|
|
|
|
MDString *Name, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, unsigned Encoding,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIBasicType,
|
|
|
|
(Tag, Name, SizeInBits, AlignInBits, Encoding));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {nullptr, nullptr, Name};
|
|
|
|
DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIDerivedType *DIDerivedType::getImpl(
|
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
|
|
|
|
unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
|
|
|
|
Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIDerivedType,
|
|
|
|
(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags, ExtraData));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
|
|
|
|
DEFINE_GETIMPL_STORE(
|
|
|
|
DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DICompositeType *DICompositeType::getImpl(
|
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
|
|
|
|
unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
|
|
|
|
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
|
|
|
|
Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
|
|
|
|
// Keep this in sync with buildODRType.
|
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
|
|
|
DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
|
|
|
|
VTableHolder, TemplateParams, Identifier));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType,
|
|
|
|
Elements, VTableHolder, TemplateParams, Identifier};
|
|
|
|
DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
DICompositeType *DICompositeType::buildODRType(
|
|
|
|
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
|
|
|
|
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
|
|
|
|
unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
|
|
|
|
Metadata *VTableHolder, Metadata *TemplateParams) {
|
|
|
|
assert(!Identifier.getString().empty() && "Expected valid identifier");
|
|
|
|
if (!Context.isODRUniquingDebugTypes())
|
|
|
|
return nullptr;
|
|
|
|
auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
|
|
|
|
if (!CT)
|
|
|
|
return CT = DICompositeType::getDistinct(
|
|
|
|
Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
|
|
|
|
VTableHolder, TemplateParams, &Identifier);
|
|
|
|
|
|
|
|
// Only mutate CT if it's a forward declaration and the new operands aren't.
|
|
|
|
assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
|
|
|
|
if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
|
|
|
|
return CT;
|
|
|
|
|
|
|
|
// Mutate CT in place. Keep this in sync with getImpl.
|
|
|
|
CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
Flags);
|
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType,
|
|
|
|
Elements, VTableHolder, TemplateParams, &Identifier};
|
|
|
|
assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
|
|
|
|
"Mismatched number of operands");
|
|
|
|
for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
|
|
|
|
if (Ops[I] != CT->getOperand(I))
|
|
|
|
CT->setOperand(I, Ops[I]);
|
|
|
|
return CT;
|
|
|
|
}
|
|
|
|
|
|
|
|
DICompositeType *DICompositeType::getODRType(
|
|
|
|
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
|
|
|
|
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
|
|
|
|
unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
|
|
|
|
Metadata *VTableHolder, Metadata *TemplateParams) {
|
|
|
|
assert(!Identifier.getString().empty() && "Expected valid identifier");
|
|
|
|
if (!Context.isODRUniquingDebugTypes())
|
|
|
|
return nullptr;
|
|
|
|
auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
|
|
|
|
if (!CT)
|
|
|
|
CT = DICompositeType::getDistinct(
|
|
|
|
Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
|
|
|
|
TemplateParams, &Identifier);
|
|
|
|
return CT;
|
|
|
|
}
|
|
|
|
|
|
|
|
DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
|
|
|
|
MDString &Identifier) {
|
|
|
|
assert(!Identifier.getString().empty() && "Expected valid identifier");
|
|
|
|
if (!Context.isODRUniquingDebugTypes())
|
|
|
|
return nullptr;
|
|
|
|
return Context.pImpl->DITypeMap->lookup(&Identifier);
|
|
|
|
}
|
|
|
|
|
2015-05-27 18:44:32 +00:00
|
|
|
DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context,
|
2016-07-23 20:41:05 +00:00
|
|
|
unsigned Flags, uint8_t CC,
|
|
|
|
Metadata *TypeArray,
|
2015-05-27 18:44:32 +00:00
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
|
2015-12-30 11:46:15 +00:00
|
|
|
Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
|
2015-05-27 18:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
|
|
|
|
MDString *Directory, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Filename) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(Directory) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {Filename, Directory};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIFile, Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DICompileUnit *DICompileUnit::getImpl(
|
|
|
|
LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
|
|
|
|
MDString *Producer, bool IsOptimized, MDString *Flags,
|
|
|
|
unsigned RuntimeVersion, MDString *SplitDebugFilename,
|
|
|
|
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
|
2016-07-23 20:41:05 +00:00
|
|
|
Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
|
|
|
|
uint64_t DWOId, StorageType Storage, bool ShouldCreate) {
|
2015-12-30 11:46:15 +00:00
|
|
|
assert(Storage != Uniqued && "Cannot unique DICompileUnit");
|
2015-05-27 18:44:32 +00:00
|
|
|
assert(isCanonical(Producer) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(Flags) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
|
2015-12-30 11:46:15 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
Metadata *Ops[] = {
|
|
|
|
File, Producer, Flags, SplitDebugFilename,
|
|
|
|
EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
|
|
|
|
Macros};
|
|
|
|
return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
|
2015-12-30 11:46:15 +00:00
|
|
|
Context, Storage, SourceLanguage, IsOptimized,
|
|
|
|
RuntimeVersion, EmissionKind, DWOId, Ops),
|
|
|
|
Storage);
|
2015-05-27 18:44:32 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
Optional<DICompileUnit::DebugEmissionKind>
|
|
|
|
DICompileUnit::getEmissionKind(StringRef Str) {
|
|
|
|
return StringSwitch<Optional<DebugEmissionKind>>(Str)
|
|
|
|
.Case("NoDebug", NoDebug)
|
|
|
|
.Case("FullDebug", FullDebug)
|
|
|
|
.Case("LineTablesOnly", LineTablesOnly)
|
|
|
|
.Default(None);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *DICompileUnit::EmissionKindString(DebugEmissionKind EK) {
|
|
|
|
switch (EK) {
|
|
|
|
case NoDebug: return "NoDebug";
|
|
|
|
case FullDebug: return "FullDebug";
|
|
|
|
case LineTablesOnly: return "LineTablesOnly";
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-27 18:44:32 +00:00
|
|
|
DISubprogram *DILocalScope::getSubprogram() const {
|
|
|
|
if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
|
|
|
|
return Block->getScope()->getSubprogram();
|
|
|
|
return const_cast<DISubprogram *>(cast<DISubprogram>(this));
|
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
|
|
|
|
if (auto *File = dyn_cast<DILexicalBlockFile>(this))
|
|
|
|
return File->getScope()->getNonLexicalBlockFileScope();
|
|
|
|
return const_cast<DILocalScope *>(this);
|
|
|
|
}
|
|
|
|
|
2015-05-27 18:44:32 +00:00
|
|
|
DISubprogram *DISubprogram::getImpl(
|
|
|
|
LLVMContext &Context, Metadata *Scope, MDString *Name,
|
|
|
|
MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
|
|
|
|
bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
|
|
|
|
Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
|
2016-07-23 20:41:05 +00:00
|
|
|
int ThisAdjustment, unsigned Flags, bool IsOptimized, Metadata *Unit,
|
|
|
|
Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-05-27 18:44:32 +00:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(LinkageName) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
|
|
|
DISubprogram,
|
|
|
|
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
|
|
|
|
ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment,
|
|
|
|
Flags, IsOptimized, Unit, TemplateParams, Declaration, Variables));
|
|
|
|
Metadata *Ops[] = {File, Scope, Name, Name,
|
|
|
|
LinkageName, Type, ContainingType, Unit,
|
|
|
|
TemplateParams, Declaration, Variables};
|
|
|
|
DEFINE_GETIMPL_STORE(DISubprogram, (Line, ScopeLine, Virtuality, VirtualIndex,
|
|
|
|
ThisAdjustment, Flags, IsLocalToUnit,
|
|
|
|
IsDefinition, IsOptimized),
|
2015-05-27 18:44:32 +00:00
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DISubprogram::describes(const Function *F) const {
|
|
|
|
assert(F && "Invalid function");
|
2015-12-30 11:46:15 +00:00
|
|
|
if (F->getSubprogram() == this)
|
2015-05-27 18:44:32 +00:00
|
|
|
return true;
|
|
|
|
StringRef Name = getLinkageName();
|
|
|
|
if (Name.empty())
|
|
|
|
Name = getName();
|
|
|
|
return F->getName() == Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
Metadata *File, unsigned Line,
|
|
|
|
unsigned Column, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-12-30 11:46:15 +00:00
|
|
|
// Fixup column.
|
|
|
|
adjustColumn(Column);
|
|
|
|
|
2015-05-27 18:44:32 +00:00
|
|
|
assert(Scope && "Expected scope");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
|
|
|
|
Metadata *Ops[] = {File, Scope};
|
|
|
|
DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
|
|
|
|
Metadata *Scope, Metadata *File,
|
|
|
|
unsigned Discriminator,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(Scope && "Expected scope");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
|
|
|
|
Metadata *Ops[] = {File, Scope};
|
|
|
|
DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
Metadata *File, MDString *Name, unsigned Line,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, Name, Line));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {File, Scope, Name};
|
|
|
|
DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops);
|
|
|
|
}
|
|
|
|
|
2015-07-05 14:21:36 +00:00
|
|
|
DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
MDString *Name, MDString *ConfigurationMacros,
|
|
|
|
MDString *IncludePath, MDString *ISysRoot,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
|
|
|
DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
|
2015-07-05 14:21:36 +00:00
|
|
|
Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
|
|
|
|
}
|
|
|
|
|
2015-05-27 18:44:32 +00:00
|
|
|
DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
|
|
|
|
MDString *Name,
|
|
|
|
Metadata *Type,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {Name, Type};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DITemplateValueParameter *DITemplateValueParameter::getImpl(
|
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
|
|
|
|
Metadata *Value, StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {Name, Type, Value};
|
|
|
|
DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIGlobalVariable *
|
|
|
|
DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
|
|
|
|
MDString *LinkageName, Metadata *File, unsigned Line,
|
|
|
|
Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
|
|
|
|
Metadata *Variable,
|
|
|
|
Metadata *StaticDataMemberDeclaration,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(LinkageName) && "Expected canonical MDString");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
|
2016-07-23 20:41:05 +00:00
|
|
|
(Scope, Name, LinkageName, File, Line, Type,
|
|
|
|
IsLocalToUnit, IsDefinition, Variable,
|
2015-05-27 18:44:32 +00:00
|
|
|
StaticDataMemberDeclaration));
|
|
|
|
Metadata *Ops[] = {Scope, Name, File, Type,
|
|
|
|
Name, LinkageName, Variable, StaticDataMemberDeclaration};
|
|
|
|
DEFINE_GETIMPL_STORE(DIGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
MDString *Name, Metadata *File,
|
|
|
|
unsigned Line, Metadata *Type,
|
|
|
|
unsigned Arg, unsigned Flags,
|
|
|
|
StorageType Storage,
|
2015-05-27 18:44:32 +00:00
|
|
|
bool ShouldCreate) {
|
|
|
|
// 64K ought to be enough for any frontend.
|
|
|
|
assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
|
|
|
|
|
|
|
|
assert(Scope && "Expected scope");
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-12-30 11:46:15 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DILocalVariable,
|
2016-07-23 20:41:05 +00:00
|
|
|
(Scope, Name, File, Line, Type, Arg, Flags));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {Scope, Name, File, Type};
|
2015-12-30 11:46:15 +00:00
|
|
|
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags), Ops);
|
2015-05-27 18:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DIExpression *DIExpression::getImpl(LLVMContext &Context,
|
|
|
|
ArrayRef<uint64_t> Elements,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
|
|
|
|
DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned DIExpression::ExprOperand::getSize() const {
|
|
|
|
switch (getOp()) {
|
|
|
|
case dwarf::DW_OP_bit_piece:
|
|
|
|
return 3;
|
|
|
|
case dwarf::DW_OP_plus:
|
2015-12-30 11:46:15 +00:00
|
|
|
case dwarf::DW_OP_minus:
|
2015-05-27 18:44:32 +00:00
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DIExpression::isValid() const {
|
|
|
|
for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
|
|
|
|
// Check that there's space for the operand.
|
|
|
|
if (I->get() + I->getSize() > E->get())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that the operand is valid.
|
|
|
|
switch (I->getOp()) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case dwarf::DW_OP_bit_piece:
|
|
|
|
// Piece expressions must be at the end.
|
|
|
|
return I->get() + I->getSize() == E->get();
|
|
|
|
case dwarf::DW_OP_plus:
|
2015-12-30 11:46:15 +00:00
|
|
|
case dwarf::DW_OP_minus:
|
2015-05-27 18:44:32 +00:00
|
|
|
case dwarf::DW_OP_deref:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DIExpression::isBitPiece() const {
|
|
|
|
assert(isValid() && "Expected valid expression");
|
|
|
|
if (unsigned N = getNumElements())
|
|
|
|
if (N >= 3)
|
|
|
|
return getElement(N - 3) == dwarf::DW_OP_bit_piece;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t DIExpression::getBitPieceOffset() const {
|
|
|
|
assert(isBitPiece() && "Expected bit piece");
|
|
|
|
return getElement(getNumElements() - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t DIExpression::getBitPieceSize() const {
|
|
|
|
assert(isBitPiece() && "Expected bit piece");
|
|
|
|
return getElement(getNumElements() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIObjCProperty *DIObjCProperty::getImpl(
|
|
|
|
LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
|
|
|
|
MDString *GetterName, MDString *SetterName, unsigned Attributes,
|
|
|
|
Metadata *Type, StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(GetterName) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(SetterName) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
|
|
|
|
SetterName, Attributes, Type));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
|
|
|
|
DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
|
|
|
|
Metadata *Scope, Metadata *Entity,
|
|
|
|
unsigned Line, MDString *Name,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIImportedEntity, (Tag, Scope, Entity, Line, Name));
|
2015-05-27 18:44:32 +00:00
|
|
|
Metadata *Ops[] = {Scope, Entity, Name};
|
|
|
|
DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
|
|
|
|
}
|
2015-12-30 11:46:15 +00:00
|
|
|
|
|
|
|
DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
|
|
|
|
unsigned Line, MDString *Name, MDString *Value,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-07-23 20:41:05 +00:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
|
2015-12-30 11:46:15 +00:00
|
|
|
Metadata *Ops[] = { Name, Value };
|
|
|
|
DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
|
|
|
|
unsigned Line, Metadata *File,
|
|
|
|
Metadata *Elements, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIMacroFile,
|
|
|
|
(MIType, Line, File, Elements));
|
|
|
|
Metadata *Ops[] = { File, Elements };
|
|
|
|
DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
|
|
|
|
}
|
|
|
|
|