25 DILocation::DILocation(
LLVMContext &
C, StorageType Storage,
unsigned Line,
27 :
MDNode(C, DILocationKind, Storage, MDs) {
29 "Expected a scope and optional inlined-at");
32 assert(Column < (1u << 16) &&
"Expected 16-bit column");
34 SubclassData32 = Line;
35 SubclassData16 = Column;
40 if (Column >= (1u << 16))
46 Metadata *InlinedAt, StorageType Storage,
54 DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
59 assert(ShouldCreate &&
"Expected non-uniqued nodes to always be created");
67 DILocation(Context, Storage, Line, Column, Ops),
73 bool GenerateLocation) {
77 if (LocA == LocB || !LocA->canDiscriminate(*LocB))
80 if (!GenerateLocation)
84 for (
DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
85 InlinedLocationsA.
insert(L);
87 for (
DILocation *L = LocB->getInlinedAt(); L; L = L->getInlinedAt()) {
89 if (InlinedLocationsA.
count(L))
93 Result->getInlinedAt());
99 #include "llvm/IR/DebugInfoFlags.def" 100 .Default(DINode::FlagZero);
105 #define HANDLE_DI_FLAG(ID, NAME) \ 107 return "DIFlag" #NAME; 108 #include "llvm/IR/DebugInfoFlags.def" 118 if (
DIFlags A = Flags & FlagAccessibility) {
119 if (A == FlagPrivate)
121 else if (A == FlagProtected)
127 if (
DIFlags R = Flags & FlagPtrToMemberRep) {
128 if (R == FlagSingleInheritance)
129 SplitFlags.
push_back(FlagSingleInheritance);
130 else if (R == FlagMultipleInheritance)
131 SplitFlags.
push_back(FlagMultipleInheritance);
133 SplitFlags.
push_back(FlagVirtualInheritance);
136 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
137 Flags &= ~FlagIndirectVirtualBase;
138 SplitFlags.
push_back(FlagIndirectVirtualBase);
141 #define HANDLE_DI_FLAG(ID, NAME) \ 142 if (DIFlags Bit = Flags & Flag##NAME) { \ 143 SplitFlags.push_back(Bit); \ 146 #include "llvm/IR/DebugInfoFlags.def" 151 if (
auto *
T = dyn_cast<DIType>(
this))
152 return T->getScope();
154 if (
auto *
SP = dyn_cast<DISubprogram>(
this))
155 return SP->getScope();
157 if (
auto *LB = dyn_cast<DILexicalBlockBase>(
this))
158 return LB->getScope();
160 if (
auto *NS = dyn_cast<DINamespace>(
this))
161 return NS->getScope();
163 if (
auto *M = dyn_cast<DIModule>(
this))
164 return M->getScope();
166 assert((isa<DIFile>(
this) || isa<DICompileUnit>(
this)) &&
167 "Unhandled type of scope.");
172 if (
auto *
T = dyn_cast<DIType>(
this))
174 if (
auto *
SP = dyn_cast<DISubprogram>(
this))
175 return SP->getName();
176 if (
auto *NS = dyn_cast<DINamespace>(
this))
177 return NS->getName();
178 if (
auto *M = dyn_cast<DIModule>(
this))
180 assert((isa<DILexicalBlockBase>(
this) || isa<DIFile>(
this) ||
181 isa<DICompileUnit>(
this)) &&
182 "Unhandled type of scope.");
198 GenericDINodeInfo::KeyTy
Key(Tag, Header, DwarfOps);
203 Hash = Key.getHash();
205 assert(ShouldCreate &&
"Expected non-uniqued nodes to always be created");
212 Context, Storage, Hash, Tag, PreOps, DwarfOps),
216 void GenericDINode::recalculateHash() {
217 setHash(GenericDINodeInfo::KeyTy::calculateHash(
this));
220 #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__ 221 #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS 222 #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \ 224 if (Storage == Uniqued) { \ 225 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \ 226 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \ 231 assert(ShouldCreate && \ 232 "Expected non-uniqued nodes to always be created"); \ 235 #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \ 236 return storeImpl(new (array_lengthof(OPS)) \ 237 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \ 238 Storage, Context.pImpl->CLASS##s) 239 #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \ 240 return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \ 241 Storage, Context.pImpl->CLASS##s) 242 #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \ 243 return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \ 244 Storage, Context.pImpl->CLASS##s) 245 #define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \ 246 return storeImpl(new (NUM_OPS) \ 247 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \ 248 Storage, Context.pImpl->CLASS##s) 254 return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
275 MDString *Name, uint64_t SizeInBits,
276 uint32_t AlignInBits,
unsigned Encoding,
280 (Tag, Name, SizeInBits, AlignInBits, Encoding));
281 Metadata *Ops[] = {
nullptr,
nullptr, Name};
287 switch (getEncoding()) {
288 case dwarf::DW_ATE_signed:
289 case dwarf::DW_ATE_signed_char:
291 case dwarf::DW_ATE_unsigned:
292 case dwarf::DW_ATE_unsigned_char:
302 uint32_t AlignInBits, uint64_t OffsetInBits,
307 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
308 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
312 DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
313 DWARFAddressSpace, Flags), Ops);
328 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
329 VTableHolder, TemplateParams, Identifier, Discriminator));
331 Elements, VTableHolder, TemplateParams,
Identifier,
334 AlignInBits, OffsetInBits, Flags),
341 uint64_t SizeInBits,
uint32_t AlignInBits, uint64_t OffsetInBits,
350 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
351 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
352 VTableHolder, TemplateParams, &Identifier, Discriminator);
355 assert(CT->getRawIdentifier() == &Identifier &&
"Wrong ODR identifier?");
356 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
360 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
363 Elements, VTableHolder, TemplateParams, &
Identifier,
366 "Mismatched number of operands");
367 for (
unsigned I = 0,
E = CT->getNumOperands();
I !=
E; ++
I)
368 if (Ops[
I] != CT->getOperand(
I))
369 CT->setOperand(
I, Ops[
I]);
376 uint64_t SizeInBits,
uint32_t AlignInBits, uint64_t OffsetInBits,
385 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
386 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
387 TemplateParams, &Identifier, Discriminator);
404 Metadata *Ops[] = {
nullptr,
nullptr,
nullptr, TypeArray};
420 return ChecksumKindName[CSKind - 1];
440 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value :
nullptr,
448 unsigned RuntimeVersion,
MDString *SplitDebugFilename,
451 uint64_t DWOId,
bool SplitDebugInlining,
bool DebugInfoForProfiling,
452 bool GnuPubnames,
StorageType Storage,
bool ShouldCreate) {
459 File, Producer, Flags, SplitDebugFilename,
460 EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
463 Context, Storage, SourceLanguage, IsOptimized,
464 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
465 DebugInfoForProfiling, GnuPubnames, Ops),
472 .Case(
"NoDebug", NoDebug)
473 .
Case(
"FullDebug", FullDebug)
474 .
Case(
"LineTablesOnly", LineTablesOnly)
480 case NoDebug:
return "NoDebug";
481 case FullDebug:
return "FullDebug";
482 case LineTablesOnly:
return "LineTablesOnly";
488 if (
auto *Block = dyn_cast<DILexicalBlockBase>(
this))
489 return Block->getScope()->getSubprogram();
490 return const_cast<DISubprogram *
>(cast<DISubprogram>(
this));
494 if (
auto *File = dyn_cast<DILexicalBlockFile>(
this))
495 return File->getScope()->getNonLexicalBlockFileScope();
502 bool IsLocalToUnit,
bool IsDefinition,
unsigned ScopeLine,
503 Metadata *ContainingType,
unsigned Virtuality,
unsigned VirtualIndex,
510 DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
511 IsDefinition, ScopeLine, ContainingType, Virtuality,
512 VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
513 TemplateParams, Declaration, RetainedNodes, ThrownTypes));
516 Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
519 if (!TemplateParams) {
526 (Line, ScopeLine, Virtuality, VirtualIndex,
527 ThisAdjustment, Flags, IsLocalToUnit, IsDefinition,
532 bool DISubprogram::describes(
const Function *
F)
const {
533 assert(F &&
"Invalid function");
549 assert(Scope &&
"Expected scope");
557 unsigned Discriminator,
560 assert(Scope &&
"Expected scope");
582 DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
610 Metadata *Type,
bool IsLocalToUnit,
bool IsDefinition,
611 Metadata *StaticDataMemberDeclaration,
617 (Scope, Name, LinkageName, File, Line, Type,
618 IsLocalToUnit, IsDefinition,
619 StaticDataMemberDeclaration, AlignInBits));
623 (Line, IsLocalToUnit, IsDefinition, AlignInBits),
635 assert(Arg <= UINT16_MAX &&
"Expected argument number to fit in 16-bits");
637 assert(Scope &&
"Expected scope");
640 (Scope, Name, File, Line, Type, Arg, Flags,
648 const Metadata *RawType = getRawType();
651 if (
auto *
T = dyn_cast<DIType>(RawType))
652 if (uint64_t
Size =
T->getSizeInBits())
655 if (
auto *DT = dyn_cast<DIDerivedType>(RawType)) {
657 RawType = DT->getRawBaseType();
673 assert(Scope &&
"Expected scope");
676 (Scope, Name, File, Line));
692 case dwarf::DW_OP_constu:
693 case dwarf::DW_OP_plus_uconst:
701 for (
auto I = expr_op_begin(),
E = expr_op_end();
I !=
E; ++
I) {
703 if (
I->get() +
I->getSize() >
E->get())
707 switch (
I->getOp()) {
712 return I->get() +
I->getSize() ==
E->get();
713 case dwarf::DW_OP_stack_value: {
715 if (
I->get() +
I->getSize() ==
E->get())
722 case dwarf::DW_OP_swap: {
730 if (getNumElements() == 1)
734 case dwarf::DW_OP_constu:
735 case dwarf::DW_OP_plus_uconst:
736 case dwarf::DW_OP_plus:
737 case dwarf::DW_OP_minus:
738 case dwarf::DW_OP_mul:
739 case dwarf::DW_OP_div:
740 case dwarf::DW_OP_mod:
741 case dwarf::DW_OP_or:
742 case dwarf::DW_OP_and:
743 case dwarf::DW_OP_xor:
744 case dwarf::DW_OP_shl:
745 case dwarf::DW_OP_shr:
746 case dwarf::DW_OP_shra:
747 case dwarf::DW_OP_deref:
748 case dwarf::DW_OP_xderef:
749 case dwarf::DW_OP_lit0:
750 case dwarf::DW_OP_not:
751 case dwarf::DW_OP_dup:
760 for (
auto I = Start;
I != End; ++
I)
773 }
else if (Offset < 0) {
781 if (getNumElements() == 0) {
786 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
787 Offset = Elements[1];
791 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
792 if (Elements[2] == dwarf::DW_OP_plus) {
793 Offset = Elements[1];
796 if (Elements[2] == dwarf::DW_OP_minus) {
797 Offset = -Elements[1];
806 int64_t
Offset,
bool DerefAfter,
812 appendOffset(Ops, Offset);
816 return prependOpcodes(Expr, Ops, StackValue);
822 assert(Expr &&
"Can't prepend ops to this expression");
830 if (
Op.getOp() == dwarf::DW_OP_stack_value)
837 Op.appendToVector(Ops);
846 assert(Expr && !Ops.
empty() &&
"Can't append ops to this expression");
852 if (
Op.getOp() == dwarf::DW_OP_stack_value ||
859 Op.appendToVector(NewOps);
862 NewOps.append(Ops.
begin(), Ops.
end());
868 assert(Expr && !Ops.
empty() &&
"Can't append ops to this expression");
871 return Op == dwarf::DW_OP_stack_value ||
874 "Can't append this op");
881 unsigned DropUntilStackValue = FI.
hasValue() ? 3 : 0;
884 bool NeedsDeref = (Expr->
getNumElements() > DropUntilStackValue) &&
885 (ExprOpsBeforeFragment.
back() != dwarf::DW_OP_stack_value);
886 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.
empty();
895 NewOps.
push_back(dwarf::DW_OP_stack_value);
900 const DIExpression *Expr,
unsigned OffsetInBits,
unsigned SizeInBits) {
905 switch (
Op.getOp()) {
907 case dwarf::DW_OP_plus:
908 case dwarf::DW_OP_minus:
917 uint64_t FragmentOffsetInBits =
Op.getArg(0);
918 uint64_t FragmentSizeInBits =
Op.getArg(1);
919 (void)FragmentSizeInBits;
920 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
921 "new fragment outside of original fragment");
922 OffsetInBits += FragmentOffsetInBits;
926 Op.appendToVector(Ops);
937 if (getNumElements() != 3 && getNumElements() != 6)
939 if (getElement(0) != dwarf::DW_OP_constu ||
940 getElement(2) != dwarf::DW_OP_stack_value)
952 Metadata *Ops[] = {Variable, Expression};
964 SetterName, Attributes, Type));
976 (Tag, Scope, Entity, File, Line, Name));
995 (MIType, Line, File, Elements));
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
ArrayRef< uint64_t > getElements() const
bool isConstant() const
Determine whether this represents a standalone constant value.
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
const T & back() const
back - Get the last element.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static DICompositeType * getODRTypeIfExists(LLVMContext &Context, MDString &Identifier)
Compute iterated dominance frontiers using a linear time algorithm.
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
unsigned getSize() const
Return the size of the operand.
Optional< Signedness > getSignedness() const
Return the signedness of this type, or None if this type is neither signed nor unsigned.
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
static IntegerType * getInt64Ty(LLVMContext &C)
static Optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
static DIExpression * prepend(const DIExpression *Expr, bool DerefBefore, int64_t Offset=0, bool DerefAfter=false, bool StackValue=false)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value...
static DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
static StringRef getName(Value *V)
Only used in LLVM metadata.
Holds a subclass of DINode.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
Holds the characteristics of one fragment of a larger variable.
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
LLVMContext & getContext() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static Optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
StringRef getString() const
static StringRef getFlagString(DIFlags Flag)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
A switch()-like statement whose cases are string literals.
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
A single checksum, represented by a Kind and a Value (a string).
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
DISubprogram * getSubprogram() const
Get the attached subprogram.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata *> MDs)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
A pair of DIGlobalVariable and DIExpression.
static DIExpression * appendToStack(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed...
Optional< FragmentInfo > getFragmentInfo() const
Retrieve the details of this fragment expression.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
LLVMContextImpl *const pImpl
An imported module (C++ using directive or similar).
DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
iterator_range< expr_op_iterator > expr_ops() const
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB, bool GenerateLocation=NoGeneratedLocation)
When two instructions are combined into a single instruction we also need to combine the original loc...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
StringRef getName() const
Optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
static DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DebugEmissionKind getEmissionKind() const
static DIFlags getFlag(StringRef Flag)
A (clang) module that has been imported by the compile unit.
unsigned unsigned DILocalScope * Scope
Generic tagged DWARF-like metadata node.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
unsigned getNumElements() const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
amdgpu Simplify well known AMD library false Value Value * Arg
Type array for a subprogram.
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
bool extractIfOffset(int64_t &Offset) const
If this is a constant offset, extract it.
static DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator)
Build a DICompositeType with the given ODR identifier.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
An iterator for expression operands.
StringRef - Represent a constant reference to a string, i.e.
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
Optional< DenseMap< const MDString *, DICompositeType * > > DITypeMap
static const char * emissionKindString(DebugEmissionKind EK)
bool empty() const
empty - Check if the array is empty.
static Optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
Basic type, like 'int' or 'float'.
DIScopeRef getScope() const