Bug Summary

File:lib/IR/DebugInfoMetadata.cpp
Warning:line 135, column 16
The result of the left shift is undefined due to shifting by '42', which is greater or equal to the width of type 'unsigned int'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name DebugInfoMetadata.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/IR -I /build/llvm-toolchain-snapshot-8~svn350071/lib/IR -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn350071/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/IR -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn350071=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-12-27-042839-1215-1 -x c++ /build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp

1//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the debug info Metadata classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/IR/DebugInfoMetadata.h"
15#include "LLVMContextImpl.h"
16#include "MetadataImpl.h"
17#include "llvm/ADT/SmallSet.h"
18#include "llvm/ADT/StringSwitch.h"
19#include "llvm/IR/DIBuilder.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/Instructions.h"
22
23#include <numeric>
24
25using namespace llvm;
26
27DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
28 unsigned Column, ArrayRef<Metadata *> MDs,
29 bool ImplicitCode)
30 : MDNode(C, DILocationKind, Storage, MDs) {
31 assert((MDs.size() == 1 || MDs.size() == 2) &&(((MDs.size() == 1 || MDs.size() == 2) && "Expected a scope and optional inlined-at"
) ? static_cast<void> (0) : __assert_fail ("(MDs.size() == 1 || MDs.size() == 2) && \"Expected a scope and optional inlined-at\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 32, __PRETTY_FUNCTION__))
32 "Expected a scope and optional inlined-at")(((MDs.size() == 1 || MDs.size() == 2) && "Expected a scope and optional inlined-at"
) ? static_cast<void> (0) : __assert_fail ("(MDs.size() == 1 || MDs.size() == 2) && \"Expected a scope and optional inlined-at\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 32, __PRETTY_FUNCTION__))
;
33
34 // Set line and column.
35 assert(Column < (1u << 16) && "Expected 16-bit column")((Column < (1u << 16) && "Expected 16-bit column"
) ? static_cast<void> (0) : __assert_fail ("Column < (1u << 16) && \"Expected 16-bit column\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 35, __PRETTY_FUNCTION__))
;
36
37 SubclassData32 = Line;
38 SubclassData16 = Column;
39
40 setImplicitCode(ImplicitCode);
41}
42
43static void adjustColumn(unsigned &Column) {
44 // Set to unknown on overflow. We only have 16 bits to play with here.
45 if (Column >= (1u << 16))
46 Column = 0;
47}
48
49DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
50 unsigned Column, Metadata *Scope,
51 Metadata *InlinedAt, bool ImplicitCode,
52 StorageType Storage, bool ShouldCreate) {
53 // Fixup column.
54 adjustColumn(Column);
55
56 if (Storage == Uniqued) {
57 if (auto *N = getUniqued(Context.pImpl->DILocations,
58 DILocationInfo::KeyTy(Line, Column, Scope,
59 InlinedAt, ImplicitCode)))
60 return N;
61 if (!ShouldCreate)
62 return nullptr;
63 } else {
64 assert(ShouldCreate && "Expected non-uniqued nodes to always be created")((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 64, __PRETTY_FUNCTION__))
;
65 }
66
67 SmallVector<Metadata *, 2> Ops;
68 Ops.push_back(Scope);
69 if (InlinedAt)
70 Ops.push_back(InlinedAt);
71 return storeImpl(new (Ops.size()) DILocation(Context, Storage, Line, Column,
72 Ops, ImplicitCode),
73 Storage, Context.pImpl->DILocations);
74}
75
76const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
77 const DILocation *LocB) {
78 if (!LocA || !LocB)
79 return nullptr;
80
81 if (LocA == LocB)
82 return LocA;
83
84 SmallPtrSet<DILocation *, 5> InlinedLocationsA;
85 for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
86 InlinedLocationsA.insert(L);
87 SmallSet<std::pair<DIScope *, DILocation *>, 5> Locations;
88 DIScope *S = LocA->getScope();
89 DILocation *L = LocA->getInlinedAt();
90 while (S) {
91 Locations.insert(std::make_pair(S, L));
92 S = S->getScope().resolve();
93 if (!S && L) {
94 S = L->getScope();
95 L = L->getInlinedAt();
96 }
97 }
98 const DILocation *Result = LocB;
99 S = LocB->getScope();
100 L = LocB->getInlinedAt();
101 while (S) {
102 if (Locations.count(std::make_pair(S, L)))
103 break;
104 S = S->getScope().resolve();
105 if (!S && L) {
106 S = L->getScope();
107 L = L->getInlinedAt();
108 }
109 }
110
111 // If the two locations are irreconsilable, just pick one. This is misleading,
112 // but on the other hand, it's a "line 0" location.
113 if (!S || !isa<DILocalScope>(S))
114 S = LocA->getScope();
115 return DILocation::get(Result->getContext(), 0, 0, S, L);
116}
117
118Optional<unsigned> DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
119 SmallVector<unsigned, 3> Components = {BD, DF, CI};
120 uint64_t RemainingWork = 0U;
121 // We use RemainingWork to figure out if we have no remaining components to
122 // encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
123 // encode anything for the latter 2.
124 // Since any of the input components is at most 32 bits, their sum will be
125 // less than 34 bits, and thus RemainingWork won't overflow.
126 RemainingWork = std::accumulate(Components.begin(), Components.end(), RemainingWork);
127
128 int I = 0;
129 unsigned Ret = 0;
130 unsigned NextBitInsertionIndex = 0;
131 while (RemainingWork > 0) {
1
Assuming 'RemainingWork' is > 0
2
Loop condition is true. Entering loop body
8
Assuming 'RemainingWork' is > 0
9
Loop condition is true. Entering loop body
15
Assuming 'RemainingWork' is > 0
16
Loop condition is true. Entering loop body
24
Assuming 'RemainingWork' is > 0
25
Loop condition is true. Entering loop body
132 unsigned C = Components[I++];
133 RemainingWork -= C;
134 unsigned EC = encodeComponent(C);
135 Ret |= (EC << NextBitInsertionIndex);
26
The result of the left shift is undefined due to shifting by '42', which is greater or equal to the width of type 'unsigned int'
136 NextBitInsertionIndex += encodingBits(C);
3
Calling 'DILocation::encodingBits'
7
Returning from 'DILocation::encodingBits'
10
Calling 'DILocation::encodingBits'
14
Returning from 'DILocation::encodingBits'
17
Calling 'DILocation::encodingBits'
22
Returning from 'DILocation::encodingBits'
23
The value 42 is assigned to 'NextBitInsertionIndex'
137 }
138
139 // Encoding may be unsuccessful because of overflow. We determine success by
140 // checking equivalence of components before & after encoding. Alternatively,
141 // we could determine Success during encoding, but the current alternative is
142 // simpler.
143 unsigned TBD, TDF, TCI = 0;
144 decodeDiscriminator(Ret, TBD, TDF, TCI);
145 if (TBD == BD && TDF == DF && TCI == CI)
146 return Ret;
147 return None;
148}
149
150void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
151 unsigned &CI) {
152 BD = getUnsignedFromPrefixEncoding(D);
153 DF = getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(D));
154 CI = getUnsignedFromPrefixEncoding(
155 getNextComponentInDiscriminator(getNextComponentInDiscriminator(D)));
156}
157
158
159DINode::DIFlags DINode::getFlag(StringRef Flag) {
160 return StringSwitch<DIFlags>(Flag)
161#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
162#include "llvm/IR/DebugInfoFlags.def"
163 .Default(DINode::FlagZero);
164}
165
166StringRef DINode::getFlagString(DIFlags Flag) {
167 switch (Flag) {
168#define HANDLE_DI_FLAG(ID, NAME) \
169 case Flag##NAME: \
170 return "DIFlag" #NAME;
171#include "llvm/IR/DebugInfoFlags.def"
172 }
173 return "";
174}
175
176DINode::DIFlags DINode::splitFlags(DIFlags Flags,
177 SmallVectorImpl<DIFlags> &SplitFlags) {
178 // Flags that are packed together need to be specially handled, so
179 // that, for example, we emit "DIFlagPublic" and not
180 // "DIFlagPrivate | DIFlagProtected".
181 if (DIFlags A = Flags & FlagAccessibility) {
182 if (A == FlagPrivate)
183 SplitFlags.push_back(FlagPrivate);
184 else if (A == FlagProtected)
185 SplitFlags.push_back(FlagProtected);
186 else
187 SplitFlags.push_back(FlagPublic);
188 Flags &= ~A;
189 }
190 if (DIFlags R = Flags & FlagPtrToMemberRep) {
191 if (R == FlagSingleInheritance)
192 SplitFlags.push_back(FlagSingleInheritance);
193 else if (R == FlagMultipleInheritance)
194 SplitFlags.push_back(FlagMultipleInheritance);
195 else
196 SplitFlags.push_back(FlagVirtualInheritance);
197 Flags &= ~R;
198 }
199 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
200 Flags &= ~FlagIndirectVirtualBase;
201 SplitFlags.push_back(FlagIndirectVirtualBase);
202 }
203
204#define HANDLE_DI_FLAG(ID, NAME) \
205 if (DIFlags Bit = Flags & Flag##NAME) { \
206 SplitFlags.push_back(Bit); \
207 Flags &= ~Bit; \
208 }
209#include "llvm/IR/DebugInfoFlags.def"
210 return Flags;
211}
212
213DIScopeRef DIScope::getScope() const {
214 if (auto *T = dyn_cast<DIType>(this))
215 return T->getScope();
216
217 if (auto *SP = dyn_cast<DISubprogram>(this))
218 return SP->getScope();
219
220 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
221 return LB->getScope();
222
223 if (auto *NS = dyn_cast<DINamespace>(this))
224 return NS->getScope();
225
226 if (auto *M = dyn_cast<DIModule>(this))
227 return M->getScope();
228
229 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&(((isa<DIFile>(this) || isa<DICompileUnit>(this))
&& "Unhandled type of scope.") ? static_cast<void
> (0) : __assert_fail ("(isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 230, __PRETTY_FUNCTION__))
230 "Unhandled type of scope.")(((isa<DIFile>(this) || isa<DICompileUnit>(this))
&& "Unhandled type of scope.") ? static_cast<void
> (0) : __assert_fail ("(isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 230, __PRETTY_FUNCTION__))
;
231 return nullptr;
232}
233
234StringRef DIScope::getName() const {
235 if (auto *T = dyn_cast<DIType>(this))
236 return T->getName();
237 if (auto *SP = dyn_cast<DISubprogram>(this))
238 return SP->getName();
239 if (auto *NS = dyn_cast<DINamespace>(this))
240 return NS->getName();
241 if (auto *M = dyn_cast<DIModule>(this))
242 return M->getName();
243 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||(((isa<DILexicalBlockBase>(this) || isa<DIFile>(this
) || isa<DICompileUnit>(this)) && "Unhandled type of scope."
) ? static_cast<void> (0) : __assert_fail ("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 245, __PRETTY_FUNCTION__))
244 isa<DICompileUnit>(this)) &&(((isa<DILexicalBlockBase>(this) || isa<DIFile>(this
) || isa<DICompileUnit>(this)) && "Unhandled type of scope."
) ? static_cast<void> (0) : __assert_fail ("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 245, __PRETTY_FUNCTION__))
245 "Unhandled type of scope.")(((isa<DILexicalBlockBase>(this) || isa<DIFile>(this
) || isa<DICompileUnit>(this)) && "Unhandled type of scope."
) ? static_cast<void> (0) : __assert_fail ("(isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || isa<DICompileUnit>(this)) && \"Unhandled type of scope.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 245, __PRETTY_FUNCTION__))
;
246 return "";
247}
248
249#ifndef NDEBUG
250static bool isCanonical(const MDString *S) {
251 return !S || !S->getString().empty();
252}
253#endif
254
255GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
256 MDString *Header,
257 ArrayRef<Metadata *> DwarfOps,
258 StorageType Storage, bool ShouldCreate) {
259 unsigned Hash = 0;
260 if (Storage == Uniqued) {
261 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
262 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
263 return N;
264 if (!ShouldCreate)
265 return nullptr;
266 Hash = Key.getHash();
267 } else {
268 assert(ShouldCreate && "Expected non-uniqued nodes to always be created")((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 268, __PRETTY_FUNCTION__))
;
269 }
270
271 // Use a nullptr for empty headers.
272 assert(isCanonical(Header) && "Expected canonical MDString")((isCanonical(Header) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Header) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 272, __PRETTY_FUNCTION__))
;
273 Metadata *PreOps[] = {Header};
274 return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
275 Context, Storage, Hash, Tag, PreOps, DwarfOps),
276 Storage, Context.pImpl->GenericDINodes);
277}
278
279void GenericDINode::recalculateHash() {
280 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
281}
282
283#define UNWRAP_ARGS_IMPL(...)... __VA_ARGS__
284#define UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS UNWRAP_ARGS_IMPL ARGS
285#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->CLASSs, CLASSInfo::KeyTy(UNWRAP_ARGS_IMPL ARGS))) return
N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 285, __PRETTY_FUNCTION__)); } } while (false)
\
286 do { \
287 if (Storage == Uniqued) { \
288 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
289 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS))) \
290 return N; \
291 if (!ShouldCreate) \
292 return nullptr; \
293 } else { \
294 assert(ShouldCreate && \((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 295, __PRETTY_FUNCTION__))
295 "Expected non-uniqued nodes to always be created")((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 295, __PRETTY_FUNCTION__))
; \
296 } \
297 } while (false)
298#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage
, UNWRAP_ARGS_IMPL ARGS, OPS), Storage, Context.pImpl->CLASSs
)
\
299 return storeImpl(new (array_lengthof(OPS)) \
300 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS, OPS), \
301 Storage, Context.pImpl->CLASS##s)
302#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS_IMPL
ARGS), Storage, Context.pImpl->CLASSs)
\
303 return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS), \
304 Storage, Context.pImpl->CLASS##s)
305#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage
, OPS), Storage, Context.pImpl->CLASSs)
\
306 return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
307 Storage, Context.pImpl->CLASS##s)
308#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS)return storeImpl(new (NUM_OPS) CLASS(Context, Storage, UNWRAP_ARGS_IMPL
ARGS, OPS), Storage, Context.pImpl->CLASSs)
\
309 return storeImpl(new (NUM_OPS) \
310 CLASS(Context, Storage, UNWRAP_ARGS(ARGS)UNWRAP_ARGS_IMPL ARGS, OPS), \
311 Storage, Context.pImpl->CLASS##s)
312
313DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
314 StorageType Storage, bool ShouldCreate) {
315 auto *CountNode = ConstantAsMetadata::get(
316 ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
317 return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
318}
319
320DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
321 int64_t Lo, StorageType Storage,
322 bool ShouldCreate) {
323 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, Lo))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubranges, DISubrangeInfo::KeyTy(CountNode, Lo))
) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 323, __PRETTY_FUNCTION__)); } } while (false)
;
324 Metadata *Ops[] = { CountNode };
325 DEFINE_GETIMPL_STORE(DISubrange, (CountNode, Lo), Ops)return storeImpl(new (array_lengthof(Ops)) DISubrange(Context
, Storage, CountNode, Lo, Ops), Storage, Context.pImpl->DISubranges
)
;
326}
327
328DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
329 bool IsUnsigned, MDString *Name,
330 StorageType Storage, bool ShouldCreate) {
331 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 331, __PRETTY_FUNCTION__))
;
332 DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIEnumerators, DIEnumeratorInfo::KeyTy(Value, IsUnsigned
, Name))) return N; if (!ShouldCreate) return nullptr; } else
{ ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 332, __PRETTY_FUNCTION__)); } } while (false)
;
333 Metadata *Ops[] = {Name};
334 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops)return storeImpl(new (array_lengthof(Ops)) DIEnumerator(Context
, Storage, Value, IsUnsigned, Ops), Storage, Context.pImpl->
DIEnumerators)
;
335}
336
337DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
338 MDString *Name, uint64_t SizeInBits,
339 uint32_t AlignInBits, unsigned Encoding,
340 DIFlags Flags, StorageType Storage,
341 bool ShouldCreate) {
342 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 342, __PRETTY_FUNCTION__))
;
343 DEFINE_GETIMPL_LOOKUP(DIBasicType,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIBasicTypes, DIBasicTypeInfo::KeyTy(Tag, Name, SizeInBits
, AlignInBits, Encoding, Flags))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 344, __PRETTY_FUNCTION__)); } } while (false)
344 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIBasicTypes, DIBasicTypeInfo::KeyTy(Tag, Name, SizeInBits
, AlignInBits, Encoding, Flags))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 344, __PRETTY_FUNCTION__)); } } while (false)
;
345 Metadata *Ops[] = {nullptr, nullptr, Name};
346 DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,return storeImpl(new (array_lengthof(Ops)) DIBasicType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Flags, Ops
), Storage, Context.pImpl->DIBasicTypes)
347 Flags), Ops)return storeImpl(new (array_lengthof(Ops)) DIBasicType(Context
, Storage, Tag, SizeInBits, AlignInBits, Encoding, Flags, Ops
), Storage, Context.pImpl->DIBasicTypes)
;
348}
349
350Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
351 switch (getEncoding()) {
352 case dwarf::DW_ATE_signed:
353 case dwarf::DW_ATE_signed_char:
354 return Signedness::Signed;
355 case dwarf::DW_ATE_unsigned:
356 case dwarf::DW_ATE_unsigned_char:
357 return Signedness::Unsigned;
358 default:
359 return None;
360 }
361}
362
363DIDerivedType *DIDerivedType::getImpl(
364 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
365 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
366 uint32_t AlignInBits, uint64_t OffsetInBits,
367 Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
368 StorageType Storage, bool ShouldCreate) {
369 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 369, __PRETTY_FUNCTION__))
;
370 DEFINE_GETIMPL_LOOKUP(DIDerivedType,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
371 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
372 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
373 ExtraData))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIDerivedTypes, DIDerivedTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, DWARFAddressSpace, Flags, ExtraData))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 373, __PRETTY_FUNCTION__)); } } while (false)
;
374 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
375 DEFINE_GETIMPL_STORE(return storeImpl(new (array_lengthof(Ops)) DIDerivedType(Context
, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace
, Flags, Ops), Storage, Context.pImpl->DIDerivedTypes)
376 DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,return storeImpl(new (array_lengthof(Ops)) DIDerivedType(Context
, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace
, Flags, Ops), Storage, Context.pImpl->DIDerivedTypes)
377 DWARFAddressSpace, Flags), Ops)return storeImpl(new (array_lengthof(Ops)) DIDerivedType(Context
, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits, DWARFAddressSpace
, Flags, Ops), Storage, Context.pImpl->DIDerivedTypes)
;
378}
379
380DICompositeType *DICompositeType::getImpl(
381 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
382 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
383 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
384 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
385 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
386 StorageType Storage, bool ShouldCreate) {
387 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 387, __PRETTY_FUNCTION__))
;
388
389 // Keep this in sync with buildODRType.
390 DEFINE_GETIMPL_LOOKUP(do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
391 DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
392 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
393 VTableHolder, TemplateParams, Identifier, Discriminator))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DICompositeTypes, DICompositeTypeInfo::KeyTy(Tag, Name
, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits
, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 393, __PRETTY_FUNCTION__)); } } while (false)
;
394 Metadata *Ops[] = {File, Scope, Name, BaseType,
395 Elements, VTableHolder, TemplateParams, Identifier,
396 Discriminator};
397 DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,return storeImpl(new (array_lengthof(Ops)) DICompositeType(Context
, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits
, Flags, Ops), Storage, Context.pImpl->DICompositeTypes)
398 AlignInBits, OffsetInBits, Flags),return storeImpl(new (array_lengthof(Ops)) DICompositeType(Context
, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits
, Flags, Ops), Storage, Context.pImpl->DICompositeTypes)
399 Ops)return storeImpl(new (array_lengthof(Ops)) DICompositeType(Context
, Storage, Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits
, Flags, Ops), Storage, Context.pImpl->DICompositeTypes)
;
400}
401
402DICompositeType *DICompositeType::buildODRType(
403 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
404 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
405 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
406 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
407 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
408 assert(!Identifier.getString().empty() && "Expected valid identifier")((!Identifier.getString().empty() && "Expected valid identifier"
) ? static_cast<void> (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 408, __PRETTY_FUNCTION__))
;
409 if (!Context.isODRUniquingDebugTypes())
410 return nullptr;
411 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
412 if (!CT)
413 return CT = DICompositeType::getDistinct(
414 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
415 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
416 VTableHolder, TemplateParams, &Identifier, Discriminator);
417
418 // Only mutate CT if it's a forward declaration and the new operands aren't.
419 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?")((CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?"
) ? static_cast<void> (0) : __assert_fail ("CT->getRawIdentifier() == &Identifier && \"Wrong ODR identifier?\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 419, __PRETTY_FUNCTION__))
;
420 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
421 return CT;
422
423 // Mutate CT in place. Keep this in sync with getImpl.
424 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
425 Flags);
426 Metadata *Ops[] = {File, Scope, Name, BaseType,
427 Elements, VTableHolder, TemplateParams, &Identifier,
428 Discriminator};
429 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&(((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands
() && "Mismatched number of operands") ? static_cast<
void> (0) : __assert_fail ("(std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() && \"Mismatched number of operands\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 430, __PRETTY_FUNCTION__))
430 "Mismatched number of operands")(((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands
() && "Mismatched number of operands") ? static_cast<
void> (0) : __assert_fail ("(std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() && \"Mismatched number of operands\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 430, __PRETTY_FUNCTION__))
;
431 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
432 if (Ops[I] != CT->getOperand(I))
433 CT->setOperand(I, Ops[I]);
434 return CT;
435}
436
437DICompositeType *DICompositeType::getODRType(
438 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
439 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
440 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
441 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
442 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
443 assert(!Identifier.getString().empty() && "Expected valid identifier")((!Identifier.getString().empty() && "Expected valid identifier"
) ? static_cast<void> (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 443, __PRETTY_FUNCTION__))
;
444 if (!Context.isODRUniquingDebugTypes())
445 return nullptr;
446 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
447 if (!CT)
448 CT = DICompositeType::getDistinct(
449 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
450 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
451 TemplateParams, &Identifier, Discriminator);
452 return CT;
453}
454
455DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
456 MDString &Identifier) {
457 assert(!Identifier.getString().empty() && "Expected valid identifier")((!Identifier.getString().empty() && "Expected valid identifier"
) ? static_cast<void> (0) : __assert_fail ("!Identifier.getString().empty() && \"Expected valid identifier\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 457, __PRETTY_FUNCTION__))
;
458 if (!Context.isODRUniquingDebugTypes())
459 return nullptr;
460 return Context.pImpl->DITypeMap->lookup(&Identifier);
461}
462
463DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
464 uint8_t CC, Metadata *TypeArray,
465 StorageType Storage,
466 bool ShouldCreate) {
467 DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubroutineTypes, DISubroutineTypeInfo::KeyTy(Flags
, CC, TypeArray))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 467, __PRETTY_FUNCTION__)); } } while (false)
;
468 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
469 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops)return storeImpl(new (array_lengthof(Ops)) DISubroutineType(Context
, Storage, Flags, CC, Ops), Storage, Context.pImpl->DISubroutineTypes
)
;
470}
471
472// FIXME: Implement this string-enum correspondence with a .def file and macros,
473// so that the association is explicit rather than implied.
474static const char *ChecksumKindName[DIFile::CSK_Last] = {
475 "CSK_MD5",
476 "CSK_SHA1"
477};
478
479StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
480 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind")((CSKind <= DIFile::CSK_Last && "Invalid checksum kind"
) ? static_cast<void> (0) : __assert_fail ("CSKind <= DIFile::CSK_Last && \"Invalid checksum kind\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 480, __PRETTY_FUNCTION__))
;
481 // The first space was originally the CSK_None variant, which is now
482 // obsolete, but the space is still reserved in ChecksumKind, so we account
483 // for it here.
484 return ChecksumKindName[CSKind - 1];
485}
486
487Optional<DIFile::ChecksumKind> DIFile::getChecksumKind(StringRef CSKindStr) {
488 return StringSwitch<Optional<DIFile::ChecksumKind>>(CSKindStr)
489 .Case("CSK_MD5", DIFile::CSK_MD5)
490 .Case("CSK_SHA1", DIFile::CSK_SHA1)
491 .Default(None);
492}
493
494DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
495 MDString *Directory,
496 Optional<DIFile::ChecksumInfo<MDString *>> CS,
497 Optional<MDString *> Source, StorageType Storage,
498 bool ShouldCreate) {
499 assert(isCanonical(Filename) && "Expected canonical MDString")((isCanonical(Filename) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Filename) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 499, __PRETTY_FUNCTION__))
;
500 assert(isCanonical(Directory) && "Expected canonical MDString")((isCanonical(Directory) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Directory) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 500, __PRETTY_FUNCTION__))
;
501 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString")(((!CS || isCanonical(CS->Value)) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("(!CS || isCanonical(CS->Value)) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 501, __PRETTY_FUNCTION__))
;
502 assert((!Source || isCanonical(*Source)) && "Expected canonical MDString")(((!Source || isCanonical(*Source)) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("(!Source || isCanonical(*Source)) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 502, __PRETTY_FUNCTION__))
;
503 DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIFiles, DIFileInfo::KeyTy(Filename, Directory, CS
, Source))) return N; if (!ShouldCreate) return nullptr; } else
{ ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 503, __PRETTY_FUNCTION__)); } } while (false)
;
504 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr,
505 Source.getValueOr(nullptr)};
506 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops)return storeImpl(new (array_lengthof(Ops)) DIFile(Context, Storage
, CS, Source, Ops), Storage, Context.pImpl->DIFiles)
;
507}
508
509DICompileUnit *DICompileUnit::getImpl(
510 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
511 MDString *Producer, bool IsOptimized, MDString *Flags,
512 unsigned RuntimeVersion, MDString *SplitDebugFilename,
513 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
514 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
515 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
516 unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
517 bool ShouldCreate) {
518 assert(Storage != Uniqued && "Cannot unique DICompileUnit")((Storage != Uniqued && "Cannot unique DICompileUnit"
) ? static_cast<void> (0) : __assert_fail ("Storage != Uniqued && \"Cannot unique DICompileUnit\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 518, __PRETTY_FUNCTION__))
;
519 assert(isCanonical(Producer) && "Expected canonical MDString")((isCanonical(Producer) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Producer) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 519, __PRETTY_FUNCTION__))
;
520 assert(isCanonical(Flags) && "Expected canonical MDString")((isCanonical(Flags) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(Flags) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 520, __PRETTY_FUNCTION__))
;
521 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString")((isCanonical(SplitDebugFilename) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(SplitDebugFilename) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 521, __PRETTY_FUNCTION__))
;
522
523 Metadata *Ops[] = {
524 File, Producer, Flags, SplitDebugFilename,
525 EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
526 Macros};
527 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
528 Context, Storage, SourceLanguage, IsOptimized,
529 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
530 DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
531 Ops),
532 Storage);
533}
534
535Optional<DICompileUnit::DebugEmissionKind>
536DICompileUnit::getEmissionKind(StringRef Str) {
537 return StringSwitch<Optional<DebugEmissionKind>>(Str)
538 .Case("NoDebug", NoDebug)
539 .Case("FullDebug", FullDebug)
540 .Case("LineTablesOnly", LineTablesOnly)
541 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
542 .Default(None);
543}
544
545Optional<DICompileUnit::DebugNameTableKind>
546DICompileUnit::getNameTableKind(StringRef Str) {
547 return StringSwitch<Optional<DebugNameTableKind>>(Str)
548 .Case("Default", DebugNameTableKind::Default)
549 .Case("GNU", DebugNameTableKind::GNU)
550 .Case("None", DebugNameTableKind::None)
551 .Default(None);
552}
553
554const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
555 switch (EK) {
556 case NoDebug: return "NoDebug";
557 case FullDebug: return "FullDebug";
558 case LineTablesOnly: return "LineTablesOnly";
559 case DebugDirectivesOnly: return "DebugDirectivesOnly";
560 }
561 return nullptr;
562}
563
564const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
565 switch (NTK) {
566 case DebugNameTableKind::Default:
567 return nullptr;
568 case DebugNameTableKind::GNU:
569 return "GNU";
570 case DebugNameTableKind::None:
571 return "None";
572 }
573 return nullptr;
574}
575
576DISubprogram *DILocalScope::getSubprogram() const {
577 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
578 return Block->getScope()->getSubprogram();
579 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
580}
581
582DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
583 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
584 return File->getScope()->getNonLexicalBlockFileScope();
585 return const_cast<DILocalScope *>(this);
586}
587
588DISubprogram::DISPFlags DISubprogram::getFlag(StringRef Flag) {
589 return StringSwitch<DISPFlags>(Flag)
590#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
591#include "llvm/IR/DebugInfoFlags.def"
592 .Default(SPFlagZero);
593}
594
595StringRef DISubprogram::getFlagString(DISPFlags Flag) {
596 switch (Flag) {
597 // Appease a warning.
598 case SPFlagVirtuality:
599 return "";
600#define HANDLE_DISP_FLAG(ID, NAME) \
601 case SPFlag##NAME: \
602 return "DISPFlag" #NAME;
603#include "llvm/IR/DebugInfoFlags.def"
604 }
605 return "";
606}
607
608DISubprogram::DISPFlags
609DISubprogram::splitFlags(DISPFlags Flags,
610 SmallVectorImpl<DISPFlags> &SplitFlags) {
611 // Multi-bit fields can require special handling. In our case, however, the
612 // only multi-bit field is virtuality, and all its values happen to be
613 // single-bit values, so the right behavior just falls out.
614#define HANDLE_DISP_FLAG(ID, NAME) \
615 if (DISPFlags Bit = Flags & SPFlag##NAME) { \
616 SplitFlags.push_back(Bit); \
617 Flags &= ~Bit; \
618 }
619#include "llvm/IR/DebugInfoFlags.def"
620 return Flags;
621}
622
623DISubprogram *DISubprogram::getImpl(
624 LLVMContext &Context, Metadata *Scope, MDString *Name,
625 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
626 unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
627 int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
628 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
629 Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
630 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 630, __PRETTY_FUNCTION__))
;
631 assert(isCanonical(LinkageName) && "Expected canonical MDString")((isCanonical(LinkageName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(LinkageName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 631, __PRETTY_FUNCTION__))
;
632 DEFINE_GETIMPL_LOOKUP(DISubprogram,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
633 (Scope, Name, LinkageName, File, Line, Type, ScopeLine,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
634 ContainingType, VirtualIndex, ThisAdjustment, Flags,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
635 SPFlags, Unit, TemplateParams, Declaration,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
636 RetainedNodes, ThrownTypes))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DISubprograms, DISubprogramInfo::KeyTy(Scope, Name
, LinkageName, File, Line, Type, ScopeLine, ContainingType, VirtualIndex
, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams, Declaration
, RetainedNodes, ThrownTypes))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 636, __PRETTY_FUNCTION__)); } } while (false)
;
637 SmallVector<Metadata *, 11> Ops = {
638 File, Scope, Name, LinkageName, Type, Unit,
639 Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
640 if (!ThrownTypes) {
641 Ops.pop_back();
642 if (!TemplateParams) {
643 Ops.pop_back();
644 if (!ContainingType)
645 Ops.pop_back();
646 }
647 }
648 DEFINE_GETIMPL_STORE_N(return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
649 DISubprogram,return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
650 (Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags), Ops,return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
651 Ops.size())return storeImpl(new (Ops.size()) DISubprogram(Context, Storage
, Line, ScopeLine, VirtualIndex, ThisAdjustment, Flags, SPFlags
, Ops), Storage, Context.pImpl->DISubprograms)
;
652}
653
654bool DISubprogram::describes(const Function *F) const {
655 assert(F && "Invalid function")((F && "Invalid function") ? static_cast<void> (
0) : __assert_fail ("F && \"Invalid function\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 655, __PRETTY_FUNCTION__))
;
656 if (F->getSubprogram() == this)
657 return true;
658 StringRef Name = getLinkageName();
659 if (Name.empty())
660 Name = getName();
661 return F->getName() == Name;
662}
663
664DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
665 Metadata *File, unsigned Line,
666 unsigned Column, StorageType Storage,
667 bool ShouldCreate) {
668 // Fixup column.
669 adjustColumn(Column);
670
671 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 671, __PRETTY_FUNCTION__))
;
672 DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILexicalBlocks, DILexicalBlockInfo::KeyTy(Scope, File
, Line, Column))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 672, __PRETTY_FUNCTION__)); } } while (false)
;
673 Metadata *Ops[] = {File, Scope};
674 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops)return storeImpl(new (array_lengthof(Ops)) DILexicalBlock(Context
, Storage, Line, Column, Ops), Storage, Context.pImpl->DILexicalBlocks
)
;
675}
676
677DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
678 Metadata *Scope, Metadata *File,
679 unsigned Discriminator,
680 StorageType Storage,
681 bool ShouldCreate) {
682 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 682, __PRETTY_FUNCTION__))
;
683 DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILexicalBlockFiles, DILexicalBlockFileInfo::KeyTy
(Scope, File, Discriminator))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 683, __PRETTY_FUNCTION__)); } } while (false)
;
684 Metadata *Ops[] = {File, Scope};
685 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops)return storeImpl(new (array_lengthof(Ops)) DILexicalBlockFile
(Context, Storage, Discriminator, Ops), Storage, Context.pImpl
->DILexicalBlockFiles)
;
686}
687
688DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
689 MDString *Name, bool ExportSymbols,
690 StorageType Storage, bool ShouldCreate) {
691 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 691, __PRETTY_FUNCTION__))
;
692 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DINamespaces, DINamespaceInfo::KeyTy(Scope, Name, ExportSymbols
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 692, __PRETTY_FUNCTION__)); } } while (false)
;
693 // The nullptr is for DIScope's File operand. This should be refactored.
694 Metadata *Ops[] = {nullptr, Scope, Name};
695 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops)return storeImpl(new (array_lengthof(Ops)) DINamespace(Context
, Storage, ExportSymbols, Ops), Storage, Context.pImpl->DINamespaces
)
;
696}
697
698DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
699 MDString *Name, MDString *ConfigurationMacros,
700 MDString *IncludePath, MDString *ISysRoot,
701 StorageType Storage, bool ShouldCreate) {
702 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 702, __PRETTY_FUNCTION__))
;
703 DEFINE_GETIMPL_LOOKUP(do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIModules, DIModuleInfo::KeyTy(Scope, Name, ConfigurationMacros
, IncludePath, ISysRoot))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 704, __PRETTY_FUNCTION__)); } } while (false)
704 DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIModules, DIModuleInfo::KeyTy(Scope, Name, ConfigurationMacros
, IncludePath, ISysRoot))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 704, __PRETTY_FUNCTION__)); } } while (false)
;
705 Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
706 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops)return storeImpl(new (array_lengthof(Ops)) DIModule(Context, Storage
, Ops), Storage, Context.pImpl->DIModules)
;
707}
708
709DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
710 MDString *Name,
711 Metadata *Type,
712 StorageType Storage,
713 bool ShouldCreate) {
714 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 714, __PRETTY_FUNCTION__))
;
715 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DITemplateTypeParameters, DITemplateTypeParameterInfo
::KeyTy(Name, Type))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 715, __PRETTY_FUNCTION__)); } } while (false)
;
716 Metadata *Ops[] = {Name, Type};
717 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops)return storeImpl(new (array_lengthof(Ops)) DITemplateTypeParameter
(Context, Storage, Ops), Storage, Context.pImpl->DITemplateTypeParameters
)
;
718}
719
720DITemplateValueParameter *DITemplateValueParameter::getImpl(
721 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
722 Metadata *Value, StorageType Storage, bool ShouldCreate) {
723 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 723, __PRETTY_FUNCTION__))
;
724 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DITemplateValueParameters, DITemplateValueParameterInfo
::KeyTy(Tag, Name, Type, Value))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 724, __PRETTY_FUNCTION__)); } } while (false)
;
725 Metadata *Ops[] = {Name, Type, Value};
726 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops)return storeImpl(new (array_lengthof(Ops)) DITemplateValueParameter
(Context, Storage, Tag, Ops), Storage, Context.pImpl->DITemplateValueParameters
)
;
727}
728
729DIGlobalVariable *
730DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
731 MDString *LinkageName, Metadata *File, unsigned Line,
732 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
733 Metadata *StaticDataMemberDeclaration,
734 Metadata *TemplateParams, uint32_t AlignInBits,
735 StorageType Storage, bool ShouldCreate) {
736 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 736, __PRETTY_FUNCTION__))
;
737 assert(isCanonical(LinkageName) && "Expected canonical MDString")((isCanonical(LinkageName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(LinkageName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 737, __PRETTY_FUNCTION__))
;
738 DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, (Scope, Name, LinkageName, File, Line,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
739 Type, IsLocalToUnit, IsDefinition,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
740 StaticDataMemberDeclaration,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
741 TemplateParams, AlignInBits))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariables, DIGlobalVariableInfo::KeyTy(Scope
, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition
, StaticDataMemberDeclaration, TemplateParams, AlignInBits)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 741, __PRETTY_FUNCTION__)); } } while (false)
;
742 Metadata *Ops[] = {Scope,
743 Name,
744 File,
745 Type,
746 Name,
747 LinkageName,
748 StaticDataMemberDeclaration,
749 TemplateParams};
750 DEFINE_GETIMPL_STORE(DIGlobalVariable,return storeImpl(new (array_lengthof(Ops)) DIGlobalVariable(Context
, Storage, Line, IsLocalToUnit, IsDefinition, AlignInBits, Ops
), Storage, Context.pImpl->DIGlobalVariables)
751 (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops)return storeImpl(new (array_lengthof(Ops)) DIGlobalVariable(Context
, Storage, Line, IsLocalToUnit, IsDefinition, AlignInBits, Ops
), Storage, Context.pImpl->DIGlobalVariables)
;
752}
753
754DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
755 MDString *Name, Metadata *File,
756 unsigned Line, Metadata *Type,
757 unsigned Arg, DIFlags Flags,
758 uint32_t AlignInBits,
759 StorageType Storage,
760 bool ShouldCreate) {
761 // 64K ought to be enough for any frontend.
762 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits")((Arg <= (65535) && "Expected argument number to fit in 16-bits"
) ? static_cast<void> (0) : __assert_fail ("Arg <= UINT16_MAX && \"Expected argument number to fit in 16-bits\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 762, __PRETTY_FUNCTION__))
;
763
764 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 764, __PRETTY_FUNCTION__))
;
765 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 765, __PRETTY_FUNCTION__))
;
766 DEFINE_GETIMPL_LOOKUP(DILocalVariable,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits))) return N
; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 768, __PRETTY_FUNCTION__)); } } while (false)
767 (Scope, Name, File, Line, Type, Arg, Flags,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits))) return N
; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 768, __PRETTY_FUNCTION__)); } } while (false)
768 AlignInBits))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILocalVariables, DILocalVariableInfo::KeyTy(Scope
, Name, File, Line, Type, Arg, Flags, AlignInBits))) return N
; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 768, __PRETTY_FUNCTION__)); } } while (false)
;
769 Metadata *Ops[] = {Scope, Name, File, Type};
770 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops)return storeImpl(new (array_lengthof(Ops)) DILocalVariable(Context
, Storage, Line, Arg, Flags, AlignInBits, Ops), Storage, Context
.pImpl->DILocalVariables)
;
771}
772
773Optional<uint64_t> DIVariable::getSizeInBits() const {
774 // This is used by the Verifier so be mindful of broken types.
775 const Metadata *RawType = getRawType();
776 while (RawType) {
777 // Try to get the size directly.
778 if (auto *T = dyn_cast<DIType>(RawType))
779 if (uint64_t Size = T->getSizeInBits())
780 return Size;
781
782 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
783 // Look at the base type.
784 RawType = DT->getRawBaseType();
785 continue;
786 }
787
788 // Missing type or size.
789 break;
790 }
791
792 // Fail gracefully.
793 return None;
794}
795
796DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
797 MDString *Name, Metadata *File, unsigned Line,
798 StorageType Storage,
799 bool ShouldCreate) {
800 assert(Scope && "Expected scope")((Scope && "Expected scope") ? static_cast<void>
(0) : __assert_fail ("Scope && \"Expected scope\"", "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 800, __PRETTY_FUNCTION__))
;
801 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 801, __PRETTY_FUNCTION__))
;
802 DEFINE_GETIMPL_LOOKUP(DILabel,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILabels, DILabelInfo::KeyTy(Scope, Name, File, Line
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 803, __PRETTY_FUNCTION__)); } } while (false)
803 (Scope, Name, File, Line))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DILabels, DILabelInfo::KeyTy(Scope, Name, File, Line
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 803, __PRETTY_FUNCTION__)); } } while (false)
;
804 Metadata *Ops[] = {Scope, Name, File};
805 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops)return storeImpl(new (array_lengthof(Ops)) DILabel(Context, Storage
, Line, Ops), Storage, Context.pImpl->DILabels)
;
806}
807
808DIExpression *DIExpression::getImpl(LLVMContext &Context,
809 ArrayRef<uint64_t> Elements,
810 StorageType Storage, bool ShouldCreate) {
811 DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIExpressions, DIExpressionInfo::KeyTy(Elements)))
return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 811, __PRETTY_FUNCTION__)); } } while (false)
;
812 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements))return storeImpl(new (0u) DIExpression(Context, Storage, Elements
), Storage, Context.pImpl->DIExpressions)
;
813}
814
815unsigned DIExpression::ExprOperand::getSize() const {
816 switch (getOp()) {
817 case dwarf::DW_OP_LLVM_fragment:
818 return 3;
819 case dwarf::DW_OP_constu:
820 case dwarf::DW_OP_plus_uconst:
821 return 2;
822 default:
823 return 1;
824 }
825}
826
827bool DIExpression::isValid() const {
828 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
829 // Check that there's space for the operand.
830 if (I->get() + I->getSize() > E->get())
831 return false;
832
833 // Check that the operand is valid.
834 switch (I->getOp()) {
835 default:
836 return false;
837 case dwarf::DW_OP_LLVM_fragment:
838 // A fragment operator must appear at the end.
839 return I->get() + I->getSize() == E->get();
840 case dwarf::DW_OP_stack_value: {
841 // Must be the last one or followed by a DW_OP_LLVM_fragment.
842 if (I->get() + I->getSize() == E->get())
843 break;
844 auto J = I;
845 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
846 return false;
847 break;
848 }
849 case dwarf::DW_OP_swap: {
850 // Must be more than one implicit element on the stack.
851
852 // FIXME: A better way to implement this would be to add a local variable
853 // that keeps track of the stack depth and introduce something like a
854 // DW_LLVM_OP_implicit_location as a placeholder for the location this
855 // DIExpression is attached to, or else pass the number of implicit stack
856 // elements into isValid.
857 if (getNumElements() == 1)
858 return false;
859 break;
860 }
861 case dwarf::DW_OP_constu:
862 case dwarf::DW_OP_plus_uconst:
863 case dwarf::DW_OP_plus:
864 case dwarf::DW_OP_minus:
865 case dwarf::DW_OP_mul:
866 case dwarf::DW_OP_div:
867 case dwarf::DW_OP_mod:
868 case dwarf::DW_OP_or:
869 case dwarf::DW_OP_and:
870 case dwarf::DW_OP_xor:
871 case dwarf::DW_OP_shl:
872 case dwarf::DW_OP_shr:
873 case dwarf::DW_OP_shra:
874 case dwarf::DW_OP_deref:
875 case dwarf::DW_OP_xderef:
876 case dwarf::DW_OP_lit0:
877 case dwarf::DW_OP_not:
878 case dwarf::DW_OP_dup:
879 break;
880 }
881 }
882 return true;
883}
884
885Optional<DIExpression::FragmentInfo>
886DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
887 for (auto I = Start; I != End; ++I)
888 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
889 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
890 return Info;
891 }
892 return None;
893}
894
895void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
896 int64_t Offset) {
897 if (Offset > 0) {
898 Ops.push_back(dwarf::DW_OP_plus_uconst);
899 Ops.push_back(Offset);
900 } else if (Offset < 0) {
901 Ops.push_back(dwarf::DW_OP_constu);
902 Ops.push_back(-Offset);
903 Ops.push_back(dwarf::DW_OP_minus);
904 }
905}
906
907bool DIExpression::extractIfOffset(int64_t &Offset) const {
908 if (getNumElements() == 0) {
909 Offset = 0;
910 return true;
911 }
912
913 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
914 Offset = Elements[1];
915 return true;
916 }
917
918 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
919 if (Elements[2] == dwarf::DW_OP_plus) {
920 Offset = Elements[1];
921 return true;
922 }
923 if (Elements[2] == dwarf::DW_OP_minus) {
924 Offset = -Elements[1];
925 return true;
926 }
927 }
928
929 return false;
930}
931
932DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
933 int64_t Offset, bool DerefAfter,
934 bool StackValue) {
935 SmallVector<uint64_t, 8> Ops;
936 if (DerefBefore)
937 Ops.push_back(dwarf::DW_OP_deref);
938
939 appendOffset(Ops, Offset);
940 if (DerefAfter)
941 Ops.push_back(dwarf::DW_OP_deref);
942
943 return prependOpcodes(Expr, Ops, StackValue);
944}
945
946DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
947 SmallVectorImpl<uint64_t> &Ops,
948 bool StackValue) {
949 assert(Expr && "Can't prepend ops to this expression")((Expr && "Can't prepend ops to this expression") ? static_cast
<void> (0) : __assert_fail ("Expr && \"Can't prepend ops to this expression\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 949, __PRETTY_FUNCTION__))
;
950
951 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
952 if (Ops.empty())
953 StackValue = false;
954 for (auto Op : Expr->expr_ops()) {
955 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
956 if (StackValue) {
957 if (Op.getOp() == dwarf::DW_OP_stack_value)
958 StackValue = false;
959 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
960 Ops.push_back(dwarf::DW_OP_stack_value);
961 StackValue = false;
962 }
963 }
964 Op.appendToVector(Ops);
965 }
966 if (StackValue)
967 Ops.push_back(dwarf::DW_OP_stack_value);
968 return DIExpression::get(Expr->getContext(), Ops);
969}
970
971DIExpression *DIExpression::append(const DIExpression *Expr,
972 ArrayRef<uint64_t> Ops) {
973 assert(Expr && !Ops.empty() && "Can't append ops to this expression")((Expr && !Ops.empty() && "Can't append ops to this expression"
) ? static_cast<void> (0) : __assert_fail ("Expr && !Ops.empty() && \"Can't append ops to this expression\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 973, __PRETTY_FUNCTION__))
;
974
975 // Copy Expr's current op list.
976 SmallVector<uint64_t, 16> NewOps;
977 for (auto Op : Expr->expr_ops()) {
978 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
979 if (Op.getOp() == dwarf::DW_OP_stack_value ||
980 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
981 NewOps.append(Ops.begin(), Ops.end());
982
983 // Ensure that the new opcodes are only appended once.
984 Ops = None;
985 }
986 Op.appendToVector(NewOps);
987 }
988
989 NewOps.append(Ops.begin(), Ops.end());
990 return DIExpression::get(Expr->getContext(), NewOps);
991}
992
993DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
994 ArrayRef<uint64_t> Ops) {
995 assert(Expr && !Ops.empty() && "Can't append ops to this expression")((Expr && !Ops.empty() && "Can't append ops to this expression"
) ? static_cast<void> (0) : __assert_fail ("Expr && !Ops.empty() && \"Can't append ops to this expression\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 995, __PRETTY_FUNCTION__))
;
996 assert(none_of(Ops,((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
997 [](uint64_t Op) {((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
998 return Op == dwarf::DW_OP_stack_value ||((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
999 Op == dwarf::DW_OP_LLVM_fragment;((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
1000 }) &&((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
1001 "Can't append this op")((none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value
|| Op == dwarf::DW_OP_LLVM_fragment; }) && "Can't append this op"
) ? static_cast<void> (0) : __assert_fail ("none_of(Ops, [](uint64_t Op) { return Op == dwarf::DW_OP_stack_value || Op == dwarf::DW_OP_LLVM_fragment; }) && \"Can't append this op\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1001, __PRETTY_FUNCTION__))
;
1002
1003 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
1004 // has no DW_OP_stack_value.
1005 //
1006 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
1007 Optional<FragmentInfo> FI = Expr->getFragmentInfo();
1008 unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
1009 ArrayRef<uint64_t> ExprOpsBeforeFragment =
1010 Expr->getElements().drop_back(DropUntilStackValue);
1011 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
1012 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
1013 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
1014
1015 // Append a DW_OP_deref after Expr's current op list if needed, then append
1016 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
1017 SmallVector<uint64_t, 16> NewOps;
1018 if (NeedsDeref)
1019 NewOps.push_back(dwarf::DW_OP_deref);
1020 NewOps.append(Ops.begin(), Ops.end());
1021 if (NeedsStackValue)
1022 NewOps.push_back(dwarf::DW_OP_stack_value);
1023 return DIExpression::append(Expr, NewOps);
1024}
1025
1026Optional<DIExpression *> DIExpression::createFragmentExpression(
1027 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
1028 SmallVector<uint64_t, 8> Ops;
1029 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
1030 if (Expr) {
1031 for (auto Op : Expr->expr_ops()) {
1032 switch (Op.getOp()) {
1033 default: break;
1034 case dwarf::DW_OP_plus:
1035 case dwarf::DW_OP_minus:
1036 // We can't safely split arithmetic into multiple fragments because we
1037 // can't express carry-over between fragments.
1038 //
1039 // FIXME: We *could* preserve the lowest fragment of a constant offset
1040 // operation if the offset fits into SizeInBits.
1041 return None;
1042 case dwarf::DW_OP_LLVM_fragment: {
1043 // Make the new offset point into the existing fragment.
1044 uint64_t FragmentOffsetInBits = Op.getArg(0);
1045 uint64_t FragmentSizeInBits = Op.getArg(1);
1046 (void)FragmentSizeInBits;
1047 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&(((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
"new fragment outside of original fragment") ? static_cast<
void> (0) : __assert_fail ("(OffsetInBits + SizeInBits <= FragmentSizeInBits) && \"new fragment outside of original fragment\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1048, __PRETTY_FUNCTION__))
1048 "new fragment outside of original fragment")(((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
"new fragment outside of original fragment") ? static_cast<
void> (0) : __assert_fail ("(OffsetInBits + SizeInBits <= FragmentSizeInBits) && \"new fragment outside of original fragment\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1048, __PRETTY_FUNCTION__))
;
1049 OffsetInBits += FragmentOffsetInBits;
1050 continue;
1051 }
1052 }
1053 Op.appendToVector(Ops);
1054 }
1055 }
1056 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
1057 Ops.push_back(OffsetInBits);
1058 Ops.push_back(SizeInBits);
1059 return DIExpression::get(Expr->getContext(), Ops);
1060}
1061
1062bool DIExpression::isConstant() const {
1063 // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
1064 if (getNumElements() != 3 && getNumElements() != 6)
1065 return false;
1066 if (getElement(0) != dwarf::DW_OP_constu ||
1067 getElement(2) != dwarf::DW_OP_stack_value)
1068 return false;
1069 if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
1070 return false;
1071 return true;
1072}
1073
1074DIGlobalVariableExpression *
1075DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
1076 Metadata *Expression, StorageType Storage,
1077 bool ShouldCreate) {
1078 DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIGlobalVariableExpressions, DIGlobalVariableExpressionInfo
::KeyTy(Variable, Expression))) return N; if (!ShouldCreate) return
nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1078, __PRETTY_FUNCTION__)); } } while (false)
;
1079 Metadata *Ops[] = {Variable, Expression};
1080 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops)return storeImpl(new (array_lengthof(Ops)) DIGlobalVariableExpression
(Context, Storage, Ops), Storage, Context.pImpl->DIGlobalVariableExpressions
)
;
1081}
1082
1083DIObjCProperty *DIObjCProperty::getImpl(
1084 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1085 MDString *GetterName, MDString *SetterName, unsigned Attributes,
1086 Metadata *Type, StorageType Storage, bool ShouldCreate) {
1087 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1087, __PRETTY_FUNCTION__))
;
1088 assert(isCanonical(GetterName) && "Expected canonical MDString")((isCanonical(GetterName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(GetterName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1088, __PRETTY_FUNCTION__))
;
1089 assert(isCanonical(SetterName) && "Expected canonical MDString")((isCanonical(SetterName) && "Expected canonical MDString"
) ? static_cast<void> (0) : __assert_fail ("isCanonical(SetterName) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1089, __PRETTY_FUNCTION__))
;
1090 DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIObjCPropertys, DIObjCPropertyInfo::KeyTy(Name, File
, Line, GetterName, SetterName, Attributes, Type))) return N;
if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1091, __PRETTY_FUNCTION__)); } } while (false)
1091 SetterName, Attributes, Type))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIObjCPropertys, DIObjCPropertyInfo::KeyTy(Name, File
, Line, GetterName, SetterName, Attributes, Type))) return N;
if (!ShouldCreate) return nullptr; } else { ((ShouldCreate &&
"Expected non-uniqued nodes to always be created") ? static_cast
<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1091, __PRETTY_FUNCTION__)); } } while (false)
;
1092 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
1093 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops)return storeImpl(new (array_lengthof(Ops)) DIObjCProperty(Context
, Storage, Line, Attributes, Ops), Storage, Context.pImpl->
DIObjCPropertys)
;
1094}
1095
1096DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
1097 Metadata *Scope, Metadata *Entity,
1098 Metadata *File, unsigned Line,
1099 MDString *Name, StorageType Storage,
1100 bool ShouldCreate) {
1101 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1101, __PRETTY_FUNCTION__))
;
1102 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIImportedEntitys, DIImportedEntityInfo::KeyTy(Tag
, Scope, Entity, File, Line, Name))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1103, __PRETTY_FUNCTION__)); } } while (false)
1103 (Tag, Scope, Entity, File, Line, Name))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIImportedEntitys, DIImportedEntityInfo::KeyTy(Tag
, Scope, Entity, File, Line, Name))) return N; if (!ShouldCreate
) return nullptr; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1103, __PRETTY_FUNCTION__)); } } while (false)
;
1104 Metadata *Ops[] = {Scope, Entity, Name, File};
1105 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops)return storeImpl(new (array_lengthof(Ops)) DIImportedEntity(Context
, Storage, Tag, Line, Ops), Storage, Context.pImpl->DIImportedEntitys
)
;
1106}
1107
1108DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
1109 unsigned Line, MDString *Name, MDString *Value,
1110 StorageType Storage, bool ShouldCreate) {
1111 assert(isCanonical(Name) && "Expected canonical MDString")((isCanonical(Name) && "Expected canonical MDString")
? static_cast<void> (0) : __assert_fail ("isCanonical(Name) && \"Expected canonical MDString\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1111, __PRETTY_FUNCTION__))
;
1112 DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIMacros, DIMacroInfo::KeyTy(MIType, Line, Name, Value
))) return N; if (!ShouldCreate) return nullptr; } else { ((ShouldCreate
&& "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1112, __PRETTY_FUNCTION__)); } } while (false)
;
1113 Metadata *Ops[] = { Name, Value };
1114 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops)return storeImpl(new (array_lengthof(Ops)) DIMacro(Context, Storage
, MIType, Line, Ops), Storage, Context.pImpl->DIMacros)
;
1115}
1116
1117DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
1118 unsigned Line, Metadata *File,
1119 Metadata *Elements, StorageType Storage,
1120 bool ShouldCreate) {
1121 DEFINE_GETIMPL_LOOKUP(DIMacroFile,do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIMacroFiles, DIMacroFileInfo::KeyTy(MIType, Line,
File, Elements))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1122, __PRETTY_FUNCTION__)); } } while (false)
1122 (MIType, Line, File, Elements))do { if (Storage == Uniqued) { if (auto *N = getUniqued(Context
.pImpl->DIMacroFiles, DIMacroFileInfo::KeyTy(MIType, Line,
File, Elements))) return N; if (!ShouldCreate) return nullptr
; } else { ((ShouldCreate && "Expected non-uniqued nodes to always be created"
) ? static_cast<void> (0) : __assert_fail ("ShouldCreate && \"Expected non-uniqued nodes to always be created\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/IR/DebugInfoMetadata.cpp"
, 1122, __PRETTY_FUNCTION__)); } } while (false)
;
1123 Metadata *Ops[] = { File, Elements };
1124 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops)return storeImpl(new (array_lengthof(Ops)) DIMacroFile(Context
, Storage, MIType, Line, Ops), Storage, Context.pImpl->DIMacroFiles
)
;
1125}

