2015-02-03 02:53:21 +08: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"
|
2015-04-07 09:21:40 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2015-02-19 04:32:57 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2015-02-03 02:53:21 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
|
2015-02-03 02:53:21 +08:00
|
|
|
unsigned Column, ArrayRef<Metadata *> MDs)
|
2015-04-30 00:38:44 +08:00
|
|
|
: MDNode(C, DILocationKind, Storage, MDs) {
|
2015-02-03 02:53:21 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
|
2015-02-03 02:53:21 +08:00
|
|
|
unsigned Column, Metadata *Scope,
|
|
|
|
Metadata *InlinedAt, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-02-07 06:50:13 +08:00
|
|
|
// Fixup column.
|
2015-02-03 02:53:21 +08:00
|
|
|
adjustColumn(Column);
|
|
|
|
|
2015-03-28 01:56:39 +08:00
|
|
|
assert(Scope && "Expected scope");
|
2015-02-03 02:53:21 +08:00
|
|
|
if (Storage == Uniqued) {
|
|
|
|
if (auto *N =
|
2015-04-30 00:38:44 +08:00
|
|
|
getUniqued(Context.pImpl->DILocations,
|
|
|
|
DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
|
2015-02-03 02:53:21 +08:00
|
|
|
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())
|
2015-04-30 00:38:44 +08:00
|
|
|
DILocation(Context, Storage, Line, Column, Ops),
|
|
|
|
Storage, Context.pImpl->DILocations);
|
2015-02-03 02:53:21 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
unsigned DILocation::computeNewDiscriminator() const {
|
2015-04-14 08:35:42 +08:00
|
|
|
// FIXME: This seems completely wrong.
|
|
|
|
//
|
|
|
|
// 1. If two modules are generated in the same context, then the second
|
|
|
|
// Module will get different discriminators than it would have if it were
|
|
|
|
// generated in its own context.
|
|
|
|
// 2. If this function is called after round-tripping to bitcode instead of
|
|
|
|
// before, it will give a different (and potentially incorrect!) return.
|
|
|
|
//
|
|
|
|
// The discriminator should instead be calculated from local information
|
|
|
|
// where it's actually needed. This logic should be moved to
|
|
|
|
// AddDiscriminators::runOnFunction(), where it doesn't pollute the
|
|
|
|
// LLVMContext.
|
|
|
|
std::pair<const char *, unsigned> Key(getFilename().data(), getLine());
|
|
|
|
return ++getContext().pImpl->DiscriminatorTable[Key];
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
unsigned DINode::getFlag(StringRef Flag) {
|
2015-04-07 09:21:40 +08:00
|
|
|
return StringSwitch<unsigned>(Flag)
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
.Default(0);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
const char *DINode::getFlagString(unsigned Flag) {
|
2015-04-07 09:21:40 +08:00
|
|
|
switch (Flag) {
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
|
|
|
case Flag##NAME: \
|
|
|
|
return "DIFlag" #NAME;
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
unsigned DINode::splitFlags(unsigned Flags,
|
|
|
|
SmallVectorImpl<unsigned> &SplitFlags) {
|
2015-04-07 09:21:40 +08:00
|
|
|
// Accessibility flags need to be specially handled, since they're packed
|
|
|
|
// together.
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
|
|
|
if (unsigned Bit = Flags & ID) { \
|
|
|
|
SplitFlags.push_back(Bit); \
|
|
|
|
Flags &= ~Bit; \
|
|
|
|
}
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
|
|
|
|
return Flags;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIScopeRef DIScope::getScope() const {
|
|
|
|
if (auto *T = dyn_cast<DIType>(this))
|
2015-04-12 01:37:23 +08:00
|
|
|
return T->getScope();
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(this))
|
2015-04-12 01:37:23 +08:00
|
|
|
return SP->getScope();
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
|
|
|
|
return DIScopeRef(LB->getScope());
|
2015-04-12 01:37:23 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *NS = dyn_cast<DINamespace>(this))
|
|
|
|
return DIScopeRef(NS->getScope());
|
2015-04-12 01:37:23 +08:00
|
|
|
|
2015-06-30 07:03:47 +08:00
|
|
|
if (auto *M = dyn_cast<DIModule>(this))
|
|
|
|
return DIScopeRef(M->getScope());
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
|
2015-04-12 01:37:23 +08:00
|
|
|
"Unhandled type of scope.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
StringRef DIScope::getName() const {
|
|
|
|
if (auto *T = dyn_cast<DIType>(this))
|
2015-04-12 01:37:23 +08:00
|
|
|
return T->getName();
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(this))
|
2015-04-12 01:37:23 +08:00
|
|
|
return SP->getName();
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *NS = dyn_cast<DINamespace>(this))
|
2015-04-12 01:37:23 +08:00
|
|
|
return NS->getName();
|
2015-06-30 07:03:47 +08:00
|
|
|
if (auto *M = dyn_cast<DIModule>(this))
|
|
|
|
return M->getName();
|
2015-04-30 00:38:44 +08:00
|
|
|
assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
|
|
|
|
isa<DICompileUnit>(this)) &&
|
2015-04-12 01:37:23 +08:00
|
|
|
"Unhandled type of scope.");
|
|
|
|
return "";
|
|
|
|
}
|
2015-04-07 09:21:40 +08:00
|
|
|
|
2015-02-03 04:01:03 +08:00
|
|
|
static StringRef getString(const MDString *S) {
|
|
|
|
if (S)
|
|
|
|
return S->getString();
|
|
|
|
return StringRef();
|
|
|
|
}
|
|
|
|
|
2015-02-03 04:20:56 +08:00
|
|
|
#ifndef NDEBUG
|
2015-02-03 04:01:03 +08:00
|
|
|
static bool isCanonical(const MDString *S) {
|
|
|
|
return !S || !S->getString().empty();
|
2015-02-03 03:54:05 +08:00
|
|
|
}
|
2015-02-03 04:20:56 +08:00
|
|
|
#endif
|
2015-02-03 03:54:05 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
|
|
|
|
MDString *Header,
|
|
|
|
ArrayRef<Metadata *> DwarfOps,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-03 02:53:21 +08:00
|
|
|
unsigned Hash = 0;
|
|
|
|
if (Storage == Uniqued) {
|
2015-04-30 00:38:44 +08:00
|
|
|
GenericDINodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
|
|
|
|
if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
|
2015-02-03 02:53:21 +08:00
|
|
|
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.
|
2015-02-03 04:01:03 +08:00
|
|
|
assert(isCanonical(Header) && "Expected canonical MDString");
|
|
|
|
Metadata *PreOps[] = {Header};
|
2015-04-30 00:38:44 +08:00
|
|
|
return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
|
2015-02-03 02:53:21 +08:00
|
|
|
Context, Storage, Hash, Tag, PreOps, DwarfOps),
|
2015-04-30 00:38:44 +08:00
|
|
|
Storage, Context.pImpl->GenericDINodes);
|
2015-02-03 02:53:21 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void GenericDINode::recalculateHash() {
|
|
|
|
setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
|
2015-02-03 02:53:21 +08:00
|
|
|
}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
|
|
|
#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) \
|
|
|
|
return storeImpl(new (ArrayRef<Metadata *>(OPS).size()) \
|
|
|
|
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)
|
2015-02-10 09:59:57 +08:00
|
|
|
#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
|
|
|
|
return storeImpl(new (ArrayRef<Metadata *>(OPS).size()) \
|
|
|
|
CLASS(Context, Storage, OPS), \
|
|
|
|
Storage, Context.pImpl->CLASS##s)
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
|
2015-02-10 08:52:32 +08:00
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo));
|
|
|
|
DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo));
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
|
2015-02-10 08:52:32 +08:00
|
|
|
MDString *Name, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, getString(Name)));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {Name};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
|
2015-02-20 07:56:07 +08:00
|
|
|
MDString *Name, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, unsigned Encoding,
|
2015-02-10 08:52:32 +08:00
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
2015-04-30 00:38:44 +08:00
|
|
|
DIBasicType, (Tag, getString(Name), SizeInBits, AlignInBits, Encoding));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {nullptr, nullptr, Name};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
|
2015-02-10 08:52:32 +08:00
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType *DIDerivedType::getImpl(
|
2015-02-10 08:52:32 +08:00
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
|
2015-02-20 07:56:07 +08:00
|
|
|
unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIDerivedType, (Tag, getString(Name), File, Line, Scope,
|
2015-02-10 08:52:32 +08:00
|
|
|
BaseType, SizeInBits, AlignInBits,
|
|
|
|
OffsetInBits, Flags, ExtraData));
|
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
|
|
|
|
DEFINE_GETIMPL_STORE(
|
2015-04-30 00:38:44 +08:00
|
|
|
DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
|
2015-02-10 08:52:32 +08:00
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompositeType *DICompositeType::getImpl(
|
2015-02-10 08:52:32 +08:00
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
|
2015-02-20 07:56:07 +08:00
|
|
|
unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
|
|
|
|
Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DICompositeType,
|
2015-02-10 08:52:32 +08:00
|
|
|
(Tag, getString(Name), File, Line, Scope, BaseType,
|
|
|
|
SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
|
|
|
|
RuntimeLang, VTableHolder, TemplateParams,
|
|
|
|
getString(Identifier)));
|
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType,
|
|
|
|
Elements, VTableHolder, TemplateParams, Identifier};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
|
2015-02-10 08:52:32 +08:00
|
|
|
AlignInBits, OffsetInBits, Flags),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context,
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Flags, Metadata *TypeArray,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, TypeArray));
|
2015-07-25 04:56:36 +08:00
|
|
|
Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DISubroutineType, (Flags), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
|
2015-02-10 08:52:32 +08:00
|
|
|
MDString *Directory, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Filename) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(Directory) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIFile, (getString(Filename), getString(Directory)));
|
IR: Change MDFile to directly store the filename/directory
In the old (well, current) schema, there are two types of file
references: untagged and tagged (the latter references the former).
!0 = !{!"filename", !"/directory"}
!1 = !{!"0x29", !1} ; DW_TAG_file_type [filename] [/directory]
The interface to `DIBuilder` universally takes the tagged version,
described by `DIFile`. However, most `file:` references actually use
the untagged version directly.
In the new hierarchy, I'm merging this into a single node: `MDFile`.
Originally I'd planned to keep the old schema unchanged until after I
moved the new hierarchy into place.
However, it turns out to be trivial to make `MDFile` match both nodes at
the same time.
- Anyone referencing !1 does so through `DIFile`, whose implementation
I need to gut anyway (as I do the rest of the `DIDescriptor`s).
- Anyone referencing !0 just references an `MDNode`, and expects a
node with two `MDString` operands.
This commit achieves that, and updates all the testcases for the parts
of the new hierarchy that used the two-node schema (I've replaced the
untagged nodes with `distinct !{}` to make the diff clear (otherwise the
metadata all gets renumbered); it might be worthwhile to come back and
delete those nodes and renumber the world, not sure).
llvm-svn: 230057
2015-02-21 04:35:17 +08:00
|
|
|
Metadata *Ops[] = {Filename, Directory};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIFile, Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DICompileUnit *DICompileUnit::getImpl(
|
2015-02-10 08:52:32 +08:00
|
|
|
LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
|
|
|
|
MDString *Producer, bool IsOptimized, MDString *Flags,
|
|
|
|
unsigned RuntimeVersion, MDString *SplitDebugFilename,
|
|
|
|
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
|
|
|
|
Metadata *Subprograms, Metadata *GlobalVariables,
|
2015-05-22 04:37:30 +08:00
|
|
|
Metadata *ImportedEntities, uint64_t DWOId,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-08-04 01:26:41 +08:00
|
|
|
assert(Storage != Uniqued && "Cannot unique DICompileUnit");
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Producer) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(Flags) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
|
2015-08-04 01:26:41 +08:00
|
|
|
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
|
|
|
|
RetainedTypes, Subprograms, GlobalVariables,
|
|
|
|
ImportedEntities};
|
2015-08-04 01:26:41 +08:00
|
|
|
return storeImpl(new (ArrayRef<Metadata *>(Ops).size()) DICompileUnit(
|
|
|
|
Context, Storage, SourceLanguage, IsOptimized,
|
|
|
|
RuntimeVersion, EmissionKind, DWOId, Ops),
|
|
|
|
Storage);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubprogram *DILocalScope::getSubprogram() const {
|
|
|
|
if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
|
2015-03-31 05:32:28 +08:00
|
|
|
return Block->getScope()->getSubprogram();
|
2015-04-30 00:38:44 +08:00
|
|
|
return const_cast<DISubprogram *>(cast<DISubprogram>(this));
|
2015-03-31 05:32:28 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubprogram *DISubprogram::getImpl(
|
2015-02-10 08:52:32 +08:00
|
|
|
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,
|
2015-11-06 06:03:56 +08:00
|
|
|
unsigned Flags, bool IsOptimized, Metadata *TemplateParams,
|
|
|
|
Metadata *Declaration, Metadata *Variables, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(LinkageName) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubprogram,
|
2015-02-10 08:52:32 +08:00
|
|
|
(Scope, getString(Name), getString(LinkageName), File,
|
|
|
|
Line, Type, IsLocalToUnit, IsDefinition, ScopeLine,
|
|
|
|
ContainingType, Virtuality, VirtualIndex, Flags,
|
2015-11-06 06:03:56 +08:00
|
|
|
IsOptimized, TemplateParams, Declaration, Variables));
|
|
|
|
Metadata *Ops[] = {File, Scope, Name, Name,
|
|
|
|
LinkageName, Type, ContainingType, TemplateParams,
|
|
|
|
Declaration, Variables};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DISubprogram,
|
2015-02-10 08:52:32 +08:00
|
|
|
(Line, ScopeLine, Virtuality, VirtualIndex, Flags,
|
|
|
|
IsLocalToUnit, IsDefinition, IsOptimized),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool DISubprogram::describes(const Function *F) const {
|
2015-04-14 03:07:27 +08:00
|
|
|
assert(F && "Invalid function");
|
2015-11-06 06:03:56 +08:00
|
|
|
if (F->getSubprogram() == this)
|
2015-04-14 03:07:27 +08:00
|
|
|
return true;
|
|
|
|
StringRef Name = getLinkageName();
|
|
|
|
if (Name.empty())
|
|
|
|
Name = getName();
|
|
|
|
return F->getName() == Name;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File, unsigned Line,
|
|
|
|
unsigned Column, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-08-29 06:58:50 +08:00
|
|
|
// Fixup column.
|
|
|
|
adjustColumn(Column);
|
|
|
|
|
2015-03-31 00:37:48 +08:00
|
|
|
assert(Scope && "Expected scope");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {File, Scope};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope, Metadata *File,
|
|
|
|
unsigned Discriminator,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-03-31 00:37:48 +08:00
|
|
|
assert(Scope && "Expected scope");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {File, Scope};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File, MDString *Name, unsigned Line,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, getString(Name), Line));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {File, Scope, Name};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-06-30 07:03:47 +08: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");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIModule,
|
|
|
|
(Scope, getString(Name), getString(ConfigurationMacros),
|
|
|
|
getString(IncludePath), getString(ISysRoot)));
|
|
|
|
Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
|
2015-02-19 08:37:21 +08:00
|
|
|
MDString *Name,
|
|
|
|
Metadata *Type,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (getString(Name), Type));
|
2015-02-19 08:37:21 +08:00
|
|
|
Metadata *Ops[] = {Name, Type};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DITemplateValueParameter *DITemplateValueParameter::getImpl(
|
2015-02-19 08:37:21 +08:00
|
|
|
LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
|
|
|
|
Metadata *Value, StorageType Storage, bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter,
|
2015-02-19 08:37:21 +08:00
|
|
|
(Tag, getString(Name), Type, Value));
|
|
|
|
Metadata *Ops[] = {Name, Type, Value};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIGlobalVariable *
|
|
|
|
DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
|
2015-02-10 08:52:32 +08:00
|
|
|
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");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
|
2015-02-10 08:52:32 +08:00
|
|
|
(Scope, getString(Name), getString(LinkageName), File,
|
|
|
|
Line, Type, IsLocalToUnit, IsDefinition, Variable,
|
|
|
|
StaticDataMemberDeclaration));
|
|
|
|
Metadata *Ops[] = {Scope, Name, File, Type,
|
|
|
|
Name, LinkageName, Variable, StaticDataMemberDeclaration};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
|
2015-02-10 08:52:32 +08:00
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
|
2015-08-01 02:58:39 +08:00
|
|
|
DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
|
|
|
|
MDString *Name, Metadata *File,
|
|
|
|
unsigned Line, Metadata *Type,
|
|
|
|
unsigned Arg, unsigned Flags,
|
|
|
|
StorageType Storage,
|
2015-04-16 06:29:27 +08:00
|
|
|
bool ShouldCreate) {
|
2015-04-28 09:07:33 +08:00
|
|
|
// 64K ought to be enough for any frontend.
|
|
|
|
assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
|
2015-02-13 09:39:44 +08:00
|
|
|
|
2015-03-28 01:56:39 +08:00
|
|
|
assert(Scope && "Expected scope");
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-08-01 02:58:39 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DILocalVariable,
|
|
|
|
(Scope, getString(Name), File, Line, Type, Arg, Flags));
|
2015-04-16 06:29:27 +08:00
|
|
|
Metadata *Ops[] = {Scope, Name, File, Type};
|
2015-08-01 02:58:39 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIExpression *DIExpression::getImpl(LLVMContext &Context,
|
2015-02-10 08:52:32 +08:00
|
|
|
ArrayRef<uint64_t> Elements,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
|
|
|
|
DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
unsigned DIExpression::ExprOperand::getSize() const {
|
2015-02-13 09:07:46 +08:00
|
|
|
switch (getOp()) {
|
|
|
|
case dwarf::DW_OP_bit_piece:
|
|
|
|
return 3;
|
|
|
|
case dwarf::DW_OP_plus:
|
2015-10-01 03:55:43 +08:00
|
|
|
case dwarf::DW_OP_minus:
|
2015-02-13 09:07:46 +08:00
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool DIExpression::isValid() const {
|
2015-02-13 09:07:46 +08:00
|
|
|
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-10-01 03:55:43 +08:00
|
|
|
case dwarf::DW_OP_minus:
|
2015-02-13 09:07:46 +08:00
|
|
|
case dwarf::DW_OP_deref:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool DIExpression::isBitPiece() const {
|
2015-04-07 11:49:59 +08:00
|
|
|
assert(isValid() && "Expected valid expression");
|
|
|
|
if (unsigned N = getNumElements())
|
|
|
|
if (N >= 3)
|
|
|
|
return getElement(N - 3) == dwarf::DW_OP_bit_piece;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
uint64_t DIExpression::getBitPieceOffset() const {
|
2015-04-07 11:49:59 +08:00
|
|
|
assert(isBitPiece() && "Expected bit piece");
|
|
|
|
return getElement(getNumElements() - 2);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
uint64_t DIExpression::getBitPieceSize() const {
|
2015-04-07 11:49:59 +08:00
|
|
|
assert(isBitPiece() && "Expected bit piece");
|
|
|
|
return getElement(getNumElements() - 1);
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIObjCProperty *DIObjCProperty::getImpl(
|
2015-02-10 08:52:32 +08:00
|
|
|
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");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIObjCProperty,
|
2015-02-10 08:52:32 +08:00
|
|
|
(getString(Name), File, Line, getString(GetterName),
|
|
|
|
getString(SetterName), Attributes, Type));
|
|
|
|
Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope, Metadata *Entity,
|
|
|
|
unsigned Line, MDString *Name,
|
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
|
2015-02-10 08:52:32 +08:00
|
|
|
(Tag, Scope, Entity, Line, getString(Name)));
|
|
|
|
Metadata *Ops[] = {Scope, Entity, Name};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|