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