/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/IR/DIBuilder.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- DIBuilder.cpp - Debug Information Builder ------------------------===// |
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 DIBuilder. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/IR/DIBuilder.h" |
15 | | #include "LLVMContextImpl.h" |
16 | | #include "llvm/ADT/STLExtras.h" |
17 | | #include "llvm/BinaryFormat/Dwarf.h" |
18 | | #include "llvm/IR/Constants.h" |
19 | | #include "llvm/IR/DebugInfo.h" |
20 | | #include "llvm/IR/IntrinsicInst.h" |
21 | | #include "llvm/IR/Module.h" |
22 | | #include "llvm/Support/Debug.h" |
23 | | |
24 | | using namespace llvm; |
25 | | using namespace llvm::dwarf; |
26 | | |
27 | | cl::opt<bool> |
28 | | UseDbgAddr("use-dbg-addr", |
29 | | llvm::cl::desc("Use llvm.dbg.addr for all local variables"), |
30 | | cl::init(false)); |
31 | | |
32 | | DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes) |
33 | | : M(m), VMContext(M.getContext()), CUNode(nullptr), |
34 | | DeclareFn(nullptr), ValueFn(nullptr), |
35 | 5.28M | AllowUnresolvedNodes(AllowUnresolvedNodes) {} |
36 | | |
37 | 35.2k | void DIBuilder::trackIfUnresolved(MDNode *N) { |
38 | 35.2k | if (!N) |
39 | 0 | return; |
40 | 35.2k | if (35.2k N->isResolved()35.2k ) |
41 | 33.2k | return; |
42 | 1.91k | |
43 | 35.2k | assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes"); |
44 | 1.91k | UnresolvedNodes.emplace_back(N); |
45 | 1.91k | } |
46 | | |
47 | 45.0k | void DIBuilder::finalizeSubprogram(DISubprogram *SP) { |
48 | 45.0k | MDTuple *Temp = SP->getVariables().get(); |
49 | 45.0k | if (!Temp || 45.0k !Temp->isTemporary()45.0k ) |
50 | 22.4k | return; |
51 | 22.5k | |
52 | 22.5k | SmallVector<Metadata *, 4> Variables; |
53 | 22.5k | |
54 | 22.5k | auto PV = PreservedVariables.find(SP); |
55 | 22.5k | if (PV != PreservedVariables.end()) |
56 | 27 | Variables.append(PV->second.begin(), PV->second.end()); |
57 | 45.0k | |
58 | 45.0k | DINodeArray AV = getOrCreateArray(Variables); |
59 | 45.0k | TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); |
60 | 45.0k | } |
61 | | |
62 | 1.36k | void DIBuilder::finalize() { |
63 | 1.36k | if (!CUNode1.36k ) { |
64 | 0 | assert(!AllowUnresolvedNodes && |
65 | 0 | "creating type nodes without a CU is not supported"); |
66 | 0 | return; |
67 | 0 | } |
68 | 1.36k | |
69 | 1.36k | CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); |
70 | 1.36k | |
71 | 1.36k | SmallVector<Metadata *, 16> RetainValues; |
72 | 1.36k | // Declarations and definitions of the same type may be retained. Some |
73 | 1.36k | // clients RAUW these pairs, leaving duplicates in the retained types |
74 | 1.36k | // list. Use a set to remove the duplicates while we transform the |
75 | 1.36k | // TrackingVHs back into Values. |
76 | 1.36k | SmallPtrSet<Metadata *, 16> RetainSet; |
77 | 1.72k | for (unsigned I = 0, E = AllRetainTypes.size(); I < E1.72k ; I++357 ) |
78 | 357 | if (357 RetainSet.insert(AllRetainTypes[I]).second357 ) |
79 | 295 | RetainValues.push_back(AllRetainTypes[I]); |
80 | 1.36k | |
81 | 1.36k | if (!RetainValues.empty()) |
82 | 104 | CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); |
83 | 1.36k | |
84 | 1.36k | DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); |
85 | 1.36k | for (auto *SP : SPs) |
86 | 22.5k | finalizeSubprogram(SP); |
87 | 1.36k | for (auto *N : RetainValues) |
88 | 295 | if (auto *295 SP295 = dyn_cast<DISubprogram>(N)) |
89 | 31 | finalizeSubprogram(SP); |
90 | 1.36k | |
91 | 1.36k | if (!AllGVs.empty()) |
92 | 160 | CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); |
93 | 1.36k | |
94 | 1.36k | if (!AllImportedModules.empty()) |
95 | 13 | CUNode->replaceImportedEntities(MDTuple::get( |
96 | 13 | VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(), |
97 | 13 | AllImportedModules.end()))); |
98 | 1.36k | |
99 | 23 | for (const auto &I : AllMacrosPerParent) { |
100 | 23 | // DIMacroNode's with nullptr parent are DICompileUnit direct children. |
101 | 23 | if (!I.first23 ) { |
102 | 5 | CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef())); |
103 | 5 | continue; |
104 | 5 | } |
105 | 18 | // Otherwise, it must be a temporary DIMacroFile that need to be resolved. |
106 | 18 | auto *TMF = cast<DIMacroFile>(I.first); |
107 | 18 | auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file, |
108 | 18 | TMF->getLine(), TMF->getFile(), |
109 | 18 | getOrCreateMacroArray(I.second.getArrayRef())); |
110 | 18 | replaceTemporary(llvm::TempDIMacroNode(TMF), MF); |
111 | 18 | } |
112 | 1.36k | |
113 | 1.36k | // Now that all temp nodes have been replaced or deleted, resolve remaining |
114 | 1.36k | // cycles. |
115 | 1.36k | for (const auto &N : UnresolvedNodes) |
116 | 1.91k | if (1.91k N && 1.91k !N->isResolved()1.88k ) |
117 | 0 | N->resolveCycles(); |
118 | 1.36k | UnresolvedNodes.clear(); |
119 | 1.36k | |
120 | 1.36k | // Can't handle unresolved nodes anymore. |
121 | 1.36k | AllowUnresolvedNodes = false; |
122 | 1.36k | } |
123 | | |
124 | | /// If N is compile unit return NULL otherwise return N. |
125 | 29.6k | static DIScope *getNonCompileUnitScope(DIScope *N) { |
126 | 29.6k | if (!N || 29.6k isa<DICompileUnit>(N)29.6k ) |
127 | 1.26k | return nullptr; |
128 | 28.4k | return cast<DIScope>(N); |
129 | 28.4k | } |
130 | | |
131 | | DICompileUnit *DIBuilder::createCompileUnit( |
132 | | unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized, |
133 | | StringRef Flags, unsigned RunTimeVer, StringRef SplitName, |
134 | | DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId, |
135 | 1.37k | bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames) { |
136 | 1.37k | |
137 | 1.37k | assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || |
138 | 1.37k | (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && |
139 | 1.37k | "Invalid Language tag"); |
140 | 1.37k | |
141 | 1.37k | assert(!CUNode && "Can only make one compile unit per DIBuilder instance"); |
142 | 1.37k | CUNode = DICompileUnit::getDistinct( |
143 | 1.37k | VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer, |
144 | 1.37k | SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId, |
145 | 1.37k | SplitDebugInlining, DebugInfoForProfiling, GnuPubnames); |
146 | 1.37k | |
147 | 1.37k | // Create a named metadata so that it is easier to find cu in a module. |
148 | 1.37k | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
149 | 1.37k | NMD->addOperand(CUNode); |
150 | 1.37k | trackIfUnresolved(CUNode); |
151 | 1.37k | return CUNode; |
152 | 1.37k | } |
153 | | |
154 | | static DIImportedEntity * |
155 | | createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, |
156 | | Metadata *NS, DIFile *File, unsigned Line, StringRef Name, |
157 | 52 | SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { |
158 | 52 | if (Line) |
159 | 52 | assert(File && "Source location has line number but no file"); |
160 | 52 | unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); |
161 | 52 | auto *M = |
162 | 52 | DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), File, Line, Name); |
163 | 52 | if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) |
164 | 52 | // A new Imported Entity was just added to the context. |
165 | 52 | // Add it to the Imported Modules list. |
166 | 49 | AllImportedModules.emplace_back(M); |
167 | 52 | return M; |
168 | 52 | } |
169 | | |
170 | | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
171 | | DINamespace *NS, DIFile *File, |
172 | 11 | unsigned Line) { |
173 | 11 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
174 | 11 | Context, NS, File, Line, StringRef(), |
175 | 11 | AllImportedModules); |
176 | 11 | } |
177 | | |
178 | | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
179 | | DIImportedEntity *NS, |
180 | 2 | DIFile *File, unsigned Line) { |
181 | 2 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
182 | 2 | Context, NS, File, Line, StringRef(), |
183 | 2 | AllImportedModules); |
184 | 2 | } |
185 | | |
186 | | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M, |
187 | 0 | DIFile *File, unsigned Line) { |
188 | 0 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
189 | 0 | Context, M, File, Line, StringRef(), |
190 | 0 | AllImportedModules); |
191 | 0 | } |
192 | | |
193 | | DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context, |
194 | | DINode *Decl, |
195 | | DIFile *File, |
196 | | unsigned Line, |
197 | 39 | StringRef Name) { |
198 | 39 | // Make sure to use the unique identifier based metadata reference for |
199 | 39 | // types that have one. |
200 | 39 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
201 | 39 | Context, Decl, File, Line, Name, |
202 | 39 | AllImportedModules); |
203 | 39 | } |
204 | | |
205 | | DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory, |
206 | 5.26k | DIFile::ChecksumKind CSKind, StringRef Checksum) { |
207 | 5.26k | return DIFile::get(VMContext, Filename, Directory, CSKind, Checksum); |
208 | 5.26k | } |
209 | | |
210 | | DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber, |
211 | | unsigned MacroType, StringRef Name, |
212 | 1.07k | StringRef Value) { |
213 | 1.07k | assert(!Name.empty() && "Unable to create macro without name"); |
214 | 1.07k | assert((MacroType == dwarf::DW_MACINFO_undef || |
215 | 1.07k | MacroType == dwarf::DW_MACINFO_define) && |
216 | 1.07k | "Unexpected macro type"); |
217 | 1.07k | auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value); |
218 | 1.07k | AllMacrosPerParent[Parent].insert(M); |
219 | 1.07k | return M; |
220 | 1.07k | } |
221 | | |
222 | | DIMacroFile *DIBuilder::createTempMacroFile(DIMacroFile *Parent, |
223 | 18 | unsigned LineNumber, DIFile *File) { |
224 | 18 | auto *MF = DIMacroFile::getTemporary(VMContext, dwarf::DW_MACINFO_start_file, |
225 | 18 | LineNumber, File, DIMacroNodeArray()) |
226 | 18 | .release(); |
227 | 18 | AllMacrosPerParent[Parent].insert(MF); |
228 | 18 | // Add the new temporary DIMacroFile to the macro per parent map as a parent. |
229 | 18 | // This is needed to assure DIMacroFile with no children to have an entry in |
230 | 18 | // the map. Otherwise, it will not be resolved in DIBuilder::finalize(). |
231 | 18 | AllMacrosPerParent.insert({MF, {}}); |
232 | 18 | return MF; |
233 | 18 | } |
234 | | |
235 | 66 | DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val) { |
236 | 66 | assert(!Name.empty() && "Unable to create enumerator without name"); |
237 | 66 | return DIEnumerator::get(VMContext, Val, Name); |
238 | 66 | } |
239 | | |
240 | 15 | DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) { |
241 | 15 | assert(!Name.empty() && "Unable to create type without name"); |
242 | 15 | return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name); |
243 | 15 | } |
244 | | |
245 | 15 | DIBasicType *DIBuilder::createNullPtrType() { |
246 | 15 | return createUnspecifiedType("decltype(nullptr)"); |
247 | 15 | } |
248 | | |
249 | | DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
250 | 583 | unsigned Encoding) { |
251 | 583 | assert(!Name.empty() && "Unable to create type without name"); |
252 | 583 | return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, |
253 | 583 | 0, Encoding); |
254 | 583 | } |
255 | | |
256 | 212 | DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { |
257 | 212 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0, |
258 | 212 | 0, 0, None, DINode::FlagZero); |
259 | 212 | } |
260 | | |
261 | | DIDerivedType *DIBuilder::createPointerType( |
262 | | DIType *PointeeTy, |
263 | | uint64_t SizeInBits, |
264 | | uint32_t AlignInBits, |
265 | | Optional<unsigned> DWARFAddressSpace, |
266 | 1.56k | StringRef Name) { |
267 | 1.56k | // FIXME: Why is there a name here? |
268 | 1.56k | return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, |
269 | 1.56k | nullptr, 0, nullptr, PointeeTy, SizeInBits, |
270 | 1.56k | AlignInBits, 0, DWARFAddressSpace, |
271 | 1.56k | DINode::FlagZero); |
272 | 1.56k | } |
273 | | |
274 | | DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, |
275 | | DIType *Base, |
276 | | uint64_t SizeInBits, |
277 | | uint32_t AlignInBits, |
278 | 34 | DINode::DIFlags Flags) { |
279 | 34 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "", |
280 | 34 | nullptr, 0, nullptr, PointeeTy, SizeInBits, |
281 | 34 | AlignInBits, 0, None, Flags, Base); |
282 | 34 | } |
283 | | |
284 | | DIDerivedType *DIBuilder::createReferenceType( |
285 | | unsigned Tag, DIType *RTy, |
286 | | uint64_t SizeInBits, |
287 | | uint32_t AlignInBits, |
288 | 124 | Optional<unsigned> DWARFAddressSpace) { |
289 | 124 | assert(RTy && "Unable to create reference type"); |
290 | 124 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy, |
291 | 124 | SizeInBits, AlignInBits, 0, DWARFAddressSpace, |
292 | 124 | DINode::FlagZero); |
293 | 124 | } |
294 | | |
295 | | DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name, |
296 | | DIFile *File, unsigned LineNo, |
297 | 302 | DIScope *Context) { |
298 | 302 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File, |
299 | 302 | LineNo, getNonCompileUnitScope(Context), Ty, 0, 0, |
300 | 302 | 0, None, DINode::FlagZero); |
301 | 302 | } |
302 | | |
303 | 0 | DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { |
304 | 0 | assert(Ty && "Invalid type!"); |
305 | 0 | assert(FriendTy && "Invalid friend type!"); |
306 | 0 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty, |
307 | 0 | FriendTy, 0, 0, 0, None, DINode::FlagZero); |
308 | 0 | } |
309 | | |
310 | | DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, |
311 | | uint64_t BaseOffset, |
312 | 141 | DINode::DIFlags Flags) { |
313 | 141 | assert(Ty && "Unable to create inheritance"); |
314 | 141 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, |
315 | 141 | 0, Ty, BaseTy, 0, 0, BaseOffset, None, Flags); |
316 | 141 | } |
317 | | |
318 | | DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, |
319 | | DIFile *File, unsigned LineNumber, |
320 | | uint64_t SizeInBits, |
321 | | uint32_t AlignInBits, |
322 | | uint64_t OffsetInBits, |
323 | 1.01k | DINode::DIFlags Flags, DIType *Ty) { |
324 | 1.01k | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
325 | 1.01k | LineNumber, getNonCompileUnitScope(Scope), Ty, |
326 | 1.01k | SizeInBits, AlignInBits, OffsetInBits, None, Flags); |
327 | 1.01k | } |
328 | | |
329 | 460 | static ConstantAsMetadata *getConstantOrNull(Constant *C) { |
330 | 460 | if (C) |
331 | 401 | return ConstantAsMetadata::get(C); |
332 | 59 | return nullptr; |
333 | 59 | } |
334 | | |
335 | | DIDerivedType *DIBuilder::createBitFieldMemberType( |
336 | | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
337 | | uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, |
338 | 14 | DINode::DIFlags Flags, DIType *Ty) { |
339 | 14 | Flags |= DINode::FlagBitField; |
340 | 14 | return DIDerivedType::get( |
341 | 14 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
342 | 14 | getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0, |
343 | 14 | OffsetInBits, None, Flags, |
344 | 14 | ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64), |
345 | 14 | StorageOffsetInBits))); |
346 | 14 | } |
347 | | |
348 | | DIDerivedType * |
349 | | DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, |
350 | | unsigned LineNumber, DIType *Ty, |
351 | | DINode::DIFlags Flags, llvm::Constant *Val, |
352 | 87 | uint32_t AlignInBits) { |
353 | 87 | Flags |= DINode::FlagStaticMember; |
354 | 87 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
355 | 87 | LineNumber, getNonCompileUnitScope(Scope), Ty, 0, |
356 | 87 | AlignInBits, 0, None, Flags, |
357 | 87 | getConstantOrNull(Val)); |
358 | 87 | } |
359 | | |
360 | | DIDerivedType * |
361 | | DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber, |
362 | | uint64_t SizeInBits, uint32_t AlignInBits, |
363 | | uint64_t OffsetInBits, DINode::DIFlags Flags, |
364 | 95 | DIType *Ty, MDNode *PropertyNode) { |
365 | 95 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
366 | 95 | LineNumber, getNonCompileUnitScope(File), Ty, |
367 | 95 | SizeInBits, AlignInBits, OffsetInBits, None, Flags, |
368 | 95 | PropertyNode); |
369 | 95 | } |
370 | | |
371 | | DIObjCProperty * |
372 | | DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, |
373 | | StringRef GetterName, StringRef SetterName, |
374 | 78 | unsigned PropertyAttributes, DIType *Ty) { |
375 | 78 | return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, |
376 | 78 | SetterName, PropertyAttributes, Ty); |
377 | 78 | } |
378 | | |
379 | | DITemplateTypeParameter * |
380 | | DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name, |
381 | 311 | DIType *Ty) { |
382 | 311 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
383 | 311 | return DITemplateTypeParameter::get(VMContext, Name, Ty); |
384 | 311 | } |
385 | | |
386 | | static DITemplateValueParameter * |
387 | | createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, |
388 | | DIScope *Context, StringRef Name, DIType *Ty, |
389 | 410 | Metadata *MD) { |
390 | 410 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
391 | 410 | return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD); |
392 | 410 | } |
393 | | |
394 | | DITemplateValueParameter * |
395 | | DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name, |
396 | 373 | DIType *Ty, Constant *Val) { |
397 | 373 | return createTemplateValueParameterHelper( |
398 | 373 | VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty, |
399 | 373 | getConstantOrNull(Val)); |
400 | 373 | } |
401 | | |
402 | | DITemplateValueParameter * |
403 | | DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name, |
404 | 31 | DIType *Ty, StringRef Val) { |
405 | 31 | return createTemplateValueParameterHelper( |
406 | 31 | VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty, |
407 | 31 | MDString::get(VMContext, Val)); |
408 | 31 | } |
409 | | |
410 | | DITemplateValueParameter * |
411 | | DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name, |
412 | 6 | DIType *Ty, DINodeArray Val) { |
413 | 6 | return createTemplateValueParameterHelper( |
414 | 6 | VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty, |
415 | 6 | Val.get()); |
416 | 6 | } |
417 | | |
418 | | DICompositeType *DIBuilder::createClassType( |
419 | | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
420 | | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
421 | | DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, |
422 | 0 | DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) { |
423 | 0 | assert((!Context || isa<DIScope>(Context)) && |
424 | 0 | "createClassType should be called with a valid Context"); |
425 | 0 |
|
426 | 0 | auto *R = DICompositeType::get( |
427 | 0 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
428 | 0 | getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, |
429 | 0 | OffsetInBits, Flags, Elements, 0, VTableHolder, |
430 | 0 | cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier); |
431 | 0 | trackIfUnresolved(R); |
432 | 0 | return R; |
433 | 0 | } |
434 | | |
435 | | DICompositeType *DIBuilder::createStructType( |
436 | | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
437 | | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
438 | | DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang, |
439 | 241 | DIType *VTableHolder, StringRef UniqueIdentifier) { |
440 | 241 | auto *R = DICompositeType::get( |
441 | 241 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
442 | 241 | getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0, |
443 | 241 | Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier); |
444 | 241 | trackIfUnresolved(R); |
445 | 241 | return R; |
446 | 241 | } |
447 | | |
448 | | DICompositeType *DIBuilder::createUnionType( |
449 | | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
450 | | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
451 | 0 | DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) { |
452 | 0 | auto *R = DICompositeType::get( |
453 | 0 | VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, |
454 | 0 | getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, |
455 | 0 | Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier); |
456 | 0 | trackIfUnresolved(R); |
457 | 0 | return R; |
458 | 0 | } |
459 | | |
460 | | DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes, |
461 | | DINode::DIFlags Flags, |
462 | 23.5k | unsigned CC) { |
463 | 23.5k | return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes); |
464 | 23.5k | } |
465 | | |
466 | | DICompositeType *DIBuilder::createEnumerationType( |
467 | | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
468 | | uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, |
469 | 57 | DIType *UnderlyingType, StringRef UniqueIdentifier) { |
470 | 57 | auto *CTy = DICompositeType::get( |
471 | 57 | VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, |
472 | 57 | getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0, |
473 | 57 | DINode::FlagZero, Elements, 0, nullptr, nullptr, UniqueIdentifier); |
474 | 57 | AllEnumTypes.push_back(CTy); |
475 | 57 | trackIfUnresolved(CTy); |
476 | 57 | return CTy; |
477 | 57 | } |
478 | | |
479 | | DICompositeType *DIBuilder::createArrayType(uint64_t Size, |
480 | | uint32_t AlignInBits, DIType *Ty, |
481 | 196 | DINodeArray Subscripts) { |
482 | 196 | auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
483 | 196 | nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, |
484 | 196 | DINode::FlagZero, Subscripts, 0, nullptr); |
485 | 196 | trackIfUnresolved(R); |
486 | 196 | return R; |
487 | 196 | } |
488 | | |
489 | | DICompositeType *DIBuilder::createVectorType(uint64_t Size, |
490 | | uint32_t AlignInBits, DIType *Ty, |
491 | 15 | DINodeArray Subscripts) { |
492 | 15 | auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
493 | 15 | nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, |
494 | 15 | DINode::FlagVector, Subscripts, 0, nullptr); |
495 | 15 | trackIfUnresolved(R); |
496 | 15 | return R; |
497 | 15 | } |
498 | | |
499 | | static DIType *createTypeWithFlags(LLVMContext &Context, DIType *Ty, |
500 | 1.75k | DINode::DIFlags FlagsToSet) { |
501 | 1.75k | auto NewTy = Ty->clone(); |
502 | 1.75k | NewTy->setFlags(NewTy->getFlags() | FlagsToSet); |
503 | 1.75k | return MDNode::replaceWithUniqued(std::move(NewTy)); |
504 | 1.75k | } |
505 | | |
506 | 128 | DIType *DIBuilder::createArtificialType(DIType *Ty) { |
507 | 128 | // FIXME: Restrict this to the nodes where it's valid. |
508 | 128 | if (Ty->isArtificial()) |
509 | 0 | return Ty; |
510 | 128 | return createTypeWithFlags(VMContext, Ty, DINode::FlagArtificial); |
511 | 128 | } |
512 | | |
513 | 1.62k | DIType *DIBuilder::createObjectPointerType(DIType *Ty) { |
514 | 1.62k | // FIXME: Restrict this to the nodes where it's valid. |
515 | 1.62k | if (Ty->isObjectPointer()) |
516 | 0 | return Ty; |
517 | 1.62k | DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial; |
518 | 1.62k | return createTypeWithFlags(VMContext, Ty, Flags); |
519 | 1.62k | } |
520 | | |
521 | 357 | void DIBuilder::retainType(DIScope *T) { |
522 | 357 | assert(T && "Expected non-null type"); |
523 | 357 | assert((isa<DIType>(T) || (isa<DISubprogram>(T) && |
524 | 357 | cast<DISubprogram>(T)->isDefinition() == false)) && |
525 | 357 | "Expected type or subprogram declaration"); |
526 | 357 | AllRetainTypes.emplace_back(T); |
527 | 357 | } |
528 | | |
529 | 12 | DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; } |
530 | | |
531 | | DICompositeType * |
532 | | DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, |
533 | | DIFile *F, unsigned Line, unsigned RuntimeLang, |
534 | | uint64_t SizeInBits, uint32_t AlignInBits, |
535 | 74 | StringRef UniqueIdentifier) { |
536 | 74 | // FIXME: Define in terms of createReplaceableForwardDecl() by calling |
537 | 74 | // replaceWithUniqued(). |
538 | 74 | auto *RetTy = DICompositeType::get( |
539 | 74 | VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, |
540 | 74 | SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, |
541 | 74 | nullptr, nullptr, UniqueIdentifier); |
542 | 74 | trackIfUnresolved(RetTy); |
543 | 74 | return RetTy; |
544 | 74 | } |
545 | | |
546 | | DICompositeType *DIBuilder::createReplaceableCompositeType( |
547 | | unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, |
548 | | unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, |
549 | 1.22k | DINode::DIFlags Flags, StringRef UniqueIdentifier) { |
550 | 1.22k | auto *RetTy = |
551 | 1.22k | DICompositeType::getTemporary( |
552 | 1.22k | VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, |
553 | 1.22k | SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr, |
554 | 1.22k | nullptr, UniqueIdentifier) |
555 | 1.22k | .release(); |
556 | 1.22k | trackIfUnresolved(RetTy); |
557 | 1.22k | return RetTy; |
558 | 1.22k | } |
559 | | |
560 | 24.4k | DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) { |
561 | 24.4k | return MDTuple::get(VMContext, Elements); |
562 | 24.4k | } |
563 | | |
564 | | DIMacroNodeArray |
565 | 20 | DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) { |
566 | 20 | return MDTuple::get(VMContext, Elements); |
567 | 20 | } |
568 | | |
569 | 23.5k | DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { |
570 | 23.5k | SmallVector<llvm::Metadata *, 16> Elts; |
571 | 29.2k | for (unsigned i = 0, e = Elements.size(); i != e29.2k ; ++i5.69k ) { |
572 | 5.69k | if (Elements[i] && 5.69k isa<MDNode>(Elements[i])3.97k ) |
573 | 3.97k | Elts.push_back(cast<DIType>(Elements[i])); |
574 | 5.69k | else |
575 | 1.72k | Elts.push_back(Elements[i]); |
576 | 5.69k | } |
577 | 23.5k | return DITypeRefArray(MDNode::get(VMContext, Elts)); |
578 | 23.5k | } |
579 | | |
580 | 219 | DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
581 | 219 | return DISubrange::get(VMContext, Count, Lo); |
582 | 219 | } |
583 | | |
584 | 507 | static void checkGlobalVariableScope(DIScope *Context) { |
585 | | #ifndef NDEBUG |
586 | | if (auto *CT = |
587 | | dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context))) |
588 | | assert(CT->getIdentifier().empty() && |
589 | | "Context of a global variable should not be a type with identifier"); |
590 | | #endif |
591 | | } |
592 | | |
593 | | DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression( |
594 | | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
595 | | unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr, |
596 | 503 | MDNode *Decl, uint32_t AlignInBits) { |
597 | 503 | checkGlobalVariableScope(Context); |
598 | 503 | |
599 | 503 | auto *GV = DIGlobalVariable::getDistinct( |
600 | 503 | VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, |
601 | 503 | LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl), |
602 | 503 | AlignInBits); |
603 | 503 | if (!Expr) |
604 | 462 | Expr = createExpression(); |
605 | 503 | auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr); |
606 | 503 | AllGVs.push_back(N); |
607 | 503 | return N; |
608 | 503 | } |
609 | | |
610 | | DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( |
611 | | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
612 | | unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl, |
613 | 4 | uint32_t AlignInBits) { |
614 | 4 | checkGlobalVariableScope(Context); |
615 | 4 | |
616 | 4 | return DIGlobalVariable::getTemporary( |
617 | 4 | VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, |
618 | 4 | LineNumber, Ty, isLocalToUnit, false, |
619 | 4 | cast_or_null<DIDerivedType>(Decl), AlignInBits) |
620 | 4 | .release(); |
621 | 4 | } |
622 | | |
623 | | static DILocalVariable *createLocalVariable( |
624 | | LLVMContext &VMContext, |
625 | | DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, |
626 | | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
627 | | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, |
628 | 3.29k | uint32_t AlignInBits) { |
629 | 3.29k | // FIXME: Why getNonCompileUnitScope()? |
630 | 3.29k | // FIXME: Why is "!Context" okay here? |
631 | 3.29k | // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT |
632 | 3.29k | // the only valid scopes)? |
633 | 3.29k | DIScope *Context = getNonCompileUnitScope(Scope); |
634 | 3.29k | |
635 | 3.29k | auto *Node = |
636 | 3.29k | DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, |
637 | 3.29k | File, LineNo, Ty, ArgNo, Flags, AlignInBits); |
638 | 3.29k | if (AlwaysPreserve3.29k ) { |
639 | 42 | // The optimizer may remove local variables. If there is an interest |
640 | 42 | // to preserve variable info in such situation then stash it in a |
641 | 42 | // named mdnode. |
642 | 42 | DISubprogram *Fn = getDISubprogram(Scope); |
643 | 42 | assert(Fn && "Missing subprogram for local variable"); |
644 | 42 | PreservedVariables[Fn].emplace_back(Node); |
645 | 42 | } |
646 | 3.29k | return Node; |
647 | 3.29k | } |
648 | | |
649 | | DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, |
650 | | DIFile *File, unsigned LineNo, |
651 | | DIType *Ty, bool AlwaysPreserve, |
652 | | DINode::DIFlags Flags, |
653 | 1.15k | uint32_t AlignInBits) { |
654 | 1.15k | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, |
655 | 1.15k | /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, |
656 | 1.15k | Flags, AlignInBits); |
657 | 1.15k | } |
658 | | |
659 | | DILocalVariable *DIBuilder::createParameterVariable( |
660 | | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
661 | 2.13k | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) { |
662 | 2.13k | assert(ArgNo && "Expected non-zero argument number for parameter"); |
663 | 2.13k | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, |
664 | 2.13k | File, LineNo, Ty, AlwaysPreserve, Flags, |
665 | 2.13k | /* AlignInBits */0); |
666 | 2.13k | } |
667 | | |
668 | 3.80k | DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { |
669 | 3.80k | return DIExpression::get(VMContext, Addr); |
670 | 3.80k | } |
671 | | |
672 | 3.27k | DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) { |
673 | 3.27k | // TODO: Remove the callers of this signed version and delete. |
674 | 3.27k | SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end()); |
675 | 3.27k | return createExpression(Addr); |
676 | 3.27k | } |
677 | | |
678 | | template <class... Ts> |
679 | 23.4k | static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { |
680 | 23.4k | if (IsDistinct) |
681 | 22.5k | return DISubprogram::getDistinct(std::forward<Ts>(Args)...); |
682 | 939 | return DISubprogram::get(std::forward<Ts>(Args)...); |
683 | 939 | } DIBuilder.cpp:llvm::DISubprogram* getSubprogram<llvm::LLVMContext&, llvm::DIScope*, llvm::StringRef&, llvm::StringRef&, llvm::DIFile*&, unsigned int&, llvm::DISubroutineType*&, bool&, bool&, unsigned int&, std::nullptr_t, int, int, int, llvm::DINode::DIFlags&, bool&, llvm::DICompileUnit*, llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>&, llvm::DISubprogram*&, llvm::MDTuple*, llvm::MDTupleTypedArrayWrapper<llvm::DIType>&>(bool, llvm::LLVMContext&&&, llvm::DIScope*&&, llvm::StringRef&&&, llvm::StringRef&&&, llvm::DIFile*&&&, unsigned int&&&, llvm::DISubroutineType*&&&, bool&&&, bool&&&, unsigned int&&&, std::nullptr_t&&, int&&, int&&, int&&, llvm::DINode::DIFlags&&&, bool&&&, llvm::DICompileUnit*&&, llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>&&&, llvm::DISubprogram*&&&, llvm::MDTuple*&&, llvm::MDTupleTypedArrayWrapper<llvm::DIType>&&&) Line | Count | Source | 679 | 22.5k | static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { | 680 | 22.5k | if (IsDistinct) | 681 | 22.5k | return DISubprogram::getDistinct(std::forward<Ts>(Args)...); | 682 | 31 | return DISubprogram::get(std::forward<Ts>(Args)...); | 683 | 31 | } |
DIBuilder.cpp:llvm::DISubprogram* getSubprogram<llvm::LLVMContext&, llvm::DIScope*, llvm::StringRef&, llvm::StringRef&, llvm::DIFile*&, unsigned int&, llvm::DISubroutineType*&, bool&, bool&, unsigned int&, llvm::DIType*&, unsigned int&, unsigned int&, int&, llvm::DINode::DIFlags&, bool&, llvm::DICompileUnit*, llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>&, std::nullptr_t, std::nullptr_t, llvm::MDTupleTypedArrayWrapper<llvm::DIType>&>(bool, llvm::LLVMContext&&&, llvm::DIScope*&&, llvm::StringRef&&&, llvm::StringRef&&&, llvm::DIFile*&&&, unsigned int&&&, llvm::DISubroutineType*&&&, bool&&&, bool&&&, unsigned int&&&, llvm::DIType*&&&, unsigned int&&&, unsigned int&&&, int&&&, llvm::DINode::DIFlags&&&, bool&&&, llvm::DICompileUnit*&&, llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>&&&, std::nullptr_t&&, std::nullptr_t&&, llvm::MDTupleTypedArrayWrapper<llvm::DIType>&&&) Line | Count | Source | 679 | 908 | static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { | 680 | 908 | if (IsDistinct) | 681 | 0 | return DISubprogram::getDistinct(std::forward<Ts>(Args)...); | 682 | 908 | return DISubprogram::get(std::forward<Ts>(Args)...); | 683 | 908 | } |
|
684 | | |
685 | | DISubprogram *DIBuilder::createFunction( |
686 | | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
687 | | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
688 | | bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags, |
689 | | bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl, |
690 | 22.5k | DITypeArray ThrownTypes) { |
691 | 22.5k | auto *Node = getSubprogram( |
692 | 22.5k | /* IsDistinct = */ isDefinition, VMContext, |
693 | 22.5k | getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty, |
694 | 22.5k | isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags, |
695 | 22.5k | isOptimized, isDefinition ? CUNode22.5k : nullptr31 , TParams, Decl, |
696 | 22.5k | MDTuple::getTemporary(VMContext, None).release(), ThrownTypes); |
697 | 22.5k | |
698 | 22.5k | if (isDefinition) |
699 | 22.5k | AllSubprograms.push_back(Node); |
700 | 22.5k | trackIfUnresolved(Node); |
701 | 22.5k | return Node; |
702 | 22.5k | } |
703 | | |
704 | | DISubprogram *DIBuilder::createTempFunctionFwdDecl( |
705 | | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
706 | | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
707 | | bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags, |
708 | | bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl, |
709 | 4 | DITypeArray ThrownTypes) { |
710 | 4 | return DISubprogram::getTemporary( |
711 | 4 | VMContext, getNonCompileUnitScope(Context), Name, LinkageName, |
712 | 4 | File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr, |
713 | 4 | 0, 0, 0, Flags, isOptimized, isDefinition ? CUNode0 : nullptr4 , |
714 | 4 | TParams, Decl, nullptr, ThrownTypes) |
715 | 4 | .release(); |
716 | 4 | } |
717 | | |
718 | | DISubprogram *DIBuilder::createMethod( |
719 | | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
720 | | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
721 | | bool isDefinition, unsigned VK, unsigned VIndex, int ThisAdjustment, |
722 | | DIType *VTableHolder, DINode::DIFlags Flags, bool isOptimized, |
723 | 908 | DITemplateParameterArray TParams, DITypeArray ThrownTypes) { |
724 | 908 | assert(getNonCompileUnitScope(Context) && |
725 | 908 | "Methods should have both a Context and a context that isn't " |
726 | 908 | "the compile unit."); |
727 | 908 | // FIXME: Do we want to use different scope/lines? |
728 | 908 | auto *SP = getSubprogram( |
729 | 908 | /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name, |
730 | 908 | LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo, |
731 | 908 | VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized, |
732 | 908 | isDefinition ? CUNode0 : nullptr908 , TParams, nullptr, nullptr, ThrownTypes); |
733 | 908 | |
734 | 908 | if (isDefinition) |
735 | 0 | AllSubprograms.push_back(SP); |
736 | 908 | trackIfUnresolved(SP); |
737 | 908 | return SP; |
738 | 908 | } |
739 | | |
740 | | DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name, |
741 | 120 | bool ExportSymbols) { |
742 | 120 | |
743 | 120 | // It is okay to *not* make anonymous top-level namespaces distinct, because |
744 | 120 | // all nodes that have an anonymous namespace as their parent scope are |
745 | 120 | // guaranteed to be unique and/or are linked to their containing |
746 | 120 | // DICompileUnit. This decision is an explicit tradeoff of link time versus |
747 | 120 | // memory usage versus code simplicity and may get revisited in the future. |
748 | 120 | return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name, |
749 | 120 | ExportSymbols); |
750 | 120 | } |
751 | | |
752 | | DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name, |
753 | | StringRef ConfigurationMacros, |
754 | | StringRef IncludePath, |
755 | 53 | StringRef ISysRoot) { |
756 | 53 | return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name, |
757 | 53 | ConfigurationMacros, IncludePath, ISysRoot); |
758 | 53 | } |
759 | | |
760 | | DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope, |
761 | | DIFile *File, |
762 | 366 | unsigned Discriminator) { |
763 | 366 | return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator); |
764 | 366 | } |
765 | | |
766 | | DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File, |
767 | 582 | unsigned Line, unsigned Col) { |
768 | 582 | // Make these distinct, to avoid merging two lexical blocks on the same |
769 | 582 | // file/line/column. |
770 | 582 | return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope), |
771 | 582 | File, Line, Col); |
772 | 582 | } |
773 | | |
774 | 3.61k | static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { |
775 | 3.61k | assert(V && "no value passed to dbg intrinsic"); |
776 | 3.61k | return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V)); |
777 | 3.61k | } |
778 | | |
779 | 3.61k | static Instruction *withDebugLoc(Instruction *I, const DILocation *DL) { |
780 | 3.61k | I->setDebugLoc(const_cast<DILocation *>(DL)); |
781 | 3.61k | return I; |
782 | 3.61k | } |
783 | | |
784 | 329 | static Function *getDeclareIntrin(Module &M) { |
785 | 1 | return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr |
786 | 328 | : Intrinsic::dbg_declare); |
787 | 329 | } |
788 | | |
789 | | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
790 | | DIExpression *Expr, const DILocation *DL, |
791 | 141 | Instruction *InsertBefore) { |
792 | 141 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare"); |
793 | 141 | assert(DL && "Expected debug loc"); |
794 | 141 | assert(DL->getScope()->getSubprogram() == |
795 | 141 | VarInfo->getScope()->getSubprogram() && |
796 | 141 | "Expected matching subprograms"); |
797 | 141 | if (!DeclareFn) |
798 | 52 | DeclareFn = getDeclareIntrin(M); |
799 | 141 | |
800 | 141 | trackIfUnresolved(VarInfo); |
801 | 141 | trackIfUnresolved(Expr); |
802 | 141 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
803 | 141 | MetadataAsValue::get(VMContext, VarInfo), |
804 | 141 | MetadataAsValue::get(VMContext, Expr)}; |
805 | 141 | return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL); |
806 | 141 | } |
807 | | |
808 | | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
809 | | DIExpression *Expr, const DILocation *DL, |
810 | 3.25k | BasicBlock *InsertAtEnd) { |
811 | 3.25k | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare"); |
812 | 3.25k | assert(DL && "Expected debug loc"); |
813 | 3.25k | assert(DL->getScope()->getSubprogram() == |
814 | 3.25k | VarInfo->getScope()->getSubprogram() && |
815 | 3.25k | "Expected matching subprograms"); |
816 | 3.25k | if (!DeclareFn) |
817 | 277 | DeclareFn = getDeclareIntrin(M); |
818 | 3.25k | |
819 | 3.25k | trackIfUnresolved(VarInfo); |
820 | 3.25k | trackIfUnresolved(Expr); |
821 | 3.25k | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
822 | 3.25k | MetadataAsValue::get(VMContext, VarInfo), |
823 | 3.25k | MetadataAsValue::get(VMContext, Expr)}; |
824 | 3.25k | |
825 | 3.25k | // If this block already has a terminator then insert this intrinsic |
826 | 3.25k | // before the terminator. |
827 | 3.25k | if (TerminatorInst *T = InsertAtEnd->getTerminator()) |
828 | 0 | return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL); |
829 | 3.25k | return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL); |
830 | 3.25k | } |
831 | | |
832 | | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, |
833 | | DILocalVariable *VarInfo, |
834 | | DIExpression *Expr, |
835 | | const DILocation *DL, |
836 | 186 | Instruction *InsertBefore) { |
837 | 186 | assert(V && "no value passed to dbg.value"); |
838 | 186 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value"); |
839 | 186 | assert(DL && "Expected debug loc"); |
840 | 186 | assert(DL->getScope()->getSubprogram() == |
841 | 186 | VarInfo->getScope()->getSubprogram() && |
842 | 186 | "Expected matching subprograms"); |
843 | 186 | if (!ValueFn) |
844 | 100 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
845 | 186 | |
846 | 186 | trackIfUnresolved(VarInfo); |
847 | 186 | trackIfUnresolved(Expr); |
848 | 186 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
849 | 186 | MetadataAsValue::get(VMContext, VarInfo), |
850 | 186 | MetadataAsValue::get(VMContext, Expr)}; |
851 | 186 | return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL); |
852 | 186 | } |
853 | | |
854 | | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, |
855 | | DILocalVariable *VarInfo, |
856 | | DIExpression *Expr, |
857 | | const DILocation *DL, |
858 | 32 | BasicBlock *InsertAtEnd) { |
859 | 32 | assert(V && "no value passed to dbg.value"); |
860 | 32 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value"); |
861 | 32 | assert(DL && "Expected debug loc"); |
862 | 32 | assert(DL->getScope()->getSubprogram() == |
863 | 32 | VarInfo->getScope()->getSubprogram() && |
864 | 32 | "Expected matching subprograms"); |
865 | 32 | if (!ValueFn) |
866 | 23 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
867 | 32 | |
868 | 32 | trackIfUnresolved(VarInfo); |
869 | 32 | trackIfUnresolved(Expr); |
870 | 32 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
871 | 32 | MetadataAsValue::get(VMContext, VarInfo), |
872 | 32 | MetadataAsValue::get(VMContext, Expr)}; |
873 | 32 | |
874 | 32 | return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL); |
875 | 32 | } |
876 | | |
877 | | void DIBuilder::replaceVTableHolder(DICompositeType *&T, |
878 | 678 | DICompositeType *VTableHolder) { |
879 | 678 | { |
880 | 678 | TypedTrackingMDRef<DICompositeType> N(T); |
881 | 678 | N->replaceVTableHolder(VTableHolder); |
882 | 678 | T = N.get(); |
883 | 678 | } |
884 | 678 | |
885 | 678 | // If this didn't create a self-reference, just return. |
886 | 678 | if (T != VTableHolder) |
887 | 626 | return; |
888 | 52 | |
889 | 52 | // Look for unresolved operands. T will drop RAUW support, orphaning any |
890 | 52 | // cycles underneath it. |
891 | 52 | if (52 T->isResolved()52 ) |
892 | 52 | for (const MDOperand &O : T->operands()) |
893 | 416 | if (auto *416 N416 = dyn_cast_or_null<MDNode>(O)) |
894 | 116 | trackIfUnresolved(N); |
895 | 678 | } |
896 | | |
897 | | void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements, |
898 | 2.08k | DINodeArray TParams) { |
899 | 2.08k | { |
900 | 2.08k | TypedTrackingMDRef<DICompositeType> N(T); |
901 | 2.08k | if (Elements) |
902 | 951 | N->replaceElements(Elements); |
903 | 2.08k | if (TParams) |
904 | 284 | N->replaceTemplateParams(DITemplateParameterArray(TParams)); |
905 | 2.08k | T = N.get(); |
906 | 2.08k | } |
907 | 2.08k | |
908 | 2.08k | // If T isn't resolved, there's no problem. |
909 | 2.08k | if (!T->isResolved()) |
910 | 44 | return; |
911 | 2.03k | |
912 | 2.03k | // If T is resolved, it may be due to a self-reference cycle. Track the |
913 | 2.03k | // arrays explicitly if they're unresolved, or else the cycles will be |
914 | 2.03k | // orphaned. |
915 | 2.03k | if (2.03k Elements2.03k ) |
916 | 951 | trackIfUnresolved(Elements.get()); |
917 | 2.03k | if (TParams) |
918 | 283 | trackIfUnresolved(TParams.get()); |
919 | 2.08k | } |