/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h

1//===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Declarations for metadata specific to debug info.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_DEBUGINFOMETADATA_H
15#define LLVM_IR_DEBUGINFOMETADATA_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/BitmaskEnum.h"
19#include "llvm/ADT/None.h"
20#include "llvm/ADT/Optional.h"
21#include "llvm/ADT/PointerUnion.h"
22#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/ADT/StringRef.h"
25#include "llvm/ADT/iterator_range.h"
26#include "llvm/BinaryFormat/Dwarf.h"
27#include "llvm/IR/Constants.h"
28#include "llvm/IR/Metadata.h"
29#include "llvm/Support/Casting.h"
30#include <cassert>
31#include <climits>
32#include <cstddef>
33#include <cstdint>
34#include <iterator>
35#include <type_traits>
36#include <vector>
37
38// Helper macros for defining get() overrides.
39#define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
40#define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
41#define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)static CLASS *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
(FORMAL)) { return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(
ARGS), Distinct); } static TempCLASS getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { return TempCLASS
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)
); }
\
42 static CLASS *getDistinct(LLVMContext &Context, \
43 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
44 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
45 } \
46 static Temp##CLASS getTemporary(LLVMContext &Context, \
47 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
48 return Temp##CLASS( \
49 getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
50 }
51#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
52 static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
53 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
54 } \
55 static CLASS *getIfExists(LLVMContext &Context, \
56 DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
57 return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
58 /* ShouldCreate */ false); \
59 } \
60 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS)static CLASS *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
(FORMAL)) { return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(
ARGS), Distinct); } static TempCLASS getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { return TempCLASS
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)
); }
61
62namespace llvm {
63
64/// Holds a subclass of DINode.
65///
66/// FIXME: This class doesn't currently make much sense. Previously it was a
67/// union beteen MDString (for ODR-uniqued types) and things like DIType. To
68/// support CodeView work, it wasn't deleted outright when MDString-based type
69/// references were deleted; we'll soon need a similar concept for CodeView
70/// DITypeIndex.
71template <class T> class TypedDINodeRef {
72 const Metadata *MD = nullptr;
73
74public:
75 TypedDINodeRef() = default;
76 TypedDINodeRef(std::nullptr_t) {}
77 TypedDINodeRef(const T *MD) : MD(MD) {}
78
79 explicit TypedDINodeRef(const Metadata *MD) : MD(MD) {
80 assert((!MD || isa<T>(MD)) && "Expected valid type ref")(((!MD || isa<T>(MD)) && "Expected valid type ref"
) ? static_cast<void> (0) : __assert_fail ("(!MD || isa<T>(MD)) && \"Expected valid type ref\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 80, __PRETTY_FUNCTION__))
;
81 }
82
83 template <class U>
84 TypedDINodeRef(
85 const TypedDINodeRef<U> &X,
86 typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
87 nullptr)
88 : MD(X) {}
89
90 operator Metadata *() const { return const_cast<Metadata *>(MD); }
91
92 T *resolve() const { return const_cast<T *>(cast_or_null<T>(MD)); }
93
94 bool operator==(const TypedDINodeRef<T> &X) const { return MD == X.MD; }
95 bool operator!=(const TypedDINodeRef<T> &X) const { return MD != X.MD; }
96};
97
98using DINodeRef = TypedDINodeRef<DINode>;
99using DIScopeRef = TypedDINodeRef<DIScope>;
100using DITypeRef = TypedDINodeRef<DIType>;
101
102class DITypeRefArray {
103 const MDTuple *N = nullptr;
104
105public:
106 DITypeRefArray() = default;
107 DITypeRefArray(const MDTuple *N) : N(N) {}
108
109 explicit operator bool() const { return get(); }
110 explicit operator MDTuple *() const { return get(); }
111
112 MDTuple *get() const { return const_cast<MDTuple *>(N); }
113 MDTuple *operator->() const { return get(); }
114 MDTuple &operator*() const { return *get(); }
115
116 // FIXME: Fix callers and remove condition on N.
117 unsigned size() const { return N ? N->getNumOperands() : 0u; }
118 DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); }
119
120 class iterator : std::iterator<std::input_iterator_tag, DITypeRef,
121 std::ptrdiff_t, void, DITypeRef> {
122 MDNode::op_iterator I = nullptr;
123
124 public:
125 iterator() = default;
126 explicit iterator(MDNode::op_iterator I) : I(I) {}
127
128 DITypeRef operator*() const { return DITypeRef(*I); }
129
130 iterator &operator++() {
131 ++I;
132 return *this;
133 }
134
135 iterator operator++(int) {
136 iterator Temp(*this);
137 ++I;
138 return Temp;
139 }
140
141 bool operator==(const iterator &X) const { return I == X.I; }
142 bool operator!=(const iterator &X) const { return I != X.I; }
143 };
144
145 // FIXME: Fix callers and remove condition on N.
146 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
147 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
148};
149
150/// Tagged DWARF-like metadata node.
151///
152/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
153/// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's
154/// potentially used for non-DWARF output.
155class DINode : public MDNode {
156 friend class LLVMContextImpl;
157 friend class MDNode;
158
159protected:
160 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
161 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
162 : MDNode(C, ID, Storage, Ops1, Ops2) {
163 assert(Tag < 1u << 16)((Tag < 1u << 16) ? static_cast<void> (0) : __assert_fail
("Tag < 1u << 16", "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 163, __PRETTY_FUNCTION__))
;
164 SubclassData16 = Tag;
165 }
166 ~DINode() = default;
167
168 template <class Ty> Ty *getOperandAs(unsigned I) const {
169 return cast_or_null<Ty>(getOperand(I));
170 }
171
172 StringRef getStringOperand(unsigned I) const {
173 if (auto *S = getOperandAs<MDString>(I))
174 return S->getString();
175 return StringRef();
176 }
177
178 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
179 if (S.empty())
180 return nullptr;
181 return MDString::get(Context, S);
182 }
183
184 /// Allow subclasses to mutate the tag.
185 void setTag(unsigned Tag) { SubclassData16 = Tag; }
186
187public:
188 unsigned getTag() const { return SubclassData16; }
189
190 /// Debug info flags.
191 ///
192 /// The three accessibility flags are mutually exclusive and rolled together
193 /// in the first two bits.
194 enum DIFlags : uint32_t {
195#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
196#define DI_FLAG_LARGEST_NEEDED
197#include "llvm/IR/DebugInfoFlags.def"
198 FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic,
199 FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance |
200 FlagVirtualInheritance,
201 LLVM_MARK_AS_BITMASK_ENUM(FlagLargest)LLVM_BITMASK_LARGEST_ENUMERATOR = FlagLargest
202 };
203
204 static DIFlags getFlag(StringRef Flag);
205 static StringRef getFlagString(DIFlags Flag);
206
207 /// Split up a flags bitfield.
208 ///
209 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
210 /// any remaining (unrecognized) bits.
211 static DIFlags splitFlags(DIFlags Flags,
212 SmallVectorImpl<DIFlags> &SplitFlags);
213
214 static bool classof(const Metadata *MD) {
215 switch (MD->getMetadataID()) {
216 default:
217 return false;
218 case GenericDINodeKind:
219 case DISubrangeKind:
220 case DIEnumeratorKind:
221 case DIBasicTypeKind:
222 case DIDerivedTypeKind:
223 case DICompositeTypeKind:
224 case DISubroutineTypeKind:
225 case DIFileKind:
226 case DICompileUnitKind:
227 case DISubprogramKind:
228 case DILexicalBlockKind:
229 case DILexicalBlockFileKind:
230 case DINamespaceKind:
231 case DITemplateTypeParameterKind:
232 case DITemplateValueParameterKind:
233 case DIGlobalVariableKind:
234 case DILocalVariableKind:
235 case DILabelKind:
236 case DIObjCPropertyKind:
237 case DIImportedEntityKind:
238 case DIModuleKind:
239 return true;
240 }
241 }
242};
243
244template <class T> struct simplify_type<const TypedDINodeRef<T>> {
245 using SimpleType = Metadata *;
246
247 static SimpleType getSimplifiedValue(const TypedDINodeRef<T> &MD) {
248 return MD;
249 }
250};
251
252template <class T>
253struct simplify_type<TypedDINodeRef<T>>
254 : simplify_type<const TypedDINodeRef<T>> {};
255
256/// Generic tagged DWARF-like metadata node.
257///
258/// An un-specialized DWARF-like metadata node. The first operand is a
259/// (possibly empty) null-separated \a MDString header that contains arbitrary
260/// fields. The remaining operands are \a dwarf_operands(), and are pointers
261/// to other metadata.
262class GenericDINode : public DINode {
263 friend class LLVMContextImpl;
264 friend class MDNode;
265
266 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
267 unsigned Tag, ArrayRef<Metadata *> Ops1,
268 ArrayRef<Metadata *> Ops2)
269 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
270 setHash(Hash);
271 }
272 ~GenericDINode() { dropAllReferences(); }
273
274 void setHash(unsigned Hash) { SubclassData32 = Hash; }
275 void recalculateHash();
276
277 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
278 StringRef Header, ArrayRef<Metadata *> DwarfOps,
279 StorageType Storage, bool ShouldCreate = true) {
280 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
281 DwarfOps, Storage, ShouldCreate);
282 }
283
284 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
285 MDString *Header, ArrayRef<Metadata *> DwarfOps,
286 StorageType Storage, bool ShouldCreate = true);
287
288 TempGenericDINode cloneImpl() const {
289 return getTemporary(
290 getContext(), getTag(), getHeader(),
291 SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
292 }
293
294public:
295 unsigned getHash() const { return SubclassData32; }
296
297 DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header,
298 ArrayRef<Metadata *> DwarfOps),
299 (Tag, Header, DwarfOps))
300 DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header,
301 ArrayRef<Metadata *> DwarfOps),
302 (Tag, Header, DwarfOps))
303
304 /// Return a (temporary) clone of this.
305 TempGenericDINode clone() const { return cloneImpl(); }
306
307 unsigned getTag() const { return SubclassData16; }
308 StringRef getHeader() const { return getStringOperand(0); }
309 MDString *getRawHeader() const { return getOperandAs<MDString>(0); }
310
311 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
312 op_iterator dwarf_op_end() const { return op_end(); }
313 op_range dwarf_operands() const {
314 return op_range(dwarf_op_begin(), dwarf_op_end());
315 }
316
317 unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
318 const MDOperand &getDwarfOperand(unsigned I) const {
319 return getOperand(I + 1);
320 }
321 void replaceDwarfOperandWith(unsigned I, Metadata *New) {
322 replaceOperandWith(I + 1, New);
323 }
324
325 static bool classof(const Metadata *MD) {
326 return MD->getMetadataID() == GenericDINodeKind;
327 }
328};
329
330/// Array subrange.
331///
332/// TODO: Merge into node for DW_TAG_array_type, which should have a custom
333/// type.
334class DISubrange : public DINode {
335 friend class LLVMContextImpl;
336 friend class MDNode;
337
338 int64_t LowerBound;
339
340 DISubrange(LLVMContext &C, StorageType Storage, Metadata *Node,
341 int64_t LowerBound, ArrayRef<Metadata *> Ops)
342 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops),
343 LowerBound(LowerBound) {}
344
345 ~DISubrange() = default;
346
347 static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
348 int64_t LowerBound, StorageType Storage,
349 bool ShouldCreate = true);
350
351 static DISubrange *getImpl(LLVMContext &Context, Metadata *CountNode,
352 int64_t LowerBound, StorageType Storage,
353 bool ShouldCreate = true);
354
355 TempDISubrange cloneImpl() const {
356 return getTemporary(getContext(), getRawCountNode(), getLowerBound());
357 }
358
359public:
360 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
361 (Count, LowerBound))
362
363 DEFINE_MDNODE_GET(DISubrange, (Metadata *CountNode, int64_t LowerBound = 0),
364 (CountNode, LowerBound))
365
366 TempDISubrange clone() const { return cloneImpl(); }
367
368 int64_t getLowerBound() const { return LowerBound; }
369
370 Metadata *getRawCountNode() const {
371 return getOperand(0).get();
372 }
373
374 typedef PointerUnion<ConstantInt*, DIVariable*> CountType;
375
376 CountType getCount() const {
377 if (auto *MD = dyn_cast<ConstantAsMetadata>(getRawCountNode()))
378 return CountType(cast<ConstantInt>(MD->getValue()));
379
380 if (auto *DV = dyn_cast<DIVariable>(getRawCountNode()))
381 return CountType(DV);
382
383 return CountType();
384 }
385
386 static bool classof(const Metadata *MD) {
387 return MD->getMetadataID() == DISubrangeKind;
388 }
389};
390
391/// Enumeration value.
392///
393/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
394/// longer creates a type cycle.
395class DIEnumerator : public DINode {
396 friend class LLVMContextImpl;
397 friend class MDNode;
398
399 int64_t Value;
400 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
401 bool IsUnsigned, ArrayRef<Metadata *> Ops)
402 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
403 Value(Value) {
404 SubclassData32 = IsUnsigned;
405 }
406 ~DIEnumerator() = default;
407
408 static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
409 bool IsUnsigned, StringRef Name,
410 StorageType Storage, bool ShouldCreate = true) {
411 return getImpl(Context, Value, IsUnsigned,
412 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
413 }
414 static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
415 bool IsUnsigned, MDString *Name,
416 StorageType Storage, bool ShouldCreate = true);
417
418 TempDIEnumerator cloneImpl() const {
419 return getTemporary(getContext(), getValue(), isUnsigned(), getName());
420 }
421
422public:
423 DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, bool IsUnsigned, StringRef Name),
424 (Value, IsUnsigned, Name))
425 DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, bool IsUnsigned, MDString *Name),
426 (Value, IsUnsigned, Name))
427
428 TempDIEnumerator clone() const { return cloneImpl(); }
429
430 int64_t getValue() const { return Value; }
431 bool isUnsigned() const { return SubclassData32; }
432 StringRef getName() const { return getStringOperand(0); }
433
434 MDString *getRawName() const { return getOperandAs<MDString>(0); }
435
436 static bool classof(const Metadata *MD) {
437 return MD->getMetadataID() == DIEnumeratorKind;
438 }
439};
440
441/// Base class for scope-like contexts.
442///
443/// Base class for lexical scopes and types (which are also declaration
444/// contexts).
445///
446/// TODO: Separate the concepts of declaration contexts and lexical scopes.
447class DIScope : public DINode {
448protected:
449 DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
450 ArrayRef<Metadata *> Ops)
451 : DINode(C, ID, Storage, Tag, Ops) {}
452 ~DIScope() = default;
453
454public:
455 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
456
457 inline StringRef getFilename() const;
458 inline StringRef getDirectory() const;
459 inline Optional<StringRef> getSource() const;
460
461 StringRef getName() const;
462 DIScopeRef getScope() const;
463
464 /// Return the raw underlying file.
465 ///
466 /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file (it
467 /// \em is the file). If \c this is an \a DIFile, we need to return \c this.
468 /// Otherwise, return the first operand, which is where all other subclasses
469 /// store their file pointer.
470 Metadata *getRawFile() const {
471 return isa<DIFile>(this) ? const_cast<DIScope *>(this)
472 : static_cast<Metadata *>(getOperand(0));
473 }
474
475 static bool classof(const Metadata *MD) {
476 switch (MD->getMetadataID()) {
477 default:
478 return false;
479 case DIBasicTypeKind:
480 case DIDerivedTypeKind:
481 case DICompositeTypeKind:
482 case DISubroutineTypeKind:
483 case DIFileKind:
484 case DICompileUnitKind:
485 case DISubprogramKind:
486 case DILexicalBlockKind:
487 case DILexicalBlockFileKind:
488 case DINamespaceKind:
489 case DIModuleKind:
490 return true;
491 }
492 }
493};
494
495/// File.
496///
497/// TODO: Merge with directory/file node (including users).
498/// TODO: Canonicalize paths on creation.
499class DIFile : public DIScope {
500 friend class LLVMContextImpl;
501 friend class MDNode;
502
503public:
504 /// Which algorithm (e.g. MD5) a checksum was generated with.
505 ///
506 /// The encoding is explicit because it is used directly in Bitcode. The
507 /// value 0 is reserved to indicate the absence of a checksum in Bitcode.
508 enum ChecksumKind {
509 // The first variant was originally CSK_None, encoded as 0. The new
510 // internal representation removes the need for this by wrapping the
511 // ChecksumInfo in an Optional, but to preserve Bitcode compatibility the 0
512 // encoding is reserved.
513 CSK_MD5 = 1,
514 CSK_SHA1 = 2,
515 CSK_Last = CSK_SHA1 // Should be last enumeration.
516 };
517
518 /// A single checksum, represented by a \a Kind and a \a Value (a string).
519 template <typename T>
520 struct ChecksumInfo {
521 /// The kind of checksum which \a Value encodes.
522 ChecksumKind Kind;
523 /// The string value of the checksum.
524 T Value;
525
526 ChecksumInfo(ChecksumKind Kind, T Value) : Kind(Kind), Value(Value) { }
527 ~ChecksumInfo() = default;
528 bool operator==(const ChecksumInfo<T> &X) const {
529 return Kind == X.Kind && Value == X.Value;
530 }
531 bool operator!=(const ChecksumInfo<T> &X) const { return !(*this == X); }
532 StringRef getKindAsString() const { return getChecksumKindAsString(Kind); }
533 };
534
535private:
536 Optional<ChecksumInfo<MDString *>> Checksum;
537 Optional<MDString *> Source;
538
539 DIFile(LLVMContext &C, StorageType Storage,
540 Optional<ChecksumInfo<MDString *>> CS, Optional<MDString *> Src,
541 ArrayRef<Metadata *> Ops)
542 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops),
543 Checksum(CS), Source(Src) {}
544 ~DIFile() = default;
545
546 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
547 StringRef Directory,
548 Optional<ChecksumInfo<StringRef>> CS,
549 Optional<StringRef> Source,
550 StorageType Storage, bool ShouldCreate = true) {
551 Optional<ChecksumInfo<MDString *>> MDChecksum;
552 if (CS)
553 MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value));
554 return getImpl(Context, getCanonicalMDString(Context, Filename),
555 getCanonicalMDString(Context, Directory), MDChecksum,
556 Source ? Optional<MDString *>(getCanonicalMDString(Context, *Source)) : None,
557 Storage, ShouldCreate);
558 }
559 static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
560 MDString *Directory,
561 Optional<ChecksumInfo<MDString *>> CS,
562 Optional<MDString *> Source, StorageType Storage,
563 bool ShouldCreate = true);
564
565 TempDIFile cloneImpl() const {
566 return getTemporary(getContext(), getFilename(), getDirectory(),
567 getChecksum(), getSource());
568 }
569
570public:
571 DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory,
572 Optional<ChecksumInfo<StringRef>> CS = None,
573 Optional<StringRef> Source = None),
574 (Filename, Directory, CS, Source))
575 DEFINE_MDNODE_GET(DIFile, (MDString * Filename, MDString *Directory,
576 Optional<ChecksumInfo<MDString *>> CS = None,
577 Optional<MDString *> Source = None),
578 (Filename, Directory, CS, Source))
579
580 TempDIFile clone() const { return cloneImpl(); }
581
582 StringRef getFilename() const { return getStringOperand(0); }
583 StringRef getDirectory() const { return getStringOperand(1); }
584 Optional<ChecksumInfo<StringRef>> getChecksum() const {
585 Optional<ChecksumInfo<StringRef>> StringRefChecksum;
586 if (Checksum)
587 StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString());
588 return StringRefChecksum;
589 }
590 Optional<StringRef> getSource() const {
591 return Source ? Optional<StringRef>((*Source)->getString()) : None;
592 }
593
594 MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
595 MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
596 Optional<ChecksumInfo<MDString *>> getRawChecksum() const { return Checksum; }
597 Optional<MDString *> getRawSource() const { return Source; }
598
599 static StringRef getChecksumKindAsString(ChecksumKind CSKind);
600 static Optional<ChecksumKind> getChecksumKind(StringRef CSKindStr);
601
602 static bool classof(const Metadata *MD) {
603 return MD->getMetadataID() == DIFileKind;
604 }
605};
606
607StringRef DIScope::getFilename() const {
608 if (auto *F = getFile())
609 return F->getFilename();
610 return "";
611}
612
613StringRef DIScope::getDirectory() const {
614 if (auto *F = getFile())
615 return F->getDirectory();
616 return "";
617}
618
619Optional<StringRef> DIScope::getSource() const {
620 if (auto *F = getFile())
621 return F->getSource();
622 return None;
623}
624
625/// Base class for types.
626///
627/// TODO: Remove the hardcoded name and context, since many types don't use
628/// them.
629/// TODO: Split up flags.
630class DIType : public DIScope {
631 unsigned Line;
632 DIFlags Flags;
633 uint64_t SizeInBits;
634 uint64_t OffsetInBits;
635 uint32_t AlignInBits;
636
637protected:
638 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
639 unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
640 uint64_t OffsetInBits, DIFlags Flags, ArrayRef<Metadata *> Ops)
641 : DIScope(C, ID, Storage, Tag, Ops) {
642 init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
643 }
644 ~DIType() = default;
645
646 void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
647 uint64_t OffsetInBits, DIFlags Flags) {
648 this->Line = Line;
649 this->Flags = Flags;
650 this->SizeInBits = SizeInBits;
651 this->AlignInBits = AlignInBits;
652 this->OffsetInBits = OffsetInBits;
653 }
654
655 /// Change fields in place.
656 void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits,
657 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags) {
658 assert(isDistinct() && "Only distinct nodes can mutate")((isDistinct() && "Only distinct nodes can mutate") ?
static_cast<void> (0) : __assert_fail ("isDistinct() && \"Only distinct nodes can mutate\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 658, __PRETTY_FUNCTION__))
;
659 setTag(Tag);
660 init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
661 }
662
663public:
664 TempDIType clone() const {
665 return TempDIType(cast<DIType>(MDNode::clone().release()));
666 }
667
668 unsigned getLine() const { return Line; }
669 uint64_t getSizeInBits() const { return SizeInBits; }
670 uint32_t getAlignInBits() const { return AlignInBits; }
671 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT8; }
672 uint64_t getOffsetInBits() const { return OffsetInBits; }
673 DIFlags getFlags() const { return Flags; }
674
675 DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
676 StringRef getName() const { return getStringOperand(2); }
677
678
679 Metadata *getRawScope() const { return getOperand(1); }
680 MDString *getRawName() const { return getOperandAs<MDString>(2); }
681
682 /// Returns a new temporary DIType with updated Flags
683 TempDIType cloneWithFlags(DIFlags NewFlags) const {
684 auto NewTy = clone();
685 NewTy->Flags = NewFlags;
686 return NewTy;
687 }
688
689 bool isPrivate() const {
690 return (getFlags() & FlagAccessibility) == FlagPrivate;
691 }
692 bool isProtected() const {
693 return (getFlags() & FlagAccessibility) == FlagProtected;
694 }
695 bool isPublic() const {
696 return (getFlags() & FlagAccessibility) == FlagPublic;
697 }
698 bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
699 bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
700 bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
701 bool isVirtual() const { return getFlags() & FlagVirtual; }
702 bool isArtificial() const { return getFlags() & FlagArtificial; }
703 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
704 bool isObjcClassComplete() const {
705 return getFlags() & FlagObjcClassComplete;
706 }
707 bool isVector() const { return getFlags() & FlagVector; }
708 bool isBitField() const { return getFlags() & FlagBitField; }
709 bool isStaticMember() const { return getFlags() & FlagStaticMember; }
710 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
711 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
712 bool isTypePassByValue() const { return getFlags() & FlagTypePassByValue; }
713 bool isTypePassByReference() const {
714 return getFlags() & FlagTypePassByReference;
715 }
716 bool isBigEndian() const { return getFlags() & FlagBigEndian; }
717 bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
718
719 static bool classof(const Metadata *MD) {
720 switch (MD->getMetadataID()) {
721 default:
722 return false;
723 case DIBasicTypeKind:
724 case DIDerivedTypeKind:
725 case DICompositeTypeKind:
726 case DISubroutineTypeKind:
727 return true;
728 }
729 }
730};
731
732/// Basic type, like 'int' or 'float'.
733///
734/// TODO: Split out DW_TAG_unspecified_type.
735/// TODO: Drop unused accessors.
736class DIBasicType : public DIType {
737 friend class LLVMContextImpl;
738 friend class MDNode;
739
740 unsigned Encoding;
741
742 DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
743 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
744 DIFlags Flags, ArrayRef<Metadata *> Ops)
745 : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
746 Flags, Ops),
747 Encoding(Encoding) {}
748 ~DIBasicType() = default;
749
750 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
751 StringRef Name, uint64_t SizeInBits,
752 uint32_t AlignInBits, unsigned Encoding,
753 DIFlags Flags, StorageType Storage,
754 bool ShouldCreate = true) {
755 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
756 SizeInBits, AlignInBits, Encoding, Flags, Storage,
757 ShouldCreate);
758 }
759 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
760 MDString *Name, uint64_t SizeInBits,
761 uint32_t AlignInBits, unsigned Encoding,
762 DIFlags Flags, StorageType Storage,
763 bool ShouldCreate = true);
764
765 TempDIBasicType cloneImpl() const {
766 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
767 getAlignInBits(), getEncoding(), getFlags());
768 }
769
770public:
771 DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
772 (Tag, Name, 0, 0, 0, FlagZero))
773 DEFINE_MDNODE_GET(DIBasicType,
774 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
775 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
776 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
777 DEFINE_MDNODE_GET(DIBasicType,
778 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
779 uint32_t AlignInBits, unsigned Encoding, DIFlags Flags),
780 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags))
781
782 TempDIBasicType clone() const { return cloneImpl(); }
783
784 unsigned getEncoding() const { return Encoding; }
785
786 enum class Signedness { Signed, Unsigned };
787
788 /// Return the signedness of this type, or None if this type is neither
789 /// signed nor unsigned.
790 Optional<Signedness> getSignedness() const;
791
792 static bool classof(const Metadata *MD) {
793 return MD->getMetadataID() == DIBasicTypeKind;
794 }
795};
796
797/// Derived types.
798///
799/// This includes qualified types, pointers, references, friends, typedefs, and
800/// class members.
801///
802/// TODO: Split out members (inheritance, fields, methods, etc.).
803class DIDerivedType : public DIType {
804 friend class LLVMContextImpl;
805 friend class MDNode;
806
807 /// The DWARF address space of the memory pointed to or referenced by a
808 /// pointer or reference type respectively.
809 Optional<unsigned> DWARFAddressSpace;
810
811 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
812 unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
813 uint64_t OffsetInBits, Optional<unsigned> DWARFAddressSpace,
814 DIFlags Flags, ArrayRef<Metadata *> Ops)
815 : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
816 AlignInBits, OffsetInBits, Flags, Ops),
817 DWARFAddressSpace(DWARFAddressSpace) {}
818 ~DIDerivedType() = default;
819
820 static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
821 StringRef Name, DIFile *File, unsigned Line,
822 DIScopeRef Scope, DITypeRef BaseType,
823 uint64_t SizeInBits, uint32_t AlignInBits,
824 uint64_t OffsetInBits,
825 Optional<unsigned> DWARFAddressSpace,
826 DIFlags Flags, Metadata *ExtraData,
827 StorageType Storage, bool ShouldCreate = true) {
828 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
829 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
830 DWARFAddressSpace, Flags, ExtraData, Storage, ShouldCreate);
831 }
832 static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
833 MDString *Name, Metadata *File, unsigned Line,
834 Metadata *Scope, Metadata *BaseType,
835 uint64_t SizeInBits, uint32_t AlignInBits,
836 uint64_t OffsetInBits,
837 Optional<unsigned> DWARFAddressSpace,
838 DIFlags Flags, Metadata *ExtraData,
839 StorageType Storage, bool ShouldCreate = true);
840
841 TempDIDerivedType cloneImpl() const {
842 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
843 getScope(), getBaseType(), getSizeInBits(),
844 getAlignInBits(), getOffsetInBits(),
845 getDWARFAddressSpace(), getFlags(), getExtraData());
846 }
847
848public:
849 DEFINE_MDNODE_GET(DIDerivedType,
850 (unsigned Tag, MDString *Name, Metadata *File,
851 unsigned Line, Metadata *Scope, Metadata *BaseType,
852 uint64_t SizeInBits, uint32_t AlignInBits,
853 uint64_t OffsetInBits,
854 Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
855 Metadata *ExtraData = nullptr),
856 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
857 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
858 ExtraData))
859 DEFINE_MDNODE_GET(DIDerivedType,
860 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
861 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
862 uint32_t AlignInBits, uint64_t OffsetInBits,
863 Optional<unsigned> DWARFAddressSpace, DIFlags Flags,
864 Metadata *ExtraData = nullptr),
865 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
866 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
867 ExtraData))
868
869 TempDIDerivedType clone() const { return cloneImpl(); }
870
871 /// Get the base type this is derived from.
872 DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
873 Metadata *getRawBaseType() const { return getOperand(3); }
874
875 /// \returns The DWARF address space of the memory pointed to or referenced by
876 /// a pointer or reference type respectively.
877 Optional<unsigned> getDWARFAddressSpace() const { return DWARFAddressSpace; }
878
879 /// Get extra data associated with this derived type.
880 ///
881 /// Class type for pointer-to-members, objective-c property node for ivars,
882 /// global constant wrapper for static members, or virtual base pointer offset
883 /// for inheritance.
884 ///
885 /// TODO: Separate out types that need this extra operand: pointer-to-member
886 /// types and member fields (static members and ivars).
887 Metadata *getExtraData() const { return getRawExtraData(); }
888 Metadata *getRawExtraData() const { return getOperand(4); }
889
890 /// Get casted version of extra data.
891 /// @{
892 DITypeRef getClassType() const {
893 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type)((getTag() == dwarf::DW_TAG_ptr_to_member_type) ? static_cast
<void> (0) : __assert_fail ("getTag() == dwarf::DW_TAG_ptr_to_member_type"
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 893, __PRETTY_FUNCTION__))
;
894 return DITypeRef(getExtraData());
895 }
896
897 DIObjCProperty *getObjCProperty() const {
898 return dyn_cast_or_null<DIObjCProperty>(getExtraData());
899 }
900
901 uint32_t getVBPtrOffset() const {
902 assert(getTag() == dwarf::DW_TAG_inheritance)((getTag() == dwarf::DW_TAG_inheritance) ? static_cast<void
> (0) : __assert_fail ("getTag() == dwarf::DW_TAG_inheritance"
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 902, __PRETTY_FUNCTION__))
;
903 if (auto *CM = cast_or_null<ConstantAsMetadata>(getExtraData()))
904 if (auto *CI = dyn_cast_or_null<ConstantInt>(CM->getValue()))
905 return static_cast<uint32_t>(CI->getZExtValue());
906 return 0;
907 }
908
909 Constant *getStorageOffsetInBits() const {
910 assert(getTag() == dwarf::DW_TAG_member && isBitField())((getTag() == dwarf::DW_TAG_member && isBitField()) ?
static_cast<void> (0) : __assert_fail ("getTag() == dwarf::DW_TAG_member && isBitField()"
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 910, __PRETTY_FUNCTION__))
;
911 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
912 return C->getValue();
913 return nullptr;
914 }
915
916 Constant *getConstant() const {
917 assert(getTag() == dwarf::DW_TAG_member && isStaticMember())((getTag() == dwarf::DW_TAG_member && isStaticMember(
)) ? static_cast<void> (0) : __assert_fail ("getTag() == dwarf::DW_TAG_member && isStaticMember()"
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 917, __PRETTY_FUNCTION__))
;
918 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
919 return C->getValue();
920 return nullptr;
921 }
922 Constant *getDiscriminantValue() const {
923 assert(getTag() == dwarf::DW_TAG_member && !isStaticMember())((getTag() == dwarf::DW_TAG_member && !isStaticMember
()) ? static_cast<void> (0) : __assert_fail ("getTag() == dwarf::DW_TAG_member && !isStaticMember()"
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 923, __PRETTY_FUNCTION__))
;
924 if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
925 return C->getValue();
926 return nullptr;
927 }
928 /// @}
929
930 static bool classof(const Metadata *MD) {
931 return MD->getMetadataID() == DIDerivedTypeKind;
932 }
933};
934
935/// Composite types.
936///
937/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
938/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
939class DICompositeType : public DIType {
940 friend class LLVMContextImpl;
941 friend class MDNode;
942
943 unsigned RuntimeLang;
944
945 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
946 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
947 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
948 ArrayRef<Metadata *> Ops)
949 : DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
950 AlignInBits, OffsetInBits, Flags, Ops),
951 RuntimeLang(RuntimeLang) {}
952 ~DICompositeType() = default;
953
954 /// Change fields in place.
955 void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang,
956 uint64_t SizeInBits, uint32_t AlignInBits,
957 uint64_t OffsetInBits, DIFlags Flags) {
958 assert(isDistinct() && "Only distinct nodes can mutate")((isDistinct() && "Only distinct nodes can mutate") ?
static_cast<void> (0) : __assert_fail ("isDistinct() && \"Only distinct nodes can mutate\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 958, __PRETTY_FUNCTION__))
;
959 assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate")((getRawIdentifier() && "Only ODR-uniqued nodes should mutate"
) ? static_cast<void> (0) : __assert_fail ("getRawIdentifier() && \"Only ODR-uniqued nodes should mutate\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 959, __PRETTY_FUNCTION__))
;
960 this->RuntimeLang = RuntimeLang;
961 DIType::mutate(Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags);
962 }
963
964 static DICompositeType *
965 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
966 unsigned Line, DIScopeRef Scope, DITypeRef BaseType,
967 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
968 DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
969 DITypeRef VTableHolder, DITemplateParameterArray TemplateParams,
970 StringRef Identifier, DIDerivedType *Discriminator,
971 StorageType Storage, bool ShouldCreate = true) {
972 return getImpl(
973 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
974 BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
975 RuntimeLang, VTableHolder, TemplateParams.get(),
976 getCanonicalMDString(Context, Identifier), Discriminator, Storage, ShouldCreate);
977 }
978 static DICompositeType *
979 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
980 unsigned Line, Metadata *Scope, Metadata *BaseType,
981 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
982 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
983 Metadata *VTableHolder, Metadata *TemplateParams,
984 MDString *Identifier, Metadata *Discriminator,
985 StorageType Storage, bool ShouldCreate = true);
986
987 TempDICompositeType cloneImpl() const {
988 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
989 getScope(), getBaseType(), getSizeInBits(),
990 getAlignInBits(), getOffsetInBits(), getFlags(),
991 getElements(), getRuntimeLang(), getVTableHolder(),
992 getTemplateParams(), getIdentifier(), getDiscriminator());
993 }
994
995public:
996 DEFINE_MDNODE_GET(DICompositeType,
997 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
998 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
999 uint32_t AlignInBits, uint64_t OffsetInBits,
1000 DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang,
1001 DITypeRef VTableHolder,
1002 DITemplateParameterArray TemplateParams = nullptr,
1003 StringRef Identifier = "", DIDerivedType *Discriminator = nullptr),
1004 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1005 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1006 VTableHolder, TemplateParams, Identifier, Discriminator))
1007 DEFINE_MDNODE_GET(DICompositeType,
1008 (unsigned Tag, MDString *Name, Metadata *File,
1009 unsigned Line, Metadata *Scope, Metadata *BaseType,
1010 uint64_t SizeInBits, uint32_t AlignInBits,
1011 uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
1012 unsigned RuntimeLang, Metadata *VTableHolder,
1013 Metadata *TemplateParams = nullptr,
1014 MDString *Identifier = nullptr,
1015 Metadata *Discriminator = nullptr),
1016 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1017 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1018 VTableHolder, TemplateParams, Identifier, Discriminator))
1019
1020 TempDICompositeType clone() const { return cloneImpl(); }
1021
1022 /// Get a DICompositeType with the given ODR identifier.
1023 ///
1024 /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped
1025 /// DICompositeType for the given ODR \c Identifier. If none exists, creates
1026 /// a new node.
1027 ///
1028 /// Else, returns \c nullptr.
1029 static DICompositeType *
1030 getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1031 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1032 Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
1033 uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
1034 unsigned RuntimeLang, Metadata *VTableHolder,
1035 Metadata *TemplateParams, Metadata *Discriminator);
1036 static DICompositeType *getODRTypeIfExists(LLVMContext &Context,
1037 MDString &Identifier);
1038
1039 /// Build a DICompositeType with the given ODR identifier.
1040 ///
1041 /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If
1042 /// it doesn't exist, creates a new one. If it does exist and \a
1043 /// isForwardDecl(), and the new arguments would be a definition, mutates the
1044 /// the type in place. In either case, returns the type.
1045 ///
1046 /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns
1047 /// nullptr.
1048 static DICompositeType *
1049 buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag,
1050 MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
1051 Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
1052 uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements,
1053 unsigned RuntimeLang, Metadata *VTableHolder,
1054 Metadata *TemplateParams, Metadata *Discriminator);
1055
1056 DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
1057 DINodeArray getElements() const {
1058 return cast_or_null<MDTuple>(getRawElements());
1059 }
1060 DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); }
1061 DITemplateParameterArray getTemplateParams() const {
1062 return cast_or_null<MDTuple>(getRawTemplateParams());
1063 }
1064 StringRef getIdentifier() const { return getStringOperand(7); }
1065 unsigned getRuntimeLang() const { return RuntimeLang; }
1066
1067 Metadata *getRawBaseType() const { return getOperand(3); }
1068 Metadata *getRawElements() const { return getOperand(4); }
1069 Metadata *getRawVTableHolder() const { return getOperand(5); }
1070 Metadata *getRawTemplateParams() const { return getOperand(6); }
1071 MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
1072 Metadata *getRawDiscriminator() const { return getOperand(8); }
1073 DIDerivedType *getDiscriminator() const { return getOperandAs<DIDerivedType>(8); }
1074
1075 /// Replace operands.
1076 ///
1077 /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
1078 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
1079 /// of its movement if necessary.
1080 /// @{
1081 void replaceElements(DINodeArray Elements) {
1082#ifndef NDEBUG
1083 for (DINode *Op : getElements())
1084 assert(is_contained(Elements->operands(), Op) &&((is_contained(Elements->operands(), Op) && "Lost a member during member list replacement"
) ? static_cast<void> (0) : __assert_fail ("is_contained(Elements->operands(), Op) && \"Lost a member during member list replacement\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 1085, __PRETTY_FUNCTION__))
1085 "Lost a member during member list replacement")((is_contained(Elements->operands(), Op) && "Lost a member during member list replacement"
) ? static_cast<void> (0) : __assert_fail ("is_contained(Elements->operands(), Op) && \"Lost a member during member list replacement\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 1085, __PRETTY_FUNCTION__))
;
1086#endif
1087 replaceOperandWith(4, Elements.get());
1088 }
1089
1090 void replaceVTableHolder(DITypeRef VTableHolder) {
1091 replaceOperandWith(5, VTableHolder);
1092 }
1093
1094 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
1095 replaceOperandWith(6, TemplateParams.get());
1096 }
1097 /// @}
1098
1099 static bool classof(const Metadata *MD) {
1100 return MD->getMetadataID() == DICompositeTypeKind;
1101 }
1102};
1103
1104/// Type array for a subprogram.
1105///
1106/// TODO: Fold the array of types in directly as operands.
1107class DISubroutineType : public DIType {
1108 friend class LLVMContextImpl;
1109 friend class MDNode;
1110
1111 /// The calling convention used with DW_AT_calling_convention. Actually of
1112 /// type dwarf::CallingConvention.
1113 uint8_t CC;
1114
1115 DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags,
1116 uint8_t CC, ArrayRef<Metadata *> Ops)
1117 : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type,
1118 0, 0, 0, 0, Flags, Ops),
1119 CC(CC) {}
1120 ~DISubroutineType() = default;
1121
1122 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1123 uint8_t CC, DITypeRefArray TypeArray,
1124 StorageType Storage,
1125 bool ShouldCreate = true) {
1126 return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate);
1127 }
1128 static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags,
1129 uint8_t CC, Metadata *TypeArray,
1130 StorageType Storage,
1131 bool ShouldCreate = true);
1132
1133 TempDISubroutineType cloneImpl() const {
1134 return getTemporary(getContext(), getFlags(), getCC(), getTypeArray());
1135 }
1136
1137public:
1138 DEFINE_MDNODE_GET(DISubroutineType,
1139 (DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray),
1140 (Flags, CC, TypeArray))
1141 DEFINE_MDNODE_GET(DISubroutineType,
1142 (DIFlags Flags, uint8_t CC, Metadata *TypeArray),
1143 (Flags, CC, TypeArray))
1144
1145 TempDISubroutineType clone() const { return cloneImpl(); }
1146
1147 uint8_t getCC() const { return CC; }
1148
1149 DITypeRefArray getTypeArray() const {
1150 return cast_or_null<MDTuple>(getRawTypeArray());
1151 }
1152
1153 Metadata *getRawTypeArray() const { return getOperand(3); }
1154
1155 static bool classof(const Metadata *MD) {
1156 return MD->getMetadataID() == DISubroutineTypeKind;
1157 }
1158};
1159
1160/// Compile unit.
1161class DICompileUnit : public DIScope {
1162 friend class LLVMContextImpl;
1163 friend class MDNode;
1164
1165public:
1166 enum DebugEmissionKind : unsigned {
1167 NoDebug = 0,
1168 FullDebug,
1169 LineTablesOnly,
1170 DebugDirectivesOnly,
1171 LastEmissionKind = DebugDirectivesOnly
1172 };
1173
1174 enum class DebugNameTableKind : unsigned {
1175 Default = 0,
1176 GNU = 1,
1177 None = 2,
1178 LastDebugNameTableKind = None
1179 };
1180
1181 static Optional<DebugEmissionKind> getEmissionKind(StringRef Str);
1182 static const char *emissionKindString(DebugEmissionKind EK);
1183 static Optional<DebugNameTableKind> getNameTableKind(StringRef Str);
1184 static const char *nameTableKindString(DebugNameTableKind PK);
1185
1186private:
1187 unsigned SourceLanguage;
1188 bool IsOptimized;
1189 unsigned RuntimeVersion;
1190 unsigned EmissionKind;
1191 uint64_t DWOId;
1192 bool SplitDebugInlining;
1193 bool DebugInfoForProfiling;
1194 unsigned NameTableKind;
1195 bool RangesBaseAddress;
1196
1197 DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
1198 bool IsOptimized, unsigned RuntimeVersion,
1199 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
1200 bool DebugInfoForProfiling, unsigned NameTableKind,
1201 bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
1202 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
1203 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
1204 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
1205 DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
1206 DebugInfoForProfiling(DebugInfoForProfiling),
1207 NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
1208 assert(Storage != Uniqued)((Storage != Uniqued) ? static_cast<void> (0) : __assert_fail
("Storage != Uniqued", "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 1208, __PRETTY_FUNCTION__))
;
1209 }
1210 ~DICompileUnit() = default;
1211
1212 static DICompileUnit *
1213 getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
1214 StringRef Producer, bool IsOptimized, StringRef Flags,
1215 unsigned RuntimeVersion, StringRef SplitDebugFilename,
1216 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
1217 DIScopeArray RetainedTypes,
1218 DIGlobalVariableExpressionArray GlobalVariables,
1219 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
1220 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1221 unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
1222 bool ShouldCreate = true) {
1223 return getImpl(Context, SourceLanguage, File,
1224 getCanonicalMDString(Context, Producer), IsOptimized,
1225 getCanonicalMDString(Context, Flags), RuntimeVersion,
1226 getCanonicalMDString(Context, SplitDebugFilename),
1227 EmissionKind, EnumTypes.get(), RetainedTypes.get(),
1228 GlobalVariables.get(), ImportedEntities.get(), Macros.get(),
1229 DWOId, SplitDebugInlining, DebugInfoForProfiling,
1230 NameTableKind, RangesBaseAddress, Storage, ShouldCreate);
1231 }
1232 static DICompileUnit *
1233 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
1234 MDString *Producer, bool IsOptimized, MDString *Flags,
1235 unsigned RuntimeVersion, MDString *SplitDebugFilename,
1236 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
1237 Metadata *GlobalVariables, Metadata *ImportedEntities,
1238 Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
1239 bool DebugInfoForProfiling, unsigned NameTableKind,
1240 bool RangesBaseAddress, StorageType Storage, bool ShouldCreate = true);
1241
1242 TempDICompileUnit cloneImpl() const {
1243 return getTemporary(
1244 getContext(), getSourceLanguage(), getFile(), getProducer(),
1245 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
1246 getEmissionKind(), getEnumTypes(), getRetainedTypes(),
1247 getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
1248 getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
1249 getRangesBaseAddress());
1250 }
1251
1252public:
1253 static void get() = delete;
1254 static void getIfExists() = delete;
1255
1256 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1257 DICompileUnit,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1258 (unsigned SourceLanguage, DIFile *File, StringRef Producer,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1259 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1260 StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1261 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1262 DIGlobalVariableExpressionArray GlobalVariables,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1263 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1264 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1265 DebugNameTableKind NameTableKind, bool RangesBaseAddress),static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1266 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1267 SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1268 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1269 DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress))static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage
, File, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, (
unsigned)NameTableKind, RangesBaseAddress)), Distinct); } static
TempDICompileUnit getTemporary(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, DIFile *File, StringRef Producer, bool
IsOptimized, StringRef Flags, unsigned RuntimeVersion, StringRef
SplitDebugFilename, DebugEmissionKind EmissionKind, DICompositeTypeArray
EnumTypes, DIScopeArray RetainedTypes, DIGlobalVariableExpressionArray
GlobalVariables, DIImportedEntityArray ImportedEntities, DIMacroNodeArray
Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, DebugNameTableKind NameTableKind, bool RangesBaseAddress)))
{ return TempDICompileUnit( getImpl(Context, DEFINE_MDNODE_GET_UNPACK
((SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion
, SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining
, DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress
)), Temporary)); }
1270 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1271 DICompileUnit,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1272 (unsigned SourceLanguage, Metadata *File, MDString *Producer,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1273 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1274 MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1275 Metadata *RetainedTypes, Metadata *GlobalVariables,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1276 Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1277 bool SplitDebugInlining, bool DebugInfoForProfiling,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1278 unsigned NameTableKind, bool RangesBaseAddress),static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1279 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1280 SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1281 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1282 DebugInfoForProfiling, NameTableKind, RangesBaseAddress))static DICompileUnit *getDistinct(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK
((unsigned SourceLanguage, Metadata *File, MDString *Producer
, bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata
*EnumTypes, Metadata *RetainedTypes, Metadata *GlobalVariables
, Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId
, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned
NameTableKind, bool RangesBaseAddress))) { return getImpl(Context
, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File, Producer, IsOptimized
, Flags, RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes
, RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId
, SplitDebugInlining, DebugInfoForProfiling, NameTableKind, RangesBaseAddress
)), Distinct); } static TempDICompileUnit getTemporary(LLVMContext
&Context, DEFINE_MDNODE_GET_UNPACK((unsigned SourceLanguage
, Metadata *File, MDString *Producer, bool IsOptimized, MDString
*Flags, unsigned RuntimeVersion, MDString *SplitDebugFilename
, unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes
, Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata
*Macros, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling
, unsigned NameTableKind, bool RangesBaseAddress))) { return TempDICompileUnit
( getImpl(Context, DEFINE_MDNODE_GET_UNPACK((SourceLanguage, File
, Producer, IsOptimized, Flags, RuntimeVersion, SplitDebugFilename
, EmissionKind, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities
, Macros, DWOId, SplitDebugInlining, DebugInfoForProfiling, NameTableKind
, RangesBaseAddress)), Temporary)); }
1283
1284 TempDICompileUnit clone() const { return cloneImpl(); }
1285
1286 unsigned getSourceLanguage() const { return SourceLanguage; }
1287 bool isOptimized() const { return IsOptimized; }
1288 unsigned getRuntimeVersion() const { return RuntimeVersion; }
1289 DebugEmissionKind getEmissionKind() const {
1290 return (DebugEmissionKind)EmissionKind;
1291 }
1292 bool isDebugDirectivesOnly() const {
1293 return EmissionKind == DebugDirectivesOnly;
1294 }
1295 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
1296 DebugNameTableKind getNameTableKind() const {
1297 return (DebugNameTableKind)NameTableKind;
1298 }
1299 bool getRangesBaseAddress() const {
1300 return RangesBaseAddress; }
1301 StringRef getProducer() const {
1302 return getStringOperand(1); }
1303 StringRef getFlags() const {
1304 return getStringOperand(2); }
1305 StringRef getSplitDebugFilename() const {
1306 return getStringOperand(3); }
1307 DICompositeTypeArray getEnumTypes() const {
1308 return cast_or_null<MDTuple>(getRawEnumTypes());
1309 }
1310 DIScopeArray getRetainedTypes() const {
1311 return cast_or_null<MDTuple>(getRawRetainedTypes());
1312 }
1313 DIGlobalVariableExpressionArray getGlobalVariables() const {
1314 return cast_or_null<MDTuple>(getRawGlobalVariables());
1315 }
1316 DIImportedEntityArray getImportedEntities() const {
1317 return cast_or_null<MDTuple>(getRawImportedEntities());
1318 }
1319 DIMacroNodeArray getMacros() const {
1320 return cast_or_null<MDTuple>(getRawMacros());
1321 }
1322 uint64_t getDWOId() const { return DWOId; }
1323 void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
1324 bool getSplitDebugInlining() const { return SplitDebugInlining; }
1325 void setSplitDebugInlining(bool SplitDebugInlining) {
1326 this->SplitDebugInlining = SplitDebugInlining;
1327 }
1328
1329 MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
1330 MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
1331 MDString *getRawSplitDebugFilename() const {
1332 return getOperandAs<MDString>(3);
1333 }
1334 Metadata *getRawEnumTypes() const { return getOperand(4); }
1335 Metadata *getRawRetainedTypes() const { return getOperand(5); }
1336 Metadata *getRawGlobalVariables() const { return getOperand(6); }
1337 Metadata *getRawImportedEntities() const { return getOperand(7); }
1338 Metadata *getRawMacros() const { return getOperand(8); }
1339
1340 /// Replace arrays.
1341 ///
1342 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
1343 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1344 /// DICompileUnit should be fairly rare.
1345 /// @{
1346 void replaceEnumTypes(DICompositeTypeArray N) {
1347 replaceOperandWith(4, N.get());
1348 }
1349 void replaceRetainedTypes(DITypeArray N) {
1350 replaceOperandWith(5, N.get());
1351 }
1352 void replaceGlobalVariables(DIGlobalVariableExpressionArray N) {
1353 replaceOperandWith(6, N.get());
1354 }
1355 void replaceImportedEntities(DIImportedEntityArray N) {
1356 replaceOperandWith(7, N.get());
1357 }
1358 void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); }
1359 /// @}
1360
1361 static bool classof(const Metadata *MD) {
1362 return MD->getMetadataID() == DICompileUnitKind;
1363 }
1364};
1365
1366/// A scope for locals.
1367///
1368/// A legal scope for lexical blocks, local variables, and debug info
1369/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
1370/// DILexicalBlockFile.
1371class DILocalScope : public DIScope {
1372protected:
1373 DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1374 ArrayRef<Metadata *> Ops)
1375 : DIScope(C, ID, Storage, Tag, Ops) {}
1376 ~DILocalScope() = default;
1377
1378public:
1379 /// Get the subprogram for this scope.
1380 ///
1381 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
1382 /// chain.
1383 DISubprogram *getSubprogram() const;
1384
1385 /// Get the first non DILexicalBlockFile scope of this scope.
1386 ///
1387 /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
1388 /// scope chain.
1389 DILocalScope *getNonLexicalBlockFileScope() const;
1390
1391 static bool classof(const Metadata *MD) {
1392 return MD->getMetadataID() == DISubprogramKind ||
1393 MD->getMetadataID() == DILexicalBlockKind ||
1394 MD->getMetadataID() == DILexicalBlockFileKind;
1395 }
1396};
1397
1398/// Debug location.
1399///
1400/// A debug location in source code, used for debug info and otherwise.
1401class DILocation : public MDNode {
1402 friend class LLVMContextImpl;
1403 friend class MDNode;
1404
1405 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
1406 unsigned Column, ArrayRef<Metadata *> MDs, bool ImplicitCode);
1407 ~DILocation() { dropAllReferences(); }
1408
1409 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1410 unsigned Column, Metadata *Scope,
1411 Metadata *InlinedAt, bool ImplicitCode,
1412 StorageType Storage, bool ShouldCreate = true);
1413 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1414 unsigned Column, DILocalScope *Scope,
1415 DILocation *InlinedAt, bool ImplicitCode,
1416 StorageType Storage, bool ShouldCreate = true) {
1417 return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
1418 static_cast<Metadata *>(InlinedAt), ImplicitCode, Storage,
1419 ShouldCreate);
1420 }
1421
1422 /// With a given unsigned int \p U, use up to 13 bits to represent it.
1423 /// old_bit 1~5 --> new_bit 1~5
1424 /// old_bit 6~12 --> new_bit 7~13
1425 /// new_bit_6 is 0 if higher bits (7~13) are all 0
1426 static unsigned getPrefixEncodingFromUnsigned(unsigned U) {
1427 U &= 0xfff;
1428 return U > 0x1f ? (((U & 0xfe0) << 1) | (U & 0x1f) | 0x20) : U;
1429 }
1430
1431 /// Reverse transformation as getPrefixEncodingFromUnsigned.
1432 static unsigned getUnsignedFromPrefixEncoding(unsigned U) {
1433 if (U & 1)
1434 return 0;
1435 U >>= 1;
1436 return (U & 0x20) ? (((U >> 1) & 0xfe0) | (U & 0x1f)) : (U & 0x1f);
1437 }
1438
1439 /// Returns the next component stored in discriminator.
1440 static unsigned getNextComponentInDiscriminator(unsigned D) {
1441 if ((D & 1) == 0)
1442 return D >> ((D & 0x40) ? 14 : 7);
1443 else
1444 return D >> 1;
1445 }
1446
1447 TempDILocation cloneImpl() const {
1448 // Get the raw scope/inlinedAt since it is possible to invoke this on
1449 // a DILocation containing temporary metadata.
1450 return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
1451 getRawInlinedAt(), isImplicitCode());
1452 }
1453
1454 static unsigned encodeComponent(unsigned C) {
1455 return (C == 0) ? 1U : (getPrefixEncodingFromUnsigned(C) << 1);
1456 }
1457
1458 static unsigned encodingBits(unsigned C) {
1459 return (C == 0) ? 1 : (C > 0x1f ? 14 : 7);
4
'?' condition is false
5
Assuming 'C' is > 31
6
'?' condition is true
11
'?' condition is false
12
Assuming 'C' is > 31
13
'?' condition is true
18
'?' condition is false
19
Assuming 'C' is > 31
20
'?' condition is true
21
Returning the value 14
1460 }
1461
1462public:
1463 // Disallow replacing operands.
1464 void replaceOperandWith(unsigned I, Metadata *New) = delete;
1465
1466 DEFINE_MDNODE_GET(DILocation,
1467 (unsigned Line, unsigned Column, Metadata *Scope,
1468 Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
1469 (Line, Column, Scope, InlinedAt, ImplicitCode))
1470 DEFINE_MDNODE_GET(DILocation,
1471 (unsigned Line, unsigned Column, DILocalScope *Scope,
1472 DILocation *InlinedAt = nullptr,
1473 bool ImplicitCode = false),
1474 (Line, Column, Scope, InlinedAt, ImplicitCode))
1475
1476 /// Return a (temporary) clone of this.
1477 TempDILocation clone() const { return cloneImpl(); }
1478
1479 unsigned getLine() const { return SubclassData32; }
1480 unsigned getColumn() const { return SubclassData16; }
1481 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1482
1483 DILocation *getInlinedAt() const {
1484 return cast_or_null<DILocation>(getRawInlinedAt());
1485 }
1486
1487 /// Check if the location corresponds to an implicit code.
1488 /// When the ImplicitCode flag is true, it means that the Instruction
1489 /// with this DILocation has been added by the front-end but it hasn't been
1490 /// written explicitly by the user (e.g. cleanup stuff in C++ put on a closing
1491 /// bracket). It's useful for code coverage to not show a counter on "empty"
1492 /// lines.
1493 bool isImplicitCode() const { return ImplicitCode; }
1494 void setImplicitCode(bool ImplicitCode) { this->ImplicitCode = ImplicitCode; }
1495
1496 DIFile *getFile() const { return getScope()->getFile(); }
1497 StringRef getFilename() const { return getScope()->getFilename(); }
1498 StringRef getDirectory() const { return getScope()->getDirectory(); }
1499 Optional<StringRef> getSource() const { return getScope()->getSource(); }
1500
1501 /// Get the scope where this is inlined.
1502 ///
1503 /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
1504 /// location.
1505 DILocalScope *getInlinedAtScope() const {
1506 if (auto *IA = getInlinedAt())
1507 return IA->getInlinedAtScope();
1508 return getScope();
1509 }
1510
1511 /// Get the DWARF discriminator.
1512 ///
1513 /// DWARF discriminators distinguish identical file locations between
1514 /// instructions that are on different basic blocks.
1515 ///
1516 /// There are 3 components stored in discriminator, from lower bits:
1517 ///
1518 /// Base discriminator: assigned by AddDiscriminators pass to identify IRs
1519 /// that are defined by the same source line, but
1520 /// different basic blocks.
1521 /// Duplication factor: assigned by optimizations that will scale down
1522 /// the execution frequency of the original IR.
1523 /// Copy Identifier: assigned by optimizations that clones the IR.
1524 /// Each copy of the IR will be assigned an identifier.
1525 ///
1526 /// Encoding:
1527 ///
1528 /// The above 3 components are encoded into a 32bit unsigned integer in
1529 /// order. If the lowest bit is 1, the current component is empty, and the
1530 /// next component will start in the next bit. Otherwise, the current
1531 /// component is non-empty, and its content starts in the next bit. The
1532 /// value of each components is either 5 bit or 12 bit: if the 7th bit
1533 /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the
1534 /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to
1535 /// represent the component. Thus, the number of bits used for a component
1536 /// is either 0 (if it and all the next components are empty); 1 - if it is
1537 /// empty; 7 - if its value is up to and including 0x1f (lsb and msb are both
1538 /// 0); or 14, if its value is up to and including 0x1ff. Note that the last
1539 /// component is also capped at 0x1ff, even in the case when both first
1540 /// components are 0, and we'd technically have 29 bits available.
1541 ///
1542 /// For precise control over the data being encoded in the discriminator,
1543 /// use encodeDiscriminator/decodeDiscriminator.
1544 ///
1545 /// Use {get|set}BaseDiscriminator and cloneWithDuplicationFactor after reading
1546 /// their documentation, as their behavior has side-effects.
1547
1548 inline unsigned getDiscriminator() const;
1549
1550 /// Returns a new DILocation with updated \p Discriminator.
1551 inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
1552
1553 /// Returns a new DILocation with updated base discriminator \p BD. Only the
1554 /// base discriminator is set in the new DILocation, the other encoded values
1555 /// are elided.
1556 /// If the discriminator cannot be encoded, the function returns None.
1557 inline Optional<const DILocation *> setBaseDiscriminator(unsigned BD) const;
1558
1559 /// Returns the duplication factor stored in the discriminator, or 1 if no
1560 /// duplication factor (or 0) is encoded.
1561 inline unsigned getDuplicationFactor() const;
1562
1563 /// Returns the copy identifier stored in the discriminator.
1564 inline unsigned getCopyIdentifier() const;
1565
1566 /// Returns the base discriminator stored in the discriminator.
1567 inline unsigned getBaseDiscriminator() const;
1568
1569 /// Returns a new DILocation with duplication factor \p DF * current
1570 /// duplication factor encoded in the discriminator. The current duplication
1571 /// factor is as defined by getDuplicationFactor().
1572 /// Returns None if encoding failed.
1573 inline Optional<const DILocation *> cloneWithDuplicationFactor(unsigned DF) const;
1574
1575 /// When two instructions are combined into a single instruction we also
1576 /// need to combine the original locations into a single location.
1577 ///
1578 /// When the locations are the same we can use either location. When they
1579 /// differ, we need a third location which is distinct from either. If they
1580 /// have the same file/line but have a different discriminator we could
1581 /// create a location with a new discriminator. If they are from different
1582 /// files/lines the location is ambiguous and can't be represented in a line
1583 /// entry. In this case, if \p GenerateLocation is true, we will set the
1584 /// merged debug location as line 0 of the nearest common scope where the two
1585 /// locations are inlined from.
1586 ///
1587 /// \p GenerateLocation: Whether the merged location can be generated when
1588 /// \p LocA and \p LocB differ.
1589 static const DILocation *getMergedLocation(const DILocation *LocA,
1590 const DILocation *LocB);
1591
1592 /// Returns the base discriminator for a given encoded discriminator \p D.
1593 static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) {
1594 return getUnsignedFromPrefixEncoding(D);
1595 }
1596
1597 /// Raw encoding of the discriminator. APIs such as setBaseDiscriminator or
1598 /// cloneWithDuplicationFactor have certain side-effects. This API, in
1599 /// conjunction with cloneWithDiscriminator, may be used to encode precisely
1600 /// the values provided. \p BD: base discriminator \p DF: duplication factor
1601 /// \p CI: copy index
1602 /// The return is None if the values cannot be encoded in 32 bits - for
1603 /// example, values for BD or DF larger than 12 bits. Otherwise, the return
1604 /// is the encoded value.
1605 static Optional<unsigned> encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI);
1606
1607 /// Raw decoder for values in an encoded discriminator D.
1608 static void decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
1609 unsigned &CI);
1610
1611 /// Returns the duplication factor for a given encoded discriminator \p D, or
1612 /// 1 if no value or 0 is encoded.
1613 static unsigned getDuplicationFactorFromDiscriminator(unsigned D) {
1614 D = getNextComponentInDiscriminator(D);
1615 unsigned Ret = getUnsignedFromPrefixEncoding(D);
1616 if (Ret == 0)
1617 return 1;
1618 return Ret;
1619 }
1620
1621 /// Returns the copy identifier for a given encoded discriminator \p D.
1622 static unsigned getCopyIdentifierFromDiscriminator(unsigned D) {
1623 return getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator(
1624 getNextComponentInDiscriminator(D)));
1625 }
1626
1627
1628 Metadata *getRawScope() const { return getOperand(0); }
1629 Metadata *getRawInlinedAt() const {
1630 if (getNumOperands() == 2)
1631 return getOperand(1);
1632 return nullptr;
1633 }
1634
1635 static bool classof(const Metadata *MD) {
1636 return MD->getMetadataID() == DILocationKind;
1637 }
1638};
1639
1640/// Subprogram description.
1641///
1642/// TODO: Remove DisplayName. It's always equal to Name.
1643/// TODO: Split up flags.
1644class DISubprogram : public DILocalScope {
1645 friend class LLVMContextImpl;
1646 friend class MDNode;
1647
1648 unsigned Line;
1649 unsigned ScopeLine;
1650 unsigned VirtualIndex;
1651
1652 /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue
1653 /// of method overrides from secondary bases by this amount. It may be
1654 /// negative.
1655 int ThisAdjustment;
1656
1657public:
1658 /// Debug info subprogram flags.
1659 enum DISPFlags : uint32_t {
1660#define HANDLE_DISP_FLAG(ID, NAME) SPFlag##NAME = ID,
1661#define DISP_FLAG_LARGEST_NEEDED
1662#include "llvm/IR/DebugInfoFlags.def"
1663 SPFlagNonvirtual = SPFlagZero,
1664 SPFlagVirtuality = SPFlagVirtual | SPFlagPureVirtual,
1665 LLVM_MARK_AS_BITMASK_ENUM(SPFlagLargest)LLVM_BITMASK_LARGEST_ENUMERATOR = SPFlagLargest
1666 };
1667
1668 static DISPFlags getFlag(StringRef Flag);
1669 static StringRef getFlagString(DISPFlags Flag);
1670
1671 /// Split up a flags bitfield for easier printing.
1672 ///
1673 /// Split \c Flags into \c SplitFlags, a vector of its components. Returns
1674 /// any remaining (unrecognized) bits.
1675 static DISPFlags splitFlags(DISPFlags Flags,
1676 SmallVectorImpl<DISPFlags> &SplitFlags);
1677
1678 // Helper for converting old bitfields to new flags word.
1679 static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
1680 bool IsOptimized,
1681 unsigned Virtuality = SPFlagNonvirtual) {
1682 // We're assuming virtuality is the low-order field.
1683 static_assert(
1684 int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
1685 int(SPFlagPureVirtual) == int(dwarf::DW_VIRTUALITY_pure_virtual),
1686 "Virtuality constant mismatch");
1687 return static_cast<DISPFlags>(
1688 (Virtuality & SPFlagVirtuality) |
1689 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
1690 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1691 (IsOptimized ? SPFlagOptimized : SPFlagZero));
1692 }
1693
1694private:
1695 DIFlags Flags;
1696 DISPFlags SPFlags;
1697
1698 DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
1699 unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment,
1700 DIFlags Flags, DISPFlags SPFlags, ArrayRef<Metadata *> Ops)
1701 : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
1702 Ops),
1703 Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
1704 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) {
1705 static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
1706 }
1707 ~DISubprogram() = default;
1708
1709 static DISubprogram *
1710 getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name,
1711 StringRef LinkageName, DIFile *File, unsigned Line,
1712 DISubroutineType *Type, unsigned ScopeLine, DITypeRef ContainingType,
1713 unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags,
1714 DISPFlags SPFlags, DICompileUnit *Unit,
1715 DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
1716 DINodeArray RetainedNodes, DITypeArray ThrownTypes,
1717 StorageType Storage, bool ShouldCreate = true) {
1718 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
1719 getCanonicalMDString(Context, LinkageName), File, Line, Type,
1720 ScopeLine, ContainingType, VirtualIndex, ThisAdjustment,
1721 Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
1722 RetainedNodes.get(), ThrownTypes.get(), Storage,
1723 ShouldCreate);
1724 }
1725 static DISubprogram *getImpl(LLVMContext &Context, Metadata *Scope,
1726 MDString *Name, MDString *LinkageName,
1727 Metadata *File, unsigned Line, Metadata *Type,
1728 unsigned ScopeLine, Metadata *ContainingType,
1729 unsigned VirtualIndex, int ThisAdjustment,
1730 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1731 Metadata *TemplateParams, Metadata *Declaration,
1732 Metadata *RetainedNodes, Metadata *ThrownTypes,
1733 StorageType Storage, bool ShouldCreate = true);
1734
1735 TempDISubprogram cloneImpl() const {
1736 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
1737 getFile(), getLine(), getType(), getScopeLine(),
1738 getContainingType(), getVirtualIndex(),
1739 getThisAdjustment(), getFlags(), getSPFlags(),
1740 getUnit(), getTemplateParams(), getDeclaration(),
1741 getRetainedNodes(), getThrownTypes());
1742 }
1743
1744public:
1745 DEFINE_MDNODE_GET(
1746 DISubprogram,
1747 (DIScopeRef Scope, StringRef Name, StringRef LinkageName, DIFile *File,
1748 unsigned Line, DISubroutineType *Type, unsigned ScopeLine,
1749 DITypeRef ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1750 DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
1751 DITemplateParameterArray TemplateParams = nullptr,
1752 DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
1753 DITypeArray ThrownTypes = nullptr),
1754 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1755 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1756 Declaration, RetainedNodes, ThrownTypes))
1757
1758 DEFINE_MDNODE_GET(
1759 DISubprogram,
1760 (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
1761 unsigned Line, Metadata *Type, unsigned ScopeLine,
1762 Metadata *ContainingType, unsigned VirtualIndex, int ThisAdjustment,
1763 DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
1764 Metadata *TemplateParams = nullptr, Metadata *Declaration = nullptr,
1765 Metadata *RetainedNodes = nullptr, Metadata *ThrownTypes = nullptr),
1766 (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
1767 VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1768 Declaration, RetainedNodes, ThrownTypes))
1769
1770 TempDISubprogram clone() const { return cloneImpl(); }
1771
1772 /// Returns a new temporary DISubprogram with updated Flags
1773 TempDISubprogram cloneWithFlags(DIFlags NewFlags) const {
1774 auto NewSP = clone();
1775 NewSP->Flags = NewFlags;
1776 return NewSP;
1777 }
1778
1779public:
1780 unsigned getLine() const { return Line; }
1781 unsigned getVirtuality() const { return getSPFlags() & SPFlagVirtuality; }
1782 unsigned getVirtualIndex() const { return VirtualIndex; }
1783 int getThisAdjustment() const { return ThisAdjustment; }
1784 unsigned getScopeLine() const { return ScopeLine; }
1785 DIFlags getFlags() const { return Flags; }
1786 DISPFlags getSPFlags() const { return SPFlags; }
1787 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
1788 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
1789 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
1790
1791 bool isArtificial() const { return getFlags() & FlagArtificial; }
1792 bool isPrivate() const {
1793 return (getFlags() & FlagAccessibility) == FlagPrivate;
1794 }
1795 bool isProtected() const {
1796 return (getFlags() & FlagAccessibility) == FlagProtected;
1797 }
1798 bool isPublic() const {
1799 return (getFlags() & FlagAccessibility) == FlagPublic;
1800 }
1801 bool isExplicit() const { return getFlags() & FlagExplicit; }
1802 bool isPrototyped() const { return getFlags() & FlagPrototyped; }
1803 bool areAllCallsDescribed() const {
1804 return getFlags() & FlagAllCallsDescribed;
1805 }
1806 bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; }
1807
1808 /// Check if this is reference-qualified.
1809 ///
1810 /// Return true if this subprogram is a C++11 reference-qualified non-static
1811 /// member function (void foo() &).
1812 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
1813
1814 /// Check if this is rvalue-reference-qualified.
1815 ///
1816 /// Return true if this subprogram is a C++11 rvalue-reference-qualified
1817 /// non-static member function (void foo() &&).
1818 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
1819
1820 /// Check if this is marked as noreturn.
1821 ///
1822 /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn
1823 bool isNoReturn() const { return getFlags() & FlagNoReturn; }
1824
1825 // Check if this routine is a compiler-generated thunk.
1826 //
1827 // Returns true if this subprogram is a thunk generated by the compiler.
1828 bool isThunk() const { return getFlags() & FlagThunk; }
1829
1830 DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
1831
1832 StringRef getName() const { return getStringOperand(2); }
1833 StringRef getLinkageName() const { return getStringOperand(3); }
1834
1835 DISubroutineType *getType() const {
1836 return cast_or_null<DISubroutineType>(getRawType());
1837 }
1838 DITypeRef getContainingType() const {
1839 return DITypeRef(getRawContainingType());
1840 }
1841
1842 DICompileUnit *getUnit() const {
1843 return cast_or_null<DICompileUnit>(getRawUnit());
1844 }
1845 void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
1846 DITemplateParameterArray getTemplateParams() const {
1847 return cast_or_null<MDTuple>(getRawTemplateParams());
1848 }
1849 DISubprogram *getDeclaration() const {
1850 return cast_or_null<DISubprogram>(getRawDeclaration());
1851 }
1852 DINodeArray getRetainedNodes() const {
1853 return cast_or_null<MDTuple>(getRawRetainedNodes());
1854 }
1855 DITypeArray getThrownTypes() const {
1856 return cast_or_null<MDTuple>(getRawThrownTypes());
1857 }
1858
1859 Metadata *getRawScope() const { return getOperand(1); }
1860 MDString *getRawName() const { return getOperandAs<MDString>(2); }
1861 MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
1862 Metadata *getRawType() const { return getOperand(4); }
1863 Metadata *getRawUnit() const { return getOperand(5); }
1864 Metadata *getRawDeclaration() const { return getOperand(6); }
1865 Metadata *getRawRetainedNodes() const { return getOperand(7); }
1866 Metadata *getRawContainingType() const {
1867 return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr;
1868 }
1869 Metadata *getRawTemplateParams() const {
1870 return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr;
1871 }
1872 Metadata *getRawThrownTypes() const {
1873 return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr;
1874 }
1875
1876 /// Check if this subprogram describes the given function.
1877 ///
1878 /// FIXME: Should this be looking through bitcasts?
1879 bool describes(const Function *F) const;
1880
1881 static bool classof(const Metadata *MD) {
1882 return MD->getMetadataID() == DISubprogramKind;
1883 }
1884};
1885
1886class DILexicalBlockBase : public DILocalScope {
1887protected:
1888 DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
1889 ArrayRef<Metadata *> Ops)
1890 : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
1891 ~DILexicalBlockBase() = default;
1892
1893public:
1894 DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
1895
1896 Metadata *getRawScope() const { return getOperand(1); }
1897
1898 static bool classof(const Metadata *MD) {
1899 return MD->getMetadataID() == DILexicalBlockKind ||
1900 MD->getMetadataID() == DILexicalBlockFileKind;
1901 }
1902};
1903
1904class DILexicalBlock : public DILexicalBlockBase {
1905 friend class LLVMContextImpl;
1906 friend class MDNode;
1907
1908 unsigned Line;
1909 uint16_t Column;
1910
1911 DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
1912 unsigned Column, ArrayRef<Metadata *> Ops)
1913 : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
1914 Column(Column) {
1915 assert(Column < (1u << 16) && "Expected 16-bit column")((Column < (1u << 16) && "Expected 16-bit column"
) ? static_cast<void> (0) : __assert_fail ("Column < (1u << 16) && \"Expected 16-bit column\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 1915, __PRETTY_FUNCTION__))
;
1916 }
1917 ~DILexicalBlock() = default;
1918
1919 static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
1920 DIFile *File, unsigned Line, unsigned Column,
1921 StorageType Storage,
1922 bool ShouldCreate = true) {
1923 return getImpl(Context, static_cast<Metadata *>(Scope),
1924 static_cast<Metadata *>(File), Line, Column, Storage,
1925 ShouldCreate);
1926 }
1927
1928 static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
1929 Metadata *File, unsigned Line, unsigned Column,
1930 StorageType Storage, bool ShouldCreate = true);
1931
1932 TempDILexicalBlock cloneImpl() const {
1933 return getTemporary(getContext(), getScope(), getFile(), getLine(),
1934 getColumn());
1935 }
1936
1937public:
1938 DEFINE_MDNODE_GET(DILexicalBlock, (DILocalScope * Scope, DIFile *File,
1939 unsigned Line, unsigned Column),
1940 (Scope, File, Line, Column))
1941 DEFINE_MDNODE_GET(DILexicalBlock, (Metadata * Scope, Metadata *File,
1942 unsigned Line, unsigned Column),
1943 (Scope, File, Line, Column))
1944
1945 TempDILexicalBlock clone() const { return cloneImpl(); }
1946
1947 unsigned getLine() const { return Line; }
1948 unsigned getColumn() const { return Column; }
1949
1950 static bool classof(const Metadata *MD) {
1951 return MD->getMetadataID() == DILexicalBlockKind;
1952 }
1953};
1954
1955class DILexicalBlockFile : public DILexicalBlockBase {
1956 friend class LLVMContextImpl;
1957 friend class MDNode;
1958
1959 unsigned Discriminator;
1960
1961 DILexicalBlockFile(LLVMContext &C, StorageType Storage,
1962 unsigned Discriminator, ArrayRef<Metadata *> Ops)
1963 : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
1964 Discriminator(Discriminator) {}
1965 ~DILexicalBlockFile() = default;
1966
1967 static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
1968 DIFile *File, unsigned Discriminator,
1969 StorageType Storage,
1970 bool ShouldCreate = true) {
1971 return getImpl(Context, static_cast<Metadata *>(Scope),
1972 static_cast<Metadata *>(File), Discriminator, Storage,
1973 ShouldCreate);
1974 }
1975
1976 static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
1977 Metadata *File, unsigned Discriminator,
1978 StorageType Storage,
1979 bool ShouldCreate = true);
1980
1981 TempDILexicalBlockFile cloneImpl() const {
1982 return getTemporary(getContext(), getScope(), getFile(),
1983 getDiscriminator());
1984 }
1985
1986public:
1987 DEFINE_MDNODE_GET(DILexicalBlockFile, (DILocalScope * Scope, DIFile *File,
1988 unsigned Discriminator),
1989 (Scope, File, Discriminator))
1990 DEFINE_MDNODE_GET(DILexicalBlockFile,
1991 (Metadata * Scope, Metadata *File, unsigned Discriminator),
1992 (Scope, File, Discriminator))
1993
1994 TempDILexicalBlockFile clone() const { return cloneImpl(); }
1995
1996 // TODO: Remove these once they're gone from DILexicalBlockBase.
1997 unsigned getLine() const = delete;
1998 unsigned getColumn() const = delete;
1999
2000 unsigned getDiscriminator() const { return Discriminator; }
2001
2002 static bool classof(const Metadata *MD) {
2003 return MD->getMetadataID() == DILexicalBlockFileKind;
2004 }
2005};
2006
2007unsigned DILocation::getDiscriminator() const {
2008 if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
2009 return F->getDiscriminator();
2010 return 0;
2011}
2012
2013const DILocation *
2014DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
2015 DIScope *Scope = getScope();
2016 // Skip all parent DILexicalBlockFile that already have a discriminator
2017 // assigned. We do not want to have nested DILexicalBlockFiles that have
2018 // mutliple discriminators because only the leaf DILexicalBlockFile's
2019 // dominator will be used.
2020 for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
2021 LBF && LBF->getDiscriminator() != 0;
2022 LBF = dyn_cast<DILexicalBlockFile>(Scope))
2023 Scope = LBF->getScope();
2024 DILexicalBlockFile *NewScope =
2025 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
2026 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2027 getInlinedAt());
2028}
2029
2030unsigned DILocation::getBaseDiscriminator() const {
2031 return getBaseDiscriminatorFromDiscriminator(getDiscriminator());
2032}
2033
2034unsigned DILocation::getDuplicationFactor() const {
2035 return getDuplicationFactorFromDiscriminator(getDiscriminator());
2036}
2037
2038unsigned DILocation::getCopyIdentifier() const {
2039 return getCopyIdentifierFromDiscriminator(getDiscriminator());
2040}
2041
2042Optional<const DILocation *> DILocation::setBaseDiscriminator(unsigned D) const {
2043 if (D == 0)
2044 return this;
2045 if (D > 0xfff)
2046 return None;
2047 return cloneWithDiscriminator(encodeComponent(D));
2048}
2049
2050Optional<const DILocation *> DILocation::cloneWithDuplicationFactor(unsigned DF) const {
2051 DF *= getDuplicationFactor();
2052 if (DF <= 1)
2053 return this;
2054
2055 unsigned BD = getBaseDiscriminator();
2056 unsigned CI = getCopyIdentifier();
2057 if (Optional<unsigned> D = encodeDiscriminator(BD, DF, CI))
2058 return cloneWithDiscriminator(*D);
2059 return None;
2060}
2061
2062class DINamespace : public DIScope {
2063 friend class LLVMContextImpl;
2064 friend class MDNode;
2065
2066 unsigned ExportSymbols : 1;
2067
2068 DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
2069 ArrayRef<Metadata *> Ops)
2070 : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
2071 Ops),
2072 ExportSymbols(ExportSymbols) {}
2073 ~DINamespace() = default;
2074
2075 static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
2076 StringRef Name, bool ExportSymbols,
2077 StorageType Storage, bool ShouldCreate = true) {
2078 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2079 ExportSymbols, Storage, ShouldCreate);
2080 }
2081 static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
2082 MDString *Name, bool ExportSymbols,
2083 StorageType Storage, bool ShouldCreate = true);
2084
2085 TempDINamespace cloneImpl() const {
2086 return getTemporary(getContext(), getScope(), getName(),
2087 getExportSymbols());
2088 }
2089
2090public:
2091 DEFINE_MDNODE_GET(DINamespace,
2092 (DIScope *Scope, StringRef Name, bool ExportSymbols),
2093 (Scope, Name, ExportSymbols))
2094 DEFINE_MDNODE_GET(DINamespace,
2095 (Metadata *Scope, MDString *Name, bool ExportSymbols),
2096 (Scope, Name, ExportSymbols))
2097
2098 TempDINamespace clone() const { return cloneImpl(); }
2099
2100 bool getExportSymbols() const { return ExportSymbols; }
2101 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2102 StringRef getName() const { return getStringOperand(2); }
2103
2104 Metadata *getRawScope() const { return getOperand(1); }
2105 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2106
2107 static bool classof(const Metadata *MD) {
2108 return MD->getMetadataID() == DINamespaceKind;
2109 }
2110};
2111
2112/// A (clang) module that has been imported by the compile unit.
2113///
2114class DIModule : public DIScope {
2115 friend class LLVMContextImpl;
2116 friend class MDNode;
2117
2118 DIModule(LLVMContext &Context, StorageType Storage, ArrayRef<Metadata *> Ops)
2119 : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
2120 ~DIModule() = default;
2121
2122 static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
2123 StringRef Name, StringRef ConfigurationMacros,
2124 StringRef IncludePath, StringRef ISysRoot,
2125 StorageType Storage, bool ShouldCreate = true) {
2126 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2127 getCanonicalMDString(Context, ConfigurationMacros),
2128 getCanonicalMDString(Context, IncludePath),
2129 getCanonicalMDString(Context, ISysRoot),
2130 Storage, ShouldCreate);
2131 }
2132 static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
2133 MDString *Name, MDString *ConfigurationMacros,
2134 MDString *IncludePath, MDString *ISysRoot,
2135 StorageType Storage, bool ShouldCreate = true);
2136
2137 TempDIModule cloneImpl() const {
2138 return getTemporary(getContext(), getScope(), getName(),
2139 getConfigurationMacros(), getIncludePath(),
2140 getISysRoot());
2141 }
2142
2143public:
2144 DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
2145 StringRef ConfigurationMacros, StringRef IncludePath,
2146 StringRef ISysRoot),
2147 (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
2148 DEFINE_MDNODE_GET(DIModule,
2149 (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
2150 MDString *IncludePath, MDString *ISysRoot),
2151 (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
2152
2153 TempDIModule clone() const { return cloneImpl(); }
2154
2155 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2156 StringRef getName() const { return getStringOperand(1); }
2157 StringRef getConfigurationMacros() const { return getStringOperand(2); }
2158 StringRef getIncludePath() const { return getStringOperand(3); }
2159 StringRef getISysRoot() const { return getStringOperand(4); }
2160
2161 Metadata *getRawScope() const { return getOperand(0); }
2162 MDString *getRawName() const { return getOperandAs<MDString>(1); }
2163 MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
2164 MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
2165 MDString *getRawISysRoot() const { return getOperandAs<MDString>(4); }
2166
2167 static bool classof(const Metadata *MD) {
2168 return MD->getMetadataID() == DIModuleKind;
2169 }
2170};
2171
2172/// Base class for template parameters.
2173class DITemplateParameter : public DINode {
2174protected:
2175 DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
2176 unsigned Tag, ArrayRef<Metadata *> Ops)
2177 : DINode(Context, ID, Storage, Tag, Ops) {}
2178 ~DITemplateParameter() = default;
2179
2180public:
2181 StringRef getName() const { return getStringOperand(0); }
2182 DITypeRef getType() const { return DITypeRef(getRawType()); }
2183
2184 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2185 Metadata *getRawType() const { return getOperand(1); }
2186
2187 static bool classof(const Metadata *MD) {
2188 return MD->getMetadataID() == DITemplateTypeParameterKind ||
2189 MD->getMetadataID() == DITemplateValueParameterKind;
2190 }
2191};
2192
2193class DITemplateTypeParameter : public DITemplateParameter {
2194 friend class LLVMContextImpl;
2195 friend class MDNode;
2196
2197 DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
2198 ArrayRef<Metadata *> Ops)
2199 : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
2200 dwarf::DW_TAG_template_type_parameter, Ops) {}
2201 ~DITemplateTypeParameter() = default;
2202
2203 static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
2204 DITypeRef Type, StorageType Storage,
2205 bool ShouldCreate = true) {
2206 return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
2207 ShouldCreate);
2208 }
2209 static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
2210 Metadata *Type, StorageType Storage,
2211 bool ShouldCreate = true);
2212
2213 TempDITemplateTypeParameter cloneImpl() const {
2214 return getTemporary(getContext(), getName(), getType());
2215 }
2216
2217public:
2218 DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DITypeRef Type),
2219 (Name, Type))
2220 DEFINE_MDNODE_GET(DITemplateTypeParameter, (MDString * Name, Metadata *Type),
2221 (Name, Type))
2222
2223 TempDITemplateTypeParameter clone() const { return cloneImpl(); }
2224
2225 static bool classof(const Metadata *MD) {
2226 return MD->getMetadataID() == DITemplateTypeParameterKind;
2227 }
2228};
2229
2230class DITemplateValueParameter : public DITemplateParameter {
2231 friend class LLVMContextImpl;
2232 friend class MDNode;
2233
2234 DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
2235 unsigned Tag, ArrayRef<Metadata *> Ops)
2236 : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
2237 Ops) {}
2238 ~DITemplateValueParameter() = default;
2239
2240 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2241 StringRef Name, DITypeRef Type,
2242 Metadata *Value, StorageType Storage,
2243 bool ShouldCreate = true) {
2244 return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
2245 Value, Storage, ShouldCreate);
2246 }
2247 static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
2248 MDString *Name, Metadata *Type,
2249 Metadata *Value, StorageType Storage,
2250 bool ShouldCreate = true);
2251
2252 TempDITemplateValueParameter cloneImpl() const {
2253 return getTemporary(getContext(), getTag(), getName(), getType(),
2254 getValue());
2255 }
2256
2257public:
2258 DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, StringRef Name,
2259 DITypeRef Type, Metadata *Value),
2260 (Tag, Name, Type, Value))
2261 DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, MDString *Name,
2262 Metadata *Type, Metadata *Value),
2263 (Tag, Name, Type, Value))
2264
2265 TempDITemplateValueParameter clone() const { return cloneImpl(); }
2266
2267 Metadata *getValue() const { return getOperand(2); }
2268
2269 static bool classof(const Metadata *MD) {
2270 return MD->getMetadataID() == DITemplateValueParameterKind;
2271 }
2272};
2273
2274/// Base class for variables.
2275class DIVariable : public DINode {
2276 unsigned Line;
2277 uint32_t AlignInBits;
2278
2279protected:
2280 DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line,
2281 ArrayRef<Metadata *> Ops, uint32_t AlignInBits = 0)
2282 : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
2283 AlignInBits(AlignInBits) {}
2284 ~DIVariable() = default;
2285
2286public:
2287 unsigned getLine() const { return Line; }
2288 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2289 StringRef getName() const { return getStringOperand(1); }
2290 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2291 DITypeRef getType() const { return DITypeRef(getRawType()); }
2292 uint32_t getAlignInBits() const { return AlignInBits; }
2293 uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT8; }
2294 /// Determines the size of the variable's type.
2295 Optional<uint64_t> getSizeInBits() const;
2296
2297 /// Return the signedness of this variable's type, or None if this type is
2298 /// neither signed nor unsigned.
2299 Optional<DIBasicType::Signedness> getSignedness() const {
2300 if (auto *BT = dyn_cast<DIBasicType>(getType().resolve()))
2301 return BT->getSignedness();
2302 return None;
2303 }
2304
2305 StringRef getFilename() const {
2306 if (auto *F = getFile())
2307 return F->getFilename();
2308 return "";
2309 }
2310
2311 StringRef getDirectory() const {
2312 if (auto *F = getFile())
2313 return F->getDirectory();
2314 return "";
2315 }
2316
2317 Optional<StringRef> getSource() const {
2318 if (auto *F = getFile())
2319 return F->getSource();
2320 return None;
2321 }
2322
2323 Metadata *getRawScope() const { return getOperand(0); }
2324 MDString *getRawName() const { return getOperandAs<MDString>(1); }
2325 Metadata *getRawFile() const { return getOperand(2); }
2326 Metadata *getRawType() const { return getOperand(3); }
2327
2328 static bool classof(const Metadata *MD) {
2329 return MD->getMetadataID() == DILocalVariableKind ||
2330 MD->getMetadataID() == DIGlobalVariableKind;
2331 }
2332};
2333
2334/// DWARF expression.
2335///
2336/// This is (almost) a DWARF expression that modifies the location of a
2337/// variable, or the location of a single piece of a variable, or (when using
2338/// DW_OP_stack_value) is the constant variable value.
2339///
2340/// TODO: Co-allocate the expression elements.
2341/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
2342/// storage types.
2343class DIExpression : public MDNode {
2344 friend class LLVMContextImpl;
2345 friend class MDNode;
2346
2347 std::vector<uint64_t> Elements;
2348
2349 DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
2350 : MDNode(C, DIExpressionKind, Storage, None),
2351 Elements(Elements.begin(), Elements.end()) {}
2352 ~DIExpression() = default;
2353
2354 static DIExpression *getImpl(LLVMContext &Context,
2355 ArrayRef<uint64_t> Elements, StorageType Storage,
2356 bool ShouldCreate = true);
2357
2358 TempDIExpression cloneImpl() const {
2359 return getTemporary(getContext(), getElements());
2360 }
2361
2362public:
2363 DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
2364
2365 TempDIExpression clone() const { return cloneImpl(); }
2366
2367 ArrayRef<uint64_t> getElements() const { return Elements; }
2368
2369 unsigned getNumElements() const { return Elements.size(); }
2370
2371 uint64_t getElement(unsigned I) const {
2372 assert(I < Elements.size() && "Index out of range")((I < Elements.size() && "Index out of range") ? static_cast
<void> (0) : __assert_fail ("I < Elements.size() && \"Index out of range\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 2372, __PRETTY_FUNCTION__))
;
2373 return Elements[I];
2374 }
2375
2376 /// Determine whether this represents a standalone constant value.
2377 bool isConstant() const;
2378
2379 using element_iterator = ArrayRef<uint64_t>::iterator;
2380
2381 element_iterator elements_begin() const { return getElements().begin(); }
2382 element_iterator elements_end() const { return getElements().end(); }
2383
2384 /// A lightweight wrapper around an expression operand.
2385 ///
2386 /// TODO: Store arguments directly and change \a DIExpression to store a
2387 /// range of these.
2388 class ExprOperand {
2389 const uint64_t *Op = nullptr;
2390
2391 public:
2392 ExprOperand() = default;
2393 explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
2394
2395 const uint64_t *get() const { return Op; }
2396
2397 /// Get the operand code.
2398 uint64_t getOp() const { return *Op; }
2399
2400 /// Get an argument to the operand.
2401 ///
2402 /// Never returns the operand itself.
2403 uint64_t getArg(unsigned I) const { return Op[I + 1]; }
2404
2405 unsigned getNumArgs() const { return getSize() - 1; }
2406
2407 /// Return the size of the operand.
2408 ///
2409 /// Return the number of elements in the operand (1 + args).
2410 unsigned getSize() const;
2411
2412 /// Append the elements of this operand to \p V.
2413 void appendToVector(SmallVectorImpl<uint64_t> &V) const {
2414 V.append(get(), get() + getSize());
2415 }
2416 };
2417
2418 /// An iterator for expression operands.
2419 class expr_op_iterator
2420 : public std::iterator<std::input_iterator_tag, ExprOperand> {
2421 ExprOperand Op;
2422
2423 public:
2424 expr_op_iterator() = default;
2425 explicit expr_op_iterator(element_iterator I) : Op(I) {}
2426
2427 element_iterator getBase() const { return Op.get(); }
2428 const ExprOperand &operator*() const { return Op; }
2429 const ExprOperand *operator->() const { return &Op; }
2430
2431 expr_op_iterator &operator++() {
2432 increment();
2433 return *this;
2434 }
2435 expr_op_iterator operator++(int) {
2436 expr_op_iterator T(*this);
2437 increment();
2438 return T;
2439 }
2440
2441 /// Get the next iterator.
2442 ///
2443 /// \a std::next() doesn't work because this is technically an
2444 /// input_iterator, but it's a perfectly valid operation. This is an
2445 /// accessor to provide the same functionality.
2446 expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
2447
2448 bool operator==(const expr_op_iterator &X) const {
2449 return getBase() == X.getBase();
2450 }
2451 bool operator!=(const expr_op_iterator &X) const {
2452 return getBase() != X.getBase();
2453 }
2454
2455 private:
2456 void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
2457 };
2458
2459 /// Visit the elements via ExprOperand wrappers.
2460 ///
2461 /// These range iterators visit elements through \a ExprOperand wrappers.
2462 /// This is not guaranteed to be a valid range unless \a isValid() gives \c
2463 /// true.
2464 ///
2465 /// \pre \a isValid() gives \c true.
2466 /// @{
2467 expr_op_iterator expr_op_begin() const {
2468 return expr_op_iterator(elements_begin());
2469 }
2470 expr_op_iterator expr_op_end() const {
2471 return expr_op_iterator(elements_end());
2472 }
2473 iterator_range<expr_op_iterator> expr_ops() const {
2474 return {expr_op_begin(), expr_op_end()};
2475 }
2476 /// @}
2477
2478 bool isValid() const;
2479
2480 static bool classof(const Metadata *MD) {
2481 return MD->getMetadataID() == DIExpressionKind;
2482 }
2483
2484 /// Return whether the first element a DW_OP_deref.
2485 bool startsWithDeref() const {
2486 return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
2487 }
2488
2489 /// Holds the characteristics of one fragment of a larger variable.
2490 struct FragmentInfo {
2491 uint64_t SizeInBits;
2492 uint64_t OffsetInBits;
2493 };
2494
2495 /// Retrieve the details of this fragment expression.
2496 static Optional<FragmentInfo> getFragmentInfo(expr_op_iterator Start,
2497 expr_op_iterator End);
2498
2499 /// Retrieve the details of this fragment expression.
2500 Optional<FragmentInfo> getFragmentInfo() const {
2501 return getFragmentInfo(expr_op_begin(), expr_op_end());
2502 }
2503
2504 /// Return whether this is a piece of an aggregate variable.
2505 bool isFragment() const { return getFragmentInfo().hasValue(); }
2506
2507 /// Append \p Ops with operations to apply the \p Offset.
2508 static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
2509
2510 /// If this is a constant offset, extract it. If there is no expression,
2511 /// return true with an offset of zero.
2512 bool extractIfOffset(int64_t &Offset) const;
2513
2514 /// Constants for DIExpression::prepend.
2515 enum { NoDeref = false, WithDeref = true, WithStackValue = true };
2516
2517 /// Prepend \p DIExpr with a deref and offset operation and optionally turn it
2518 /// into a stack value.
2519 static DIExpression *prepend(const DIExpression *Expr, bool DerefBefore,
2520 int64_t Offset = 0, bool DerefAfter = false,
2521 bool StackValue = false);
2522
2523 /// Prepend \p DIExpr with the given opcodes and optionally turn it into a
2524 /// stack value.
2525 static DIExpression *prependOpcodes(const DIExpression *Expr,
2526 SmallVectorImpl<uint64_t> &Ops,
2527 bool StackValue = false);
2528
2529 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
2530 /// returned expression is a stack value only if \p DIExpr is a stack value.
2531 /// If \p DIExpr describes a fragment, the returned expression will describe
2532 /// the same fragment.
2533 static DIExpression *append(const DIExpression *Expr, ArrayRef<uint64_t> Ops);
2534
2535 /// Convert \p DIExpr into a stack value if it isn't one already by appending
2536 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
2537 /// If \p DIExpr describes a fragment, the returned expression will describe
2538 /// the same fragment.
2539 static DIExpression *appendToStack(const DIExpression *Expr,
2540 ArrayRef<uint64_t> Ops);
2541
2542 /// Create a DIExpression to describe one part of an aggregate variable that
2543 /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
2544 /// will be appended to the elements of \c Expr. If \c Expr already contains
2545 /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
2546 /// into the existing fragment.
2547 ///
2548 /// \param OffsetInBits Offset of the piece in bits.
2549 /// \param SizeInBits Size of the piece in bits.
2550 /// \return Creating a fragment expression may fail if \c Expr
2551 /// contains arithmetic operations that would be truncated.
2552 static Optional<DIExpression *>
2553 createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits,
2554 unsigned SizeInBits);
2555
2556 /// Determine the relative position of the fragments described by this
2557 /// DIExpression and \p Other.
2558 /// Returns -1 if this is entirely before Other, 0 if this and Other overlap,
2559 /// 1 if this is entirely after Other.
2560 int fragmentCmp(const DIExpression *Other) const {
2561 auto Fragment1 = *getFragmentInfo();
2562 auto Fragment2 = *Other->getFragmentInfo();
2563 unsigned l1 = Fragment1.OffsetInBits;
2564 unsigned l2 = Fragment2.OffsetInBits;
2565 unsigned r1 = l1 + Fragment1.SizeInBits;
2566 unsigned r2 = l2 + Fragment2.SizeInBits;
2567 if (r1 <= l2)
2568 return -1;
2569 else if (r2 <= l1)
2570 return 1;
2571 else
2572 return 0;
2573 }
2574
2575 /// Check if fragments overlap between this DIExpression and \p Other.
2576 bool fragmentsOverlap(const DIExpression *Other) const {
2577 if (!isFragment() || !Other->isFragment())
2578 return true;
2579 return fragmentCmp(Other) == 0;
2580 }
2581};
2582
2583/// Global variables.
2584///
2585/// TODO: Remove DisplayName. It's always equal to Name.
2586class DIGlobalVariable : public DIVariable {
2587 friend class LLVMContextImpl;
2588 friend class MDNode;
2589
2590 bool IsLocalToUnit;
2591 bool IsDefinition;
2592
2593 DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
2594 bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits,
2595 ArrayRef<Metadata *> Ops)
2596 : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
2597 IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
2598 ~DIGlobalVariable() = default;
2599
2600 static DIGlobalVariable *
2601 getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2602 StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type,
2603 bool IsLocalToUnit, bool IsDefinition,
2604 DIDerivedType *StaticDataMemberDeclaration, MDTuple *TemplateParams,
2605 uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true) {
2606 return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
2607 getCanonicalMDString(Context, LinkageName), File, Line, Type,
2608 IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration,
2609 cast_or_null<Metadata>(TemplateParams), AlignInBits, Storage,
2610 ShouldCreate);
2611 }
2612 static DIGlobalVariable *
2613 getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
2614 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
2615 bool IsLocalToUnit, bool IsDefinition,
2616 Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
2617 uint32_t AlignInBits, StorageType Storage, bool ShouldCreate = true);
2618
2619 TempDIGlobalVariable cloneImpl() const {
2620 return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
2621 getFile(), getLine(), getType(), isLocalToUnit(),
2622 isDefinition(), getStaticDataMemberDeclaration(),
2623 getTemplateParams(), getAlignInBits());
2624 }
2625
2626public:
2627 DEFINE_MDNODE_GET(DIGlobalVariable,
2628 (DIScope * Scope, StringRef Name, StringRef LinkageName,
2629 DIFile *File, unsigned Line, DITypeRef Type,
2630 bool IsLocalToUnit, bool IsDefinition,
2631 DIDerivedType *StaticDataMemberDeclaration,
2632 MDTuple *TemplateParams, uint32_t AlignInBits),
2633 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2634 IsDefinition, StaticDataMemberDeclaration, TemplateParams,
2635 AlignInBits))
2636 DEFINE_MDNODE_GET(DIGlobalVariable,
2637 (Metadata * Scope, MDString *Name, MDString *LinkageName,
2638 Metadata *File, unsigned Line, Metadata *Type,
2639 bool IsLocalToUnit, bool IsDefinition,
2640 Metadata *StaticDataMemberDeclaration,
2641 Metadata *TemplateParams, uint32_t AlignInBits),
2642 (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
2643 IsDefinition, StaticDataMemberDeclaration, TemplateParams,
2644 AlignInBits))
2645
2646 TempDIGlobalVariable clone() const { return cloneImpl(); }
2647
2648 bool isLocalToUnit() const { return IsLocalToUnit; }
2649 bool isDefinition() const { return IsDefinition; }
2650 StringRef getDisplayName() const { return getStringOperand(4); }
2651 StringRef getLinkageName() const { return getStringOperand(5); }
2652 DIDerivedType *getStaticDataMemberDeclaration() const {
2653 return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
2654 }
2655
2656 MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
2657 Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(6); }
2658 Metadata *getRawTemplateParams() const { return getOperand(7); }
2659 MDTuple *getTemplateParams() const { return getOperandAs<MDTuple>(7); }
2660
2661 static bool classof(const Metadata *MD) {
2662 return MD->getMetadataID() == DIGlobalVariableKind;
2663 }
2664};
2665
2666/// Local variable.
2667///
2668/// TODO: Split up flags.
2669class DILocalVariable : public DIVariable {
2670 friend class LLVMContextImpl;
2671 friend class MDNode;
2672
2673 unsigned Arg : 16;
2674 DIFlags Flags;
2675
2676 DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
2677 unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
2678 ArrayRef<Metadata *> Ops)
2679 : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
2680 Arg(Arg), Flags(Flags) {
2681 assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range")((Arg < (1 << 16) && "DILocalVariable: Arg out of range"
) ? static_cast<void> (0) : __assert_fail ("Arg < (1 << 16) && \"DILocalVariable: Arg out of range\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 2681, __PRETTY_FUNCTION__))
;
2682 }
2683 ~DILocalVariable() = default;
2684
2685 static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
2686 StringRef Name, DIFile *File, unsigned Line,
2687 DITypeRef Type, unsigned Arg, DIFlags Flags,
2688 uint32_t AlignInBits, StorageType Storage,
2689 bool ShouldCreate = true) {
2690 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
2691 Line, Type, Arg, Flags, AlignInBits, Storage, ShouldCreate);
2692 }
2693 static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
2694 MDString *Name, Metadata *File, unsigned Line,
2695 Metadata *Type, unsigned Arg, DIFlags Flags,
2696 uint32_t AlignInBits, StorageType Storage,
2697 bool ShouldCreate = true);
2698
2699 TempDILocalVariable cloneImpl() const {
2700 return getTemporary(getContext(), getScope(), getName(), getFile(),
2701 getLine(), getType(), getArg(), getFlags(),
2702 getAlignInBits());
2703 }
2704
2705public:
2706 DEFINE_MDNODE_GET(DILocalVariable,
2707 (DILocalScope * Scope, StringRef Name, DIFile *File,
2708 unsigned Line, DITypeRef Type, unsigned Arg,
2709 DIFlags Flags, uint32_t AlignInBits),
2710 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
2711 DEFINE_MDNODE_GET(DILocalVariable,
2712 (Metadata * Scope, MDString *Name, Metadata *File,
2713 unsigned Line, Metadata *Type, unsigned Arg,
2714 DIFlags Flags, uint32_t AlignInBits),
2715 (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
2716
2717 TempDILocalVariable clone() const { return cloneImpl(); }
2718
2719 /// Get the local scope for this variable.
2720 ///
2721 /// Variables must be defined in a local scope.
2722 DILocalScope *getScope() const {
2723 return cast<DILocalScope>(DIVariable::getScope());
2724 }
2725
2726 bool isParameter() const { return Arg; }
2727 unsigned getArg() const { return Arg; }
2728 DIFlags getFlags() const { return Flags; }
2729
2730 bool isArtificial() const { return getFlags() & FlagArtificial; }
2731 bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
2732
2733 /// Check that a location is valid for this variable.
2734 ///
2735 /// Check that \c DL exists, is in the same subprogram, and has the same
2736 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
2737 /// to a \a DbgInfoIntrinsic.)
2738 bool isValidLocationForIntrinsic(const DILocation *DL) const {
2739 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
2740 }
2741
2742 static bool classof(const Metadata *MD) {
2743 return MD->getMetadataID() == DILocalVariableKind;
2744 }
2745};
2746
2747/// Label.
2748///
2749class DILabel : public DINode {
2750 friend class LLVMContextImpl;
2751 friend class MDNode;
2752
2753 unsigned Line;
2754
2755 DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
2756 ArrayRef<Metadata *> Ops)
2757 : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {}
2758 ~DILabel() = default;
2759
2760 static DILabel *getImpl(LLVMContext &Context, DIScope *Scope,
2761 StringRef Name, DIFile *File, unsigned Line,
2762 StorageType Storage,
2763 bool ShouldCreate = true) {
2764 return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
2765 Line, Storage, ShouldCreate);
2766 }
2767 static DILabel *getImpl(LLVMContext &Context, Metadata *Scope,
2768 MDString *Name, Metadata *File, unsigned Line,
2769 StorageType Storage,
2770 bool ShouldCreate = true);
2771
2772 TempDILabel cloneImpl() const {
2773 return getTemporary(getContext(), getScope(), getName(), getFile(),
2774 getLine());
2775 }
2776
2777public:
2778 DEFINE_MDNODE_GET(DILabel,
2779 (DILocalScope * Scope, StringRef Name, DIFile *File,
2780 unsigned Line),
2781 (Scope, Name, File, Line))
2782 DEFINE_MDNODE_GET(DILabel,
2783 (Metadata * Scope, MDString *Name, Metadata *File,
2784 unsigned Line),
2785 (Scope, Name, File, Line))
2786
2787 TempDILabel clone() const { return cloneImpl(); }
2788
2789 /// Get the local scope for this label.
2790 ///
2791 /// Labels must be defined in a local scope.
2792 DILocalScope *getScope() const {
2793 return cast_or_null<DILocalScope>(getRawScope());
2794 }
2795 unsigned getLine() const { return Line; }
2796 StringRef getName() const { return getStringOperand(1); }
2797 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2798
2799 Metadata *getRawScope() const { return getOperand(0); }
2800 MDString *getRawName() const { return getOperandAs<MDString>(1); }
2801 Metadata *getRawFile() const { return getOperand(2); }
2802
2803 /// Check that a location is valid for this label.
2804 ///
2805 /// Check that \c DL exists, is in the same subprogram, and has the same
2806 /// inlined-at location as \c this. (Otherwise, it's not a valid attachment
2807 /// to a \a DbgInfoIntrinsic.)
2808 bool isValidLocationForIntrinsic(const DILocation *DL) const {
2809 return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
2810 }
2811
2812 static bool classof(const Metadata *MD) {
2813 return MD->getMetadataID() == DILabelKind;
2814 }
2815};
2816
2817class DIObjCProperty : public DINode {
2818 friend class LLVMContextImpl;
2819 friend class MDNode;
2820
2821 unsigned Line;
2822 unsigned Attributes;
2823
2824 DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
2825 unsigned Attributes, ArrayRef<Metadata *> Ops)
2826 : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
2827 Ops),
2828 Line(Line), Attributes(Attributes) {}
2829 ~DIObjCProperty() = default;
2830
2831 static DIObjCProperty *
2832 getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
2833 StringRef GetterName, StringRef SetterName, unsigned Attributes,
2834 DITypeRef Type, StorageType Storage, bool ShouldCreate = true) {
2835 return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
2836 getCanonicalMDString(Context, GetterName),
2837 getCanonicalMDString(Context, SetterName), Attributes, Type,
2838 Storage, ShouldCreate);
2839 }
2840 static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
2841 Metadata *File, unsigned Line,
2842 MDString *GetterName, MDString *SetterName,
2843 unsigned Attributes, Metadata *Type,
2844 StorageType Storage, bool ShouldCreate = true);
2845
2846 TempDIObjCProperty cloneImpl() const {
2847 return getTemporary(getContext(), getName(), getFile(), getLine(),
2848 getGetterName(), getSetterName(), getAttributes(),
2849 getType());
2850 }
2851
2852public:
2853 DEFINE_MDNODE_GET(DIObjCProperty,
2854 (StringRef Name, DIFile *File, unsigned Line,
2855 StringRef GetterName, StringRef SetterName,
2856 unsigned Attributes, DITypeRef Type),
2857 (Name, File, Line, GetterName, SetterName, Attributes,
2858 Type))
2859 DEFINE_MDNODE_GET(DIObjCProperty,
2860 (MDString * Name, Metadata *File, unsigned Line,
2861 MDString *GetterName, MDString *SetterName,
2862 unsigned Attributes, Metadata *Type),
2863 (Name, File, Line, GetterName, SetterName, Attributes,
2864 Type))
2865
2866 TempDIObjCProperty clone() const { return cloneImpl(); }
2867
2868 unsigned getLine() const { return Line; }
2869 unsigned getAttributes() const { return Attributes; }
2870 StringRef getName() const { return getStringOperand(0); }
2871 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2872 StringRef getGetterName() const { return getStringOperand(2); }
2873 StringRef getSetterName() const { return getStringOperand(3); }
2874 DITypeRef getType() const { return DITypeRef(getRawType()); }
2875
2876 StringRef getFilename() const {
2877 if (auto *F = getFile())
2878 return F->getFilename();
2879 return "";
2880 }
2881
2882 StringRef getDirectory() const {
2883 if (auto *F = getFile())
2884 return F->getDirectory();
2885 return "";
2886 }
2887
2888 Optional<StringRef> getSource() const {
2889 if (auto *F = getFile())
2890 return F->getSource();
2891 return None;
2892 }
2893
2894 MDString *getRawName() const { return getOperandAs<MDString>(0); }
2895 Metadata *getRawFile() const { return getOperand(1); }
2896 MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
2897 MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
2898 Metadata *getRawType() const { return getOperand(4); }
2899
2900 static bool classof(const Metadata *MD) {
2901 return MD->getMetadataID() == DIObjCPropertyKind;
2902 }
2903};
2904
2905/// An imported module (C++ using directive or similar).
2906class DIImportedEntity : public DINode {
2907 friend class LLVMContextImpl;
2908 friend class MDNode;
2909
2910 unsigned Line;
2911
2912 DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
2913 unsigned Line, ArrayRef<Metadata *> Ops)
2914 : DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
2915 ~DIImportedEntity() = default;
2916
2917 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2918 DIScope *Scope, DINodeRef Entity,
2919 DIFile *File, unsigned Line, StringRef Name,
2920 StorageType Storage,
2921 bool ShouldCreate = true) {
2922 return getImpl(Context, Tag, Scope, Entity, File, Line,
2923 getCanonicalMDString(Context, Name), Storage, ShouldCreate);
2924 }
2925 static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
2926 Metadata *Scope, Metadata *Entity,
2927 Metadata *File, unsigned Line,
2928 MDString *Name, StorageType Storage,
2929 bool ShouldCreate = true);
2930
2931 TempDIImportedEntity cloneImpl() const {
2932 return getTemporary(getContext(), getTag(), getScope(), getEntity(),
2933 getFile(), getLine(), getName());
2934 }
2935
2936public:
2937 DEFINE_MDNODE_GET(DIImportedEntity,
2938 (unsigned Tag, DIScope *Scope, DINodeRef Entity,
2939 DIFile *File, unsigned Line, StringRef Name = ""),
2940 (Tag, Scope, Entity, File, Line, Name))
2941 DEFINE_MDNODE_GET(DIImportedEntity,
2942 (unsigned Tag, Metadata *Scope, Metadata *Entity,
2943 Metadata *File, unsigned Line, MDString *Name),
2944 (Tag, Scope, Entity, File, Line, Name))
2945
2946 TempDIImportedEntity clone() const { return cloneImpl(); }
2947
2948 unsigned getLine() const { return Line; }
2949 DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
2950 DINodeRef getEntity() const { return DINodeRef(getRawEntity()); }
2951 StringRef getName() const { return getStringOperand(2); }
2952 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
2953
2954 Metadata *getRawScope() const { return getOperand(0); }
2955 Metadata *getRawEntity() const { return getOperand(1); }
2956 MDString *getRawName() const { return getOperandAs<MDString>(2); }
2957 Metadata *getRawFile() const { return getOperand(3); }
2958
2959 static bool classof(const Metadata *MD) {
2960 return MD->getMetadataID() == DIImportedEntityKind;
2961 }
2962};
2963
2964/// A pair of DIGlobalVariable and DIExpression.
2965class DIGlobalVariableExpression : public MDNode {
2966 friend class LLVMContextImpl;
2967 friend class MDNode;
2968
2969 DIGlobalVariableExpression(LLVMContext &C, StorageType Storage,
2970 ArrayRef<Metadata *> Ops)
2971 : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {}
2972 ~DIGlobalVariableExpression() = default;
2973
2974 static DIGlobalVariableExpression *
2975 getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression,
2976 StorageType Storage, bool ShouldCreate = true);
2977
2978 TempDIGlobalVariableExpression cloneImpl() const {
2979 return getTemporary(getContext(), getVariable(), getExpression());
2980 }
2981
2982public:
2983 DEFINE_MDNODE_GET(DIGlobalVariableExpression,
2984 (Metadata * Variable, Metadata *Expression),
2985 (Variable, Expression))
2986
2987 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
2988
2989 Metadata *getRawVariable() const { return getOperand(0); }
2990
2991 DIGlobalVariable *getVariable() const {
2992 return cast_or_null<DIGlobalVariable>(getRawVariable());
2993 }
2994
2995 Metadata *getRawExpression() const { return getOperand(1); }
2996
2997 DIExpression *getExpression() const {
2998 return cast<DIExpression>(getRawExpression());
2999 }
3000
3001 static bool classof(const Metadata *MD) {
3002 return MD->getMetadataID() == DIGlobalVariableExpressionKind;
3003 }
3004};
3005
3006/// Macro Info DWARF-like metadata node.
3007///
3008/// A metadata node with a DWARF macro info (i.e., a constant named
3009/// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a
3010/// DIMacroNode
3011/// because it's potentially used for non-DWARF output.
3012class DIMacroNode : public MDNode {
3013 friend class LLVMContextImpl;
3014 friend class MDNode;
3015
3016protected:
3017 DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
3018 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
3019 : MDNode(C, ID, Storage, Ops1, Ops2) {
3020 assert(MIType < 1u << 16)((MIType < 1u << 16) ? static_cast<void> (0) :
__assert_fail ("MIType < 1u << 16", "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 3020, __PRETTY_FUNCTION__))
;
3021 SubclassData16 = MIType;
3022 }
3023 ~DIMacroNode() = default;
3024
3025 template <class Ty> Ty *getOperandAs(unsigned I) const {
3026 return cast_or_null<Ty>(getOperand(I));
3027 }
3028
3029 StringRef getStringOperand(unsigned I) const {
3030 if (auto *S = getOperandAs<MDString>(I))
3031 return S->getString();
3032 return StringRef();
3033 }
3034
3035 static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
3036 if (S.empty())
3037 return nullptr;
3038 return MDString::get(Context, S);
3039 }
3040
3041public:
3042 unsigned getMacinfoType() const { return SubclassData16; }
3043
3044 static bool classof(const Metadata *MD) {
3045 switch (MD->getMetadataID()) {
3046 default:
3047 return false;
3048 case DIMacroKind:
3049 case DIMacroFileKind:
3050 return true;
3051 }
3052 }
3053};
3054
3055class DIMacro : public DIMacroNode {
3056 friend class LLVMContextImpl;
3057 friend class MDNode;
3058
3059 unsigned Line;
3060
3061 DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
3062 ArrayRef<Metadata *> Ops)
3063 : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
3064 ~DIMacro() = default;
3065
3066 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3067 StringRef Name, StringRef Value, StorageType Storage,
3068 bool ShouldCreate = true) {
3069 return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name),
3070 getCanonicalMDString(Context, Value), Storage, ShouldCreate);
3071 }
3072 static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
3073 MDString *Name, MDString *Value, StorageType Storage,
3074 bool ShouldCreate = true);
3075
3076 TempDIMacro cloneImpl() const {
3077 return getTemporary(getContext(), getMacinfoType(), getLine(), getName(),
3078 getValue());
3079 }
3080
3081public:
3082 DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name,
3083 StringRef Value = ""),
3084 (MIType, Line, Name, Value))
3085 DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name,
3086 MDString *Value),
3087 (MIType, Line, Name, Value))
3088
3089 TempDIMacro clone() const { return cloneImpl(); }
3090
3091 unsigned getLine() const { return Line; }
3092
3093 StringRef getName() const { return getStringOperand(0); }
3094 StringRef getValue() const { return getStringOperand(1); }
3095
3096 MDString *getRawName() const { return getOperandAs<MDString>(0); }
3097 MDString *getRawValue() const { return getOperandAs<MDString>(1); }
3098
3099 static bool classof(const Metadata *MD) {
3100 return MD->getMetadataID() == DIMacroKind;
3101 }
3102};
3103
3104class DIMacroFile : public DIMacroNode {
3105 friend class LLVMContextImpl;
3106 friend class MDNode;
3107
3108 unsigned Line;
3109
3110 DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
3111 unsigned Line, ArrayRef<Metadata *> Ops)
3112 : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
3113 ~DIMacroFile() = default;
3114
3115 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3116 unsigned Line, DIFile *File,
3117 DIMacroNodeArray Elements, StorageType Storage,
3118 bool ShouldCreate = true) {
3119 return getImpl(Context, MIType, Line, static_cast<Metadata *>(File),
3120 Elements.get(), Storage, ShouldCreate);
3121 }
3122
3123 static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
3124 unsigned Line, Metadata *File, Metadata *Elements,
3125 StorageType Storage, bool ShouldCreate = true);
3126
3127 TempDIMacroFile cloneImpl() const {
3128 return getTemporary(getContext(), getMacinfoType(), getLine(), getFile(),
3129 getElements());
3130 }
3131
3132public:
3133 DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File,
3134 DIMacroNodeArray Elements),
3135 (MIType, Line, File, Elements))
3136 DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line,
3137 Metadata *File, Metadata *Elements),
3138 (MIType, Line, File, Elements))
3139
3140 TempDIMacroFile clone() const { return cloneImpl(); }
3141
3142 void replaceElements(DIMacroNodeArray Elements) {
3143#ifndef NDEBUG
3144 for (DIMacroNode *Op : getElements())
3145 assert(is_contained(Elements->operands(), Op) &&((is_contained(Elements->operands(), Op) && "Lost a macro node during macro node list replacement"
) ? static_cast<void> (0) : __assert_fail ("is_contained(Elements->operands(), Op) && \"Lost a macro node during macro node list replacement\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 3146, __PRETTY_FUNCTION__))
3146 "Lost a macro node during macro node list replacement")((is_contained(Elements->operands(), Op) && "Lost a macro node during macro node list replacement"
) ? static_cast<void> (0) : __assert_fail ("is_contained(Elements->operands(), Op) && \"Lost a macro node during macro node list replacement\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/IR/DebugInfoMetadata.h"
, 3146, __PRETTY_FUNCTION__))
;
3147#endif
3148 replaceOperandWith(1, Elements.get());
3149 }
3150
3151 unsigned getLine() const { return Line; }
3152 DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3153
3154 DIMacroNodeArray getElements() const {
3155 return cast_or_null<MDTuple>(getRawElements());
3156 }
3157
3158 Metadata *getRawFile() const { return getOperand(0); }
3159 Metadata *getRawElements() const { return getOperand(1); }
3160
3161 static bool classof(const Metadata *MD) {
3162 return MD->getMetadataID() == DIMacroFileKind;
3163 }
3164};
3165
3166} // end namespace llvm
3167
3168#undef DEFINE_MDNODE_GET_UNPACK_IMPL
3169#undef DEFINE_MDNODE_GET_UNPACK
3170#undef DEFINE_MDNODE_GET
3171
3172#endif // LLVM_IR_DEBUGINFOMETADATA_H