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"
|
2017-11-07 07:15:21 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2015-04-07 09:21:40 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2017-04-28 16:44:30 +08:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2015-02-19 04:32:57 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2017-11-07 07:15:21 +08:00
|
|
|
#include "llvm/IR/Instructions.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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-13 04:58:24 +08:00
|
|
|
const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
|
|
|
|
const DILocation *LocB,
|
|
|
|
bool GenerateLocation) {
|
2017-11-07 07:15:21 +08:00
|
|
|
if (!LocA || !LocB)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (LocA == LocB || !LocA->canDiscriminate(*LocB))
|
|
|
|
return LocA;
|
|
|
|
|
2018-04-13 04:58:24 +08:00
|
|
|
if (!GenerateLocation)
|
2017-11-07 07:15:21 +08:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
SmallPtrSet<DILocation *, 5> InlinedLocationsA;
|
|
|
|
for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
|
|
|
|
InlinedLocationsA.insert(L);
|
|
|
|
const DILocation *Result = LocB;
|
|
|
|
for (DILocation *L = LocB->getInlinedAt(); L; L = L->getInlinedAt()) {
|
|
|
|
Result = L;
|
|
|
|
if (InlinedLocationsA.count(L))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DILocation::get(Result->getContext(), 0, 0, Result->getScope(),
|
|
|
|
Result->getInlinedAt());
|
|
|
|
}
|
|
|
|
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags DINode::getFlag(StringRef Flag) {
|
|
|
|
return StringSwitch<DIFlags>(Flag)
|
2015-04-07 09:21:40 +08:00
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
2016-09-06 18:46:28 +08:00
|
|
|
.Default(DINode::FlagZero);
|
2015-04-07 09:21:40 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 13:57:50 +08:00
|
|
|
StringRef DINode::getFlagString(DIFlags Flag) {
|
2015-04-07 09:21:40 +08:00
|
|
|
switch (Flag) {
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
|
|
|
case Flag##NAME: \
|
|
|
|
return "DIFlag" #NAME;
|
|
|
|
#include "llvm/IR/DebugInfoFlags.def"
|
|
|
|
}
|
2016-09-06 18:46:28 +08:00
|
|
|
return "";
|
2015-04-07 09:21:40 +08:00
|
|
|
}
|
|
|
|
|
2016-09-06 18:46:28 +08:00
|
|
|
DINode::DIFlags DINode::splitFlags(DIFlags Flags,
|
2016-09-07 01:03:02 +08:00
|
|
|
SmallVectorImpl<DIFlags> &SplitFlags) {
|
2016-10-26 06:11:52 +08:00
|
|
|
// Flags that are packed together need to be specially handled, so
|
|
|
|
// that, for example, we emit "DIFlagPublic" and not
|
|
|
|
// "DIFlagPrivate | DIFlagProtected".
|
2016-09-06 18:46:28 +08:00
|
|
|
if (DIFlags A = Flags & FlagAccessibility) {
|
2015-04-07 09:21:40 +08:00
|
|
|
if (A == FlagPrivate)
|
|
|
|
SplitFlags.push_back(FlagPrivate);
|
|
|
|
else if (A == FlagProtected)
|
|
|
|
SplitFlags.push_back(FlagProtected);
|
|
|
|
else
|
|
|
|
SplitFlags.push_back(FlagPublic);
|
|
|
|
Flags &= ~A;
|
|
|
|
}
|
2016-09-06 18:46:28 +08:00
|
|
|
if (DIFlags R = Flags & FlagPtrToMemberRep) {
|
2016-06-18 05:31:33 +08:00
|
|
|
if (R == FlagSingleInheritance)
|
|
|
|
SplitFlags.push_back(FlagSingleInheritance);
|
|
|
|
else if (R == FlagMultipleInheritance)
|
|
|
|
SplitFlags.push_back(FlagMultipleInheritance);
|
|
|
|
else
|
|
|
|
SplitFlags.push_back(FlagVirtualInheritance);
|
|
|
|
Flags &= ~R;
|
|
|
|
}
|
2016-10-26 06:11:52 +08:00
|
|
|
if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
|
|
|
|
Flags &= ~FlagIndirectVirtualBase;
|
|
|
|
SplitFlags.push_back(FlagIndirectVirtualBase);
|
|
|
|
}
|
2015-04-07 09:21:40 +08:00
|
|
|
|
|
|
|
#define HANDLE_DI_FLAG(ID, NAME) \
|
2016-09-06 18:46:28 +08:00
|
|
|
if (DIFlags Bit = Flags & Flag##NAME) { \
|
2015-04-07 09:21:40 +08:00
|
|
|
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))
|
2016-04-24 05:08:00 +08:00
|
|
|
return 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))
|
2016-04-24 05:08:00 +08:00
|
|
|
return 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))
|
2016-04-24 05:08:00 +08:00
|
|
|
return M->getScope();
|
2015-06-30 07:03:47 +08:00
|
|
|
|
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: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) {
|
2016-03-19 09:02:34 +08:00
|
|
|
GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
|
2015-04-30 00:38:44 +08:00
|
|
|
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) \
|
2016-04-14 01:42:56 +08:00
|
|
|
return storeImpl(new (array_lengthof(OPS)) \
|
2015-02-10 08:52:32 +08: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)
|
2015-02-10 09:59:57 +08:00
|
|
|
#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
|
2016-04-14 01:42:56 +08:00
|
|
|
return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
|
2015-02-10 09:59:57 +08:00
|
|
|
Storage, Context.pImpl->CLASS##s)
|
2017-04-27 07:59:52 +08:00
|
|
|
#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
|
|
|
|
return storeImpl(new (NUM_OPS) \
|
|
|
|
CLASS(Context, Storage, UNWRAP_ARGS(ARGS), 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) {
|
[Metadata] Extend 'count' field of DISubrange to take a metadata node
Summary:
This patch extends the DISubrange 'count' field to take either a
(signed) constant integer value or a reference to a DILocalVariable
or DIGlobalVariable.
This is patch [1/3] in a series to extend LLVM's DISubrange Metadata
node to support debugging of C99 variable length arrays and vectors with
runtime length like the Scalable Vector Extension for AArch64. It is
also a first step towards representing more complex cases like arrays
in Fortran.
Reviewers: echristo, pcc, aprantl, dexonsmith, clayborg, kristof.beyls, dblaikie
Reviewed By: aprantl
Subscribers: rnk, probinson, fhahn, aemerson, rengolin, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D41695
llvm-svn: 323313
2018-01-24 17:56:07 +08:00
|
|
|
auto *CountNode = ConstantAsMetadata::get(
|
|
|
|
ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
|
|
|
|
return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
|
|
|
|
int64_t Lo, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, Lo));
|
|
|
|
Metadata *Ops[] = { CountNode };
|
|
|
|
DEFINE_GETIMPL_STORE(DISubrange, (CountNode, Lo), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
|
2018-02-13 00:10:09 +08:00
|
|
|
bool IsUnsigned, MDString *Name,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2018-02-13 00:10:09 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {Name};
|
2018-02-13 00:10:09 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), 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,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint32_t AlignInBits, unsigned Encoding,
|
2015-02-10 08:52:32 +08:00
|
|
|
StorageType Storage, bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIBasicType,
|
|
|
|
(Tag, 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,
|
2017-03-09 07:55:44 +08:00
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits,
|
|
|
|
Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIDerivedType,
|
|
|
|
(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
2017-03-09 07:55:44 +08:00
|
|
|
AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
|
|
|
|
ExtraData));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
|
|
|
|
DEFINE_GETIMPL_STORE(
|
2017-03-09 07:55:44 +08:00
|
|
|
DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
DWARFAddressSpace, Flags), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
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,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
|
2018-02-07 07:45:59 +08:00
|
|
|
Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2016-04-17 11:58:21 +08:00
|
|
|
|
2016-04-20 02:00:19 +08:00
|
|
|
// Keep this in sync with buildODRType.
|
2016-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
|
|
|
DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
|
|
|
|
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
|
2018-02-07 07:45:59 +08:00
|
|
|
VTableHolder, TemplateParams, Identifier, Discriminator));
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Ops[] = {File, Scope, Name, BaseType,
|
2018-02-07 07:45:59 +08:00
|
|
|
Elements, VTableHolder, TemplateParams, Identifier,
|
|
|
|
Discriminator};
|
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);
|
|
|
|
}
|
|
|
|
|
2016-04-20 02:00:19 +08:00
|
|
|
DICompositeType *DICompositeType::buildODRType(
|
|
|
|
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
|
|
|
|
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
|
2016-09-06 18:46:28 +08:00
|
|
|
DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
|
2018-02-07 07:45:59 +08:00
|
|
|
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
|
2016-04-20 02:00:19 +08:00
|
|
|
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,
|
2018-02-07 07:45:59 +08:00
|
|
|
VTableHolder, TemplateParams, &Identifier, Discriminator);
|
2016-04-20 02:00:19 +08:00
|
|
|
|
|
|
|
// 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,
|
2018-02-07 07:45:59 +08:00
|
|
|
Elements, VTableHolder, TemplateParams, &Identifier,
|
|
|
|
Discriminator};
|
2016-05-03 00:45:02 +08:00
|
|
|
assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
|
2016-04-20 02:00:19 +08:00
|
|
|
"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;
|
|
|
|
}
|
|
|
|
|
2016-04-19 22:55:09 +08:00
|
|
|
DICompositeType *DICompositeType::getODRType(
|
|
|
|
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
|
|
|
|
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
|
2016-10-18 22:31:22 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
|
2016-09-06 18:46:28 +08:00
|
|
|
DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
|
2018-02-07 07:45:59 +08:00
|
|
|
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
|
2016-04-19 22:55:09 +08:00
|
|
|
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,
|
2018-02-07 07:45:59 +08:00
|
|
|
TemplateParams, &Identifier, Discriminator);
|
2016-04-19 22:55:09 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-09-07 01:03:02 +08:00
|
|
|
DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
|
|
|
|
uint8_t CC, Metadata *TypeArray,
|
2015-02-10 08:52:32 +08:00
|
|
|
StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2016-06-09 04:34:29 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
|
2015-07-25 04:56:36 +08:00
|
|
|
Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
|
2016-06-09 04:34:29 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2017-09-20 02:14:45 +08:00
|
|
|
// FIXME: Implement this string-enum correspondence with a .def file and macros,
|
|
|
|
// so that the association is explicit rather than implied.
|
2018-02-13 03:45:54 +08:00
|
|
|
static const char *ChecksumKindName[DIFile::CSK_Last] = {
|
2016-12-25 18:12:09 +08:00
|
|
|
"CSK_MD5",
|
|
|
|
"CSK_SHA1"
|
|
|
|
};
|
|
|
|
|
2018-02-13 03:45:54 +08:00
|
|
|
StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
|
|
|
|
assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
|
|
|
|
// The first space was originally the CSK_None variant, which is now
|
|
|
|
// obsolete, but the space is still reserved in ChecksumKind, so we account
|
|
|
|
// for it here.
|
|
|
|
return ChecksumKindName[CSKind - 1];
|
2016-12-25 18:12:09 +08:00
|
|
|
}
|
|
|
|
|
2018-02-13 03:45:54 +08:00
|
|
|
Optional<DIFile::ChecksumKind> DIFile::getChecksumKind(StringRef CSKindStr) {
|
|
|
|
return StringSwitch<Optional<DIFile::ChecksumKind>>(CSKindStr)
|
|
|
|
.Case("CSK_MD5", DIFile::CSK_MD5)
|
|
|
|
.Case("CSK_SHA1", DIFile::CSK_SHA1)
|
|
|
|
.Default(None);
|
2016-12-25 18:12:09 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
|
2018-02-13 03:45:54 +08:00
|
|
|
MDString *Directory,
|
|
|
|
Optional<DIFile::ChecksumInfo<MDString *>> CS,
|
2018-02-24 07:01:06 +08:00
|
|
|
Optional<MDString *> Source, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Filename) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(Directory) && "Expected canonical MDString");
|
2018-02-13 03:45:54 +08:00
|
|
|
assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
|
2018-02-24 07:01:06 +08:00
|
|
|
assert((!Source || isCanonical(*Source)) && "Expected canonical MDString");
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source));
|
|
|
|
Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr,
|
|
|
|
Source.getValueOr(nullptr)};
|
|
|
|
DEFINE_GETIMPL_STORE(DIFile, (CS, Source), 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,
|
2016-04-15 23:57:41 +08:00
|
|
|
Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
|
Change debug-info-for-profiling from a TargetOption to a function attribute.
Summary: LTO requires the debug-info-for-profiling to be a function attribute.
Reviewers: echristo, mehdi_amini, dblaikie, probinson, aprantl
Reviewed By: mehdi_amini, dblaikie, aprantl
Subscribers: aprantl, probinson, ahatanak, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D29203
llvm-svn: 293833
2017-02-02 06:45:09 +08:00
|
|
|
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
|
2017-09-13 05:50:41 +08:00
|
|
|
bool GnuPubnames, 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
|
|
|
|
2016-04-15 23:57:41 +08:00
|
|
|
Metadata *Ops[] = {
|
|
|
|
File, Producer, Flags, SplitDebugFilename,
|
|
|
|
EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
|
|
|
|
Macros};
|
2017-09-13 05:50:41 +08:00
|
|
|
return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
|
|
|
|
Context, Storage, SourceLanguage, IsOptimized,
|
|
|
|
RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
|
|
|
|
DebugInfoForProfiling, GnuPubnames, Ops),
|
2015-08-04 01:26:41 +08:00
|
|
|
Storage);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2016-04-01 07:56:58 +08: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-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
|
|
|
}
|
|
|
|
|
2016-04-22 00:58:49 +08:00
|
|
|
DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
|
|
|
|
if (auto *File = dyn_cast<DILexicalBlockFile>(this))
|
|
|
|
return File->getScope()->getNonLexicalBlockFileScope();
|
|
|
|
return const_cast<DILocalScope *>(this);
|
|
|
|
}
|
|
|
|
|
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,
|
2016-09-06 18:46:28 +08:00
|
|
|
int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
|
2016-07-01 10:41:21 +08:00
|
|
|
Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
|
2017-04-27 06:56:44 +08:00
|
|
|
Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
|
|
|
assert(isCanonical(LinkageName) && "Expected canonical MDString");
|
2016-07-01 10:41:21 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
2017-04-27 06:56:44 +08:00
|
|
|
DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
|
|
|
|
IsDefinition, ScopeLine, ContainingType, Virtuality,
|
|
|
|
VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
|
|
|
|
TemplateParams, Declaration, Variables, ThrownTypes));
|
2017-04-27 07:59:52 +08:00
|
|
|
SmallVector<Metadata *, 11> Ops = {
|
|
|
|
File, Scope, Name, LinkageName, Type, Unit,
|
|
|
|
Declaration, Variables, ContainingType, TemplateParams, ThrownTypes};
|
|
|
|
if (!ThrownTypes) {
|
|
|
|
Ops.pop_back();
|
|
|
|
if (!TemplateParams) {
|
|
|
|
Ops.pop_back();
|
|
|
|
if (!ContainingType)
|
|
|
|
Ops.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEFINE_GETIMPL_STORE_N(DISubprogram,
|
|
|
|
(Line, ScopeLine, Virtuality, VirtualIndex,
|
|
|
|
ThisAdjustment, Flags, IsLocalToUnit, IsDefinition,
|
|
|
|
IsOptimized),
|
|
|
|
Ops, Ops.size());
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
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,
|
2017-04-29 06:25:46 +08:00
|
|
|
MDString *Name, bool ExportSymbols,
|
|
|
|
StorageType Storage, bool ShouldCreate) {
|
2015-02-10 08:52:32 +08:00
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2017-04-29 06:25:46 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
|
|
|
|
// The nullptr is for DIScope's File operand. This should be refactored.
|
|
|
|
Metadata *Ops[] = {nullptr, Scope, Name};
|
|
|
|
DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), 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");
|
2016-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(
|
|
|
|
DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
|
2015-06-30 07:03:47 +08:00
|
|
|
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");
|
2016-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (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");
|
2016-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
|
2015-02-19 08:37:21 +08:00
|
|
|
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 *StaticDataMemberDeclaration,
|
2016-12-20 10:09:43 +08:00
|
|
|
uint32_t AlignInBits, 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(DIGlobalVariable,
|
2016-03-19 09:02:34 +08:00
|
|
|
(Scope, Name, LinkageName, File, Line, Type,
|
2016-12-20 10:09:43 +08:00
|
|
|
IsLocalToUnit, IsDefinition,
|
2016-10-20 08:13:12 +08:00
|
|
|
StaticDataMemberDeclaration, AlignInBits));
|
2016-12-20 10:09:43 +08:00
|
|
|
Metadata *Ops[] = {
|
|
|
|
Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration};
|
2016-10-20 08:13:12 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIGlobalVariable,
|
|
|
|
(Line, IsLocalToUnit, IsDefinition, AlignInBits),
|
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,
|
2016-09-06 18:46:28 +08:00
|
|
|
unsigned Arg, DIFlags Flags,
|
2016-10-27 05:32:29 +08:00
|
|
|
uint32_t AlignInBits,
|
2015-08-01 02:58:39 +08:00
|
|
|
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,
|
2016-10-20 08:13:12 +08:00
|
|
|
(Scope, Name, File, Line, Type, Arg, Flags,
|
|
|
|
AlignInBits));
|
2015-04-16 06:29:27 +08:00
|
|
|
Metadata *Ops[] = {Scope, Name, File, Type};
|
2016-10-20 08:13:12 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
|
2017-11-28 08:57:51 +08:00
|
|
|
Optional<uint64_t> DIVariable::getSizeInBits() const {
|
|
|
|
// This is used by the Verifier so be mindful of broken types.
|
|
|
|
const Metadata *RawType = getRawType();
|
|
|
|
while (RawType) {
|
|
|
|
// Try to get the size directly.
|
|
|
|
if (auto *T = dyn_cast<DIType>(RawType))
|
|
|
|
if (uint64_t Size = T->getSizeInBits())
|
|
|
|
return Size;
|
|
|
|
|
|
|
|
if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
|
|
|
|
// Look at the base type.
|
|
|
|
RawType = DT->getRawBaseType();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Missing type or size.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail gracefully.
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
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()) {
|
2016-12-06 02:04:47 +08:00
|
|
|
case dwarf::DW_OP_LLVM_fragment:
|
2015-02-13 09:07:46 +08:00
|
|
|
return 3;
|
2016-09-13 09:12:59 +08:00
|
|
|
case dwarf::DW_OP_constu:
|
2017-06-14 00:54:44 +08:00
|
|
|
case dwarf::DW_OP_plus_uconst:
|
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;
|
2016-12-06 02:04:47 +08:00
|
|
|
case dwarf::DW_OP_LLVM_fragment:
|
2016-12-20 10:09:43 +08:00
|
|
|
// A fragment operator must appear at the end.
|
2015-02-13 09:07:46 +08:00
|
|
|
return I->get() + I->getSize() == E->get();
|
2016-12-20 10:09:43 +08:00
|
|
|
case dwarf::DW_OP_stack_value: {
|
|
|
|
// Must be the last one or followed by a DW_OP_LLVM_fragment.
|
|
|
|
if (I->get() + I->getSize() == E->get())
|
|
|
|
break;
|
|
|
|
auto J = I;
|
|
|
|
if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-08 08:28:57 +08:00
|
|
|
case dwarf::DW_OP_swap: {
|
|
|
|
// Must be more than one implicit element on the stack.
|
|
|
|
|
|
|
|
// FIXME: A better way to implement this would be to add a local variable
|
|
|
|
// that keeps track of the stack depth and introduce something like a
|
|
|
|
// DW_LLVM_OP_implicit_location as a placeholder for the location this
|
|
|
|
// DIExpression is attached to, or else pass the number of implicit stack
|
|
|
|
// elements into isValid.
|
|
|
|
if (getNumElements() == 1)
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-13 09:12:59 +08:00
|
|
|
case dwarf::DW_OP_constu:
|
2017-06-14 00:54:44 +08:00
|
|
|
case dwarf::DW_OP_plus_uconst:
|
2015-02-13 09:07:46 +08:00
|
|
|
case dwarf::DW_OP_plus:
|
2015-10-01 03:55:43 +08:00
|
|
|
case dwarf::DW_OP_minus:
|
2017-09-21 18:04:02 +08:00
|
|
|
case dwarf::DW_OP_mul:
|
2018-02-13 09:09:52 +08:00
|
|
|
case dwarf::DW_OP_div:
|
|
|
|
case dwarf::DW_OP_mod:
|
2018-02-10 03:19:55 +08:00
|
|
|
case dwarf::DW_OP_or:
|
2018-02-14 21:10:35 +08:00
|
|
|
case dwarf::DW_OP_and:
|
2018-02-13 09:09:46 +08:00
|
|
|
case dwarf::DW_OP_xor:
|
2018-02-13 09:09:49 +08:00
|
|
|
case dwarf::DW_OP_shl:
|
|
|
|
case dwarf::DW_OP_shr:
|
|
|
|
case dwarf::DW_OP_shra:
|
2015-02-13 09:07:46 +08:00
|
|
|
case dwarf::DW_OP_deref:
|
2017-03-08 08:28:57 +08:00
|
|
|
case dwarf::DW_OP_xderef:
|
2015-02-13 09:07:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:27:12 +08:00
|
|
|
Optional<DIExpression::FragmentInfo>
|
|
|
|
DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
|
|
|
|
for (auto I = Start; I != End; ++I)
|
|
|
|
if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
|
|
|
|
DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
|
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
return None;
|
2015-04-07 11:49:59 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 16:44:30 +08:00
|
|
|
void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
|
|
|
|
int64_t Offset) {
|
|
|
|
if (Offset > 0) {
|
2017-06-14 21:14:38 +08:00
|
|
|
Ops.push_back(dwarf::DW_OP_plus_uconst);
|
2017-04-28 16:44:30 +08:00
|
|
|
Ops.push_back(Offset);
|
|
|
|
} else if (Offset < 0) {
|
2017-06-14 21:14:38 +08:00
|
|
|
Ops.push_back(dwarf::DW_OP_constu);
|
2017-04-28 16:44:30 +08:00
|
|
|
Ops.push_back(-Offset);
|
2017-06-14 21:14:38 +08:00
|
|
|
Ops.push_back(dwarf::DW_OP_minus);
|
2017-04-28 16:44:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 03:59:29 +08:00
|
|
|
bool DIExpression::extractIfOffset(int64_t &Offset) const {
|
|
|
|
if (getNumElements() == 0) {
|
|
|
|
Offset = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-14 21:14:38 +08:00
|
|
|
|
|
|
|
if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
|
2017-05-10 03:59:29 +08:00
|
|
|
Offset = Elements[1];
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-14 21:14:38 +08:00
|
|
|
|
|
|
|
if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
|
|
|
|
if (Elements[2] == dwarf::DW_OP_plus) {
|
|
|
|
Offset = Elements[1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Elements[2] == dwarf::DW_OP_minus) {
|
|
|
|
Offset = -Elements[1];
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-10 03:59:29 +08:00
|
|
|
}
|
2017-06-14 21:14:38 +08:00
|
|
|
|
2017-05-10 03:59:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-09 05:58:18 +08:00
|
|
|
DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
|
|
|
|
int64_t Offset, bool DerefAfter,
|
|
|
|
bool StackValue) {
|
2017-04-28 16:44:30 +08:00
|
|
|
SmallVector<uint64_t, 8> Ops;
|
2017-12-09 05:58:18 +08:00
|
|
|
if (DerefBefore)
|
|
|
|
Ops.push_back(dwarf::DW_OP_deref);
|
|
|
|
|
2017-04-28 16:44:30 +08:00
|
|
|
appendOffset(Ops, Offset);
|
2017-12-09 05:58:18 +08:00
|
|
|
if (DerefAfter)
|
2017-04-28 16:44:30 +08:00
|
|
|
Ops.push_back(dwarf::DW_OP_deref);
|
2017-12-09 05:58:18 +08:00
|
|
|
|
2018-04-28 05:41:36 +08:00
|
|
|
return prependOpcodes(Expr, Ops, StackValue);
|
2018-02-10 03:19:55 +08:00
|
|
|
}
|
|
|
|
|
2018-04-28 05:41:36 +08:00
|
|
|
DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
|
|
|
|
SmallVectorImpl<uint64_t> &Ops,
|
|
|
|
bool StackValue) {
|
2017-04-29 01:51:05 +08:00
|
|
|
if (Expr)
|
|
|
|
for (auto Op : Expr->expr_ops()) {
|
2017-04-28 16:44:30 +08:00
|
|
|
// A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
|
|
|
|
if (StackValue) {
|
|
|
|
if (Op.getOp() == dwarf::DW_OP_stack_value)
|
|
|
|
StackValue = false;
|
|
|
|
else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
|
|
|
|
Ops.push_back(dwarf::DW_OP_stack_value);
|
|
|
|
StackValue = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ops.push_back(Op.getOp());
|
|
|
|
for (unsigned I = 0; I < Op.getNumArgs(); ++I)
|
|
|
|
Ops.push_back(Op.getArg(I));
|
|
|
|
}
|
|
|
|
if (StackValue)
|
|
|
|
Ops.push_back(dwarf::DW_OP_stack_value);
|
2017-04-29 01:51:05 +08:00
|
|
|
return DIExpression::get(Expr->getContext(), Ops);
|
2017-04-28 16:44:30 +08:00
|
|
|
}
|
|
|
|
|
2017-11-07 08:45:34 +08:00
|
|
|
Optional<DIExpression *> DIExpression::createFragmentExpression(
|
|
|
|
const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
|
2017-08-31 04:04:17 +08:00
|
|
|
SmallVector<uint64_t, 8> Ops;
|
|
|
|
// Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
|
|
|
|
if (Expr) {
|
|
|
|
for (auto Op : Expr->expr_ops()) {
|
2017-11-07 08:45:34 +08:00
|
|
|
switch (Op.getOp()) {
|
|
|
|
default: break;
|
|
|
|
case dwarf::DW_OP_plus:
|
|
|
|
case dwarf::DW_OP_minus:
|
|
|
|
// We can't safely split arithmetic into multiple fragments because we
|
|
|
|
// can't express carry-over between fragments.
|
|
|
|
//
|
|
|
|
// FIXME: We *could* preserve the lowest fragment of a constant offset
|
|
|
|
// operation if the offset fits into SizeInBits.
|
|
|
|
return None;
|
|
|
|
case dwarf::DW_OP_LLVM_fragment: {
|
2017-08-31 04:04:17 +08:00
|
|
|
// Make the new offset point into the existing fragment.
|
|
|
|
uint64_t FragmentOffsetInBits = Op.getArg(0);
|
[DebugInfo] Correction for an assert in DIExpression::createFragmentExpression
Summary:
When we create a fragment expression, and there already is an
old fragment expression, we assert that the new fragment is
within the range for the old fragment.
If for example the old fragment expression says that we
describe bit 10-16 of a variable (Offset=10, Size=6),
and we now want to create a new fragment expression only
describing bit 3-6 of the original value, then the resulting
fragment expression should have Offset=13, Size=3.
The assert is supposed to catch if the resulting fragment
expression is outside the range for the old fragment. However,
it used to verify that the Offset+Size of the new fragment was
smaller or equal than Offset+Size for the old fragment. What
we really want to check is that Offset+Size of the new fragment
is smaller than the Size of the old fragment.
Reviewers: aprantl, vsk
Reviewed By: aprantl
Subscribers: davide, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D46391
llvm-svn: 331465
2018-05-04 01:04:21 +08:00
|
|
|
uint64_t FragmentSizeInBits = Op.getArg(1);
|
|
|
|
(void)FragmentSizeInBits;
|
|
|
|
assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
|
2017-08-31 04:04:17 +08:00
|
|
|
"new fragment outside of original fragment");
|
|
|
|
OffsetInBits += FragmentOffsetInBits;
|
2017-11-07 08:45:34 +08:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-31 04:04:17 +08:00
|
|
|
}
|
|
|
|
Ops.push_back(Op.getOp());
|
|
|
|
for (unsigned I = 0; I < Op.getNumArgs(); ++I)
|
|
|
|
Ops.push_back(Op.getArg(I));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ops.push_back(dwarf::DW_OP_LLVM_fragment);
|
|
|
|
Ops.push_back(OffsetInBits);
|
|
|
|
Ops.push_back(SizeInBits);
|
|
|
|
return DIExpression::get(Expr->getContext(), Ops);
|
|
|
|
}
|
|
|
|
|
2016-12-20 10:09:43 +08:00
|
|
|
bool DIExpression::isConstant() const {
|
|
|
|
// Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
|
|
|
|
if (getNumElements() != 3 && getNumElements() != 6)
|
|
|
|
return false;
|
|
|
|
if (getElement(0) != dwarf::DW_OP_constu ||
|
|
|
|
getElement(2) != dwarf::DW_OP_stack_value)
|
|
|
|
return false;
|
|
|
|
if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIGlobalVariableExpression *
|
|
|
|
DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
|
|
|
|
Metadata *Expression, StorageType Storage,
|
|
|
|
bool ShouldCreate) {
|
|
|
|
DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
|
|
|
|
Metadata *Ops[] = {Variable, Expression};
|
|
|
|
DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops);
|
|
|
|
}
|
|
|
|
|
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");
|
2016-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
|
|
|
|
SetterName, Attributes, Type));
|
2015-02-10 08:52:32 +08:00
|
|
|
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,
|
2017-07-19 08:09:54 +08:00
|
|
|
Metadata *File, unsigned Line,
|
|
|
|
MDString *Name, StorageType Storage,
|
2015-02-10 08:52:32 +08:00
|
|
|
bool ShouldCreate) {
|
|
|
|
assert(isCanonical(Name) && "Expected canonical MDString");
|
2017-07-19 08:09:54 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
|
|
|
|
(Tag, Scope, Entity, File, Line, Name));
|
|
|
|
Metadata *Ops[] = {Scope, Entity, Name, File};
|
2015-04-30 00:38:44 +08:00
|
|
|
DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
2015-12-10 20:56:35 +08: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-03-19 09:02:34 +08:00
|
|
|
DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
|
2015-12-10 20:56:35 +08: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);
|
|
|
|
}
|