LLVM 21.0.0git
DebugInfo.cpp
Go to the documentation of this file.
1//===- DebugInfo.cpp - Debug Information Helper Classes -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the helper classes used to build and interpret debug
10// information in LLVM IR form.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm-c/DebugInfo.h"
15#include "LLVMContextImpl.h"
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/IR/BasicBlock.h"
23#include "llvm/IR/Constants.h"
24#include "llvm/IR/DIBuilder.h"
25#include "llvm/IR/DebugInfo.h"
27#include "llvm/IR/DebugLoc.h"
29#include "llvm/IR/Function.h"
31#include "llvm/IR/Instruction.h"
33#include "llvm/IR/LLVMContext.h"
34#include "llvm/IR/Metadata.h"
35#include "llvm/IR/Module.h"
36#include "llvm/IR/PassManager.h"
38#include <algorithm>
39#include <cassert>
40#include <optional>
41#include <utility>
42
43using namespace llvm;
44using namespace llvm::at;
45using namespace llvm::dwarf;
46
48 // This function is hot. Check whether the value has any metadata to avoid a
49 // DenseMap lookup. This check is a bitfield datamember lookup.
50 if (!V->isUsedByMetadata())
51 return {};
53 if (!L)
54 return {};
55 auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
56 if (!MDV)
57 return {};
58
60 for (User *U : MDV->users())
61 if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
62 Declares.push_back(DDI);
63
64 return Declares;
65}
67 // This function is hot. Check whether the value has any metadata to avoid a
68 // DenseMap lookup. This check is a bitfield datamember lookup.
69 if (!V->isUsedByMetadata())
70 return {};
72 if (!L)
73 return {};
74
76 for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers())
77 if (DVR->getType() == DbgVariableRecord::LocationType::Declare)
78 Declares.push_back(DVR);
79
80 return Declares;
81}
82
84 // This function is hot. Check whether the value has any metadata to avoid a
85 // DenseMap lookup. This check is a bitfield datamember lookup.
86 if (!V->isUsedByMetadata())
87 return {};
89 if (!L)
90 return {};
91
93 for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers())
94 if (DVR->isValueOfVariable())
95 Values.push_back(DVR);
96
97 return Values;
98}
99
100template <typename IntrinsicT, bool DbgAssignAndValuesOnly>
101static void
103 SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
104 // This function is hot. Check whether the value has any metadata to avoid a
105 // DenseMap lookup.
106 if (!V->isUsedByMetadata())
107 return;
108
109 LLVMContext &Ctx = V->getContext();
110 // TODO: If this value appears multiple times in a DIArgList, we should still
111 // only add the owning DbgValueInst once; use this set to track ArgListUsers.
112 // This behaviour can be removed when we can automatically remove duplicates.
113 // V will also appear twice in a dbg.assign if its used in the both the value
114 // and address components.
115 SmallPtrSet<IntrinsicT *, 4> EncounteredIntrinsics;
116 SmallPtrSet<DbgVariableRecord *, 4> EncounteredDbgVariableRecords;
117
118 /// Append IntrinsicT users of MetadataAsValue(MD).
119 auto AppendUsers = [&Ctx, &EncounteredIntrinsics,
120 &EncounteredDbgVariableRecords, &Result,
121 DbgVariableRecords](Metadata *MD) {
122 if (auto *MDV = MetadataAsValue::getIfExists(Ctx, MD)) {
123 for (User *U : MDV->users())
124 if (IntrinsicT *DVI = dyn_cast<IntrinsicT>(U))
125 if (EncounteredIntrinsics.insert(DVI).second)
126 Result.push_back(DVI);
127 }
128 if (!DbgVariableRecords)
129 return;
130 // Get DbgVariableRecords that use this as a single value.
131 if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
132 for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers()) {
133 if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
134 if (EncounteredDbgVariableRecords.insert(DVR).second)
135 DbgVariableRecords->push_back(DVR);
136 }
137 }
138 };
139
140 if (auto *L = LocalAsMetadata::getIfExists(V)) {
141 AppendUsers(L);
142 for (Metadata *AL : L->getAllArgListUsers()) {
143 AppendUsers(AL);
144 if (!DbgVariableRecords)
145 continue;
146 DIArgList *DI = cast<DIArgList>(AL);
148 if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
149 if (EncounteredDbgVariableRecords.insert(DVR).second)
150 DbgVariableRecords->push_back(DVR);
151 }
152 }
153}
154
157 SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
158 findDbgIntrinsics<DbgValueInst, /*DbgAssignAndValuesOnly=*/true>(
159 DbgValues, V, DbgVariableRecords);
160}
161
164 SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
165 findDbgIntrinsics<DbgVariableIntrinsic, /*DbgAssignAndValuesOnly=*/false>(
166 DbgUsers, V, DbgVariableRecords);
167}
168
170 if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
171 return LocalScope->getSubprogram();
172 return nullptr;
173}
174
176 // Original dbg.declare must have a location.
177 const DebugLoc &DeclareLoc = DII->getDebugLoc();
178 MDNode *Scope = DeclareLoc.getScope();
179 DILocation *InlinedAt = DeclareLoc.getInlinedAt();
180 // Because no machine insts can come from debug intrinsics, only the scope
181 // and inlinedAt is significant. Zero line numbers are used in case this
182 // DebugLoc leaks into any adjacent instructions. Produce an unknown location
183 // with the correct scope / inlinedAt fields.
184 return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
185}
186
188 // Original dbg.declare must have a location.
189 const DebugLoc &DeclareLoc = DVR->getDebugLoc();
190 MDNode *Scope = DeclareLoc.getScope();
191 DILocation *InlinedAt = DeclareLoc.getInlinedAt();
192 // Because no machine insts can come from debug intrinsics, only the scope
193 // and inlinedAt is significant. Zero line numbers are used in case this
194 // DebugLoc leaks into any adjacent instructions. Produce an unknown location
195 // with the correct scope / inlinedAt fields.
196 return DILocation::get(DVR->getContext(), 0, 0, Scope, InlinedAt);
197}
198
199//===----------------------------------------------------------------------===//
200// DebugInfoFinder implementations.
201//===----------------------------------------------------------------------===//
202
204 CUs.clear();
205 SPs.clear();
206 GVs.clear();
207 TYs.clear();
208 Scopes.clear();
209 NodesSeen.clear();
210}
211
213 for (auto *CU : M.debug_compile_units())
214 processCompileUnit(CU);
215 for (auto &F : M.functions()) {
216 if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
218 // There could be subprograms from inlined functions referenced from
219 // instructions only. Walk the function to find them.
220 for (const BasicBlock &BB : F)
221 for (const Instruction &I : BB)
223 }
224}
225
226void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) {
227 if (!addCompileUnit(CU))
228 return;
229 for (auto *DIG : CU->getGlobalVariables()) {
230 if (!addGlobalVariable(DIG))
231 continue;
232 auto *GV = DIG->getVariable();
233 processScope(GV->getScope());
234 processType(GV->getType());
235 }
236 for (auto *ET : CU->getEnumTypes())
237 processType(ET);
238 for (auto *RT : CU->getRetainedTypes())
239 if (auto *T = dyn_cast<DIType>(RT))
240 processType(T);
241 else
242 processSubprogram(cast<DISubprogram>(RT));
243 for (auto *Import : CU->getImportedEntities()) {
244 auto *Entity = Import->getEntity();
245 if (auto *T = dyn_cast<DIType>(Entity))
246 processType(T);
247 else if (auto *SP = dyn_cast<DISubprogram>(Entity))
249 else if (auto *NS = dyn_cast<DINamespace>(Entity))
250 processScope(NS->getScope());
251 else if (auto *M = dyn_cast<DIModule>(Entity))
252 processScope(M->getScope());
253 }
254}
255
257 const Instruction &I) {
258 if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
259 processVariable(M, DVI->getVariable());
260
261 if (auto DbgLoc = I.getDebugLoc())
262 processLocation(M, DbgLoc.get());
263
264 for (const DbgRecord &DPR : I.getDbgRecordRange())
265 processDbgRecord(M, DPR);
266}
267
269 if (!Loc)
270 return;
271 processScope(Loc->getScope());
272 processLocation(M, Loc->getInlinedAt());
273}
274
276 if (const DbgVariableRecord *DVR = dyn_cast<const DbgVariableRecord>(&DR))
277 processVariable(M, DVR->getVariable());
279}
280
281void DebugInfoFinder::processType(DIType *DT) {
282 if (!addType(DT))
283 return;
284 processScope(DT->getScope());
285 if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
286 for (DIType *Ref : ST->getTypeArray())
287 processType(Ref);
288 return;
289 }
290 if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
291 processType(DCT->getBaseType());
292 for (Metadata *D : DCT->getElements()) {
293 if (auto *T = dyn_cast<DIType>(D))
294 processType(T);
295 else if (auto *SP = dyn_cast<DISubprogram>(D))
297 }
298 return;
299 }
300 if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
301 processType(DDT->getBaseType());
302 }
303}
304
305void DebugInfoFinder::processScope(DIScope *Scope) {
306 if (!Scope)
307 return;
308 if (auto *Ty = dyn_cast<DIType>(Scope)) {
309 processType(Ty);
310 return;
311 }
312 if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
313 addCompileUnit(CU);
314 return;
315 }
316 if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
318 return;
319 }
320 if (!addScope(Scope))
321 return;
322 if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
323 processScope(LB->getScope());
324 } else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
325 processScope(NS->getScope());
326 } else if (auto *M = dyn_cast<DIModule>(Scope)) {
327 processScope(M->getScope());
328 }
329}
330
332 if (!addSubprogram(SP))
333 return;
334 processScope(SP->getScope());
335 // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
336 // ValueMap containing identity mappings for all of the DICompileUnit's, not
337 // just DISubprogram's, referenced from anywhere within the Function being
338 // cloned prior to calling MapMetadata / RemapInstruction to avoid their
339 // duplication later as DICompileUnit's are also directly referenced by
340 // llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well.
341 // Also, DICompileUnit's may reference DISubprogram's too and therefore need
342 // to be at least looked through.
343 processCompileUnit(SP->getUnit());
344 processType(SP->getType());
345 for (auto *Element : SP->getTemplateParams()) {
346 if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
347 processType(TType->getType());
348 } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
349 processType(TVal->getType());
350 }
351 }
352}
353
355 const DILocalVariable *DV) {
356 if (!NodesSeen.insert(DV).second)
357 return;
358 processScope(DV->getScope());
359 processType(DV->getType());
360}
361
362bool DebugInfoFinder::addType(DIType *DT) {
363 if (!DT)
364 return false;
365
366 if (!NodesSeen.insert(DT).second)
367 return false;
368
369 TYs.push_back(const_cast<DIType *>(DT));
370 return true;
371}
372
373bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
374 if (!CU)
375 return false;
376 if (!NodesSeen.insert(CU).second)
377 return false;
378
379 CUs.push_back(CU);
380 return true;
381}
382
383bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) {
384 if (!NodesSeen.insert(DIG).second)
385 return false;
386
387 GVs.push_back(DIG);
388 return true;
389}
390
391bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
392 if (!SP)
393 return false;
394
395 if (!NodesSeen.insert(SP).second)
396 return false;
397
398 SPs.push_back(SP);
399 return true;
400}
401
402bool DebugInfoFinder::addScope(DIScope *Scope) {
403 if (!Scope)
404 return false;
405 // FIXME: Ocaml binding generates a scope with no content, we treat it
406 // as null for now.
407 if (Scope->getNumOperands() == 0)
408 return false;
409 if (!NodesSeen.insert(Scope).second)
410 return false;
411 Scopes.push_back(Scope);
412 return true;
413}
414
416 MDNode *OrigLoopID, function_ref<Metadata *(Metadata *)> Updater) {
417 assert(OrigLoopID && OrigLoopID->getNumOperands() > 0 &&
418 "Loop ID needs at least one operand");
419 assert(OrigLoopID && OrigLoopID->getOperand(0).get() == OrigLoopID &&
420 "Loop ID should refer to itself");
421
422 // Save space for the self-referential LoopID.
423 SmallVector<Metadata *, 4> MDs = {nullptr};
424
425 for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) {
426 Metadata *MD = OrigLoopID->getOperand(i);
427 if (!MD)
428 MDs.push_back(nullptr);
429 else if (Metadata *NewMD = Updater(MD))
430 MDs.push_back(NewMD);
431 }
432
433 MDNode *NewLoopID = MDNode::getDistinct(OrigLoopID->getContext(), MDs);
434 // Insert the self-referential LoopID.
435 NewLoopID->replaceOperandWith(0, NewLoopID);
436 return NewLoopID;
437}
438
440 Instruction &I, function_ref<Metadata *(Metadata *)> Updater) {
441 MDNode *OrigLoopID = I.getMetadata(LLVMContext::MD_loop);
442 if (!OrigLoopID)
443 return;
444 MDNode *NewLoopID = updateLoopMetadataDebugLocationsImpl(OrigLoopID, Updater);
445 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
446}
447
448/// Return true if a node is a DILocation or if a DILocation is
449/// indirectly referenced by one of the node's children.
452 Metadata *MD) {
453 MDNode *N = dyn_cast_or_null<MDNode>(MD);
454 if (!N)
455 return false;
456 if (isa<DILocation>(N) || Reachable.count(N))
457 return true;
458 if (!Visited.insert(N).second)
459 return false;
460 for (auto &OpIt : N->operands()) {
461 Metadata *Op = OpIt.get();
462 if (isDILocationReachable(Visited, Reachable, Op)) {
463 // Don't return just yet as we want to visit all MD's children to
464 // initialize DILocationReachable in stripDebugLocFromLoopID
465 Reachable.insert(N);
466 }
467 }
468 return Reachable.count(N);
469}
470
472 SmallPtrSetImpl<Metadata *> &AllDILocation,
473 const SmallPtrSetImpl<Metadata *> &DIReachable,
474 Metadata *MD) {
475 MDNode *N = dyn_cast_or_null<MDNode>(MD);
476 if (!N)
477 return false;
478 if (isa<DILocation>(N) || AllDILocation.count(N))
479 return true;
480 if (!DIReachable.count(N))
481 return false;
482 if (!Visited.insert(N).second)
483 return false;
484 for (auto &OpIt : N->operands()) {
485 Metadata *Op = OpIt.get();
486 if (Op == MD)
487 continue;
488 if (!isAllDILocation(Visited, AllDILocation, DIReachable, Op)) {
489 return false;
490 }
491 }
492 AllDILocation.insert(N);
493 return true;
494}
495
496static Metadata *
498 const SmallPtrSetImpl<Metadata *> &DIReachable, Metadata *MD) {
499 if (isa<DILocation>(MD) || AllDILocation.count(MD))
500 return nullptr;
501
502 if (!DIReachable.count(MD))
503 return MD;
504
505 MDNode *N = dyn_cast_or_null<MDNode>(MD);
506 if (!N)
507 return MD;
508
510 bool HasSelfRef = false;
511 for (unsigned i = 0; i < N->getNumOperands(); ++i) {
512 Metadata *A = N->getOperand(i);
513 if (!A) {
514 Args.push_back(nullptr);
515 } else if (A == MD) {
516 assert(i == 0 && "expected i==0 for self-reference");
517 HasSelfRef = true;
518 Args.push_back(nullptr);
519 } else if (Metadata *NewArg =
520 stripLoopMDLoc(AllDILocation, DIReachable, A)) {
521 Args.push_back(NewArg);
522 }
523 }
524 if (Args.empty() || (HasSelfRef && Args.size() == 1))
525 return nullptr;
526
527 MDNode *NewMD = N->isDistinct() ? MDNode::getDistinct(N->getContext(), Args)
528 : MDNode::get(N->getContext(), Args);
529 if (HasSelfRef)
530 NewMD->replaceOperandWith(0, NewMD);
531 return NewMD;
532}
533
535 assert(!N->operands().empty() && "Missing self reference?");
536 SmallPtrSet<Metadata *, 8> Visited, DILocationReachable, AllDILocation;
537 // If we already visited N, there is nothing to do.
538 if (!Visited.insert(N).second)
539 return N;
540
541 // If there is no debug location, we do not have to rewrite this
542 // MDNode. This loop also initializes DILocationReachable, later
543 // needed by updateLoopMetadataDebugLocationsImpl; the use of
544 // count_if avoids an early exit.
545 if (!llvm::count_if(llvm::drop_begin(N->operands()),
546 [&Visited, &DILocationReachable](const MDOperand &Op) {
547 return isDILocationReachable(
548 Visited, DILocationReachable, Op.get());
549 }))
550 return N;
551
552 Visited.clear();
553 // If there is only the debug location without any actual loop metadata, we
554 // can remove the metadata.
555 if (llvm::all_of(llvm::drop_begin(N->operands()),
556 [&Visited, &AllDILocation,
557 &DILocationReachable](const MDOperand &Op) {
558 return isAllDILocation(Visited, AllDILocation,
559 DILocationReachable, Op.get());
560 }))
561 return nullptr;
562
564 N, [&AllDILocation, &DILocationReachable](Metadata *MD) -> Metadata * {
565 return stripLoopMDLoc(AllDILocation, DILocationReachable, MD);
566 });
567}
568
570 bool Changed = false;
571 if (F.hasMetadata(LLVMContext::MD_dbg)) {
572 Changed = true;
573 F.setSubprogram(nullptr);
574 }
575
577 for (BasicBlock &BB : F) {
579 if (isa<DbgInfoIntrinsic>(&I)) {
580 I.eraseFromParent();
581 Changed = true;
582 continue;
583 }
584 if (I.getDebugLoc()) {
585 Changed = true;
586 I.setDebugLoc(DebugLoc());
587 }
588 if (auto *LoopID = I.getMetadata(LLVMContext::MD_loop)) {
589 auto *NewLoopID = LoopIDsMap.lookup(LoopID);
590 if (!NewLoopID)
591 NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
592 if (NewLoopID != LoopID)
593 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
594 }
595 // Strip other attachments that are or use debug info.
596 if (I.hasMetadataOtherThanDebugLoc()) {
597 // Heapallocsites point into the DIType system.
598 I.setMetadata("heapallocsite", nullptr);
599 // DIAssignID are debug info metadata primitives.
600 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
601 }
602 I.dropDbgRecords();
603 }
604 }
605 return Changed;
606}
607
609 bool Changed = false;
610
611 for (NamedMDNode &NMD : llvm::make_early_inc_range(M.named_metadata())) {
612 // We're stripping debug info, and without them, coverage information
613 // doesn't quite make sense.
614 if (NMD.getName().starts_with("llvm.dbg.") ||
615 NMD.getName() == "llvm.gcov") {
616 NMD.eraseFromParent();
617 Changed = true;
618 }
619 }
620
621 for (Function &F : M)
622 Changed |= stripDebugInfo(F);
623
624 for (auto &GV : M.globals()) {
625 Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
626 }
627
628 if (GVMaterializer *Materializer = M.getMaterializer())
629 Materializer->setStripDebugInfo();
630
631 return Changed;
632}
633
634namespace {
635
636/// Helper class to downgrade -g metadata to -gline-tables-only metadata.
637class DebugTypeInfoRemoval {
639
640public:
641 /// The (void)() type.
642 MDNode *EmptySubroutineType;
643
644private:
645 /// Remember what linkage name we originally had before stripping. If we end
646 /// up making two subprograms identical who originally had different linkage
647 /// names, then we need to make one of them distinct, to avoid them getting
648 /// uniqued. Maps the new node to the old linkage name.
650
651 // TODO: Remember the distinct subprogram we created for a given linkage name,
652 // so that we can continue to unique whenever possible. Map <newly created
653 // node, old linkage name> to the first (possibly distinct) mdsubprogram
654 // created for that combination. This is not strictly needed for correctness,
655 // but can cut down on the number of MDNodes and let us diff cleanly with the
656 // output of -gline-tables-only.
657
658public:
659 DebugTypeInfoRemoval(LLVMContext &C)
660 : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0,
661 MDNode::get(C, {}))) {}
662
663 Metadata *map(Metadata *M) {
664 if (!M)
665 return nullptr;
666 auto Replacement = Replacements.find(M);
667 if (Replacement != Replacements.end())
668 return Replacement->second;
669
670 return M;
671 }
672 MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); }
673
674 /// Recursively remap N and all its referenced children. Does a DF post-order
675 /// traversal, so as to remap bottoms up.
676 void traverseAndRemap(MDNode *N) { traverse(N); }
677
678private:
679 // Create a new DISubprogram, to replace the one given.
680 DISubprogram *getReplacementSubprogram(DISubprogram *MDS) {
681 auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile()));
682 StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
683 DISubprogram *Declaration = nullptr;
684 auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
685 DIType *ContainingType =
686 cast_or_null<DIType>(map(MDS->getContainingType()));
687 auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
688 auto Variables = nullptr;
689 auto TemplateParams = nullptr;
690
691 // Make a distinct DISubprogram, for situations that warrent it.
692 auto distinctMDSubprogram = [&]() {
693 return DISubprogram::getDistinct(
694 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
695 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(),
696 ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(),
697 MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration,
698 Variables);
699 };
700
701 if (MDS->isDistinct())
702 return distinctMDSubprogram();
703
704 auto *NewMDS = DISubprogram::get(
705 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
706 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType,
707 MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(),
708 MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables);
709
710 StringRef OldLinkageName = MDS->getLinkageName();
711
712 // See if we need to make a distinct one.
713 auto OrigLinkage = NewToLinkageName.find(NewMDS);
714 if (OrigLinkage != NewToLinkageName.end()) {
715 if (OrigLinkage->second == OldLinkageName)
716 // We're good.
717 return NewMDS;
718
719 // Otherwise, need to make a distinct one.
720 // TODO: Query the map to see if we already have one.
721 return distinctMDSubprogram();
722 }
723
724 NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
725 return NewMDS;
726 }
727
728 /// Create a new compile unit, to replace the one given
729 DICompileUnit *getReplacementCU(DICompileUnit *CU) {
730 // Drop skeleton CUs.
731 if (CU->getDWOId())
732 return nullptr;
733
734 auto *File = cast_or_null<DIFile>(map(CU->getFile()));
735 MDTuple *EnumTypes = nullptr;
736 MDTuple *RetainedTypes = nullptr;
737 MDTuple *GlobalVariables = nullptr;
738 MDTuple *ImportedEntities = nullptr;
739 return DICompileUnit::getDistinct(
740 CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(),
741 CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
742 CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
743 RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
744 CU->getDWOId(), CU->getSplitDebugInlining(),
745 CU->getDebugInfoForProfiling(), CU->getNameTableKind(),
746 CU->getRangesBaseAddress(), CU->getSysRoot(), CU->getSDK());
747 }
748
749 DILocation *getReplacementMDLocation(DILocation *MLD) {
750 auto *Scope = map(MLD->getScope());
751 auto *InlinedAt = map(MLD->getInlinedAt());
752 if (MLD->isDistinct())
753 return DILocation::getDistinct(MLD->getContext(), MLD->getLine(),
754 MLD->getColumn(), Scope, InlinedAt);
755 return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(),
756 Scope, InlinedAt);
757 }
758
759 /// Create a new generic MDNode, to replace the one given
760 MDNode *getReplacementMDNode(MDNode *N) {
762 Ops.reserve(N->getNumOperands());
763 for (auto &I : N->operands())
764 if (I)
765 Ops.push_back(map(I));
766 auto *Ret = MDNode::get(N->getContext(), Ops);
767 return Ret;
768 }
769
770 /// Attempt to re-map N to a newly created node.
771 void remap(MDNode *N) {
772 if (Replacements.count(N))
773 return;
774
775 auto doRemap = [&](MDNode *N) -> MDNode * {
776 if (!N)
777 return nullptr;
778 if (auto *MDSub = dyn_cast<DISubprogram>(N)) {
779 remap(MDSub->getUnit());
780 return getReplacementSubprogram(MDSub);
781 }
782 if (isa<DISubroutineType>(N))
783 return EmptySubroutineType;
784 if (auto *CU = dyn_cast<DICompileUnit>(N))
785 return getReplacementCU(CU);
786 if (isa<DIFile>(N))
787 return N;
788 if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N))
789 // Remap to our referenced scope (recursively).
790 return mapNode(MDLB->getScope());
791 if (auto *MLD = dyn_cast<DILocation>(N))
792 return getReplacementMDLocation(MLD);
793
794 // Otherwise, if we see these, just drop them now. Not strictly necessary,
795 // but this speeds things up a little.
796 if (isa<DINode>(N))
797 return nullptr;
798
799 return getReplacementMDNode(N);
800 };
801 // Seperate recursive doRemap and operator [] into 2 lines to avoid
802 // out-of-order evaluations since both of them can access the same memory
803 // location in map Replacements.
804 auto Value = doRemap(N);
805 Replacements[N] = Value;
806 }
807
808 /// Do the remapping traversal.
809 void traverse(MDNode *);
810};
811
812} // end anonymous namespace
813
814void DebugTypeInfoRemoval::traverse(MDNode *N) {
815 if (!N || Replacements.count(N))
816 return;
817
818 // To avoid cycles, as well as for efficiency sake, we will sometimes prune
819 // parts of the graph.
820 auto prune = [](MDNode *Parent, MDNode *Child) {
821 if (auto *MDS = dyn_cast<DISubprogram>(Parent))
822 return Child == MDS->getRetainedNodes().get();
823 return false;
824 };
825
827 DenseSet<MDNode *> Opened;
828
829 // Visit each node starting at N in post order, and map them.
830 ToVisit.push_back(N);
831 while (!ToVisit.empty()) {
832 auto *N = ToVisit.back();
833 if (!Opened.insert(N).second) {
834 // Close it.
835 remap(N);
836 ToVisit.pop_back();
837 continue;
838 }
839 for (auto &I : N->operands())
840 if (auto *MDN = dyn_cast_or_null<MDNode>(I))
841 if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) &&
842 !isa<DICompileUnit>(MDN))
843 ToVisit.push_back(MDN);
844 }
845}
846
848 bool Changed = false;
849
850 // First off, delete the debug intrinsics.
851 auto RemoveUses = [&](StringRef Name) {
852 if (auto *DbgVal = M.getFunction(Name)) {
853 while (!DbgVal->use_empty())
854 cast<Instruction>(DbgVal->user_back())->eraseFromParent();
855 DbgVal->eraseFromParent();
856 Changed = true;
857 }
858 };
859 RemoveUses("llvm.dbg.declare");
860 RemoveUses("llvm.dbg.label");
861 RemoveUses("llvm.dbg.value");
862
863 // Delete non-CU debug info named metadata nodes.
864 for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
865 NMI != NME;) {
866 NamedMDNode *NMD = &*NMI;
867 ++NMI;
868 // Specifically keep dbg.cu around.
869 if (NMD->getName() == "llvm.dbg.cu")
870 continue;
871 }
872
873 // Drop all dbg attachments from global variables.
874 for (auto &GV : M.globals())
875 GV.eraseMetadata(LLVMContext::MD_dbg);
876
877 DebugTypeInfoRemoval Mapper(M.getContext());
878 auto remap = [&](MDNode *Node) -> MDNode * {
879 if (!Node)
880 return nullptr;
881 Mapper.traverseAndRemap(Node);
882 auto *NewNode = Mapper.mapNode(Node);
883 Changed |= Node != NewNode;
884 Node = NewNode;
885 return NewNode;
886 };
887
888 // Rewrite the DebugLocs to be equivalent to what
889 // -gline-tables-only would have created.
890 for (auto &F : M) {
891 if (auto *SP = F.getSubprogram()) {
892 Mapper.traverseAndRemap(SP);
893 auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
894 Changed |= SP != NewSP;
895 F.setSubprogram(NewSP);
896 }
897 for (auto &BB : F) {
898 for (auto &I : BB) {
899 auto remapDebugLoc = [&](const DebugLoc &DL) -> DebugLoc {
900 auto *Scope = DL.getScope();
901 MDNode *InlinedAt = DL.getInlinedAt();
902 Scope = remap(Scope);
903 InlinedAt = remap(InlinedAt);
904 return DILocation::get(M.getContext(), DL.getLine(), DL.getCol(),
905 Scope, InlinedAt);
906 };
907
908 if (I.getDebugLoc() != DebugLoc())
909 I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
910
911 // Remap DILocations in llvm.loop attachments.
913 if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
914 return remapDebugLoc(Loc).get();
915 return MD;
916 });
917
918 // Strip heapallocsite attachments, they point into the DIType system.
919 if (I.hasMetadataOtherThanDebugLoc())
920 I.setMetadata("heapallocsite", nullptr);
921
922 // Strip any DbgRecords attached.
923 I.dropDbgRecords();
924 }
925 }
926 }
927
928 // Create a new llvm.dbg.cu, which is equivalent to the one
929 // -gline-tables-only would have created.
930 for (auto &NMD : M.named_metadata()) {
932 for (MDNode *Op : NMD.operands())
933 Ops.push_back(remap(Op));
934
935 if (!Changed)
936 continue;
937
938 NMD.clearOperands();
939 for (auto *Op : Ops)
940 if (Op)
941 NMD.addOperand(Op);
942 }
943 return Changed;
944}
945
947 if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
948 M.getModuleFlag("Debug Info Version")))
949 return Val->getZExtValue();
950 return 0;
951}
952
955}
956
958 ArrayRef<const Instruction *> SourceInstructions) {
959 // Replace all uses (and attachments) of all the DIAssignIDs
960 // on SourceInstructions with a single merged value.
961 assert(getFunction() && "Uninserted instruction merged");
962 // Collect up the DIAssignID tags.
964 for (const Instruction *I : SourceInstructions) {
965 if (auto *MD = I->getMetadata(LLVMContext::MD_DIAssignID))
966 IDs.push_back(cast<DIAssignID>(MD));
967 assert(getFunction() == I->getFunction() &&
968 "Merging with instruction from another function not allowed");
969 }
970
971 // Add this instruction's DIAssignID too, if it has one.
972 if (auto *MD = getMetadata(LLVMContext::MD_DIAssignID))
973 IDs.push_back(cast<DIAssignID>(MD));
974
975 if (IDs.empty())
976 return; // No DIAssignID tags to process.
977
978 DIAssignID *MergeID = IDs[0];
979 for (auto It = std::next(IDs.begin()), End = IDs.end(); It != End; ++It) {
980 if (*It != MergeID)
981 at::RAUW(*It, MergeID);
982 }
983 setMetadata(LLVMContext::MD_DIAssignID, MergeID);
984}
985
987
989 const DebugLoc &DL = getDebugLoc();
990 if (!DL)
991 return;
992
993 // If this isn't a call, drop the location to allow a location from a
994 // preceding instruction to propagate.
995 bool MayLowerToCall = false;
996 if (isa<CallBase>(this)) {
997 auto *II = dyn_cast<IntrinsicInst>(this);
998 MayLowerToCall =
999 !II || IntrinsicInst::mayLowerToFunctionCall(II->getIntrinsicID());
1000 }
1001
1002 if (!MayLowerToCall) {
1004 return;
1005 }
1006
1007 // Set a line 0 location for calls to preserve scope information in case
1008 // inlining occurs.
1010 if (SP)
1011 // If a function scope is available, set it on the line 0 location. When
1012 // hoisting a call to a predecessor block, using the function scope avoids
1013 // making it look like the callee was reached earlier than it should be.
1015 else
1016 // The parent function has no scope. Go ahead and drop the location. If
1017 // the parent function is inlined, and the callee has a subprogram, the
1018 // inliner will attach a location to the call.
1019 //
1020 // One alternative is to set a line 0 location with the existing scope and
1021 // inlinedAt info. The location might be sensitive to when inlining occurs.
1023}
1024
1025//===----------------------------------------------------------------------===//
1026// LLVM C API implementations.
1027//===----------------------------------------------------------------------===//
1028
1030 switch (lang) {
1031#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
1032 case LLVMDWARFSourceLanguage##NAME: \
1033 return ID;
1034#include "llvm/BinaryFormat/Dwarf.def"
1035#undef HANDLE_DW_LANG
1036 }
1037 llvm_unreachable("Unhandled Tag");
1038}
1039
1040template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) {
1041 return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
1042}
1043
1045 return static_cast<DINode::DIFlags>(Flags);
1046}
1047
1049 return static_cast<LLVMDIFlags>(Flags);
1050}
1051
1053pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) {
1054 return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized);
1055}
1056
1059}
1060
1062 return wrap(new DIBuilder(*unwrap(M), false));
1063}
1064
1066 return wrap(new DIBuilder(*unwrap(M)));
1067}
1068
1071}
1072
1074 return StripDebugInfo(*unwrap(M));
1075}
1076
1078 delete unwrap(Builder);
1079}
1080
1082 unwrap(Builder)->finalize();
1083}
1084
1086 LLVMMetadataRef subprogram) {
1087 unwrap(Builder)->finalizeSubprogram(unwrapDI<DISubprogram>(subprogram));
1088}
1089
1092 LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
1093 LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
1094 unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
1095 LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
1096 LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
1097 const char *SDK, size_t SDKLen) {
1098 auto File = unwrapDI<DIFile>(FileRef);
1099
1100 return wrap(unwrap(Builder)->createCompileUnit(
1102 StringRef(Producer, ProducerLen), isOptimized, StringRef(Flags, FlagsLen),
1103 RuntimeVer, StringRef(SplitName, SplitNameLen),
1104 static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
1105 SplitDebugInlining, DebugInfoForProfiling,
1107 StringRef(SysRoot, SysRootLen), StringRef(SDK, SDKLen)));
1108}
1109
1111LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
1112 size_t FilenameLen, const char *Directory,
1113 size_t DirectoryLen) {
1114 return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
1115 StringRef(Directory, DirectoryLen)));
1116}
1117
1120 const char *Name, size_t NameLen,
1121 const char *ConfigMacros, size_t ConfigMacrosLen,
1122 const char *IncludePath, size_t IncludePathLen,
1123 const char *APINotesFile, size_t APINotesFileLen) {
1124 return wrap(unwrap(Builder)->createModule(
1125 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
1126 StringRef(ConfigMacros, ConfigMacrosLen),
1127 StringRef(IncludePath, IncludePathLen),
1128 StringRef(APINotesFile, APINotesFileLen)));
1129}
1130
1132 LLVMMetadataRef ParentScope,
1133 const char *Name, size_t NameLen,
1134 LLVMBool ExportSymbols) {
1135 return wrap(unwrap(Builder)->createNameSpace(
1136 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols));
1137}
1138
1140 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1141 size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
1142 LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1143 LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
1144 unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
1145 return wrap(unwrap(Builder)->createFunction(
1146 unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
1147 unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine,
1148 map_from_llvmDIFlags(Flags),
1149 pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr,
1150 nullptr, nullptr));
1151}
1152
1153
1155 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1156 LLVMMetadataRef File, unsigned Line, unsigned Col) {
1157 return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope),
1158 unwrapDI<DIFile>(File),
1159 Line, Col));
1160}
1161
1164 LLVMMetadataRef Scope,
1165 LLVMMetadataRef File,
1166 unsigned Discriminator) {
1167 return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope),
1168 unwrapDI<DIFile>(File),
1169 Discriminator));
1170}
1171
1174 LLVMMetadataRef Scope,
1175 LLVMMetadataRef NS,
1176 LLVMMetadataRef File,
1177 unsigned Line) {
1178 return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
1179 unwrapDI<DINamespace>(NS),
1180 unwrapDI<DIFile>(File),
1181 Line));
1182}
1183
1185 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1186 LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line,
1187 LLVMMetadataRef *Elements, unsigned NumElements) {
1188 auto Elts =
1189 (NumElements > 0)
1190 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1191 : nullptr;
1192 return wrap(unwrap(Builder)->createImportedModule(
1193 unwrapDI<DIScope>(Scope), unwrapDI<DIImportedEntity>(ImportedEntity),
1194 unwrapDI<DIFile>(File), Line, Elts));
1195}
1196
1199 LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements,
1200 unsigned NumElements) {
1201 auto Elts =
1202 (NumElements > 0)
1203 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1204 : nullptr;
1205 return wrap(unwrap(Builder)->createImportedModule(
1206 unwrapDI<DIScope>(Scope), unwrapDI<DIModule>(M), unwrapDI<DIFile>(File),
1207 Line, Elts));
1208}
1209
1212 LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen,
1213 LLVMMetadataRef *Elements, unsigned NumElements) {
1214 auto Elts =
1215 (NumElements > 0)
1216 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1217 : nullptr;
1218 return wrap(unwrap(Builder)->createImportedDeclaration(
1219 unwrapDI<DIScope>(Scope), unwrapDI<DINode>(Decl), unwrapDI<DIFile>(File),
1220 Line, {Name, NameLen}, Elts));
1221}
1222
1225 unsigned Column, LLVMMetadataRef Scope,
1226 LLVMMetadataRef InlinedAt) {
1227 return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
1228 unwrap(InlinedAt)));
1229}
1230
1232 return unwrapDI<DILocation>(Location)->getLine();
1233}
1234
1236 return unwrapDI<DILocation>(Location)->getColumn();
1237}
1238
1240 return wrap(unwrapDI<DILocation>(Location)->getScope());
1241}
1242
1244 return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
1245}
1246
1248 return wrap(unwrapDI<DIScope>(Scope)->getFile());
1249}
1250
1251const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) {
1252 auto Dir = unwrapDI<DIFile>(File)->getDirectory();
1253 *Len = Dir.size();
1254 return Dir.data();
1255}
1256
1257const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
1258 auto Name = unwrapDI<DIFile>(File)->getFilename();
1259 *Len = Name.size();
1260 return Name.data();
1261}
1262
1263const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
1264 if (auto Src = unwrapDI<DIFile>(File)->getSource()) {
1265 *Len = Src->size();
1266 return Src->data();
1267 }
1268 *Len = 0;
1269 return "";
1270}
1271
1273 LLVMMetadataRef ParentMacroFile,
1274 unsigned Line,
1276 const char *Name, size_t NameLen,
1277 const char *Value, size_t ValueLen) {
1278 return wrap(
1279 unwrap(Builder)->createMacro(unwrapDI<DIMacroFile>(ParentMacroFile), Line,
1280 static_cast<MacinfoRecordType>(RecordType),
1281 {Name, NameLen}, {Value, ValueLen}));
1282}
1283
1286 LLVMMetadataRef ParentMacroFile, unsigned Line,
1287 LLVMMetadataRef File) {
1288 return wrap(unwrap(Builder)->createTempMacroFile(
1289 unwrapDI<DIMacroFile>(ParentMacroFile), Line, unwrapDI<DIFile>(File)));
1290}
1291
1293 const char *Name, size_t NameLen,
1294 int64_t Value,
1295 LLVMBool IsUnsigned) {
1296 return wrap(unwrap(Builder)->createEnumerator({Name, NameLen}, Value,
1297 IsUnsigned != 0));
1298}
1299
1301 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1302 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1303 uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements,
1304 unsigned NumElements, LLVMMetadataRef ClassTy) {
1305auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1306 NumElements});
1307return wrap(unwrap(Builder)->createEnumerationType(
1308 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1309 LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
1310}
1311
1313 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1314 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1315 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1316 LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
1317 const char *UniqueId, size_t UniqueIdLen) {
1318 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1319 NumElements});
1320 return wrap(unwrap(Builder)->createUnionType(
1321 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1322 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1323 Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
1324}
1325
1326
1329 uint32_t AlignInBits, LLVMMetadataRef Ty,
1330 LLVMMetadataRef *Subscripts,
1331 unsigned NumSubscripts) {
1332 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1333 NumSubscripts});
1334 return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
1335 unwrapDI<DIType>(Ty), Subs));
1336}
1337
1340 uint32_t AlignInBits, LLVMMetadataRef Ty,
1341 LLVMMetadataRef *Subscripts,
1342 unsigned NumSubscripts) {
1343 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1344 NumSubscripts});
1345 return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
1346 unwrapDI<DIType>(Ty), Subs));
1347}
1348
1351 size_t NameLen, uint64_t SizeInBits,
1352 LLVMDWARFTypeEncoding Encoding,
1353 LLVMDIFlags Flags) {
1354 return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
1355 SizeInBits, Encoding,
1356 map_from_llvmDIFlags(Flags)));
1357}
1358
1360 LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
1361 uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,
1362 const char *Name, size_t NameLen) {
1363 return wrap(unwrap(Builder)->createPointerType(
1364 unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, AddressSpace,
1365 {Name, NameLen}));
1366}
1367
1369 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1370 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1371 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1372 LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
1373 unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
1374 const char *UniqueId, size_t UniqueIdLen) {
1375 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1376 NumElements});
1377 return wrap(unwrap(Builder)->createStructType(
1378 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1379 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1380 unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
1381 unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
1382}
1383
1385 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1386 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
1387 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1388 LLVMMetadataRef Ty) {
1389 return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope),
1390 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
1391 OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty)));
1392}
1393
1396 size_t NameLen) {
1397 return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
1398}
1399
1401 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1402 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1403 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
1404 uint32_t AlignInBits) {
1405 return wrap(unwrap(Builder)->createStaticMemberType(
1406 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1407 LineNumber, unwrapDI<DIType>(Type), map_from_llvmDIFlags(Flags),
1408 unwrap<Constant>(ConstantVal), DW_TAG_member, AlignInBits));
1409}
1410
1413 const char *Name, size_t NameLen,
1414 LLVMMetadataRef File, unsigned LineNo,
1415 uint64_t SizeInBits, uint32_t AlignInBits,
1416 uint64_t OffsetInBits, LLVMDIFlags Flags,
1417 LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
1418 return wrap(unwrap(Builder)->createObjCIVar(
1419 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1420 SizeInBits, AlignInBits, OffsetInBits,
1421 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty),
1422 unwrapDI<MDNode>(PropertyNode)));
1423}
1424
1427 const char *Name, size_t NameLen,
1428 LLVMMetadataRef File, unsigned LineNo,
1429 const char *GetterName, size_t GetterNameLen,
1430 const char *SetterName, size_t SetterNameLen,
1431 unsigned PropertyAttributes,
1432 LLVMMetadataRef Ty) {
1433 return wrap(unwrap(Builder)->createObjCProperty(
1434 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1435 {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
1436 PropertyAttributes, unwrapDI<DIType>(Ty)));
1437}
1438
1441 LLVMBool Implicit) {
1442 return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type),
1443 Implicit));
1444}
1445
1448 const char *Name, size_t NameLen,
1449 LLVMMetadataRef File, unsigned LineNo,
1450 LLVMMetadataRef Scope, uint32_t AlignInBits) {
1451 return wrap(unwrap(Builder)->createTypedef(
1452 unwrapDI<DIType>(Type), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1453 unwrapDI<DIScope>(Scope), AlignInBits));
1454}
1455
1459 uint64_t BaseOffset, uint32_t VBPtrOffset,
1460 LLVMDIFlags Flags) {
1461 return wrap(unwrap(Builder)->createInheritance(
1462 unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy),
1463 BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
1464}
1465
1468 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1469 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1470 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1471 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1472 return wrap(unwrap(Builder)->createForwardDecl(
1473 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1474 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1475 AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
1476}
1477
1480 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1481 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1482 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1483 LLVMDIFlags Flags, const char *UniqueIdentifier,
1484 size_t UniqueIdentifierLen) {
1485 return wrap(unwrap(Builder)->createReplaceableCompositeType(
1486 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1487 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1488 AlignInBits, map_from_llvmDIFlags(Flags),
1489 {UniqueIdentifier, UniqueIdentifierLen}));
1490}
1491
1495 return wrap(unwrap(Builder)->createQualifiedType(Tag,
1496 unwrapDI<DIType>(Type)));
1497}
1498
1502 return wrap(unwrap(Builder)->createReferenceType(Tag,
1503 unwrapDI<DIType>(Type)));
1504}
1505
1508 return wrap(unwrap(Builder)->createNullPtrType());
1509}
1510
1513 LLVMMetadataRef PointeeType,
1514 LLVMMetadataRef ClassType,
1515 uint64_t SizeInBits,
1516 uint32_t AlignInBits,
1517 LLVMDIFlags Flags) {
1518 return wrap(unwrap(Builder)->createMemberPointerType(
1519 unwrapDI<DIType>(PointeeType),
1520 unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
1521 map_from_llvmDIFlags(Flags)));
1522}
1523
1526 LLVMMetadataRef Scope,
1527 const char *Name, size_t NameLen,
1528 LLVMMetadataRef File, unsigned LineNumber,
1529 uint64_t SizeInBits,
1530 uint64_t OffsetInBits,
1531 uint64_t StorageOffsetInBits,
1533 return wrap(unwrap(Builder)->createBitFieldMemberType(
1534 unwrapDI<DIScope>(Scope), {Name, NameLen},
1535 unwrapDI<DIFile>(File), LineNumber,
1536 SizeInBits, OffsetInBits, StorageOffsetInBits,
1537 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type)));
1538}
1539
1541 LLVMMetadataRef Scope, const char *Name, size_t NameLen,
1542 LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
1543 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1544 LLVMMetadataRef DerivedFrom,
1545 LLVMMetadataRef *Elements, unsigned NumElements,
1546 LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode,
1547 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1548 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1549 NumElements});
1550 return wrap(unwrap(Builder)->createClassType(
1551 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1552 LineNumber, SizeInBits, AlignInBits, OffsetInBits,
1553 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom), Elts,
1554 /*RunTimeLang=*/0, unwrapDI<DIType>(VTableHolder),
1555 unwrapDI<MDNode>(TemplateParamsNode),
1556 {UniqueIdentifier, UniqueIdentifierLen}));
1557}
1558
1562 return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
1563}
1564
1566 return unwrapDI<DINode>(MD)->getTag();
1567}
1568
1569const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
1570 StringRef Str = unwrapDI<DIType>(DType)->getName();
1571 *Length = Str.size();
1572 return Str.data();
1573}
1574
1576 return unwrapDI<DIType>(DType)->getSizeInBits();
1577}
1578
1580 return unwrapDI<DIType>(DType)->getOffsetInBits();
1581}
1582
1584 return unwrapDI<DIType>(DType)->getAlignInBits();
1585}
1586
1588 return unwrapDI<DIType>(DType)->getLine();
1589}
1590
1592 return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags());
1593}
1594
1596 LLVMMetadataRef *Types,
1597 size_t Length) {
1598 return wrap(
1599 unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
1600}
1601
1604 LLVMMetadataRef File,
1605 LLVMMetadataRef *ParameterTypes,
1606 unsigned NumParameterTypes,
1607 LLVMDIFlags Flags) {
1608 auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
1609 NumParameterTypes});
1610 return wrap(unwrap(Builder)->createSubroutineType(
1611 Elts, map_from_llvmDIFlags(Flags)));
1612}
1613
1615 uint64_t *Addr, size_t Length) {
1616 return wrap(
1617 unwrap(Builder)->createExpression(ArrayRef<uint64_t>(Addr, Length)));
1618}
1619
1622 uint64_t Value) {
1623 return wrap(unwrap(Builder)->createConstantValueExpression(Value));
1624}
1625
1627 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1628 size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File,
1629 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1630 LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) {
1631 return wrap(unwrap(Builder)->createGlobalVariableExpression(
1632 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
1633 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1634 true, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
1635 nullptr, AlignInBits));
1636}
1637
1639 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getVariable());
1640}
1641
1643 LLVMMetadataRef GVE) {
1644 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getExpression());
1645}
1646
1648 return wrap(unwrapDI<DIVariable>(Var)->getFile());
1649}
1650
1652 return wrap(unwrapDI<DIVariable>(Var)->getScope());
1653}
1654
1656 return unwrapDI<DIVariable>(Var)->getLine();
1657}
1658
1660 size_t Count) {
1661 return wrap(
1662 MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
1663}
1664
1666 MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode));
1667}
1668
1670 LLVMMetadataRef Replacement) {
1671 auto *Node = unwrapDI<MDNode>(TargetMetadata);
1672 Node->replaceAllUsesWith(unwrap(Replacement));
1674}
1675
1677 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1678 size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File,
1679 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1680 LLVMMetadataRef Decl, uint32_t AlignInBits) {
1681 return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
1682 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen},
1683 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1684 unwrapDI<MDNode>(Decl), nullptr, AlignInBits));
1685}
1686
1688 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1690 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1691 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1692 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1693 unwrap<Instruction>(Instr));
1694 // This assert will fail if the module is in the old debug info format.
1695 // This function should only be called if the module is in the new
1696 // debug info format.
1697 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1698 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1699 assert(isa<DbgRecord *>(DbgInst) &&
1700 "Function unexpectedly in old debug info format");
1701 return wrap(cast<DbgRecord *>(DbgInst));
1702}
1703
1705 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1707 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1708 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1709 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block));
1710 // This assert will fail if the module is in the old debug info format.
1711 // This function should only be called if the module is in the new
1712 // debug info format.
1713 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1714 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1715 assert(isa<DbgRecord *>(DbgInst) &&
1716 "Function unexpectedly in old debug info format");
1717 return wrap(cast<DbgRecord *>(DbgInst));
1718}
1719
1721 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1723 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1724 unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1725 unwrap<DILocation>(DebugLoc), unwrap<Instruction>(Instr));
1726 // This assert will fail if the module is in the old debug info format.
1727 // This function should only be called if the module is in the new
1728 // debug info format.
1729 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1730 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1731 assert(isa<DbgRecord *>(DbgInst) &&
1732 "Function unexpectedly in old debug info format");
1733 return wrap(cast<DbgRecord *>(DbgInst));
1734}
1735
1737 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1739 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1740 unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1741 unwrap<DILocation>(DebugLoc), unwrap(Block));
1742 // This assert will fail if the module is in the old debug info format.
1743 // This function should only be called if the module is in the new
1744 // debug info format.
1745 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1746 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1747 assert(isa<DbgRecord *>(DbgInst) &&
1748 "Function unexpectedly in old debug info format");
1749 return wrap(cast<DbgRecord *>(DbgInst));
1750}
1751
1753 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1754 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1755 LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) {
1756 return wrap(unwrap(Builder)->createAutoVariable(
1757 unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File),
1758 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1759 map_from_llvmDIFlags(Flags), AlignInBits));
1760}
1761
1763 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1764 size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo,
1765 LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) {
1766 return wrap(unwrap(Builder)->createParameterVariable(
1767 unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File),
1768 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1769 map_from_llvmDIFlags(Flags)));
1770}
1771
1773 int64_t Lo, int64_t Count) {
1774 return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
1775}
1776
1779 size_t Length) {
1780 Metadata **DataValue = unwrap(Data);
1781 return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get());
1782}
1783
1785 return wrap(unwrap<Function>(Func)->getSubprogram());
1786}
1787
1789 unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
1790}
1791
1793 return unwrapDI<DISubprogram>(Subprogram)->getLine();
1794}
1795
1797 return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
1798}
1799
1801 if (Loc)
1802 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc)));
1803 else
1804 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
1805}
1806
1808 LLVMDIBuilderRef Builder,
1809 LLVMMetadataRef Context, const char *Name, size_t NameLen,
1810 LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve) {
1811 return wrap(unwrap(Builder)->createLabel(
1812 unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
1813 unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
1814}
1815
1817 LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
1818 LLVMMetadataRef Location, LLVMValueRef InsertBefore) {
1819 DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
1820 unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
1821 unwrap<Instruction>(InsertBefore));
1822 // This assert will fail if the module is in the old debug info format.
1823 // This function should only be called if the module is in the new
1824 // debug info format.
1825 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1826 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1827 assert(isa<DbgRecord *>(DbgInst) &&
1828 "Function unexpectedly in old debug info format");
1829 return wrap(cast<DbgRecord *>(DbgInst));
1830}
1831
1833 LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
1834 LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd) {
1835 DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
1836 unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
1837 unwrap(InsertAtEnd));
1838 // This assert will fail if the module is in the old debug info format.
1839 // This function should only be called if the module is in the new
1840 // debug info format.
1841 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1842 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1843 assert(isa<DbgRecord *>(DbgInst) &&
1844 "Function unexpectedly in old debug info format");
1845 return wrap(cast<DbgRecord *>(DbgInst));
1846}
1847
1849 switch(unwrap(Metadata)->getMetadataID()) {
1850#define HANDLE_METADATA_LEAF(CLASS) \
1851 case Metadata::CLASS##Kind: \
1852 return (LLVMMetadataKind)LLVM##CLASS##MetadataKind;
1853#include "llvm/IR/Metadata.def"
1854 default:
1856 }
1857}
1858
1860 assert(ID && "Expected non-null ID");
1861 LLVMContext &Ctx = ID->getContext();
1862 auto &Map = Ctx.pImpl->AssignmentIDToInstrs;
1863
1864 auto MapIt = Map.find(ID);
1865 if (MapIt == Map.end())
1866 return make_range(nullptr, nullptr);
1867
1868 return make_range(MapIt->second.begin(), MapIt->second.end());
1869}
1870
1872 assert(ID && "Expected non-null ID");
1873 LLVMContext &Ctx = ID->getContext();
1874
1875 auto *IDAsValue = MetadataAsValue::getIfExists(Ctx, ID);
1876
1877 // The ID is only used wrapped in MetadataAsValue(ID), so lets check that
1878 // one of those already exists first.
1879 if (!IDAsValue)
1881
1882 return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
1883}
1884
1886 auto Range = getAssignmentMarkers(Inst);
1888 if (Range.empty() && DVRAssigns.empty())
1889 return;
1890 SmallVector<DbgAssignIntrinsic *> ToDelete(Range.begin(), Range.end());
1891 for (auto *DAI : ToDelete)
1892 DAI->eraseFromParent();
1893 for (auto *DVR : DVRAssigns)
1894 DVR->eraseFromParent();
1895}
1896
1898 // Replace attachments.
1899 AssignmentInstRange InstRange = getAssignmentInsts(Old);
1900 // Use intermediate storage for the instruction ptrs because the
1901 // getAssignmentInsts range iterators will be invalidated by adding and
1902 // removing DIAssignID attachments.
1903 SmallVector<Instruction *> InstVec(InstRange.begin(), InstRange.end());
1904 for (auto *I : InstVec)
1905 I->setMetadata(LLVMContext::MD_DIAssignID, New);
1906
1907 Old->replaceAllUsesWith(New);
1908}
1909
1913 for (BasicBlock &BB : *F) {
1914 for (Instruction &I : BB) {
1915 for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
1916 if (DVR.isDbgAssign())
1917 DPToDelete.push_back(&DVR);
1918 if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
1919 ToDelete.push_back(DAI);
1920 else
1921 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
1922 }
1923 }
1924 for (auto *DAI : ToDelete)
1925 DAI->eraseFromParent();
1926 for (auto *DVR : DPToDelete)
1927 DVR->eraseFromParent();
1928}
1929
1930/// FIXME: Remove this wrapper function and call
1931/// DIExpression::calculateFragmentIntersect directly.
1932template <typename T>
1934 const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
1935 uint64_t SliceSizeInBits, const T *AssignRecord,
1936 std::optional<DIExpression::FragmentInfo> &Result) {
1937 // No overlap if this DbgRecord describes a killed location.
1938 if (AssignRecord->isKillAddress())
1939 return false;
1940
1941 int64_t AddrOffsetInBits;
1942 {
1943 int64_t AddrOffsetInBytes;
1944 SmallVector<uint64_t> PostOffsetOps; //< Unused.
1945 // Bail if we can't find a constant offset (or none) in the expression.
1946 if (!AssignRecord->getAddressExpression()->extractLeadingOffset(
1947 AddrOffsetInBytes, PostOffsetOps))
1948 return false;
1949 AddrOffsetInBits = AddrOffsetInBytes * 8;
1950 }
1951
1952 Value *Addr = AssignRecord->getAddress();
1953 // FIXME: It may not always be zero.
1954 int64_t BitExtractOffsetInBits = 0;
1956 AssignRecord->getFragmentOrEntireVariable();
1957
1958 int64_t OffsetFromLocationInBits; //< Unused.
1960 DL, Dest, SliceOffsetInBits, SliceSizeInBits, Addr, AddrOffsetInBits,
1961 BitExtractOffsetInBits, VarFrag, Result, OffsetFromLocationInBits);
1962}
1963
1964/// FIXME: Remove this wrapper function and call
1965/// DIExpression::calculateFragmentIntersect directly.
1967 const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
1968 uint64_t SliceSizeInBits, const DbgAssignIntrinsic *DbgAssign,
1969 std::optional<DIExpression::FragmentInfo> &Result) {
1970 return calculateFragmentIntersectImpl(DL, Dest, SliceOffsetInBits,
1971 SliceSizeInBits, DbgAssign, Result);
1972}
1973
1974/// FIXME: Remove this wrapper function and call
1975/// DIExpression::calculateFragmentIntersect directly.
1977 const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
1978 uint64_t SliceSizeInBits, const DbgVariableRecord *DVRAssign,
1979 std::optional<DIExpression::FragmentInfo> &Result) {
1980 return calculateFragmentIntersectImpl(DL, Dest, SliceOffsetInBits,
1981 SliceSizeInBits, DVRAssign, Result);
1982}
1983
1984/// Update inlined instructions' DIAssignID metadata. We need to do this
1985/// otherwise a function inlined more than once into the same function
1986/// will cause DIAssignID to be shared by many instructions.
1988 Instruction &I) {
1989 auto GetNewID = [&Map](Metadata *Old) {
1990 DIAssignID *OldID = cast<DIAssignID>(Old);
1991 if (DIAssignID *NewID = Map.lookup(OldID))
1992 return NewID;
1994 Map[OldID] = NewID;
1995 return NewID;
1996 };
1997 // If we find a DIAssignID attachment or use, replace it with a new version.
1998 for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
1999 if (DVR.isDbgAssign())
2000 DVR.setAssignId(GetNewID(DVR.getAssignID()));
2001 }
2002 if (auto *ID = I.getMetadata(LLVMContext::MD_DIAssignID))
2003 I.setMetadata(LLVMContext::MD_DIAssignID, GetNewID(ID));
2004 else if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
2005 DAI->setAssignId(GetNewID(DAI->getAssignID()));
2006}
2007
2008/// Collect constant properies (base, size, offset) of \p StoreDest.
2009/// Return std::nullopt if any properties are not constants or the
2010/// offset from the base pointer is negative.
2011static std::optional<AssignmentInfo>
2012getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest,
2013 TypeSize SizeInBits) {
2014 if (SizeInBits.isScalable())
2015 return std::nullopt;
2016 APInt GEPOffset(DL.getIndexTypeSizeInBits(StoreDest->getType()), 0);
2017 const Value *Base = StoreDest->stripAndAccumulateConstantOffsets(
2018 DL, GEPOffset, /*AllowNonInbounds*/ true);
2019
2020 if (GEPOffset.isNegative())
2021 return std::nullopt;
2022
2023 uint64_t OffsetInBytes = GEPOffset.getLimitedValue();
2024 // Check for overflow.
2025 if (OffsetInBytes == UINT64_MAX)
2026 return std::nullopt;
2027 if (const auto *Alloca = dyn_cast<AllocaInst>(Base))
2028 return AssignmentInfo(DL, Alloca, OffsetInBytes * 8, SizeInBits);
2029 return std::nullopt;
2030}
2031
2032std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2033 const MemIntrinsic *I) {
2034 const Value *StoreDest = I->getRawDest();
2035 // Assume 8 bit bytes.
2036 auto *ConstLengthInBytes = dyn_cast<ConstantInt>(I->getLength());
2037 if (!ConstLengthInBytes)
2038 // We can't use a non-const size, bail.
2039 return std::nullopt;
2040 uint64_t SizeInBits = 8 * ConstLengthInBytes->getZExtValue();
2041 return getAssignmentInfoImpl(DL, StoreDest, TypeSize::getFixed(SizeInBits));
2042}
2043
2044std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2045 const StoreInst *SI) {
2046 TypeSize SizeInBits = DL.getTypeSizeInBits(SI->getValueOperand()->getType());
2047 return getAssignmentInfoImpl(DL, SI->getPointerOperand(), SizeInBits);
2048}
2049
2050std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2051 const AllocaInst *AI) {
2052 TypeSize SizeInBits = DL.getTypeSizeInBits(AI->getAllocatedType());
2053 return getAssignmentInfoImpl(DL, AI, SizeInBits);
2054}
2055
2056/// Returns nullptr if the assignment shouldn't be attributed to this variable.
2057static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
2058 Instruction &StoreLikeInst, const VarRecord &VarRec,
2059 DIBuilder &DIB) {
2060 auto *ID = StoreLikeInst.getMetadata(LLVMContext::MD_DIAssignID);
2061 assert(ID && "Store instruction must have DIAssignID metadata");
2062 (void)ID;
2063
2064 const uint64_t StoreStartBit = Info.OffsetInBits;
2065 const uint64_t StoreEndBit = Info.OffsetInBits + Info.SizeInBits;
2066
2067 uint64_t FragStartBit = StoreStartBit;
2068 uint64_t FragEndBit = StoreEndBit;
2069
2070 bool StoreToWholeVariable = Info.StoreToWholeAlloca;
2071 if (auto Size = VarRec.Var->getSizeInBits()) {
2072 // NOTE: trackAssignments doesn't understand base expressions yet, so all
2073 // variables that reach here are guaranteed to start at offset 0 in the
2074 // alloca.
2075 const uint64_t VarStartBit = 0;
2076 const uint64_t VarEndBit = *Size;
2077
2078 // FIXME: trim FragStartBit when nonzero VarStartBit is supported.
2079 FragEndBit = std::min(FragEndBit, VarEndBit);
2080
2081 // Discard stores to bits outside this variable.
2082 if (FragStartBit >= FragEndBit)
2083 return;
2084
2085 StoreToWholeVariable = FragStartBit <= VarStartBit && FragEndBit >= *Size;
2086 }
2087
2088 DIExpression *Expr = DIExpression::get(StoreLikeInst.getContext(), {});
2089 if (!StoreToWholeVariable) {
2090 auto R = DIExpression::createFragmentExpression(Expr, FragStartBit,
2091 FragEndBit - FragStartBit);
2092 assert(R.has_value() && "failed to create fragment expression");
2093 Expr = *R;
2094 }
2095 DIExpression *AddrExpr = DIExpression::get(StoreLikeInst.getContext(), {});
2096 if (StoreLikeInst.getParent()->IsNewDbgInfoFormat) {
2098 &StoreLikeInst, Val, VarRec.Var, Expr, Dest, AddrExpr, VarRec.DL);
2099 (void)Assign;
2100 LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
2101 return;
2102 }
2103 auto Assign = DIB.insertDbgAssign(&StoreLikeInst, Val, VarRec.Var, Expr, Dest,
2104 AddrExpr, VarRec.DL);
2105 (void)Assign;
2106 LLVM_DEBUG(if (!Assign.isNull()) {
2107 if (const auto *Record = dyn_cast<DbgRecord *>(Assign))
2108 errs() << " > INSERT: " << *Record << "\n";
2109 else
2110 errs() << " > INSERT: " << *cast<Instruction *>(Assign) << "\n";
2111 });
2112}
2113
2114#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).
2115#define DEBUG_TYPE "assignment-tracking"
2116
2118 const StorageToVarsMap &Vars, const DataLayout &DL,
2119 bool DebugPrints) {
2120 // Early-exit if there are no interesting variables.
2121 if (Vars.empty())
2122 return;
2123
2124 auto &Ctx = Start->getContext();
2125 auto &Module = *Start->getModule();
2126
2127 // Undef type doesn't matter, so long as it isn't void. Let's just use i1.
2128 auto *Undef = UndefValue::get(Type::getInt1Ty(Ctx));
2129 DIBuilder DIB(Module, /*AllowUnresolved*/ false);
2130
2131 // Scan the instructions looking for stores to local variables' storage.
2132 LLVM_DEBUG(errs() << "# Scanning instructions\n");
2133 for (auto BBI = Start; BBI != End; ++BBI) {
2134 for (Instruction &I : *BBI) {
2135
2136 std::optional<AssignmentInfo> Info;
2137 Value *ValueComponent = nullptr;
2138 Value *DestComponent = nullptr;
2139 if (auto *AI = dyn_cast<AllocaInst>(&I)) {
2140 // We want to track the variable's stack home from its alloca's
2141 // position onwards so we treat it as an assignment (where the stored
2142 // value is Undef).
2143 Info = getAssignmentInfo(DL, AI);
2144 ValueComponent = Undef;
2145 DestComponent = AI;
2146 } else if (auto *SI = dyn_cast<StoreInst>(&I)) {
2147 Info = getAssignmentInfo(DL, SI);
2148 ValueComponent = SI->getValueOperand();
2149 DestComponent = SI->getPointerOperand();
2150 } else if (auto *MI = dyn_cast<MemTransferInst>(&I)) {
2152 // May not be able to represent this value easily.
2153 ValueComponent = Undef;
2154 DestComponent = MI->getOperand(0);
2155 } else if (auto *MI = dyn_cast<MemSetInst>(&I)) {
2157 // If we're zero-initing we can state the assigned value is zero,
2158 // otherwise use undef.
2159 auto *ConstValue = dyn_cast<ConstantInt>(MI->getOperand(1));
2160 if (ConstValue && ConstValue->isZero())
2161 ValueComponent = ConstValue;
2162 else
2163 ValueComponent = Undef;
2164 DestComponent = MI->getOperand(0);
2165 } else {
2166 // Not a store-like instruction.
2167 continue;
2168 }
2169
2170 assert(ValueComponent && DestComponent);
2171 LLVM_DEBUG(errs() << "SCAN: Found store-like: " << I << "\n");
2172
2173 // Check if getAssignmentInfo failed to understand this store.
2174 if (!Info.has_value()) {
2175 LLVM_DEBUG(
2176 errs()
2177 << " | SKIP: Untrackable store (e.g. through non-const gep)\n");
2178 continue;
2179 }
2180 LLVM_DEBUG(errs() << " | BASE: " << *Info->Base << "\n");
2181
2182 // Check if the store destination is a local variable with debug info.
2183 auto LocalIt = Vars.find(Info->Base);
2184 if (LocalIt == Vars.end()) {
2185 LLVM_DEBUG(
2186 errs()
2187 << " | SKIP: Base address not associated with local variable\n");
2188 continue;
2189 }
2190
2191 DIAssignID *ID =
2192 cast_or_null<DIAssignID>(I.getMetadata(LLVMContext::MD_DIAssignID));
2193 if (!ID) {
2195 I.setMetadata(LLVMContext::MD_DIAssignID, ID);
2196 }
2197
2198 for (const VarRecord &R : LocalIt->second)
2199 emitDbgAssign(*Info, ValueComponent, DestComponent, I, R, DIB);
2200 }
2201 }
2202}
2203
2204bool AssignmentTrackingPass::runOnFunction(Function &F) {
2205 // No value in assignment tracking without optimisations.
2206 if (F.hasFnAttribute(Attribute::OptimizeNone))
2207 return /*Changed*/ false;
2208
2209 bool Changed = false;
2210 auto *DL = &F.getDataLayout();
2211 // Collect a map of {backing storage : dbg.declares} (currently "backing
2212 // storage" is limited to Allocas). We'll use this to find dbg.declares to
2213 // delete after running `trackAssignments`.
2216 // Create another similar map of {storage : variables} that we'll pass to
2217 // trackAssignments.
2218 StorageToVarsMap Vars;
2219 auto ProcessDeclare = [&](auto *Declare, auto &DeclareList) {
2220 // FIXME: trackAssignments doesn't let you specify any modifiers to the
2221 // variable (e.g. fragment) or location (e.g. offset), so we have to
2222 // leave dbg.declares with non-empty expressions in place.
2223 if (Declare->getExpression()->getNumElements() != 0)
2224 return;
2225 if (!Declare->getAddress())
2226 return;
2227 if (AllocaInst *Alloca =
2228 dyn_cast<AllocaInst>(Declare->getAddress()->stripPointerCasts())) {
2229 // FIXME: Skip VLAs for now (let these variables use dbg.declares).
2230 if (!Alloca->isStaticAlloca())
2231 return;
2232 // Similarly, skip scalable vectors (use dbg.declares instead).
2233 if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
2234 return;
2235 DeclareList[Alloca].insert(Declare);
2236 Vars[Alloca].insert(VarRecord(Declare));
2237 }
2238 };
2239 for (auto &BB : F) {
2240 for (auto &I : BB) {
2241 for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
2242 if (DVR.isDbgDeclare())
2243 ProcessDeclare(&DVR, DVRDeclares);
2244 }
2245 if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(&I))
2246 ProcessDeclare(DDI, DbgDeclares);
2247 }
2248 }
2249
2250 // FIXME: Locals can be backed by caller allocas (sret, byval).
2251 // Note: trackAssignments doesn't respect dbg.declare's IR positions (as it
2252 // doesn't "understand" dbg.declares). However, this doesn't appear to break
2253 // any rules given this description of dbg.declare from
2254 // llvm/docs/SourceLevelDebugging.rst:
2255 //
2256 // It is not control-dependent, meaning that if a call to llvm.dbg.declare
2257 // exists and has a valid location argument, that address is considered to
2258 // be the true home of the variable across its entire lifetime.
2259 trackAssignments(F.begin(), F.end(), Vars, *DL);
2260
2261 // Delete dbg.declares for variables now tracked with assignment tracking.
2262 auto DeleteSubsumedDeclare = [&](const auto &Markers, auto &Declares) {
2263 (void)Markers;
2264 for (auto *Declare : Declares) {
2265 // Assert that the alloca that Declare uses is now linked to a dbg.assign
2266 // describing the same variable (i.e. check that this dbg.declare has
2267 // been replaced by a dbg.assign). Use DebugVariableAggregate to Discard
2268 // the fragment part because trackAssignments may alter the
2269 // fragment. e.g. if the alloca is smaller than the variable, then
2270 // trackAssignments will create an alloca-sized fragment for the
2271 // dbg.assign.
2272 assert(llvm::any_of(Markers, [Declare](auto *Assign) {
2273 return DebugVariableAggregate(Assign) ==
2274 DebugVariableAggregate(Declare);
2275 }));
2276 // Delete Declare because the variable location is now tracked using
2277 // assignment tracking.
2278 Declare->eraseFromParent();
2279 Changed = true;
2280 }
2281 };
2282 for (auto &P : DbgDeclares)
2283 DeleteSubsumedDeclare(at::getAssignmentMarkers(P.first), P.second);
2284 for (auto &P : DVRDeclares)
2285 DeleteSubsumedDeclare(at::getDVRAssignmentMarkers(P.first), P.second);
2286 return Changed;
2287}
2288
2290 "debug-info-assignment-tracking";
2291
2295 ConstantInt::get(Type::getInt1Ty(M.getContext()), 1)));
2296}
2297
2299 Metadata *Value = M.getModuleFlag(AssignmentTrackingModuleFlag);
2300 return Value && !cast<ConstantAsMetadata>(Value)->getValue()->isZeroValue();
2301}
2302
2305}
2306
2309 if (!runOnFunction(F))
2310 return PreservedAnalyses::all();
2311
2312 // Record that this module uses assignment tracking. It doesn't matter that
2313 // some functons in the module may not use it - the debug info in those
2314 // functions will still be handled properly.
2315 setAssignmentTrackingModuleFlag(*F.getParent());
2316
2317 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2318 // return PreservedAnalyses::all()?
2321 return PA;
2322}
2323
2326 bool Changed = false;
2327 for (auto &F : M)
2328 Changed |= runOnFunction(F);
2329
2330 if (!Changed)
2331 return PreservedAnalyses::all();
2332
2333 // Record that this module uses assignment tracking.
2335
2336 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2337 // return PreservedAnalyses::all()?
2340 return PA;
2341}
2342
2343#undef DEBUG_TYPE
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
Definition: DIBuilder.cpp:857
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, DINodeArray Elements, SmallVectorImpl< TrackingMDNodeRef > &ImportedModules)
Definition: DIBuilder.cpp:161
static void setAssignmentTrackingModuleFlag(Module &M)
Definition: DebugInfo.cpp:2292
static DISubprogram::DISPFlags pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized)
Definition: DebugInfo.cpp:1053
static Metadata * stripLoopMDLoc(const SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
Definition: DebugInfo.cpp:497
static MDNode * updateLoopMetadataDebugLocationsImpl(MDNode *OrigLoopID, function_ref< Metadata *(Metadata *)> Updater)
Definition: DebugInfo.cpp:415
static MDNode * stripDebugLocFromLoopID(MDNode *N)
Definition: DebugInfo.cpp:534
bool calculateFragmentIntersectImpl(const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const T *AssignRecord, std::optional< DIExpression::FragmentInfo > &Result)
FIXME: Remove this wrapper function and call DIExpression::calculateFragmentIntersect directly.
Definition: DebugInfo.cpp:1933
static const char * AssignmentTrackingModuleFlag
Definition: DebugInfo.cpp:2289
static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags)
Definition: DebugInfo.cpp:1044
static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang)
Definition: DebugInfo.cpp:1029
static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest, Instruction &StoreLikeInst, const VarRecord &VarRec, DIBuilder &DIB)
Returns nullptr if the assignment shouldn't be attributed to this variable.
Definition: DebugInfo.cpp:2057
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags)
Definition: DebugInfo.cpp:1048
static void findDbgIntrinsics(SmallVectorImpl< IntrinsicT * > &Result, Value *V, SmallVectorImpl< DbgVariableRecord * > *DbgVariableRecords)
Definition: DebugInfo.cpp:102
static bool getAssignmentTrackingModuleFlag(const Module &M)
Definition: DebugInfo.cpp:2298
static bool isAllDILocation(SmallPtrSetImpl< Metadata * > &Visited, SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
Definition: DebugInfo.cpp:471
static bool isDILocationReachable(SmallPtrSetImpl< Metadata * > &Visited, SmallPtrSetImpl< Metadata * > &Reachable, Metadata *MD)
Return true if a node is a DILocation or if a DILocation is indirectly referenced by one of the node'...
Definition: DebugInfo.cpp:450
DIT * unwrapDI(LLVMMetadataRef Ref)
Definition: DebugInfo.cpp:1040
static std::optional< AssignmentInfo > getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest, TypeSize SizeInBits)
Collect constant properies (base, size, offset) of StoreDest.
Definition: DebugInfo.cpp:2012
#define LLVM_DEBUG(...)
Definition: Debug.h:106
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
uint64_t Addr
std::string Name
uint64_t Size
bool End
Definition: ELF_riscv.cpp:480
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
This file contains the declarations for metadata subclasses.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
#define P(N)
R600 Emit Clause Markers
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:26
Class for arbitrary precision integers.
Definition: APInt.h:78
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:329
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition: APInt.h:475
an instruction to allocate memory on the stack
Definition: Instructions.h:63
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:117
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: DebugInfo.cpp:2307
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
Represents analyses that only rely on functions' control flow.
Definition: Analysis.h:72
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:532
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
Assignment ID.
static DIAssignID * getDistinct(LLVMContext &Context)
DbgInstPtr insertDbgAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *SrcVar, DIExpression *ValExpr, Value *Addr, DIExpression *AddrExpr, const DILocation *DL)
Insert a new llvm.dbg.assign intrinsic call.
Definition: DIBuilder.cpp:979
DWARF expression.
static bool calculateFragmentIntersect(const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a...
static std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
A pair of DIGlobalVariable and DIExpression.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getScope() const
Get the local scope for this variable.
Debug location.
static DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Tagged DWARF-like metadata node.
DIFlags
Debug info flags.
Base class for scope-like contexts.
StringRef getName() const
DIFile * getFile() const
DIScope * getScope() const
Subprogram description.
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
DISPFlags
Debug info subprogram flags.
Type array for a subprogram.
Base class for types.
std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
DIType * getType() const
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
This represents the llvm.dbg.assign instruction.
This represents the llvm.dbg.declare instruction.
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
This represents the llvm.dbg.value instruction.
This is the common base class for debug info intrinsics for variables.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
static DbgVariableRecord * createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable, DIExpression *Expression, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:256
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:212
void processVariable(const Module &M, const DILocalVariable *DVI)
Process a DILocalVariable.
Definition: DebugInfo.cpp:354
void processSubprogram(DISubprogram *SP)
Process subprogram.
Definition: DebugInfo.cpp:331
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:268
void reset()
Clear all lists.
Definition: DebugInfo.cpp:203
void processDbgRecord(const Module &M, const DbgRecord &DR)
Process a DbgRecord (e.g, treat a DbgVariableRecord like a DbgVariableIntrinsic).
Definition: DebugInfo.cpp:275
A debug info location.
Definition: DebugLoc.h:33
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:20
MDNode * getScope() const
Definition: DebugLoc.cpp:34
DILocation * getInlinedAt() const
Definition: DebugLoc.cpp:39
Identifies a unique instance of a whole variable (discards/ignores fragment information).
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:156
bool empty() const
Definition: DenseMap.h:98
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:211
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
BasicBlockListType::iterator iterator
Definition: Function.h:68
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1874
void mergeDIAssignID(ArrayRef< const Instruction * > SourceInstructions)
Merge the DIAssignID metadata from this instruction and those attached to instructions in SourceInstr...
Definition: DebugInfo.cpp:957
void dropLocation()
Drop the instruction's debug location.
Definition: DebugInfo.cpp:988
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:511
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:72
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:426
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1679
void updateLocationAfterHoist()
Updates the debug location given that the instruction has been hoisted from a block to a predecessor ...
Definition: DebugInfo.cpp:986
void applyMergedLocation(DILocation *LocA, DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
Definition: DebugInfo.cpp:953
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:508
static bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
DenseMap< DIAssignID *, SmallVector< Instruction *, 1 > > AssignmentIDToInstrs
Map DIAssignID -> Instructions with that attachment.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:69
static LocalAsMetadata * getIfExists(Value *Local)
Definition: Metadata.h:562
Metadata node.
Definition: Metadata.h:1073
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:1077
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1557
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition: Metadata.h:1270
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Definition: Metadata.cpp:1049
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1434
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1549
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1440
bool isDistinct() const
Definition: Metadata.h:1256
LLVMContext & getContext() const
Definition: Metadata.h:1237
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:895
Metadata * get() const
Definition: Metadata.h:924
Tuple of metadata.
Definition: Metadata.h:1479
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1526
This is the common base class for memset/memcpy/memmove.
static MetadataAsValue * getIfExists(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:111
Root of the metadata hierarchy.
Definition: Metadata.h:62
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
@ Max
Takes the max of the two values, which are required to be integers.
Definition: Module.h:147
A tuple of MDNodes.
Definition: Metadata.h:1737
StringRef getName() const
Definition: Metadata.cpp:1442
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
void preserveSet()
Mark an analysis set as preserved.
Definition: Analysis.h:146
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:363
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:452
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:384
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
bool empty() const
Definition: SmallVector.h:81
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void reserve(size_type N)
Definition: SmallVector.h:663
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An instruction for storing to memory.
Definition: Instructions.h:292
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition: TinyPtrVector.h:29
void push_back(EltTy NewVal)
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition: TypeSize.h:345
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static IntegerType * getInt1Ty(LLVMContext &C)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1859
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr, bool LookThroughIntToPtr=false) const
Accumulate the constant offset this value has compared to a base pointer.
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1094
user_iterator_impl< User > user_iterator
Definition: Value.h:390
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:213
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:95
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
Definition: ilist_node.h:32
A range adaptor for a pair of iterators.
IteratorT end() const
IteratorT begin() const
LLVMMetadataRef LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode)
Create debugging information entry for Objective-C instance variable.
Definition: DebugInfo.cpp:1412
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location)
Get the "inline at" location associated with this debug location.
Definition: DebugInfo.cpp:1243
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create an array of DI Nodes.
Definition: DebugInfo.cpp:1777
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef ClassTy)
Create debugging information entry for an enumeration.
Definition: DebugInfo.cpp:1300
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef M, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported module.
Definition: DebugInfo.cpp:1197
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType)
Get the size of this DIType in bits.
Definition: DebugInfo.cpp:1575
LLVMDWARFMacinfoRecordType
Describes the kind of macro declaration used for LLVMDIBuilderCreateMacro.
Definition: DebugInfo.h:211
LLVMMetadataRef LLVMDIBuilderCreateFunction(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *LinkageName, size_t LinkageNameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool IsLocalToUnit, LLVMBool IsDefinition, unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized)
Create a new descriptor for the specified subprogram.
Definition: DebugInfo.cpp:1139
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Only use in "new debug format" (LLVMIsNewDbgInfoFormat() is true).
Definition: DebugInfo.cpp:1704
LLVMMetadataRef LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Type)
Create debugging information entry for a bit field member.
Definition: DebugInfo.cpp:1525
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetVariable(LLVMMetadataRef GVE)
Retrieves the DIVariable associated with this global variable expression.
Definition: DebugInfo.cpp:1638
LLVMMetadataRef LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagArtificial set.
Definition: DebugInfo.cpp:1560
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, LLVMBool Implicit)
Create a uniqued DIType* clone with FlagObjectPointer.
Definition: DebugInfo.cpp:1439
void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder)
Construct any deferred debug info descriptors.
Definition: DebugInfo.cpp:1081
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Discriminator)
Create a descriptor for a lexical block with a new file attached.
Definition: DebugInfo.cpp:1163
unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram)
Get the line associated with a given subprogram.
Definition: DebugInfo.cpp:1792
LLVMMetadataRef LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen)
Create a DWARF unspecified type.
Definition: DebugInfo.cpp:1395
LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, LLVMBool ExportSymbols)
Creates a new descriptor for a namespace with the specified parent scope.
Definition: DebugInfo.cpp:1131
LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt)
Creates a new DebugLocation that describes a source location.
Definition: DebugInfo.cpp:1224
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType)
Get the alignment of this DIType in bits.
Definition: DebugInfo.cpp:1583
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetExpression(LLVMMetadataRef GVE)
Retrieves the DIExpression associated with this global variable expression.
Definition: DebugInfo.cpp:1642
LLVMMetadataRef LLVMDIVariableGetScope(LLVMMetadataRef Var)
Get the metadata of the scope associated with a given variable.
Definition: DebugInfo.cpp:1651
LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst)
Get the debug location for the given instruction.
Definition: DebugInfo.cpp:1796
LLVMMetadataRef LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a c++ style reference or rvalue reference type.
Definition: DebugInfo.cpp:1500
LLVMMetadataRef LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, const char *ConfigMacros, size_t ConfigMacrosLen, const char *IncludePath, size_t IncludePathLen, const char *APINotesFile, size_t APINotesFileLen)
Creates a new descriptor for a module with the specified parent scope.
Definition: DebugInfo.cpp:1119
LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M)
Construct a builder for a module, and do not allow for unresolved nodes attached to the module.
Definition: DebugInfo.cpp:1061
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP)
Set the subprogram attached to a function.
Definition: DebugInfo.cpp:1788
LLVMDWARFSourceLanguage
Source languages known by DWARF.
Definition: DebugInfo.h:78
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, int64_t LowerBound, int64_t Count)
Create a descriptor for a value range.
Definition: DebugInfo.cpp:1772
LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M)
Construct a builder for a module and collect unresolved nodes attached to the module in order to reso...
Definition: DebugInfo.cpp:1065
void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode)
Deallocate a temporary node.
Definition: DebugInfo.cpp:1665
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location)
Get the local scope associated with this debug location.
Definition: DebugInfo.cpp:1239
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef NS, LLVMMetadataRef File, unsigned Line)
Create a descriptor for an imported namespace.
Definition: DebugInfo.cpp:1173
LLVMMetadataRef LLVMDIBuilderCreateTempMacroFile(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentMacroFile, unsigned Line, LLVMMetadataRef File)
Create debugging information temporary entry for a macro file.
Definition: DebugInfo.cpp:1285
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc)
Set the debug location for the given instruction.
Definition: DebugInfo.cpp:1800
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, int64_t Value, LLVMBool IsUnsigned)
Create debugging information entry for an enumerator.
Definition: DebugInfo.cpp:1292
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, uint64_t *Addr, size_t Length)
Create a new descriptor for the specified variable which has a complex address expression for its add...
Definition: DebugInfo.cpp:1614
LLVMMetadataRef LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts)
Create debugging information entry for a vector type.
Definition: DebugInfo.cpp:1339
LLVMMetadataRef LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeType, LLVMMetadataRef ClassType, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags)
Create debugging information entry for a pointer to member.
Definition: DebugInfo.cpp:1512
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location)
Get the column number of this debug location.
Definition: DebugInfo.cpp:1235
LLVMDIFlags
Debug info flags.
Definition: DebugInfo.h:34
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits)
Create a new descriptor for a local auto variable.
Definition: DebugInfo.cpp:1752
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, size_t NumElements)
Create a new temporary MDNode.
Definition: DebugInfo.cpp:1659
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType)
Get the flags associated with this DIType.
Definition: DebugInfo.cpp:1591
const char * LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len)
Get the directory of a given file.
Definition: DebugInfo.cpp:1251
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TempTargetMetadata, LLVMMetadataRef Replacement)
Replace all uses of temporary metadata.
Definition: DebugInfo.cpp:1669
const char * LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len)
Get the name of a given file.
Definition: DebugInfo.cpp:1257
LLVMMetadataRef LLVMDIBuilderCreateLabel(LLVMDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve)
Create a new descriptor for a label.
Definition: DebugInfo.cpp:1807
unsigned LLVMDebugMetadataVersion(void)
The current debug metadata version number.
Definition: DebugInfo.cpp:1057
unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef Module)
The version of debug metadata that's present in the provided Module.
Definition: DebugInfo.cpp:1069
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType)
Get the source line where this DIType is declared.
Definition: DebugInfo.cpp:1587
LLVMMetadataRef LLVMDIVariableGetFile(LLVMMetadataRef Var)
Get the metadata of the file associated with a given variable.
Definition: DebugInfo.cpp:1647
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported module that aliases another imported entity descriptor.
Definition: DebugInfo.cpp:1184
LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal, uint32_t AlignInBits)
Create debugging information entry for a C++ static data member.
Definition: DebugInfo.cpp:1400
uint16_t LLVMGetDINodeTag(LLVMMetadataRef MD)
Get the dwarf::Tag of a DINode.
Definition: DebugInfo.cpp:1565
LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits)
Create a new descriptor for the specified variable.
Definition: DebugInfo.cpp:1626
LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Decl, uint32_t AlignInBits)
Create a new descriptor for the specified global variable that is temporary and meant to be RAUWed.
Definition: DebugInfo.cpp:1676
LLVMMetadataRef LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a qualified type, e.g.
Definition: DebugInfo.cpp:1493
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata)
Obtain the enumerated type of a Metadata instance.
Definition: DebugInfo.cpp:1848
LLVMMetadataRef LLVMDIBuilderCreateUnionType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, const char *UniqueId, size_t UniqueIdLen)
Create debugging information entry for a union.
Definition: DebugInfo.cpp:1312
LLVMMetadataRef LLVMDIBuilderCreateForwardDecl(LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create a permanent forward-declared type.
Definition: DebugInfo.cpp:1467
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags)
Create a new descriptor for a function parameter variable.
Definition: DebugInfo.cpp:1762
LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, LLVMMetadataRef File, LLVMMetadataRef *ParameterTypes, unsigned NumParameterTypes, LLVMDIFlags Flags)
Create subroutine type.
Definition: DebugInfo.cpp:1603
LLVMMetadataRef LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, const char *GetterName, size_t GetterNameLen, const char *SetterName, size_t SetterNameLen, unsigned PropertyAttributes, LLVMMetadataRef Ty)
Create debugging information entry for Objective-C property.
Definition: DebugInfo.cpp:1426
LLVMMetadataRef LLVMDIBuilderCreateMacro(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentMacroFile, unsigned Line, LLVMDWARFMacinfoRecordType RecordType, const char *Name, size_t NameLen, const char *Value, size_t ValueLen)
Create debugging information entry for a macro.
Definition: DebugInfo.cpp:1272
LLVMDWARFEmissionKind
The amount of debug information to emit.
Definition: DebugInfo.h:152
LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo, LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd)
Insert a new llvm.dbg.label intrinsic call.
Definition: DebugInfo.cpp:1832
LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts)
Create debugging information entry for an array.
Definition: DebugInfo.cpp:1328
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Only use in "new debug format" (LLVMIsNewDbgInfoFormat() is true).
Definition: DebugInfo.cpp:1736
LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope)
Get the metadata of the file associated with a given scope.
Definition: DebugInfo.cpp:1247
void LLVMDIBuilderFinalizeSubprogram(LLVMDIBuilderRef Builder, LLVMMetadataRef Subprogram)
Finalize a specific subprogram.
Definition: DebugInfo.cpp:1085
LLVMMetadataRef LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, uint64_t Value)
Create a new descriptor for the specified variable that does not have an address, but does have a con...
Definition: DebugInfo.cpp:1621
LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create debugging information entry for a class.
Definition: DebugInfo.cpp:1540
LLVMMetadataRef LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty)
Create debugging information entry for a member.
Definition: DebugInfo.cpp:1384
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location)
Get the line number of this debug location.
Definition: DebugInfo.cpp:1231
LLVMMetadataRef LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder)
Create C++11 nullptr type.
Definition: DebugInfo.cpp:1507
LLVMMetadataRef LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder, LLVMMetadataRef Ty, LLVMMetadataRef BaseTy, uint64_t BaseOffset, uint32_t VBPtrOffset, LLVMDIFlags Flags)
Create debugging information entry to establish inheritance relationship between two types.
Definition: DebugInfo.cpp:1457
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, LLVMBool isOptimized, const char *Flags, size_t FlagsLen, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen, const char *SDK, size_t SDKLen)
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
Definition: DebugInfo.cpp:1090
LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef Module)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:1073
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Only use in "new debug format" (LLVMIsNewDbgInfoFormat() is true).
Definition: DebugInfo.cpp:1687
LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo, LLVMMetadataRef Location, LLVMValueRef InsertBefore)
Insert a new llvm.dbg.label intrinsic call.
Definition: DebugInfo.cpp:1816
LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, uint64_t SizeInBits, LLVMDWARFTypeEncoding Encoding, LLVMDIFlags Flags)
Create debugging information entry for a basic type.
Definition: DebugInfo.cpp:1350
unsigned LLVMDIVariableGetLine(LLVMMetadataRef Var)
Get the source line where this DIVariable is declared.
Definition: DebugInfo.cpp:1655
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Only use in "new debug format" (LLVMIsNewDbgInfoFormat() is true).
Definition: DebugInfo.cpp:1720
unsigned LLVMDWARFTypeEncoding
An LLVM DWARF type encoding.
Definition: DebugInfo.h:204
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned Column)
Create a descriptor for a lexical block with the specified parent context.
Definition: DebugInfo.cpp:1154
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create a type array.
Definition: DebugInfo.cpp:1595
LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create a temporary forward-declared type.
Definition: DebugInfo.cpp:1479
const char * LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len)
Get the source of a given file.
Definition: DebugInfo.cpp:1263
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType)
Get the offset of this DIType in bits.
Definition: DebugInfo.cpp:1579
LLVMMetadataRef LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef Decl, LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported function, type, or variable.
Definition: DebugInfo.cpp:1210
LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen, const char *Directory, size_t DirectoryLen)
Create a file descriptor to hold debugging information for a file.
Definition: DebugInfo.cpp:1111
const char * LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length)
Get the name of this DIType.
Definition: DebugInfo.cpp:1569
unsigned LLVMMetadataKind
Definition: DebugInfo.h:199
LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope, uint32_t AlignInBits)
Create debugging information entry for a typedef.
Definition: DebugInfo.cpp:1447
LLVMMetadataRef LLVMDIBuilderCreateStructType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder, const char *UniqueId, size_t UniqueIdLen)
Create debugging information entry for a struct.
Definition: DebugInfo.cpp:1368
void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder)
Deallocates the DIBuilder and everything it owns.
Definition: DebugInfo.cpp:1077
LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, const char *Name, size_t NameLen)
Create debugging information entry for a pointer.
Definition: DebugInfo.cpp:1359
LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func)
Get the metadata of the subprogram attached to a function.
Definition: DebugInfo.cpp:1784
@ LLVMGenericDINodeMetadataKind
Definition: DebugInfo.h:170
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
struct LLVMOpaqueDbgRecord * LLVMDbgRecordRef
Definition: Types.h:175
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:53
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
Definition: Types.h:82
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
Definition: Types.h:89
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
struct LLVMOpaqueDIBuilder * LLVMDIBuilderRef
Represents an LLVM debug info builder.
Definition: Types.h:117
#define UINT64_MAX
Definition: DataTypes.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Assignment Tracking (at).
Definition: DebugInfo.h:181
void deleteAll(Function *F)
Remove all Assignment Tracking related intrinsics and metadata from F.
Definition: DebugInfo.cpp:1910
AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
Definition: DebugInfo.cpp:1859
AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)
Return a range of dbg.assign intrinsics which use \ID as an operand.
Definition: DebugInfo.cpp:1871
void trackAssignments(Function::iterator Start, Function::iterator End, const StorageToVarsMap &Vars, const DataLayout &DL, bool DebugPrints=false)
Track assignments to Vars between Start and End.
Definition: DebugInfo.cpp:2117
void remapAssignID(DenseMap< DIAssignID *, DIAssignID * > &Map, Instruction &I)
Replace DIAssignID uses and attachments with IDs from Map.
Definition: DebugInfo.cpp:1987
SmallVector< DbgVariableRecord * > getDVRAssignmentMarkers(const Instruction *Inst)
Definition: DebugInfo.h:240
void deleteAssignmentMarkers(const Instruction *Inst)
Delete the llvm.dbg.assign intrinsics linked to Inst.
Definition: DebugInfo.cpp:1885
std::optional< AssignmentInfo > getAssignmentInfo(const DataLayout &DL, const MemIntrinsic *I)
Definition: DebugInfo.cpp:2032
bool calculateFragmentIntersect(const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const DbgAssignIntrinsic *DbgAssign, std::optional< DIExpression::FragmentInfo > &Result)
Calculate the fragment of the variable in DAI covered from (Dest + SliceOffsetInBits) to to (Dest + S...
Definition: DebugInfo.cpp:1966
void RAUW(DIAssignID *Old, DIAssignID *New)
Replace all uses (and attachments) of Old with New.
Definition: DebugInfo.cpp:1897
Calculates the starting offsets for various sections within the .debug_names section.
Definition: Dwarf.h:34
MacinfoRecordType
Definition: Dwarf.h:801
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition: STLExtras.h:329
@ Length
Definition: DWP.cpp:480
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1739
TinyPtrVector< DbgDeclareInst * > findDbgDeclares(Value *V)
Finds dbg.declare intrinsics declaring local variables as living in the memory that 'V' points to.
Definition: DebugInfo.cpp:47
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:569
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V, SmallVectorImpl< DbgVariableRecord * > *DbgVariableRecords=nullptr)
Finds the debug info intrinsics describing a value.
Definition: DebugInfo.cpp:162
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
@ Import
Import information from summary.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:657
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V, SmallVectorImpl< DbgVariableRecord * > *DbgVariableRecords=nullptr)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: DebugInfo.cpp:155
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1746
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
bool stripNonLineTableDebugInfo(Module &M)
Downgrade the debug info in a module to contain only line table information.
Definition: DebugInfo.cpp:847
DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII)
Produce a DebugLoc to use for each dbg.declare that is promoted to a dbg.value.
Definition: DebugInfo.cpp:175
TinyPtrVector< DbgVariableRecord * > findDVRValues(Value *V)
As above, for DVRValues.
Definition: DebugInfo.cpp:83
unsigned getDebugMetadataVersionFromModule(const Module &M)
Return Debug Info Metadata Version by checking module flags.
Definition: DebugInfo.cpp:946
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:608
@ Ref
The access may reference the value stored in memory.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:336
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
Definition: DebugInfo.cpp:2303
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition: STLExtras.h:1945
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:331
TinyPtrVector< DbgVariableRecord * > findDVRDeclares(Value *V)
As above, for DVRDeclares.
Definition: DebugInfo.cpp:66
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
void updateLoopMetadataDebugLocations(Instruction &I, function_ref< Metadata *(Metadata *)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
Definition: DebugInfo.cpp:439
@ DEBUG_METADATA_VERSION
Definition: Metadata.h:52
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:169
#define N
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
Describes properties of a store that has a static size and offset into a some base storage.
Definition: DebugInfo.h:338
Helper struct for trackAssignments, below.
Definition: DebugInfo.h:283
DILocation * DL
Definition: DebugInfo.h:285
DILocalVariable * Var
Definition: DebugInfo.h:284