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