LLVM 22.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())
76 if (DVR->isValueOfVariable())
77 Values.push_back(DVR);
78
79 return Values;
80}
81
82template <bool DbgAssignAndValuesOnly>
83static void
85 SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
86 // This function is hot. Check whether the value has any metadata to avoid a
87 // DenseMap lookup.
88 if (!V->isUsedByMetadata())
89 return;
90
91 // TODO: If this value appears multiple times in a DIArgList, we should still
92 // only add the owning dbg.value once; use this set to track ArgListUsers.
93 // This behaviour can be removed when we can automatically remove duplicates.
94 // V will also appear twice in a dbg.assign if its used in the both the value
95 // and address components.
96 SmallPtrSet<DbgVariableRecord *, 4> EncounteredDbgVariableRecords;
97
98 /// Append users of MetadataAsValue(MD).
99 auto AppendUsers = [&EncounteredDbgVariableRecords,
100 &DbgVariableRecords](Metadata *MD) {
101 // Get DbgVariableRecords that use this as a single value.
103 for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers()) {
104 if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
105 if (EncounteredDbgVariableRecords.insert(DVR).second)
106 DbgVariableRecords.push_back(DVR);
107 }
108 }
109 };
110
111 if (auto *L = LocalAsMetadata::getIfExists(V)) {
112 AppendUsers(L);
113 for (Metadata *AL : L->getAllArgListUsers()) {
114 AppendUsers(AL);
115 DIArgList *DI = cast<DIArgList>(AL);
117 if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
118 if (EncounteredDbgVariableRecords.insert(DVR).second)
119 DbgVariableRecords.push_back(DVR);
120 }
121 }
122}
123
125 Value *V, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
126 findDbgIntrinsics</*DbgAssignAndValuesOnly=*/true>(V, DbgVariableRecords);
127}
128
130 Value *V, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
131 findDbgIntrinsics</*DbgAssignAndValuesOnly=*/false>(V, DbgVariableRecords);
132}
133
135 if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
136 return LocalScope->getSubprogram();
137 return nullptr;
138}
139
141 // Original dbg.declare must have a location.
142 const DebugLoc &DeclareLoc = DVR->getDebugLoc();
143 MDNode *Scope = DeclareLoc.getScope();
144 DILocation *InlinedAt = DeclareLoc.getInlinedAt();
145 // Because no machine insts can come from debug intrinsics, only the scope
146 // and inlinedAt is significant. Zero line numbers are used in case this
147 // DebugLoc leaks into any adjacent instructions. Produce an unknown location
148 // with the correct scope / inlinedAt fields.
149 return DILocation::get(DVR->getContext(), 0, 0, Scope, InlinedAt);
150}
151
152//===----------------------------------------------------------------------===//
153// DebugInfoFinder implementations.
154//===----------------------------------------------------------------------===//
155
157 CUs.clear();
158 SPs.clear();
159 GVs.clear();
160 TYs.clear();
161 Scopes.clear();
162 NodesSeen.clear();
163}
164
166 for (auto *CU : M.debug_compile_units())
167 processCompileUnit(CU);
168 for (auto &F : M.functions()) {
169 if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
171 // There could be subprograms from inlined functions referenced from
172 // instructions only. Walk the function to find them.
173 for (const BasicBlock &BB : F)
174 for (const Instruction &I : BB)
176 }
177}
178
179void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) {
180 if (!addCompileUnit(CU))
181 return;
182 for (auto *DIG : CU->getGlobalVariables()) {
183 if (!addGlobalVariable(DIG))
184 continue;
185 auto *GV = DIG->getVariable();
186 processScope(GV->getScope());
187 processType(GV->getType());
188 }
189 for (auto *ET : CU->getEnumTypes())
190 processType(ET);
191 for (auto *RT : CU->getRetainedTypes())
192 if (auto *T = dyn_cast<DIType>(RT))
193 processType(T);
194 else
196 for (auto *Import : CU->getImportedEntities())
197 processImportedEntity(Import);
198}
199
201 const Instruction &I) {
202 if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
203 processVariable(DVI->getVariable());
204
205 if (auto DbgLoc = I.getDebugLoc())
206 processLocation(M, DbgLoc.get());
207
208 for (const DbgRecord &DPR : I.getDbgRecordRange())
209 processDbgRecord(M, DPR);
210}
211
213 if (!Loc)
214 return;
215 processScope(Loc->getScope());
216 processLocation(M, Loc->getInlinedAt());
217}
218
221 processVariable(DVR->getVariable());
223}
224
225void DebugInfoFinder::processType(DIType *DT) {
226 if (!addType(DT))
227 return;
228 processScope(DT->getScope());
229 if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
230 for (DIType *Ref : ST->getTypeArray())
231 processType(Ref);
232 return;
233 }
234 if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
235 processType(DCT->getBaseType());
236 for (Metadata *D : DCT->getElements()) {
237 if (auto *T = dyn_cast<DIType>(D))
238 processType(T);
239 else if (auto *SP = dyn_cast<DISubprogram>(D))
241 }
242 return;
243 }
244 if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
245 processType(DDT->getBaseType());
246 }
247}
248
249void DebugInfoFinder::processImportedEntity(const DIImportedEntity *Import) {
250 auto *Entity = Import->getEntity();
251 if (auto *T = dyn_cast<DIType>(Entity))
252 processType(T);
253 else if (auto *SP = dyn_cast<DISubprogram>(Entity))
255 else if (auto *NS = dyn_cast<DINamespace>(Entity))
256 processScope(NS->getScope());
257 else if (auto *M = dyn_cast<DIModule>(Entity))
258 processScope(M->getScope());
259}
260
261void DebugInfoFinder::processScope(DIScope *Scope) {
262 if (!Scope)
263 return;
264 if (auto *Ty = dyn_cast<DIType>(Scope)) {
265 processType(Ty);
266 return;
267 }
268 if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
269 addCompileUnit(CU);
270 return;
271 }
272 if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
274 return;
275 }
276 if (!addScope(Scope))
277 return;
278 if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
279 processScope(LB->getScope());
280 } else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
281 processScope(NS->getScope());
282 } else if (auto *M = dyn_cast<DIModule>(Scope)) {
283 processScope(M->getScope());
284 }
285}
286
288 if (!addSubprogram(SP))
289 return;
290 processScope(SP->getScope());
291 // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
292 // ValueMap containing identity mappings for all of the DICompileUnit's, not
293 // just DISubprogram's, referenced from anywhere within the Function being
294 // cloned prior to calling MapMetadata / RemapInstruction to avoid their
295 // duplication later as DICompileUnit's are also directly referenced by
296 // llvm.dbg.cu list. Therefore we need to collect DICompileUnit's here as
297 // well. Also, DICompileUnit's may reference DISubprogram's too and therefore
298 // need to be at least looked through.
299 processCompileUnit(SP->getUnit());
300 processType(SP->getType());
301 for (auto *Element : SP->getTemplateParams()) {
302 if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
303 processType(TType->getType());
304 } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
305 processType(TVal->getType());
306 }
307 }
308
309 SP->forEachRetainedNode(
310 [this](const DILocalVariable *LV) { processVariable(LV); },
311 [](const DILabel *L) {},
312 [this](const DIImportedEntity *IE) { processImportedEntity(IE); });
313}
314
316 if (!NodesSeen.insert(DV).second)
317 return;
318 processScope(DV->getScope());
319 processType(DV->getType());
320}
321
322bool DebugInfoFinder::addType(DIType *DT) {
323 if (!DT)
324 return false;
325
326 if (!NodesSeen.insert(DT).second)
327 return false;
328
329 TYs.push_back(DT);
330 return true;
331}
332
333bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
334 if (!CU)
335 return false;
336 if (!NodesSeen.insert(CU).second)
337 return false;
338
339 CUs.push_back(CU);
340 return true;
341}
342
343bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) {
344 if (!NodesSeen.insert(DIG).second)
345 return false;
346
347 GVs.push_back(DIG);
348 return true;
349}
350
351bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
352 if (!SP)
353 return false;
354
355 if (!NodesSeen.insert(SP).second)
356 return false;
357
358 SPs.push_back(SP);
359 return true;
360}
361
362bool DebugInfoFinder::addScope(DIScope *Scope) {
363 if (!Scope)
364 return false;
365 // FIXME: Ocaml binding generates a scope with no content, we treat it
366 // as null for now.
367 if (Scope->getNumOperands() == 0)
368 return false;
369 if (!NodesSeen.insert(Scope).second)
370 return false;
371 Scopes.push_back(Scope);
372 return true;
373}
374
375/// Recursively handle DILocations in followup metadata etc.
376///
377/// TODO: If for example a followup loop metadata would reference itself this
378/// function would go into infinite recursion. We do not expect such cycles in
379/// the loop metadata (except for the self-referencing first element
380/// "LoopID"). However, we could at least handle such situations more gracefully
381/// somehow (e.g. by keeping track of visited nodes and dropping metadata).
383 Metadata *MetadataIn, function_ref<Metadata *(Metadata *)> Updater) {
384 const MDTuple *M = dyn_cast_or_null<MDTuple>(MetadataIn);
385 // The loop metadata options should start with a MDString.
386 if (!M || M->getNumOperands() < 1 || !isa<MDString>(M->getOperand(0)))
387 return MetadataIn;
388
389 bool Updated = false;
390 SmallVector<Metadata *, 4> MDs{M->getOperand(0)};
391 for (Metadata *MD : llvm::drop_begin(M->operands())) {
392 if (!MD) {
393 MDs.push_back(nullptr);
394 continue;
395 }
396 Metadata *NewMD =
397 Updater(updateLoopMetadataDebugLocationsRecursive(MD, Updater));
398 if (NewMD)
399 MDs.push_back(NewMD);
400 Updated |= NewMD != MD;
401 }
402
403 assert(!M->isDistinct() && "M should not be distinct.");
404 return Updated ? MDNode::get(M->getContext(), MDs) : MetadataIn;
405}
406
408 MDNode *OrigLoopID, function_ref<Metadata *(Metadata *)> Updater) {
409 assert(OrigLoopID && OrigLoopID->getNumOperands() > 0 &&
410 "Loop ID needs at least one operand");
411 assert(OrigLoopID && OrigLoopID->getOperand(0).get() == OrigLoopID &&
412 "Loop ID should refer to itself");
413
414 // Save space for the self-referential LoopID.
415 SmallVector<Metadata *, 4> MDs = {nullptr};
416
417 for (Metadata *MD : llvm::drop_begin(OrigLoopID->operands())) {
418 if (!MD)
419 MDs.push_back(nullptr);
420 else if (Metadata *NewMD = Updater(
422 MDs.push_back(NewMD);
423 }
424
425 MDNode *NewLoopID = MDNode::getDistinct(OrigLoopID->getContext(), MDs);
426 // Insert the self-referential LoopID.
427 NewLoopID->replaceOperandWith(0, NewLoopID);
428 return NewLoopID;
429}
430
432 Instruction &I, function_ref<Metadata *(Metadata *)> Updater) {
433 MDNode *OrigLoopID = I.getMetadata(LLVMContext::MD_loop);
434 if (!OrigLoopID)
435 return;
436 MDNode *NewLoopID = updateLoopMetadataDebugLocationsImpl(OrigLoopID, Updater);
437 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
438}
439
440/// Return true if a node is a DILocation or if a DILocation is
441/// indirectly referenced by one of the node's children.
444 Metadata *MD) {
446 if (!N)
447 return false;
448 if (isa<DILocation>(N) || Reachable.count(N))
449 return true;
450 if (!Visited.insert(N).second)
451 return false;
452 for (auto &OpIt : N->operands()) {
453 Metadata *Op = OpIt.get();
454 if (isDILocationReachable(Visited, Reachable, Op)) {
455 // Don't return just yet as we want to visit all MD's children to
456 // initialize DILocationReachable in stripDebugLocFromLoopID
457 Reachable.insert(N);
458 }
459 }
460 return Reachable.count(N);
461}
462
464 SmallPtrSetImpl<Metadata *> &AllDILocation,
465 const SmallPtrSetImpl<Metadata *> &DIReachable,
466 Metadata *MD) {
468 if (!N)
469 return false;
470 if (isa<DILocation>(N) || AllDILocation.count(N))
471 return true;
472 if (!DIReachable.count(N))
473 return false;
474 if (!Visited.insert(N).second)
475 return false;
476 for (auto &OpIt : N->operands()) {
477 Metadata *Op = OpIt.get();
478 if (Op == MD)
479 continue;
480 if (!isAllDILocation(Visited, AllDILocation, DIReachable, Op)) {
481 return false;
482 }
483 }
484 AllDILocation.insert(N);
485 return true;
486}
487
488static Metadata *
490 const SmallPtrSetImpl<Metadata *> &DIReachable, Metadata *MD) {
491 if (isa<DILocation>(MD) || AllDILocation.count(MD))
492 return nullptr;
493
494 if (!DIReachable.count(MD))
495 return MD;
496
498 if (!N)
499 return MD;
500
502 bool HasSelfRef = false;
503 for (unsigned i = 0; i < N->getNumOperands(); ++i) {
504 Metadata *A = N->getOperand(i);
505 if (!A) {
506 Args.push_back(nullptr);
507 } else if (A == MD) {
508 assert(i == 0 && "expected i==0 for self-reference");
509 HasSelfRef = true;
510 Args.push_back(nullptr);
511 } else if (Metadata *NewArg =
512 stripLoopMDLoc(AllDILocation, DIReachable, A)) {
513 Args.push_back(NewArg);
514 }
515 }
516 if (Args.empty() || (HasSelfRef && Args.size() == 1))
517 return nullptr;
518
519 MDNode *NewMD = N->isDistinct() ? MDNode::getDistinct(N->getContext(), Args)
520 : MDNode::get(N->getContext(), Args);
521 if (HasSelfRef)
522 NewMD->replaceOperandWith(0, NewMD);
523 return NewMD;
524}
525
527 assert(!N->operands().empty() && "Missing self reference?");
528 SmallPtrSet<Metadata *, 8> Visited, DILocationReachable, AllDILocation;
529 // If we already visited N, there is nothing to do.
530 if (!Visited.insert(N).second)
531 return N;
532
533 // If there is no debug location, we do not have to rewrite this
534 // MDNode. This loop also initializes DILocationReachable, later
535 // needed by updateLoopMetadataDebugLocationsImpl; the use of
536 // count_if avoids an early exit.
537 if (!llvm::count_if(llvm::drop_begin(N->operands()),
538 [&Visited, &DILocationReachable](const MDOperand &Op) {
539 return isDILocationReachable(
540 Visited, DILocationReachable, Op.get());
541 }))
542 return N;
543
544 Visited.clear();
545 // If there is only the debug location without any actual loop metadata, we
546 // can remove the metadata.
547 if (llvm::all_of(llvm::drop_begin(N->operands()),
548 [&Visited, &AllDILocation,
549 &DILocationReachable](const MDOperand &Op) {
550 return isAllDILocation(Visited, AllDILocation,
551 DILocationReachable, Op.get());
552 }))
553 return nullptr;
554
556 N, [&AllDILocation, &DILocationReachable](Metadata *MD) -> Metadata * {
557 return stripLoopMDLoc(AllDILocation, DILocationReachable, MD);
558 });
559}
560
562 bool Changed = false;
563 if (F.hasMetadata(LLVMContext::MD_dbg)) {
564 Changed = true;
565 F.setSubprogram(nullptr);
566 }
567
569 for (BasicBlock &BB : F) {
571 if (I.getDebugLoc()) {
572 Changed = true;
573 I.setDebugLoc(DebugLoc());
574 }
575 if (auto *LoopID = I.getMetadata(LLVMContext::MD_loop)) {
576 auto *NewLoopID = LoopIDsMap.lookup(LoopID);
577 if (!NewLoopID)
578 NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
579 if (NewLoopID != LoopID)
580 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
581 }
582 // Strip other attachments that are or use debug info.
583 if (I.hasMetadataOtherThanDebugLoc()) {
584 // Heapallocsites point into the DIType system.
585 I.setMetadata("heapallocsite", nullptr);
586 // DIAssignID are debug info metadata primitives.
587 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
588 }
589 I.dropDbgRecords();
590 }
591 }
592 return Changed;
593}
594
596 llvm::TimeTraceScope timeScope("Strip debug info");
597 bool Changed = false;
598
599 for (NamedMDNode &NMD : llvm::make_early_inc_range(M.named_metadata())) {
600 // We're stripping debug info, and without them, coverage information
601 // doesn't quite make sense.
602 if (NMD.getName().starts_with("llvm.dbg.") ||
603 NMD.getName() == "llvm.gcov") {
604 NMD.eraseFromParent();
605 Changed = true;
606 }
607 }
608
609 for (Function &F : M)
611
612 for (auto &GV : M.globals()) {
613 Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
614 }
615
616 if (GVMaterializer *Materializer = M.getMaterializer())
617 Materializer->setStripDebugInfo();
618
619 return Changed;
620}
621
622namespace {
623
624/// Helper class to downgrade -g metadata to -gline-tables-only metadata.
625class DebugTypeInfoRemoval {
627
628public:
629 /// The (void)() type.
630 MDNode *EmptySubroutineType;
631
632private:
633 /// Remember what linkage name we originally had before stripping. If we end
634 /// up making two subprograms identical who originally had different linkage
635 /// names, then we need to make one of them distinct, to avoid them getting
636 /// uniqued. Maps the new node to the old linkage name.
638
639 // TODO: Remember the distinct subprogram we created for a given linkage name,
640 // so that we can continue to unique whenever possible. Map <newly created
641 // node, old linkage name> to the first (possibly distinct) mdsubprogram
642 // created for that combination. This is not strictly needed for correctness,
643 // but can cut down on the number of MDNodes and let us diff cleanly with the
644 // output of -gline-tables-only.
645
646public:
647 DebugTypeInfoRemoval(LLVMContext &C)
648 : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0,
649 MDNode::get(C, {}))) {}
650
651 Metadata *map(Metadata *M) {
652 if (!M)
653 return nullptr;
654 auto Replacement = Replacements.find(M);
655 if (Replacement != Replacements.end())
656 return Replacement->second;
657
658 return M;
659 }
660 MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); }
661
662 /// Recursively remap N and all its referenced children. Does a DF post-order
663 /// traversal, so as to remap bottoms up.
664 void traverseAndRemap(MDNode *N) { traverse(N); }
665
666private:
667 // Create a new DISubprogram, to replace the one given.
668 DISubprogram *getReplacementSubprogram(DISubprogram *MDS) {
669 auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile()));
670 StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
671 DISubprogram *Declaration = nullptr;
672 auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
673 DIType *ContainingType =
674 cast_or_null<DIType>(map(MDS->getContainingType()));
675 auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
676 auto Variables = nullptr;
677 auto TemplateParams = nullptr;
678
679 // Make a distinct DISubprogram, for situations that warrant it.
680 auto distinctMDSubprogram = [&]() {
681 return DISubprogram::getDistinct(
682 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
683 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(),
684 ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(),
685 MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration,
686 Variables);
687 };
688
689 if (MDS->isDistinct())
690 return distinctMDSubprogram();
691
692 auto *NewMDS = DISubprogram::get(
693 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
694 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType,
695 MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(),
696 MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables);
697
698 StringRef OldLinkageName = MDS->getLinkageName();
699
700 // See if we need to make a distinct one.
701 auto OrigLinkage = NewToLinkageName.find(NewMDS);
702 if (OrigLinkage != NewToLinkageName.end()) {
703 if (OrigLinkage->second == OldLinkageName)
704 // We're good.
705 return NewMDS;
706
707 // Otherwise, need to make a distinct one.
708 // TODO: Query the map to see if we already have one.
709 return distinctMDSubprogram();
710 }
711
712 NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
713 return NewMDS;
714 }
715
716 /// Create a new compile unit, to replace the one given
717 DICompileUnit *getReplacementCU(DICompileUnit *CU) {
718 // Drop skeleton CUs.
719 if (CU->getDWOId())
720 return nullptr;
721
722 auto *File = cast_or_null<DIFile>(map(CU->getFile()));
723 MDTuple *EnumTypes = nullptr;
724 MDTuple *RetainedTypes = nullptr;
725 MDTuple *GlobalVariables = nullptr;
726 MDTuple *ImportedEntities = nullptr;
727 return DICompileUnit::getDistinct(
728 CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(),
729 CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
731 RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
732 CU->getDWOId(), CU->getSplitDebugInlining(),
734 CU->getRangesBaseAddress(), CU->getSysRoot(), CU->getSDK());
735 }
736
737 DILocation *getReplacementMDLocation(DILocation *MLD) {
738 auto *Scope = map(MLD->getScope());
739 auto *InlinedAt = map(MLD->getInlinedAt());
740 if (MLD->isDistinct())
741 return DILocation::getDistinct(MLD->getContext(), MLD->getLine(),
742 MLD->getColumn(), Scope, InlinedAt);
743 return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(),
744 Scope, InlinedAt);
745 }
746
747 /// Create a new generic MDNode, to replace the one given
748 MDNode *getReplacementMDNode(MDNode *N) {
750 Ops.reserve(N->getNumOperands());
751 for (auto &I : N->operands())
752 if (I)
753 Ops.push_back(map(I));
754 auto *Ret = MDNode::get(N->getContext(), Ops);
755 return Ret;
756 }
757
758 /// Attempt to re-map N to a newly created node.
759 void remap(MDNode *N) {
760 if (Replacements.count(N))
761 return;
762
763 auto doRemap = [&](MDNode *N) -> MDNode * {
764 if (!N)
765 return nullptr;
766 if (auto *MDSub = dyn_cast<DISubprogram>(N)) {
767 remap(MDSub->getUnit());
768 return getReplacementSubprogram(MDSub);
769 }
771 return EmptySubroutineType;
772 if (auto *CU = dyn_cast<DICompileUnit>(N))
773 return getReplacementCU(CU);
774 if (isa<DIFile>(N))
775 return N;
776 if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N))
777 // Remap to our referenced scope (recursively).
778 return mapNode(MDLB->getScope());
779 if (auto *MLD = dyn_cast<DILocation>(N))
780 return getReplacementMDLocation(MLD);
781
782 // Otherwise, if we see these, just drop them now. Not strictly necessary,
783 // but this speeds things up a little.
784 if (isa<DINode>(N))
785 return nullptr;
786
787 return getReplacementMDNode(N);
788 };
789 // Separate recursive doRemap and operator [] into 2 lines to avoid
790 // out-of-order evaluations since both of them can access the same memory
791 // location in map Replacements.
792 auto Value = doRemap(N);
793 Replacements[N] = Value;
794 }
795
796 /// Do the remapping traversal.
797 void traverse(MDNode *);
798};
799
800} // end anonymous namespace
801
802void DebugTypeInfoRemoval::traverse(MDNode *N) {
803 if (!N || Replacements.count(N))
804 return;
805
806 // To avoid cycles, as well as for efficiency sake, we will sometimes prune
807 // parts of the graph.
808 auto prune = [](MDNode *Parent, MDNode *Child) {
809 if (auto *MDS = dyn_cast<DISubprogram>(Parent))
810 return Child == MDS->getRetainedNodes().get();
811 return false;
812 };
813
815 DenseSet<MDNode *> Opened;
816
817 // Visit each node starting at N in post order, and map them.
818 ToVisit.push_back(N);
819 while (!ToVisit.empty()) {
820 auto *N = ToVisit.back();
821 if (!Opened.insert(N).second) {
822 // Close it.
823 remap(N);
824 ToVisit.pop_back();
825 continue;
826 }
827 for (auto &I : N->operands())
828 if (auto *MDN = dyn_cast_or_null<MDNode>(I))
829 if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) &&
830 !isa<DICompileUnit>(MDN))
831 ToVisit.push_back(MDN);
832 }
833}
834
836 bool Changed = false;
837
838 // Delete non-CU debug info named metadata nodes.
839 for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
840 NMI != NME;) {
841 NamedMDNode *NMD = &*NMI;
842 ++NMI;
843 // Specifically keep dbg.cu around.
844 if (NMD->getName() == "llvm.dbg.cu")
845 continue;
846 }
847
848 // Drop all dbg attachments from global variables.
849 for (auto &GV : M.globals())
850 GV.eraseMetadata(LLVMContext::MD_dbg);
851
852 DebugTypeInfoRemoval Mapper(M.getContext());
853 auto remap = [&](MDNode *Node) -> MDNode * {
854 if (!Node)
855 return nullptr;
856 Mapper.traverseAndRemap(Node);
857 auto *NewNode = Mapper.mapNode(Node);
858 Changed |= Node != NewNode;
859 Node = NewNode;
860 return NewNode;
861 };
862
863 // Rewrite the DebugLocs to be equivalent to what
864 // -gline-tables-only would have created.
865 for (auto &F : M) {
866 if (auto *SP = F.getSubprogram()) {
867 Mapper.traverseAndRemap(SP);
868 auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
869 Changed |= SP != NewSP;
870 F.setSubprogram(NewSP);
871 }
872 for (auto &BB : F) {
873 for (auto &I : BB) {
874 auto remapDebugLoc = [&](const DebugLoc &DL) -> DebugLoc {
875 auto *Scope = DL.getScope();
876 MDNode *InlinedAt = DL.getInlinedAt();
877 Scope = remap(Scope);
878 InlinedAt = remap(InlinedAt);
879 return DILocation::get(M.getContext(), DL.getLine(), DL.getCol(),
880 Scope, InlinedAt);
881 };
882
883 if (I.getDebugLoc() != DebugLoc())
884 I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
885
886 // Remap DILocations in llvm.loop attachments.
888 if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
889 return remapDebugLoc(Loc).get();
890 return MD;
891 });
892
893 // Strip heapallocsite attachments, they point into the DIType system.
894 if (I.hasMetadataOtherThanDebugLoc())
895 I.setMetadata("heapallocsite", nullptr);
896
897 // Strip any DbgRecords attached.
898 I.dropDbgRecords();
899 }
900 }
901 }
902
903 // Create a new llvm.dbg.cu, which is equivalent to the one
904 // -gline-tables-only would have created.
905 for (auto &NMD : M.named_metadata()) {
907 for (MDNode *Op : NMD.operands())
908 Ops.push_back(remap(Op));
909
910 if (!Changed)
911 continue;
912
913 NMD.clearOperands();
914 for (auto *Op : Ops)
915 if (Op)
916 NMD.addOperand(Op);
917 }
918 return Changed;
919}
920
923 M.getModuleFlag("Debug Info Version")))
924 return Val->getZExtValue();
925 return 0;
926}
927
931
933 ArrayRef<const Instruction *> SourceInstructions) {
934 // Replace all uses (and attachments) of all the DIAssignIDs
935 // on SourceInstructions with a single merged value.
936 assert(getFunction() && "Uninserted instruction merged");
937 // Collect up the DIAssignID tags.
939 for (const Instruction *I : SourceInstructions) {
940 if (auto *MD = I->getMetadata(LLVMContext::MD_DIAssignID))
942 assert(getFunction() == I->getFunction() &&
943 "Merging with instruction from another function not allowed");
944 }
945
946 // Add this instruction's DIAssignID too, if it has one.
947 if (auto *MD = getMetadata(LLVMContext::MD_DIAssignID))
949
950 if (IDs.empty())
951 return; // No DIAssignID tags to process.
952
953 DIAssignID *MergeID = IDs[0];
954 for (DIAssignID *AssignID : drop_begin(IDs)) {
955 if (AssignID != MergeID)
956 at::RAUW(AssignID, MergeID);
957 }
958 setMetadata(LLVMContext::MD_DIAssignID, MergeID);
959}
960
962
964 const DebugLoc &DL = getDebugLoc();
965 if (!DL) {
967 return;
968 }
969
970 // If this isn't a call, drop the location to allow a location from a
971 // preceding instruction to propagate.
972 bool MayLowerToCall = false;
973 if (isa<CallBase>(this)) {
974 auto *II = dyn_cast<IntrinsicInst>(this);
975 MayLowerToCall =
976 !II || IntrinsicInst::mayLowerToFunctionCall(II->getIntrinsicID());
977 }
978
979 if (!MayLowerToCall) {
981 return;
982 }
983
984 // Set a line 0 location for calls to preserve scope information in case
985 // inlining occurs.
987 if (SP)
988 // If a function scope is available, set it on the line 0 location. When
989 // hoisting a call to a predecessor block, using the function scope avoids
990 // making it look like the callee was reached earlier than it should be.
992 else
993 // The parent function has no scope. Go ahead and drop the location. If
994 // the parent function is inlined, and the callee has a subprogram, the
995 // inliner will attach a location to the call.
996 //
997 // One alternative is to set a line 0 location with the existing scope and
998 // inlinedAt info. The location might be sensitive to when inlining occurs.
1000}
1001
1002//===----------------------------------------------------------------------===//
1003// LLVM C API implementations.
1004//===----------------------------------------------------------------------===//
1005
1007 switch (lang) {
1008#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
1009 case LLVMDWARFSourceLanguage##NAME: \
1010 return ID;
1011#include "llvm/BinaryFormat/Dwarf.def"
1012#undef HANDLE_DW_LANG
1013 }
1014 llvm_unreachable("Unhandled Tag");
1015}
1016
1017template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) {
1018 return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
1019}
1020
1022 return static_cast<DINode::DIFlags>(Flags);
1023}
1024
1026 return static_cast<LLVMDIFlags>(Flags);
1027}
1028
1030pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) {
1031 return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized);
1032}
1033
1036}
1037
1041
1045
1049
1053
1055 delete unwrap(Builder);
1056}
1057
1059 unwrap(Builder)->finalize();
1060}
1061
1063 LLVMMetadataRef subprogram) {
1064 unwrap(Builder)->finalizeSubprogram(unwrapDI<DISubprogram>(subprogram));
1065}
1066
1069 LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
1070 LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
1071 unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
1072 LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
1073 LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
1074 const char *SDK, size_t SDKLen) {
1075 auto File = unwrapDI<DIFile>(FileRef);
1076
1077 return wrap(unwrap(Builder)->createCompileUnit(
1079 StringRef(Producer, ProducerLen), isOptimized, StringRef(Flags, FlagsLen),
1080 RuntimeVer, StringRef(SplitName, SplitNameLen),
1081 static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
1082 SplitDebugInlining, DebugInfoForProfiling,
1084 StringRef(SysRoot, SysRootLen), StringRef(SDK, SDKLen)));
1085}
1086
1088LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
1089 size_t FilenameLen, const char *Directory,
1090 size_t DirectoryLen) {
1091 return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
1092 StringRef(Directory, DirectoryLen)));
1093}
1094
1097 switch (CSKind) {
1099 return llvm::DIFile::CSK_MD5;
1104 }
1105 llvm_unreachable("Unhandled Checksum Kind");
1106}
1107
1109 LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen,
1110 const char *Directory, size_t DirectoryLen, LLVMChecksumKind ChecksumKind,
1111 const char *Checksum, size_t ChecksumLen, const char *Source,
1112 size_t SourceLen) {
1113 StringRef ChkSum = StringRef(Checksum, ChecksumLen);
1114 auto CSK = map_from_llvmChecksumKind(ChecksumKind);
1115 llvm::DIFile::ChecksumInfo<StringRef> CSInfo(CSK, ChkSum);
1116 std::optional<StringRef> Src;
1117 if (SourceLen > 0)
1118 Src = StringRef(Source, SourceLen);
1119 return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
1120 StringRef(Directory, DirectoryLen),
1121 CSInfo, Src));
1122}
1123
1126 const char *Name, size_t NameLen,
1127 const char *ConfigMacros, size_t ConfigMacrosLen,
1128 const char *IncludePath, size_t IncludePathLen,
1129 const char *APINotesFile, size_t APINotesFileLen) {
1130 return wrap(unwrap(Builder)->createModule(
1131 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
1132 StringRef(ConfigMacros, ConfigMacrosLen),
1133 StringRef(IncludePath, IncludePathLen),
1134 StringRef(APINotesFile, APINotesFileLen)));
1135}
1136
1138 LLVMMetadataRef ParentScope,
1139 const char *Name, size_t NameLen,
1140 LLVMBool ExportSymbols) {
1141 return wrap(unwrap(Builder)->createNameSpace(
1142 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols));
1143}
1144
1146 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1147 size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
1148 LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1149 LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
1150 unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
1151 return wrap(unwrap(Builder)->createFunction(
1152 unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
1153 unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine,
1154 map_from_llvmDIFlags(Flags),
1155 pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr,
1156 nullptr, nullptr));
1157}
1158
1159
1161 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1162 LLVMMetadataRef File, unsigned Line, unsigned Col) {
1163 return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope),
1164 unwrapDI<DIFile>(File),
1165 Line, Col));
1166}
1167
1170 LLVMMetadataRef Scope,
1171 LLVMMetadataRef File,
1172 unsigned Discriminator) {
1173 return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope),
1174 unwrapDI<DIFile>(File),
1175 Discriminator));
1176}
1177
1180 LLVMMetadataRef Scope,
1181 LLVMMetadataRef NS,
1182 LLVMMetadataRef File,
1183 unsigned Line) {
1184 return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
1186 unwrapDI<DIFile>(File),
1187 Line));
1188}
1189
1191 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1192 LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line,
1193 LLVMMetadataRef *Elements, unsigned NumElements) {
1194 auto Elts =
1195 (NumElements > 0)
1196 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1197 : nullptr;
1198 return wrap(unwrap(Builder)->createImportedModule(
1199 unwrapDI<DIScope>(Scope), unwrapDI<DIImportedEntity>(ImportedEntity),
1200 unwrapDI<DIFile>(File), Line, Elts));
1201}
1202
1205 LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements,
1206 unsigned NumElements) {
1207 auto Elts =
1208 (NumElements > 0)
1209 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1210 : nullptr;
1211 return wrap(unwrap(Builder)->createImportedModule(
1213 Line, Elts));
1214}
1215
1218 LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen,
1219 LLVMMetadataRef *Elements, unsigned NumElements) {
1220 auto Elts =
1221 (NumElements > 0)
1222 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1223 : nullptr;
1224 return wrap(unwrap(Builder)->createImportedDeclaration(
1226 Line, {Name, NameLen}, Elts));
1227}
1228
1231 unsigned Column, LLVMMetadataRef Scope,
1232 LLVMMetadataRef InlinedAt) {
1233 return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
1234 unwrap(InlinedAt)));
1235}
1236
1238 return unwrapDI<DILocation>(Location)->getLine();
1239}
1240
1242 return unwrapDI<DILocation>(Location)->getColumn();
1243}
1244
1246 return wrap(unwrapDI<DILocation>(Location)->getScope());
1247}
1248
1250 return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
1251}
1252
1254 return wrap(unwrapDI<DIScope>(Scope)->getFile());
1255}
1256
1257const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) {
1258 auto Dir = unwrapDI<DIFile>(File)->getDirectory();
1259 *Len = Dir.size();
1260 return Dir.data();
1261}
1262
1263const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
1264 auto Name = unwrapDI<DIFile>(File)->getFilename();
1265 *Len = Name.size();
1266 return Name.data();
1267}
1268
1269const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
1270 if (auto Src = unwrapDI<DIFile>(File)->getSource()) {
1271 *Len = Src->size();
1272 return Src->data();
1273 }
1274 *Len = 0;
1275 return "";
1276}
1277
1279 LLVMMetadataRef ParentMacroFile,
1280 unsigned Line,
1282 const char *Name, size_t NameLen,
1283 const char *Value, size_t ValueLen) {
1284 return wrap(
1285 unwrap(Builder)->createMacro(unwrapDI<DIMacroFile>(ParentMacroFile), Line,
1286 static_cast<MacinfoRecordType>(RecordType),
1287 {Name, NameLen}, {Value, ValueLen}));
1288}
1289
1292 LLVMMetadataRef ParentMacroFile, unsigned Line,
1293 LLVMMetadataRef File) {
1294 return wrap(unwrap(Builder)->createTempMacroFile(
1295 unwrapDI<DIMacroFile>(ParentMacroFile), Line, unwrapDI<DIFile>(File)));
1296}
1297
1299 const char *Name, size_t NameLen,
1300 int64_t Value,
1301 LLVMBool IsUnsigned) {
1302 return wrap(unwrap(Builder)->createEnumerator({Name, NameLen}, Value,
1303 IsUnsigned != 0));
1304}
1305
1307 LLVMDIBuilderRef Builder, const char *Name, size_t NameLen,
1308 uint64_t SizeInBits, const uint64_t Words[], LLVMBool IsUnsigned) {
1309 uint64_t NumWords = (SizeInBits + 63) / 64;
1310 return wrap(unwrap(Builder)->createEnumerator(
1311 {Name, NameLen},
1312 APSInt(APInt(SizeInBits, ArrayRef(Words, NumWords)), IsUnsigned != 0)));
1313}
1314
1316 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1317 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1318 uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements,
1319 unsigned NumElements, LLVMMetadataRef ClassTy) {
1320auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1321 NumElements});
1322return wrap(unwrap(Builder)->createEnumerationType(
1323 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1324 LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
1325}
1326
1328 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1329 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1330 uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef BaseTy) {
1331 return wrap(unwrap(Builder)->createSetType(
1332 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1333 LineNumber, SizeInBits, AlignInBits, unwrapDI<DIType>(BaseTy)));
1334}
1335
1337 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1338 size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t SizeInBits,
1339 uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
1340 LLVMMetadataRef LowerBound, LLVMMetadataRef UpperBound,
1341 LLVMMetadataRef Stride, LLVMMetadataRef Bias) {
1342 return wrap(unwrap(Builder)->createSubrangeType(
1343 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, unwrapDI<DIScope>(Scope),
1344 SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1345 unwrapDI<DIType>(BaseTy), unwrap(LowerBound), unwrap(UpperBound),
1346 unwrap(Stride), unwrap(Bias)));
1347}
1348
1349/// MD may be nullptr, a DIExpression or DIVariable.
1351 if (!MD)
1352 return nullptr;
1353 MDNode *MDN = unwrapDI<MDNode>(MD);
1354 if (auto *E = dyn_cast<DIExpression>(MDN))
1355 return E;
1356 assert(isa<DIVariable>(MDN) && "Expected DIExpression or DIVariable");
1357 return cast<DIVariable>(MDN);
1358}
1359
1361 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1362 size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t Size,
1363 uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts,
1364 unsigned NumSubscripts, LLVMMetadataRef DataLocation,
1365 LLVMMetadataRef Associated, LLVMMetadataRef Allocated, LLVMMetadataRef Rank,
1366 LLVMMetadataRef BitStride) {
1367 auto Subs =
1368 unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts});
1369 return wrap(unwrap(Builder)->createArrayType(
1370 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1371 Size, AlignInBits, unwrapDI<DIType>(Ty), Subs,
1372 unwrapExprVar(DataLocation), unwrapExprVar(Associated),
1373 unwrapExprVar(Allocated), unwrapExprVar(Rank), unwrap(BitStride)));
1374}
1375
1377 LLVMMetadataRef *Elements, unsigned NumElements) {
1378 auto CT = unwrap<DICompositeType>(*T);
1379 auto Elts =
1380 unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements});
1381 unwrap(Builder)->replaceArrays(CT, Elts);
1382}
1383
1385 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1386 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1387 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1388 LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
1389 const char *UniqueId, size_t UniqueIdLen) {
1390 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1391 NumElements});
1392 return wrap(unwrap(Builder)->createUnionType(
1393 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1394 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1395 Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
1396}
1397
1398
1401 uint32_t AlignInBits, LLVMMetadataRef Ty,
1402 LLVMMetadataRef *Subscripts,
1403 unsigned NumSubscripts) {
1404 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1405 NumSubscripts});
1406 return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
1407 unwrapDI<DIType>(Ty), Subs));
1408}
1409
1412 uint32_t AlignInBits, LLVMMetadataRef Ty,
1413 LLVMMetadataRef *Subscripts,
1414 unsigned NumSubscripts) {
1415 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1416 NumSubscripts});
1417 return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
1418 unwrapDI<DIType>(Ty), Subs));
1419}
1420
1423 size_t NameLen, uint64_t SizeInBits,
1424 LLVMDWARFTypeEncoding Encoding,
1425 LLVMDIFlags Flags) {
1426 return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
1427 SizeInBits, Encoding,
1428 map_from_llvmDIFlags(Flags)));
1429}
1430
1432 LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
1433 uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,
1434 const char *Name, size_t NameLen) {
1435 return wrap(unwrap(Builder)->createPointerType(
1436 unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, AddressSpace,
1437 {Name, NameLen}));
1438}
1439
1441 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1442 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1443 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1444 LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
1445 unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
1446 const char *UniqueId, size_t UniqueIdLen) {
1447 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1448 NumElements});
1449 return wrap(unwrap(Builder)->createStructType(
1450 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1451 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1452 unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
1453 unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
1454}
1455
1457 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1458 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
1459 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1460 LLVMMetadataRef Ty) {
1461 return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope),
1462 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
1463 OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty)));
1464}
1465
1468 size_t NameLen) {
1469 return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
1470}
1471
1473 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1474 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1475 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
1476 uint32_t AlignInBits) {
1477 return wrap(unwrap(Builder)->createStaticMemberType(
1478 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1479 LineNumber, unwrapDI<DIType>(Type), map_from_llvmDIFlags(Flags),
1480 unwrap<Constant>(ConstantVal), DW_TAG_member, AlignInBits));
1481}
1482
1485 const char *Name, size_t NameLen,
1486 LLVMMetadataRef File, unsigned LineNo,
1487 uint64_t SizeInBits, uint32_t AlignInBits,
1488 uint64_t OffsetInBits, LLVMDIFlags Flags,
1489 LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
1490 return wrap(unwrap(Builder)->createObjCIVar(
1491 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1492 SizeInBits, AlignInBits, OffsetInBits,
1494 unwrapDI<MDNode>(PropertyNode)));
1495}
1496
1499 const char *Name, size_t NameLen,
1500 LLVMMetadataRef File, unsigned LineNo,
1501 const char *GetterName, size_t GetterNameLen,
1502 const char *SetterName, size_t SetterNameLen,
1503 unsigned PropertyAttributes,
1504 LLVMMetadataRef Ty) {
1505 return wrap(unwrap(Builder)->createObjCProperty(
1506 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1507 {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
1508 PropertyAttributes, unwrapDI<DIType>(Ty)));
1509}
1510
1513 LLVMBool Implicit) {
1514 return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type),
1515 Implicit));
1516}
1517
1520 const char *Name, size_t NameLen,
1521 LLVMMetadataRef File, unsigned LineNo,
1522 LLVMMetadataRef Scope, uint32_t AlignInBits) {
1523 return wrap(unwrap(Builder)->createTypedef(
1524 unwrapDI<DIType>(Type), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1525 unwrapDI<DIScope>(Scope), AlignInBits));
1526}
1527
1531 uint64_t BaseOffset, uint32_t VBPtrOffset,
1532 LLVMDIFlags Flags) {
1533 return wrap(unwrap(Builder)->createInheritance(
1535 BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
1536}
1537
1540 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1541 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1542 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1543 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1544 return wrap(unwrap(Builder)->createForwardDecl(
1545 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1546 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1547 AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
1548}
1549
1552 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1553 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1554 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1555 LLVMDIFlags Flags, const char *UniqueIdentifier,
1556 size_t UniqueIdentifierLen) {
1557 return wrap(unwrap(Builder)->createReplaceableCompositeType(
1558 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1559 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1560 AlignInBits, map_from_llvmDIFlags(Flags),
1561 {UniqueIdentifier, UniqueIdentifierLen}));
1562}
1563
1567 return wrap(unwrap(Builder)->createQualifiedType(Tag,
1569}
1570
1574 return wrap(unwrap(Builder)->createReferenceType(Tag,
1576}
1577
1580 return wrap(unwrap(Builder)->createNullPtrType());
1581}
1582
1585 LLVMMetadataRef PointeeType,
1586 LLVMMetadataRef ClassType,
1587 uint64_t SizeInBits,
1588 uint32_t AlignInBits,
1589 LLVMDIFlags Flags) {
1590 return wrap(unwrap(Builder)->createMemberPointerType(
1591 unwrapDI<DIType>(PointeeType),
1592 unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
1593 map_from_llvmDIFlags(Flags)));
1594}
1595
1598 LLVMMetadataRef Scope,
1599 const char *Name, size_t NameLen,
1600 LLVMMetadataRef File, unsigned LineNumber,
1601 uint64_t SizeInBits,
1602 uint64_t OffsetInBits,
1603 uint64_t StorageOffsetInBits,
1605 return wrap(unwrap(Builder)->createBitFieldMemberType(
1606 unwrapDI<DIScope>(Scope), {Name, NameLen},
1607 unwrapDI<DIFile>(File), LineNumber,
1608 SizeInBits, OffsetInBits, StorageOffsetInBits,
1610}
1611
1613 LLVMMetadataRef Scope, const char *Name, size_t NameLen,
1614 LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
1615 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1616 LLVMMetadataRef DerivedFrom,
1617 LLVMMetadataRef *Elements, unsigned NumElements,
1618 LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode,
1619 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1620 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1621 NumElements});
1622 return wrap(unwrap(Builder)->createClassType(
1623 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1624 LineNumber, SizeInBits, AlignInBits, OffsetInBits,
1625 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom), Elts,
1626 /*RunTimeLang=*/0, unwrapDI<DIType>(VTableHolder),
1627 unwrapDI<MDNode>(TemplateParamsNode),
1628 {UniqueIdentifier, UniqueIdentifierLen}));
1629}
1630
1634 return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
1635}
1636
1638 return unwrapDI<DINode>(MD)->getTag();
1639}
1640
1641const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
1642 StringRef Str = unwrapDI<DIType>(DType)->getName();
1643 *Length = Str.size();
1644 return Str.data();
1645}
1646
1648 return unwrapDI<DIType>(DType)->getSizeInBits();
1649}
1650
1652 return unwrapDI<DIType>(DType)->getOffsetInBits();
1653}
1654
1656 return unwrapDI<DIType>(DType)->getAlignInBits();
1657}
1658
1660 return unwrapDI<DIType>(DType)->getLine();
1661}
1662
1666
1668 LLVMMetadataRef *Types,
1669 size_t Length) {
1670 return wrap(
1671 unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
1672}
1673
1676 LLVMMetadataRef File,
1677 LLVMMetadataRef *ParameterTypes,
1678 unsigned NumParameterTypes,
1679 LLVMDIFlags Flags) {
1680 auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
1681 NumParameterTypes});
1682 return wrap(unwrap(Builder)->createSubroutineType(
1683 Elts, map_from_llvmDIFlags(Flags)));
1684}
1685
1687 uint64_t *Addr, size_t Length) {
1688 return wrap(
1689 unwrap(Builder)->createExpression(ArrayRef<uint64_t>(Addr, Length)));
1690}
1691
1694 uint64_t Value) {
1695 return wrap(unwrap(Builder)->createConstantValueExpression(Value));
1696}
1697
1699 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1700 size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File,
1701 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1702 LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) {
1703 return wrap(unwrap(Builder)->createGlobalVariableExpression(
1704 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
1705 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1706 true, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
1707 nullptr, AlignInBits));
1708}
1709
1713
1718
1722
1726
1728 return unwrapDI<DIVariable>(Var)->getLine();
1729}
1730
1732 size_t Count) {
1733 return wrap(
1734 MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
1735}
1736
1740
1742 LLVMMetadataRef Replacement) {
1743 auto *Node = unwrapDI<MDNode>(TargetMetadata);
1744 Node->replaceAllUsesWith(unwrap(Replacement));
1746}
1747
1749 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1750 size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File,
1751 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1752 LLVMMetadataRef Decl, uint32_t AlignInBits) {
1753 return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
1754 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen},
1755 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1756 unwrapDI<MDNode>(Decl), nullptr, AlignInBits));
1757}
1758
1760 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1762 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1763 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1765 Instr ? InsertPosition(unwrap<Instruction>(Instr)->getIterator())
1766 : nullptr);
1767 // This assert will fail if the module is in the old debug info format.
1768 // This function should only be called if the module is in the new
1769 // debug info format.
1770 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1771 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1772 assert(isa<DbgRecord *>(DbgInst) &&
1773 "Function unexpectedly in old debug info format");
1774 return wrap(cast<DbgRecord *>(DbgInst));
1775}
1776
1778 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1780 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1781 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1783 // This assert will fail if the module is in the old debug info format.
1784 // This function should only be called if the module is in the new
1785 // debug info format.
1786 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1787 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1788 assert(isa<DbgRecord *>(DbgInst) &&
1789 "Function unexpectedly in old debug info format");
1790 return wrap(cast<DbgRecord *>(DbgInst));
1791}
1792
1794 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1796 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1799 Instr ? InsertPosition(unwrap<Instruction>(Instr)->getIterator())
1800 : nullptr);
1801 // This assert will fail if the module is in the old debug info format.
1802 // This function should only be called if the module is in the new
1803 // debug info format.
1804 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1805 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1806 assert(isa<DbgRecord *>(DbgInst) &&
1807 "Function unexpectedly in old debug info format");
1808 return wrap(cast<DbgRecord *>(DbgInst));
1809}
1810
1812 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1814 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1817 Block ? InsertPosition(unwrap(Block)->end()) : nullptr);
1818 // This assert will fail if the module is in the old debug info format.
1819 // This function should only be called if the module is in the new
1820 // debug info format.
1821 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1822 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1823 assert(isa<DbgRecord *>(DbgInst) &&
1824 "Function unexpectedly in old debug info format");
1825 return wrap(cast<DbgRecord *>(DbgInst));
1826}
1827
1829 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1830 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1831 LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) {
1832 return wrap(unwrap(Builder)->createAutoVariable(
1833 unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File),
1834 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1835 map_from_llvmDIFlags(Flags), AlignInBits));
1836}
1837
1839 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1840 size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo,
1841 LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) {
1842 return wrap(unwrap(Builder)->createParameterVariable(
1843 unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File),
1844 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1845 map_from_llvmDIFlags(Flags)));
1846}
1847
1849 int64_t Lo, int64_t Count) {
1850 return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
1851}
1852
1855 size_t Length) {
1856 Metadata **DataValue = unwrap(Data);
1857 return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get());
1858}
1859
1863
1865 unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
1866}
1867
1869 return unwrapDI<DISubprogram>(Subprogram)->getLine();
1870}
1871
1873 LLVMMetadataRef SubroutineType) {
1874 unwrapDI<DISubprogram>(Subprogram)
1875 ->replaceType(unwrapDI<DISubroutineType>(SubroutineType));
1876}
1877
1881
1883 if (Loc)
1884 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc)));
1885 else
1886 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
1887}
1888
1890 LLVMMetadataRef Context,
1891 const char *Name, size_t NameLen,
1892 LLVMMetadataRef File, unsigned LineNo,
1893 LLVMBool AlwaysPreserve) {
1894 return wrap(unwrap(Builder)->createLabel(
1895 unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
1896 unwrapDI<DIFile>(File), LineNo, /*Column*/ 0, /*IsArtificial*/ false,
1897 /*CoroSuspendIdx*/ std::nullopt, AlwaysPreserve));
1898}
1899
1901 LLVMMetadataRef LabelInfo,
1902 LLVMMetadataRef Location,
1903 LLVMValueRef InsertBefore) {
1904 DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
1905 unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
1906 InsertBefore
1907 ? InsertPosition(unwrap<Instruction>(InsertBefore)->getIterator())
1908 : nullptr);
1909 // This assert will fail if the module is in the old debug info format.
1910 // This function should only be called if the module is in the new
1911 // debug info format.
1912 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1913 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1914 assert(isa<DbgRecord *>(DbgInst) &&
1915 "Function unexpectedly in old debug info format");
1916 return wrap(cast<DbgRecord *>(DbgInst));
1917}
1918
1920 LLVMMetadataRef LabelInfo,
1921 LLVMMetadataRef Location,
1922 LLVMBasicBlockRef InsertAtEnd) {
1923 DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
1924 unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
1925 InsertAtEnd ? InsertPosition(unwrap(InsertAtEnd)->end()) : nullptr);
1926 // This assert will fail if the module is in the old debug info format.
1927 // This function should only be called if the module is in the new
1928 // debug info format.
1929 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1930 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1931 assert(isa<DbgRecord *>(DbgInst) &&
1932 "Function unexpectedly in old debug info format");
1933 return wrap(cast<DbgRecord *>(DbgInst));
1934}
1935
1937 switch(unwrap(Metadata)->getMetadataID()) {
1938#define HANDLE_METADATA_LEAF(CLASS) \
1939 case Metadata::CLASS##Kind: \
1940 return (LLVMMetadataKind)LLVM##CLASS##MetadataKind;
1941#include "llvm/IR/Metadata.def"
1942 default:
1944 }
1945}
1946
1948 assert(ID && "Expected non-null ID");
1949 LLVMContext &Ctx = ID->getContext();
1950 auto &Map = Ctx.pImpl->AssignmentIDToInstrs;
1951
1952 auto MapIt = Map.find(ID);
1953 if (MapIt == Map.end())
1954 return make_range(nullptr, nullptr);
1955
1956 return make_range(MapIt->second.begin(), MapIt->second.end());
1957}
1958
1960 for (auto *DVR : getDVRAssignmentMarkers(Inst))
1961 DVR->eraseFromParent();
1962}
1963
1965 // Replace attachments.
1966 AssignmentInstRange InstRange = getAssignmentInsts(Old);
1967 // Use intermediate storage for the instruction ptrs because the
1968 // getAssignmentInsts range iterators will be invalidated by adding and
1969 // removing DIAssignID attachments.
1970 SmallVector<Instruction *> InstVec(InstRange.begin(), InstRange.end());
1971 for (auto *I : InstVec)
1972 I->setMetadata(LLVMContext::MD_DIAssignID, New);
1973
1974 Old->replaceAllUsesWith(New);
1975}
1976
1978 for (BasicBlock &BB : *F) {
1979 for (Instruction &I : BB) {
1980 for (DbgVariableRecord &DVR :
1981 make_early_inc_range(filterDbgVars(I.getDbgRecordRange())))
1982 if (DVR.isDbgAssign())
1983 DVR.eraseFromParent();
1984
1985 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
1986 }
1987 }
1988}
1989
1991 const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
1992 uint64_t SliceSizeInBits, const DbgVariableRecord *AssignRecord,
1993 std::optional<DIExpression::FragmentInfo> &Result) {
1994 // No overlap if this DbgRecord describes a killed location.
1995 if (AssignRecord->isKillAddress())
1996 return false;
1997
1998 int64_t AddrOffsetInBits;
1999 {
2000 int64_t AddrOffsetInBytes;
2001 SmallVector<uint64_t> PostOffsetOps; //< Unused.
2002 // Bail if we can't find a constant offset (or none) in the expression.
2003 if (!AssignRecord->getAddressExpression()->extractLeadingOffset(
2004 AddrOffsetInBytes, PostOffsetOps))
2005 return false;
2006 AddrOffsetInBits = AddrOffsetInBytes * 8;
2007 }
2008
2009 Value *Addr = AssignRecord->getAddress();
2010 // FIXME: It may not always be zero.
2011 int64_t BitExtractOffsetInBits = 0;
2013 AssignRecord->getFragmentOrEntireVariable();
2014
2015 int64_t OffsetFromLocationInBits; //< Unused.
2017 DL, Dest, SliceOffsetInBits, SliceSizeInBits, Addr, AddrOffsetInBits,
2018 BitExtractOffsetInBits, VarFrag, Result, OffsetFromLocationInBits);
2019}
2020
2021/// Update inlined instructions' DIAssignID metadata. We need to do this
2022/// otherwise a function inlined more than once into the same function
2023/// will cause DIAssignID to be shared by many instructions.
2025 Instruction &I) {
2026 auto GetNewID = [&Map](Metadata *Old) {
2027 DIAssignID *OldID = cast<DIAssignID>(Old);
2028 if (DIAssignID *NewID = Map.lookup(OldID))
2029 return NewID;
2031 Map[OldID] = NewID;
2032 return NewID;
2033 };
2034 // If we find a DIAssignID attachment or use, replace it with a new version.
2035 for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
2036 if (DVR.isDbgAssign())
2037 DVR.setAssignId(GetNewID(DVR.getAssignID()));
2038 }
2039 if (auto *ID = I.getMetadata(LLVMContext::MD_DIAssignID))
2040 I.setMetadata(LLVMContext::MD_DIAssignID, GetNewID(ID));
2041}
2042
2043/// Collect constant properties (base, size, offset) of \p StoreDest.
2044/// Return std::nullopt if any properties are not constants or the
2045/// offset from the base pointer is negative.
2046static std::optional<AssignmentInfo>
2047getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest,
2048 TypeSize SizeInBits) {
2049 if (SizeInBits.isScalable())
2050 return std::nullopt;
2051 APInt GEPOffset(DL.getIndexTypeSizeInBits(StoreDest->getType()), 0);
2052 const Value *Base = StoreDest->stripAndAccumulateConstantOffsets(
2053 DL, GEPOffset, /*AllowNonInbounds*/ true);
2054
2055 if (GEPOffset.isNegative())
2056 return std::nullopt;
2057
2058 uint64_t OffsetInBytes = GEPOffset.getLimitedValue();
2059 // Check for overflow.
2060 if (OffsetInBytes == UINT64_MAX)
2061 return std::nullopt;
2062 if (const auto *Alloca = dyn_cast<AllocaInst>(Base))
2063 return AssignmentInfo(DL, Alloca, OffsetInBytes * 8, SizeInBits);
2064 return std::nullopt;
2065}
2066
2067std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2068 const MemIntrinsic *I) {
2069 const Value *StoreDest = I->getRawDest();
2070 // Assume 8 bit bytes.
2071 auto *ConstLengthInBytes = dyn_cast<ConstantInt>(I->getLength());
2072 if (!ConstLengthInBytes)
2073 // We can't use a non-const size, bail.
2074 return std::nullopt;
2075 uint64_t SizeInBits = 8 * ConstLengthInBytes->getZExtValue();
2076 return getAssignmentInfoImpl(DL, StoreDest, TypeSize::getFixed(SizeInBits));
2077}
2078
2079std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2080 const StoreInst *SI) {
2081 TypeSize SizeInBits = DL.getTypeSizeInBits(SI->getValueOperand()->getType());
2082 return getAssignmentInfoImpl(DL, SI->getPointerOperand(), SizeInBits);
2083}
2084
2085std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2086 const AllocaInst *AI) {
2087 TypeSize SizeInBits = DL.getTypeSizeInBits(AI->getAllocatedType());
2088 return getAssignmentInfoImpl(DL, AI, SizeInBits);
2089}
2090
2091/// Returns nullptr if the assignment shouldn't be attributed to this variable.
2093 Instruction &StoreLikeInst, const VarRecord &VarRec,
2094 DIBuilder &DIB) {
2095 auto *ID = StoreLikeInst.getMetadata(LLVMContext::MD_DIAssignID);
2096 assert(ID && "Store instruction must have DIAssignID metadata");
2097 (void)ID;
2098
2099 const uint64_t StoreStartBit = Info.OffsetInBits;
2100 const uint64_t StoreEndBit = Info.OffsetInBits + Info.SizeInBits;
2101
2102 uint64_t FragStartBit = StoreStartBit;
2103 uint64_t FragEndBit = StoreEndBit;
2104
2105 bool StoreToWholeVariable = Info.StoreToWholeAlloca;
2106 if (auto Size = VarRec.Var->getSizeInBits()) {
2107 // NOTE: trackAssignments doesn't understand base expressions yet, so all
2108 // variables that reach here are guaranteed to start at offset 0 in the
2109 // alloca.
2110 const uint64_t VarStartBit = 0;
2111 const uint64_t VarEndBit = *Size;
2112
2113 // FIXME: trim FragStartBit when nonzero VarStartBit is supported.
2114 FragEndBit = std::min(FragEndBit, VarEndBit);
2115
2116 // Discard stores to bits outside this variable.
2117 if (FragStartBit >= FragEndBit)
2118 return;
2119
2120 StoreToWholeVariable = FragStartBit <= VarStartBit && FragEndBit >= *Size;
2121 }
2122
2123 DIExpression *Expr = DIExpression::get(StoreLikeInst.getContext(), {});
2124 if (!StoreToWholeVariable) {
2125 auto R = DIExpression::createFragmentExpression(Expr, FragStartBit,
2126 FragEndBit - FragStartBit);
2127 assert(R.has_value() && "failed to create fragment expression");
2128 Expr = *R;
2129 }
2130 DIExpression *AddrExpr = DIExpression::get(StoreLikeInst.getContext(), {});
2132 &StoreLikeInst, Val, VarRec.Var, Expr, Dest, AddrExpr, VarRec.DL);
2133 (void)Assign;
2134 LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
2135}
2136
2137#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).
2138#define DEBUG_TYPE "assignment-tracking"
2139
2141 const StorageToVarsMap &Vars, const DataLayout &DL,
2142 bool DebugPrints) {
2143 // Early-exit if there are no interesting variables.
2144 if (Vars.empty())
2145 return;
2146
2147 auto &Ctx = Start->getContext();
2148 auto &Module = *Start->getModule();
2149
2150 // Poison type doesn't matter, so long as it isn't void. Let's just use i1.
2152 DIBuilder DIB(Module, /*AllowUnresolved*/ false);
2153
2154 // Scan the instructions looking for stores to local variables' storage.
2155 LLVM_DEBUG(errs() << "# Scanning instructions\n");
2156 for (auto BBI = Start; BBI != End; ++BBI) {
2157 for (Instruction &I : *BBI) {
2158
2159 std::optional<AssignmentInfo> Info;
2160 Value *ValueComponent = nullptr;
2161 Value *DestComponent = nullptr;
2162 if (auto *AI = dyn_cast<AllocaInst>(&I)) {
2163 // We want to track the variable's stack home from its alloca's
2164 // position onwards so we treat it as an assignment (where the stored
2165 // value is poison).
2166 Info = getAssignmentInfo(DL, AI);
2167 ValueComponent = Poison;
2168 DestComponent = AI;
2169 } else if (auto *SI = dyn_cast<StoreInst>(&I)) {
2170 Info = getAssignmentInfo(DL, SI);
2171 ValueComponent = SI->getValueOperand();
2172 DestComponent = SI->getPointerOperand();
2173 } else if (auto *MI = dyn_cast<MemTransferInst>(&I)) {
2174 Info = getAssignmentInfo(DL, MI);
2175 // May not be able to represent this value easily.
2176 ValueComponent = Poison;
2177 DestComponent = MI->getOperand(0);
2178 } else if (auto *MI = dyn_cast<MemSetInst>(&I)) {
2179 Info = getAssignmentInfo(DL, MI);
2180 // If we're zero-initing we can state the assigned value is zero,
2181 // otherwise use undef.
2182 auto *ConstValue = dyn_cast<ConstantInt>(MI->getOperand(1));
2183 if (ConstValue && ConstValue->isZero())
2184 ValueComponent = ConstValue;
2185 else
2186 ValueComponent = Poison;
2187 DestComponent = MI->getOperand(0);
2188 } else {
2189 // Not a store-like instruction.
2190 continue;
2191 }
2192
2193 assert(ValueComponent && DestComponent);
2194 LLVM_DEBUG(errs() << "SCAN: Found store-like: " << I << "\n");
2195
2196 // Check if getAssignmentInfo failed to understand this store.
2197 if (!Info.has_value()) {
2198 LLVM_DEBUG(
2199 errs()
2200 << " | SKIP: Untrackable store (e.g. through non-const gep)\n");
2201 continue;
2202 }
2203 LLVM_DEBUG(errs() << " | BASE: " << *Info->Base << "\n");
2204
2205 // Check if the store destination is a local variable with debug info.
2206 auto LocalIt = Vars.find(Info->Base);
2207 if (LocalIt == Vars.end()) {
2208 LLVM_DEBUG(
2209 errs()
2210 << " | SKIP: Base address not associated with local variable\n");
2211 continue;
2212 }
2213
2214 DIAssignID *ID =
2215 cast_or_null<DIAssignID>(I.getMetadata(LLVMContext::MD_DIAssignID));
2216 if (!ID) {
2218 I.setMetadata(LLVMContext::MD_DIAssignID, ID);
2219 }
2220
2221 for (const VarRecord &R : LocalIt->second)
2222 emitDbgAssign(*Info, ValueComponent, DestComponent, I, R, DIB);
2223 }
2224 }
2225}
2226
2227bool AssignmentTrackingPass::runOnFunction(Function &F) {
2228 // No value in assignment tracking without optimisations.
2229 if (F.hasFnAttribute(Attribute::OptimizeNone))
2230 return /*Changed*/ false;
2231
2232 bool Changed = false;
2233 auto *DL = &F.getDataLayout();
2234 // Collect a map of {backing storage : dbg.declares} (currently "backing
2235 // storage" is limited to Allocas). We'll use this to find dbg.declares to
2236 // delete after running `trackAssignments`.
2238 // Create another similar map of {storage : variables} that we'll pass to
2239 // trackAssignments.
2240 StorageToVarsMap Vars;
2241 auto ProcessDeclare = [&](DbgVariableRecord &Declare) {
2242 // FIXME: trackAssignments doesn't let you specify any modifiers to the
2243 // variable (e.g. fragment) or location (e.g. offset), so we have to
2244 // leave dbg.declares with non-empty expressions in place.
2245 if (Declare.getExpression()->getNumElements() != 0)
2246 return;
2247 if (!Declare.getAddress())
2248 return;
2249 if (AllocaInst *Alloca =
2250 dyn_cast<AllocaInst>(Declare.getAddress()->stripPointerCasts())) {
2251 // FIXME: Skip VLAs for now (let these variables use dbg.declares).
2252 if (!Alloca->isStaticAlloca())
2253 return;
2254 // Similarly, skip scalable vectors (use dbg.declares instead).
2255 if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
2256 return;
2257 DVRDeclares[Alloca].insert(&Declare);
2258 Vars[Alloca].insert(VarRecord(&Declare));
2259 }
2260 };
2261 for (auto &BB : F) {
2262 for (auto &I : BB) {
2263 for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
2264 if (DVR.isDbgDeclare())
2265 ProcessDeclare(DVR);
2266 }
2267 }
2268 }
2269
2270 // FIXME: Locals can be backed by caller allocas (sret, byval).
2271 // Note: trackAssignments doesn't respect dbg.declare's IR positions (as it
2272 // doesn't "understand" dbg.declares). However, this doesn't appear to break
2273 // any rules given this description of dbg.declare from
2274 // llvm/docs/SourceLevelDebugging.rst:
2275 //
2276 // It is not control-dependent, meaning that if a call to llvm.dbg.declare
2277 // exists and has a valid location argument, that address is considered to
2278 // be the true home of the variable across its entire lifetime.
2279 trackAssignments(F.begin(), F.end(), Vars, *DL);
2280
2281 // Delete dbg.declares for variables now tracked with assignment tracking.
2282 for (auto &[Insts, Declares] : DVRDeclares) {
2284 for (auto *Declare : Declares) {
2285 // Assert that the alloca that Declare uses is now linked to a dbg.assign
2286 // describing the same variable (i.e. check that this dbg.declare has
2287 // been replaced by a dbg.assign). Use DebugVariableAggregate to Discard
2288 // the fragment part because trackAssignments may alter the
2289 // fragment. e.g. if the alloca is smaller than the variable, then
2290 // trackAssignments will create an alloca-sized fragment for the
2291 // dbg.assign.
2292 assert(llvm::any_of(Markers, [Declare](auto *Assign) {
2293 return DebugVariableAggregate(Assign) ==
2294 DebugVariableAggregate(Declare);
2295 }));
2296 // Delete Declare because the variable location is now tracked using
2297 // assignment tracking.
2298 Declare->eraseFromParent();
2299 Changed = true;
2300 }
2301 };
2302 return Changed;
2303}
2304
2306 "debug-info-assignment-tracking";
2307
2311 ConstantInt::get(Type::getInt1Ty(M.getContext()), 1)));
2312}
2313
2315 Metadata *Value = M.getModuleFlag(AssignmentTrackingModuleFlag);
2316 return Value && !cast<ConstantAsMetadata>(Value)->getValue()->isZeroValue();
2317}
2318
2322
2325 if (!runOnFunction(F))
2326 return PreservedAnalyses::all();
2327
2328 // Record that this module uses assignment tracking. It doesn't matter that
2329 // some functions in the module may not use it - the debug info in those
2330 // functions will still be handled properly.
2331 setAssignmentTrackingModuleFlag(*F.getParent());
2332
2333 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2334 // return PreservedAnalyses::all()?
2337 return PA;
2338}
2339
2342 bool Changed = false;
2343 for (auto &F : M)
2344 Changed |= runOnFunction(F);
2345
2346 if (!Changed)
2347 return PreservedAnalyses::all();
2348
2349 // Record that this module uses assignment tracking.
2351
2352 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2353 // return PreservedAnalyses::all()?
2356 return PA;
2357}
2358
2359#undef DEBUG_TYPE
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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< 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")
Analysis containing CSE Info
Definition CSEInfo.cpp:27
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
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)
Definition DebugInfo.cpp:84
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
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
This file contains the declarations for metadata subclasses.
#define T
uint64_t IntrinsicInst * II
R600 Emit Clause Markers
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:114
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:330
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:476
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
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:536
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 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...
LLVM_ABI bool extractLeadingOffset(int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps) const
Assuming that the expression operates on an address, extract a constant offset and the successive ops...
ChecksumKind
Which algorithm (e.g.
A pair of DIGlobalVariable and DIExpression.
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.
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 a language name and its version.
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.
Type array for a subprogram.
Base class for types.
DIScope * getScope() const
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:63
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:124
LLVM_ABI DILocation * get() const
Get the underlying DILocation.
Definition DebugLoc.cpp:48
LLVM_ABI MDNode * getScope() const
Definition DebugLoc.cpp:62
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:181
LLVM_ABI DILocation * getInlinedAt() const
Definition DebugLoc.cpp:67
static DebugLoc getDropped()
Definition DebugLoc.h:164
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition DenseMap.h:205
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:233
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
BasicBlockListType::iterator iterator
Definition Function.h:69
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:566
Metadata node.
Definition Metadata.h:1078
LLVM_ABI void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1577
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition Metadata.h:1282
static LLVM_ABI void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1442
ArrayRef< MDOperand > operands() const
Definition Metadata.h:1440
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1569
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1448
bool isDistinct() const
Definition Metadata.h:1261
LLVMContext & getContext() const
Definition Metadata.h:1242
Tracking metadata reference owned by Metadata.
Definition Metadata.h:900
Metadata * get() const
Definition Metadata.h:929
Tuple of metadata.
Definition Metadata.h:1497
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition Metadata.h:1546
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:1757
LLVM_ABI StringRef getName() const
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
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:45
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:293
static LLVM_ABI ValueAsMetadata * getIfExists(Value *V)
Definition Metadata.cpp:522
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
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.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.cpp:1099
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
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:180
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:221
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:209
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:153
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:214
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:204
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:173
@ CSK_SHA1
Definition DebugInfo.h:209
@ CSK_SHA256
Definition DebugInfo.h:209
@ CSK_MD5
Definition DebugInfo.h:209
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
Assignment Tracking (at).
Definition DebugInfo.h:171
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:176
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:193
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:276
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:815
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:708
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:316
@ Length
Definition DWP.cpp:477
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
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:1725
LLVM_ABI void findDbgValues(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the dbg.values describing a value.
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
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
@ Import
Import information from summary.
Definition IPO.h:56
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:632
auto cast_or_null(const Y &Val)
Definition Casting.h:714
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:1732
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
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:65
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
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:351
LLVM_ABI bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
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
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:1961
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:346
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.
PointerUnion< Instruction *, DbgRecord * > DbgInstPtr
Definition DIBuilder.h:44
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:287
Helper struct for trackAssignments, below.
Definition DebugInfo.h:234
DILocation * DL
Definition DebugInfo.h:236
DILocalVariable * Var
Definition DebugInfo.h:235