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