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