LLVM 17.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/DenseMap.h"
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/IR/BasicBlock.h"
23#include "llvm/IR/Constants.h"
24#include "llvm/IR/DIBuilder.h"
25#include "llvm/IR/DebugInfo.h"
27#include "llvm/IR/DebugLoc.h"
28#include "llvm/IR/Function.h"
30#include "llvm/IR/Instruction.h"
32#include "llvm/IR/LLVMContext.h"
33#include "llvm/IR/Metadata.h"
34#include "llvm/IR/Module.h"
35#include "llvm/IR/PassManager.h"
37#include <algorithm>
38#include <cassert>
39#include <optional>
40#include <utility>
41
42using namespace llvm;
43using namespace llvm::at;
44using namespace llvm::dwarf;
45
47 // This function is hot. Check whether the value has any metadata to avoid a
48 // DenseMap lookup.
49 if (!V->isUsedByMetadata())
50 return {};
52 if (!L)
53 return {};
54 auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
55 if (!MDV)
56 return {};
57
59 for (User *U : MDV->users()) {
60 if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
61 Declares.push_back(DDI);
62 }
63
64 return Declares;
65}
66
68 // This function is hot. Check whether the value has any metadata to avoid a
69 // DenseMap lookup.
70 if (!V->isUsedByMetadata())
71 return;
72 // TODO: If this value appears multiple times in a DIArgList, we should still
73 // only add the owning DbgValueInst once; use this set to track ArgListUsers.
74 // This behaviour can be removed when we can automatically remove duplicates.
75 SmallPtrSet<DbgValueInst *, 4> EncounteredDbgValues;
76 if (auto *L = LocalAsMetadata::getIfExists(V)) {
77 if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L)) {
78 for (User *U : MDV->users())
79 if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(U))
80 DbgValues.push_back(DVI);
81 }
82 for (Metadata *AL : L->getAllArgListUsers()) {
83 if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), AL)) {
84 for (User *U : MDV->users())
85 if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(U))
86 if (EncounteredDbgValues.insert(DVI).second)
87 DbgValues.push_back(DVI);
88 }
89 }
90 }
91}
92
94 Value *V) {
95 // This function is hot. Check whether the value has any metadata to avoid a
96 // DenseMap lookup.
97 if (!V->isUsedByMetadata())
98 return;
99 // TODO: If this value appears multiple times in a DIArgList, we should still
100 // only add the owning DbgValueInst once; use this set to track ArgListUsers.
101 // This behaviour can be removed when we can automatically remove duplicates.
102 SmallPtrSet<DbgVariableIntrinsic *, 4> EncounteredDbgValues;
103 if (auto *L = LocalAsMetadata::getIfExists(V)) {
104 if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L)) {
105 for (User *U : MDV->users())
106 if (DbgVariableIntrinsic *DII = dyn_cast<DbgVariableIntrinsic>(U))
107 DbgUsers.push_back(DII);
108 }
109 for (Metadata *AL : L->getAllArgListUsers()) {
110 if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), AL)) {
111 for (User *U : MDV->users())
112 if (DbgVariableIntrinsic *DII = dyn_cast<DbgVariableIntrinsic>(U))
113 if (EncounteredDbgValues.insert(DII).second)
114 DbgUsers.push_back(DII);
115 }
116 }
117 }
118}
119
121 if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
122 return LocalScope->getSubprogram();
123 return nullptr;
124}
125
127 // Original dbg.declare must have a location.
128 const DebugLoc &DeclareLoc = DII->getDebugLoc();
129 MDNode *Scope = DeclareLoc.getScope();
130 DILocation *InlinedAt = DeclareLoc.getInlinedAt();
131 // Because no machine insts can come from debug intrinsics, only the scope
132 // and inlinedAt is significant. Zero line numbers are used in case this
133 // DebugLoc leaks into any adjacent instructions. Produce an unknown location
134 // with the correct scope / inlinedAt fields.
135 return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
136}
137
138//===----------------------------------------------------------------------===//
139// DebugInfoFinder implementations.
140//===----------------------------------------------------------------------===//
141
143 CUs.clear();
144 SPs.clear();
145 GVs.clear();
146 TYs.clear();
147 Scopes.clear();
148 NodesSeen.clear();
149}
150
152 for (auto *CU : M.debug_compile_units())
153 processCompileUnit(CU);
154 for (auto &F : M.functions()) {
155 if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
157 // There could be subprograms from inlined functions referenced from
158 // instructions only. Walk the function to find them.
159 for (const BasicBlock &BB : F)
160 for (const Instruction &I : BB)
162 }
163}
164
165void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) {
166 if (!addCompileUnit(CU))
167 return;
168 for (auto *DIG : CU->getGlobalVariables()) {
169 if (!addGlobalVariable(DIG))
170 continue;
171 auto *GV = DIG->getVariable();
172 processScope(GV->getScope());
173 processType(GV->getType());
174 }
175 for (auto *ET : CU->getEnumTypes())
176 processType(ET);
177 for (auto *RT : CU->getRetainedTypes())
178 if (auto *T = dyn_cast<DIType>(RT))
179 processType(T);
180 else
181 processSubprogram(cast<DISubprogram>(RT));
182 for (auto *Import : CU->getImportedEntities()) {
183 auto *Entity = Import->getEntity();
184 if (auto *T = dyn_cast<DIType>(Entity))
185 processType(T);
186 else if (auto *SP = dyn_cast<DISubprogram>(Entity))
188 else if (auto *NS = dyn_cast<DINamespace>(Entity))
189 processScope(NS->getScope());
190 else if (auto *M = dyn_cast<DIModule>(Entity))
191 processScope(M->getScope());
192 }
193}
194
196 const Instruction &I) {
197 if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
198 processVariable(M, *DVI);
199
200 if (auto DbgLoc = I.getDebugLoc())
201 processLocation(M, DbgLoc.get());
202}
203
205 if (!Loc)
206 return;
207 processScope(Loc->getScope());
208 processLocation(M, Loc->getInlinedAt());
209}
210
211void DebugInfoFinder::processType(DIType *DT) {
212 if (!addType(DT))
213 return;
214 processScope(DT->getScope());
215 if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
216 for (DIType *Ref : ST->getTypeArray())
217 processType(Ref);
218 return;
219 }
220 if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
221 processType(DCT->getBaseType());
222 for (Metadata *D : DCT->getElements()) {
223 if (auto *T = dyn_cast<DIType>(D))
224 processType(T);
225 else if (auto *SP = dyn_cast<DISubprogram>(D))
227 }
228 return;
229 }
230 if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
231 processType(DDT->getBaseType());
232 }
233}
234
235void DebugInfoFinder::processScope(DIScope *Scope) {
236 if (!Scope)
237 return;
238 if (auto *Ty = dyn_cast<DIType>(Scope)) {
239 processType(Ty);
240 return;
241 }
242 if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
243 addCompileUnit(CU);
244 return;
245 }
246 if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
248 return;
249 }
250 if (!addScope(Scope))
251 return;
252 if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
253 processScope(LB->getScope());
254 } else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
255 processScope(NS->getScope());
256 } else if (auto *M = dyn_cast<DIModule>(Scope)) {
257 processScope(M->getScope());
258 }
259}
260
262 if (!addSubprogram(SP))
263 return;
264 processScope(SP->getScope());
265 // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
266 // ValueMap containing identity mappings for all of the DICompileUnit's, not
267 // just DISubprogram's, referenced from anywhere within the Function being
268 // cloned prior to calling MapMetadata / RemapInstruction to avoid their
269 // duplication later as DICompileUnit's are also directly referenced by
270 // llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well.
271 // Also, DICompileUnit's may reference DISubprogram's too and therefore need
272 // to be at least looked through.
273 processCompileUnit(SP->getUnit());
274 processType(SP->getType());
275 for (auto *Element : SP->getTemplateParams()) {
276 if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
277 processType(TType->getType());
278 } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
279 processType(TVal->getType());
280 }
281 }
282}
283
285 const DbgVariableIntrinsic &DVI) {
286 auto *N = dyn_cast<MDNode>(DVI.getVariable());
287 if (!N)
288 return;
289
290 auto *DV = dyn_cast<DILocalVariable>(N);
291 if (!DV)
292 return;
293
294 if (!NodesSeen.insert(DV).second)
295 return;
296 processScope(DV->getScope());
297 processType(DV->getType());
298}
299
300bool DebugInfoFinder::addType(DIType *DT) {
301 if (!DT)
302 return false;
303
304 if (!NodesSeen.insert(DT).second)
305 return false;
306
307 TYs.push_back(const_cast<DIType *>(DT));
308 return true;
309}
310
311bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
312 if (!CU)
313 return false;
314 if (!NodesSeen.insert(CU).second)
315 return false;
316
317 CUs.push_back(CU);
318 return true;
319}
320
321bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) {
322 if (!NodesSeen.insert(DIG).second)
323 return false;
324
325 GVs.push_back(DIG);
326 return true;
327}
328
329bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
330 if (!SP)
331 return false;
332
333 if (!NodesSeen.insert(SP).second)
334 return false;
335
336 SPs.push_back(SP);
337 return true;
338}
339
340bool DebugInfoFinder::addScope(DIScope *Scope) {
341 if (!Scope)
342 return false;
343 // FIXME: Ocaml binding generates a scope with no content, we treat it
344 // as null for now.
345 if (Scope->getNumOperands() == 0)
346 return false;
347 if (!NodesSeen.insert(Scope).second)
348 return false;
349 Scopes.push_back(Scope);
350 return true;
351}
352
354 MDNode *OrigLoopID, function_ref<Metadata *(Metadata *)> Updater) {
355 assert(OrigLoopID && OrigLoopID->getNumOperands() > 0 &&
356 "Loop ID needs at least one operand");
357 assert(OrigLoopID && OrigLoopID->getOperand(0).get() == OrigLoopID &&
358 "Loop ID should refer to itself");
359
360 // Save space for the self-referential LoopID.
361 SmallVector<Metadata *, 4> MDs = {nullptr};
362
363 for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) {
364 Metadata *MD = OrigLoopID->getOperand(i);
365 if (!MD)
366 MDs.push_back(nullptr);
367 else if (Metadata *NewMD = Updater(MD))
368 MDs.push_back(NewMD);
369 }
370
371 MDNode *NewLoopID = MDNode::getDistinct(OrigLoopID->getContext(), MDs);
372 // Insert the self-referential LoopID.
373 NewLoopID->replaceOperandWith(0, NewLoopID);
374 return NewLoopID;
375}
376
378 Instruction &I, function_ref<Metadata *(Metadata *)> Updater) {
379 MDNode *OrigLoopID = I.getMetadata(LLVMContext::MD_loop);
380 if (!OrigLoopID)
381 return;
382 MDNode *NewLoopID = updateLoopMetadataDebugLocationsImpl(OrigLoopID, Updater);
383 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
384}
385
386/// Return true if a node is a DILocation or if a DILocation is
387/// indirectly referenced by one of the node's children.
390 Metadata *MD) {
391 MDNode *N = dyn_cast_or_null<MDNode>(MD);
392 if (!N)
393 return false;
394 if (isa<DILocation>(N) || Reachable.count(N))
395 return true;
396 if (!Visited.insert(N).second)
397 return false;
398 for (auto &OpIt : N->operands()) {
399 Metadata *Op = OpIt.get();
400 if (isDILocationReachable(Visited, Reachable, Op)) {
401 // Don't return just yet as we want to visit all MD's children to
402 // initialize DILocationReachable in stripDebugLocFromLoopID
403 Reachable.insert(N);
404 }
405 }
406 return Reachable.count(N);
407}
408
410 SmallPtrSetImpl<Metadata *> &AllDILocation,
411 const SmallPtrSetImpl<Metadata *> &DIReachable,
412 Metadata *MD) {
413 MDNode *N = dyn_cast_or_null<MDNode>(MD);
414 if (!N)
415 return false;
416 if (isa<DILocation>(N) || AllDILocation.count(N))
417 return true;
418 if (!DIReachable.count(N))
419 return false;
420 if (!Visited.insert(N).second)
421 return false;
422 for (auto &OpIt : N->operands()) {
423 Metadata *Op = OpIt.get();
424 if (Op == MD)
425 continue;
426 if (!isAllDILocation(Visited, AllDILocation, DIReachable, Op)) {
427 return false;
428 }
429 }
430 AllDILocation.insert(N);
431 return true;
432}
433
434static Metadata *
436 const SmallPtrSetImpl<Metadata *> &DIReachable, Metadata *MD) {
437 if (isa<DILocation>(MD) || AllDILocation.count(MD))
438 return nullptr;
439
440 if (!DIReachable.count(MD))
441 return MD;
442
443 MDNode *N = dyn_cast_or_null<MDNode>(MD);
444 if (!N)
445 return MD;
446
448 bool HasSelfRef = false;
449 for (unsigned i = 0; i < N->getNumOperands(); ++i) {
450 Metadata *A = N->getOperand(i);
451 if (!A) {
452 Args.push_back(nullptr);
453 } else if (A == MD) {
454 assert(i == 0 && "expected i==0 for self-reference");
455 HasSelfRef = true;
456 Args.push_back(nullptr);
457 } else if (Metadata *NewArg =
458 stripLoopMDLoc(AllDILocation, DIReachable, A)) {
459 Args.push_back(NewArg);
460 }
461 }
462 if (Args.empty() || (HasSelfRef && Args.size() == 1))
463 return nullptr;
464
465 MDNode *NewMD = N->isDistinct() ? MDNode::getDistinct(N->getContext(), Args)
466 : MDNode::get(N->getContext(), Args);
467 if (HasSelfRef)
468 NewMD->replaceOperandWith(0, NewMD);
469 return NewMD;
470}
471
473 assert(!N->operands().empty() && "Missing self reference?");
474 SmallPtrSet<Metadata *, 8> Visited, DILocationReachable, AllDILocation;
475 // If we already visited N, there is nothing to do.
476 if (!Visited.insert(N).second)
477 return N;
478
479 // If there is no debug location, we do not have to rewrite this
480 // MDNode. This loop also initializes DILocationReachable, later
481 // needed by updateLoopMetadataDebugLocationsImpl; the use of
482 // count_if avoids an early exit.
483 if (!llvm::count_if(llvm::drop_begin(N->operands()),
484 [&Visited, &DILocationReachable](const MDOperand &Op) {
485 return isDILocationReachable(
486 Visited, DILocationReachable, Op.get());
487 }))
488 return N;
489
490 Visited.clear();
491 // If there is only the debug location without any actual loop metadata, we
492 // can remove the metadata.
493 if (llvm::all_of(llvm::drop_begin(N->operands()),
494 [&Visited, &AllDILocation,
495 &DILocationReachable](const MDOperand &Op) {
496 return isAllDILocation(Visited, AllDILocation,
497 DILocationReachable, Op.get());
498 }))
499 return nullptr;
500
502 N, [&AllDILocation, &DILocationReachable](Metadata *MD) -> Metadata * {
503 return stripLoopMDLoc(AllDILocation, DILocationReachable, MD);
504 });
505}
506
508 bool Changed = false;
509 if (F.hasMetadata(LLVMContext::MD_dbg)) {
510 Changed = true;
511 F.setSubprogram(nullptr);
512 }
513
515 for (BasicBlock &BB : F) {
517 if (isa<DbgInfoIntrinsic>(&I)) {
518 I.eraseFromParent();
519 Changed = true;
520 continue;
521 }
522 if (I.getDebugLoc()) {
523 Changed = true;
524 I.setDebugLoc(DebugLoc());
525 }
526 if (auto *LoopID = I.getMetadata(LLVMContext::MD_loop)) {
527 auto *NewLoopID = LoopIDsMap.lookup(LoopID);
528 if (!NewLoopID)
529 NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
530 if (NewLoopID != LoopID)
531 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
532 }
533 // Strip other attachments that are or use debug info.
534 if (I.hasMetadataOtherThanDebugLoc()) {
535 // Heapallocsites point into the DIType system.
536 I.setMetadata("heapallocsite", nullptr);
537 // DIAssignID are debug info metadata primitives.
538 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
539 }
540 }
541 }
542 return Changed;
543}
544
546 bool Changed = false;
547
548 for (NamedMDNode &NMD : llvm::make_early_inc_range(M.named_metadata())) {
549 // We're stripping debug info, and without them, coverage information
550 // doesn't quite make sense.
551 if (NMD.getName().startswith("llvm.dbg.") ||
552 NMD.getName() == "llvm.gcov") {
553 NMD.eraseFromParent();
554 Changed = true;
555 }
556 }
557
558 for (Function &F : M)
559 Changed |= stripDebugInfo(F);
560
561 for (auto &GV : M.globals()) {
562 Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
563 }
564
565 if (GVMaterializer *Materializer = M.getMaterializer())
566 Materializer->setStripDebugInfo();
567
568 return Changed;
569}
570
571namespace {
572
573/// Helper class to downgrade -g metadata to -gline-tables-only metadata.
574class DebugTypeInfoRemoval {
576
577public:
578 /// The (void)() type.
579 MDNode *EmptySubroutineType;
580
581private:
582 /// Remember what linkage name we originally had before stripping. If we end
583 /// up making two subprograms identical who originally had different linkage
584 /// names, then we need to make one of them distinct, to avoid them getting
585 /// uniqued. Maps the new node to the old linkage name.
587
588 // TODO: Remember the distinct subprogram we created for a given linkage name,
589 // so that we can continue to unique whenever possible. Map <newly created
590 // node, old linkage name> to the first (possibly distinct) mdsubprogram
591 // created for that combination. This is not strictly needed for correctness,
592 // but can cut down on the number of MDNodes and let us diff cleanly with the
593 // output of -gline-tables-only.
594
595public:
596 DebugTypeInfoRemoval(LLVMContext &C)
597 : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0,
598 MDNode::get(C, {}))) {}
599
600 Metadata *map(Metadata *M) {
601 if (!M)
602 return nullptr;
603 auto Replacement = Replacements.find(M);
604 if (Replacement != Replacements.end())
605 return Replacement->second;
606
607 return M;
608 }
609 MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); }
610
611 /// Recursively remap N and all its referenced children. Does a DF post-order
612 /// traversal, so as to remap bottoms up.
613 void traverseAndRemap(MDNode *N) { traverse(N); }
614
615private:
616 // Create a new DISubprogram, to replace the one given.
617 DISubprogram *getReplacementSubprogram(DISubprogram *MDS) {
618 auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile()));
619 StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
620 DISubprogram *Declaration = nullptr;
621 auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
622 DIType *ContainingType =
623 cast_or_null<DIType>(map(MDS->getContainingType()));
624 auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
625 auto Variables = nullptr;
626 auto TemplateParams = nullptr;
627
628 // Make a distinct DISubprogram, for situations that warrent it.
629 auto distinctMDSubprogram = [&]() {
630 return DISubprogram::getDistinct(
631 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
632 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(),
633 ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(),
634 MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration,
635 Variables);
636 };
637
638 if (MDS->isDistinct())
639 return distinctMDSubprogram();
640
641 auto *NewMDS = DISubprogram::get(
642 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
643 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType,
644 MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(),
645 MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables);
646
647 StringRef OldLinkageName = MDS->getLinkageName();
648
649 // See if we need to make a distinct one.
650 auto OrigLinkage = NewToLinkageName.find(NewMDS);
651 if (OrigLinkage != NewToLinkageName.end()) {
652 if (OrigLinkage->second == OldLinkageName)
653 // We're good.
654 return NewMDS;
655
656 // Otherwise, need to make a distinct one.
657 // TODO: Query the map to see if we already have one.
658 return distinctMDSubprogram();
659 }
660
661 NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
662 return NewMDS;
663 }
664
665 /// Create a new compile unit, to replace the one given
666 DICompileUnit *getReplacementCU(DICompileUnit *CU) {
667 // Drop skeleton CUs.
668 if (CU->getDWOId())
669 return nullptr;
670
671 auto *File = cast_or_null<DIFile>(map(CU->getFile()));
672 MDTuple *EnumTypes = nullptr;
673 MDTuple *RetainedTypes = nullptr;
674 MDTuple *GlobalVariables = nullptr;
675 MDTuple *ImportedEntities = nullptr;
676 return DICompileUnit::getDistinct(
677 CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(),
678 CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
679 CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
680 RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
681 CU->getDWOId(), CU->getSplitDebugInlining(),
682 CU->getDebugInfoForProfiling(), CU->getNameTableKind(),
683 CU->getRangesBaseAddress(), CU->getSysRoot(), CU->getSDK());
684 }
685
686 DILocation *getReplacementMDLocation(DILocation *MLD) {
687 auto *Scope = map(MLD->getScope());
688 auto *InlinedAt = map(MLD->getInlinedAt());
689 if (MLD->isDistinct())
690 return DILocation::getDistinct(MLD->getContext(), MLD->getLine(),
691 MLD->getColumn(), Scope, InlinedAt);
692 return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(),
693 Scope, InlinedAt);
694 }
695
696 /// Create a new generic MDNode, to replace the one given
697 MDNode *getReplacementMDNode(MDNode *N) {
699 Ops.reserve(N->getNumOperands());
700 for (auto &I : N->operands())
701 if (I)
702 Ops.push_back(map(I));
703 auto *Ret = MDNode::get(N->getContext(), Ops);
704 return Ret;
705 }
706
707 /// Attempt to re-map N to a newly created node.
708 void remap(MDNode *N) {
709 if (Replacements.count(N))
710 return;
711
712 auto doRemap = [&](MDNode *N) -> MDNode * {
713 if (!N)
714 return nullptr;
715 if (auto *MDSub = dyn_cast<DISubprogram>(N)) {
716 remap(MDSub->getUnit());
717 return getReplacementSubprogram(MDSub);
718 }
719 if (isa<DISubroutineType>(N))
720 return EmptySubroutineType;
721 if (auto *CU = dyn_cast<DICompileUnit>(N))
722 return getReplacementCU(CU);
723 if (isa<DIFile>(N))
724 return N;
725 if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N))
726 // Remap to our referenced scope (recursively).
727 return mapNode(MDLB->getScope());
728 if (auto *MLD = dyn_cast<DILocation>(N))
729 return getReplacementMDLocation(MLD);
730
731 // Otherwise, if we see these, just drop them now. Not strictly necessary,
732 // but this speeds things up a little.
733 if (isa<DINode>(N))
734 return nullptr;
735
736 return getReplacementMDNode(N);
737 };
738 Replacements[N] = doRemap(N);
739 }
740
741 /// Do the remapping traversal.
742 void traverse(MDNode *);
743};
744
745} // end anonymous namespace
746
747void DebugTypeInfoRemoval::traverse(MDNode *N) {
748 if (!N || Replacements.count(N))
749 return;
750
751 // To avoid cycles, as well as for efficiency sake, we will sometimes prune
752 // parts of the graph.
753 auto prune = [](MDNode *Parent, MDNode *Child) {
754 if (auto *MDS = dyn_cast<DISubprogram>(Parent))
755 return Child == MDS->getRetainedNodes().get();
756 return false;
757 };
758
760 DenseSet<MDNode *> Opened;
761
762 // Visit each node starting at N in post order, and map them.
763 ToVisit.push_back(N);
764 while (!ToVisit.empty()) {
765 auto *N = ToVisit.back();
766 if (!Opened.insert(N).second) {
767 // Close it.
768 remap(N);
769 ToVisit.pop_back();
770 continue;
771 }
772 for (auto &I : N->operands())
773 if (auto *MDN = dyn_cast_or_null<MDNode>(I))
774 if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) &&
775 !isa<DICompileUnit>(MDN))
776 ToVisit.push_back(MDN);
777 }
778}
779
781 bool Changed = false;
782
783 // First off, delete the debug intrinsics.
784 auto RemoveUses = [&](StringRef Name) {
785 if (auto *DbgVal = M.getFunction(Name)) {
786 while (!DbgVal->use_empty())
787 cast<Instruction>(DbgVal->user_back())->eraseFromParent();
788 DbgVal->eraseFromParent();
789 Changed = true;
790 }
791 };
792 RemoveUses("llvm.dbg.declare");
793 RemoveUses("llvm.dbg.label");
794 RemoveUses("llvm.dbg.value");
795
796 // Delete non-CU debug info named metadata nodes.
797 for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
798 NMI != NME;) {
799 NamedMDNode *NMD = &*NMI;
800 ++NMI;
801 // Specifically keep dbg.cu around.
802 if (NMD->getName() == "llvm.dbg.cu")
803 continue;
804 }
805
806 // Drop all dbg attachments from global variables.
807 for (auto &GV : M.globals())
808 GV.eraseMetadata(LLVMContext::MD_dbg);
809
810 DebugTypeInfoRemoval Mapper(M.getContext());
811 auto remap = [&](MDNode *Node) -> MDNode * {
812 if (!Node)
813 return nullptr;
814 Mapper.traverseAndRemap(Node);
815 auto *NewNode = Mapper.mapNode(Node);
816 Changed |= Node != NewNode;
817 Node = NewNode;
818 return NewNode;
819 };
820
821 // Rewrite the DebugLocs to be equivalent to what
822 // -gline-tables-only would have created.
823 for (auto &F : M) {
824 if (auto *SP = F.getSubprogram()) {
825 Mapper.traverseAndRemap(SP);
826 auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
827 Changed |= SP != NewSP;
828 F.setSubprogram(NewSP);
829 }
830 for (auto &BB : F) {
831 for (auto &I : BB) {
832 auto remapDebugLoc = [&](const DebugLoc &DL) -> DebugLoc {
833 auto *Scope = DL.getScope();
834 MDNode *InlinedAt = DL.getInlinedAt();
835 Scope = remap(Scope);
836 InlinedAt = remap(InlinedAt);
837 return DILocation::get(M.getContext(), DL.getLine(), DL.getCol(),
838 Scope, InlinedAt);
839 };
840
841 if (I.getDebugLoc() != DebugLoc())
842 I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
843
844 // Remap DILocations in llvm.loop attachments.
846 if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
847 return remapDebugLoc(Loc).get();
848 return MD;
849 });
850
851 // Strip heapallocsite attachments, they point into the DIType system.
852 if (I.hasMetadataOtherThanDebugLoc())
853 I.setMetadata("heapallocsite", nullptr);
854 }
855 }
856 }
857
858 // Create a new llvm.dbg.cu, which is equivalent to the one
859 // -gline-tables-only would have created.
860 for (auto &NMD : M.named_metadata()) {
862 for (MDNode *Op : NMD.operands())
863 Ops.push_back(remap(Op));
864
865 if (!Changed)
866 continue;
867
868 NMD.clearOperands();
869 for (auto *Op : Ops)
870 if (Op)
871 NMD.addOperand(Op);
872 }
873 return Changed;
874}
875
877 if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
878 M.getModuleFlag("Debug Info Version")))
879 return Val->getZExtValue();
880 return 0;
881}
882
884 const DILocation *LocB) {
886}
887
889 ArrayRef<const Instruction *> SourceInstructions) {
890 // Replace all uses (and attachments) of all the DIAssignIDs
891 // on SourceInstructions with a single merged value.
892 assert(getFunction() && "Uninserted instruction merged");
893 // Collect up the DIAssignID tags.
895 for (const Instruction *I : SourceInstructions) {
896 if (auto *MD = I->getMetadata(LLVMContext::MD_DIAssignID))
897 IDs.push_back(cast<DIAssignID>(MD));
898 assert(getFunction() == I->getFunction() &&
899 "Merging with instruction from another function not allowed");
900 }
901
902 // Add this instruction's DIAssignID too, if it has one.
903 if (auto *MD = getMetadata(LLVMContext::MD_DIAssignID))
904 IDs.push_back(cast<DIAssignID>(MD));
905
906 if (IDs.empty())
907 return; // No DIAssignID tags to process.
908
909 DIAssignID *MergeID = IDs[0];
910 for (auto It = std::next(IDs.begin()), End = IDs.end(); It != End; ++It) {
911 if (*It != MergeID)
912 at::RAUW(*It, MergeID);
913 }
914 setMetadata(LLVMContext::MD_DIAssignID, MergeID);
915}
916
918
920 const DebugLoc &DL = getDebugLoc();
921 if (!DL)
922 return;
923
924 // If this isn't a call, drop the location to allow a location from a
925 // preceding instruction to propagate.
926 bool MayLowerToCall = false;
927 if (isa<CallBase>(this)) {
928 auto *II = dyn_cast<IntrinsicInst>(this);
929 MayLowerToCall =
930 !II || IntrinsicInst::mayLowerToFunctionCall(II->getIntrinsicID());
931 }
932
933 if (!MayLowerToCall) {
935 return;
936 }
937
938 // Set a line 0 location for calls to preserve scope information in case
939 // inlining occurs.
941 if (SP)
942 // If a function scope is available, set it on the line 0 location. When
943 // hoisting a call to a predecessor block, using the function scope avoids
944 // making it look like the callee was reached earlier than it should be.
946 else
947 // The parent function has no scope. Go ahead and drop the location. If
948 // the parent function is inlined, and the callee has a subprogram, the
949 // inliner will attach a location to the call.
950 //
951 // One alternative is to set a line 0 location with the existing scope and
952 // inlinedAt info. The location might be sensitive to when inlining occurs.
954}
955
956//===----------------------------------------------------------------------===//
957// LLVM C API implementations.
958//===----------------------------------------------------------------------===//
959
961 switch (lang) {
962#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
963 case LLVMDWARFSourceLanguage##NAME: \
964 return ID;
965#include "llvm/BinaryFormat/Dwarf.def"
966#undef HANDLE_DW_LANG
967 }
968 llvm_unreachable("Unhandled Tag");
969}
970
971template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) {
972 return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
973}
974
976 return static_cast<DINode::DIFlags>(Flags);
977}
978
980 return static_cast<LLVMDIFlags>(Flags);
981}
982
984pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) {
985 return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized);
986}
987
990}
991
993 return wrap(new DIBuilder(*unwrap(M), false));
994}
995
997 return wrap(new DIBuilder(*unwrap(M)));
998}
999
1002}
1003
1005 return StripDebugInfo(*unwrap(M));
1006}
1007
1009 delete unwrap(Builder);
1010}
1011
1013 unwrap(Builder)->finalize();
1014}
1015
1017 LLVMMetadataRef subprogram) {
1018 unwrap(Builder)->finalizeSubprogram(unwrapDI<DISubprogram>(subprogram));
1019}
1020
1023 LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
1024 LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
1025 unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
1026 LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
1027 LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
1028 const char *SDK, size_t SDKLen) {
1029 auto File = unwrapDI<DIFile>(FileRef);
1030
1031 return wrap(unwrap(Builder)->createCompileUnit(
1033 StringRef(Producer, ProducerLen), isOptimized, StringRef(Flags, FlagsLen),
1034 RuntimeVer, StringRef(SplitName, SplitNameLen),
1035 static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
1036 SplitDebugInlining, DebugInfoForProfiling,
1038 StringRef(SysRoot, SysRootLen), StringRef(SDK, SDKLen)));
1039}
1040
1042LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
1043 size_t FilenameLen, const char *Directory,
1044 size_t DirectoryLen) {
1045 return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
1046 StringRef(Directory, DirectoryLen)));
1047}
1048
1051 const char *Name, size_t NameLen,
1052 const char *ConfigMacros, size_t ConfigMacrosLen,
1053 const char *IncludePath, size_t IncludePathLen,
1054 const char *APINotesFile, size_t APINotesFileLen) {
1055 return wrap(unwrap(Builder)->createModule(
1056 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
1057 StringRef(ConfigMacros, ConfigMacrosLen),
1058 StringRef(IncludePath, IncludePathLen),
1059 StringRef(APINotesFile, APINotesFileLen)));
1060}
1061
1063 LLVMMetadataRef ParentScope,
1064 const char *Name, size_t NameLen,
1065 LLVMBool ExportSymbols) {
1066 return wrap(unwrap(Builder)->createNameSpace(
1067 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols));
1068}
1069
1071 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1072 size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
1073 LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1074 LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
1075 unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
1076 return wrap(unwrap(Builder)->createFunction(
1077 unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
1078 unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine,
1080 pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr,
1081 nullptr, nullptr));
1082}
1083
1084
1086 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1087 LLVMMetadataRef File, unsigned Line, unsigned Col) {
1088 return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope),
1089 unwrapDI<DIFile>(File),
1090 Line, Col));
1091}
1092
1095 LLVMMetadataRef Scope,
1096 LLVMMetadataRef File,
1097 unsigned Discriminator) {
1098 return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope),
1099 unwrapDI<DIFile>(File),
1100 Discriminator));
1101}
1102
1105 LLVMMetadataRef Scope,
1106 LLVMMetadataRef NS,
1107 LLVMMetadataRef File,
1108 unsigned Line) {
1109 return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
1110 unwrapDI<DINamespace>(NS),
1111 unwrapDI<DIFile>(File),
1112 Line));
1113}
1114
1116 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1117 LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line,
1118 LLVMMetadataRef *Elements, unsigned NumElements) {
1119 auto Elts =
1120 (NumElements > 0)
1121 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1122 : nullptr;
1124 unwrapDI<DIScope>(Scope), unwrapDI<DIImportedEntity>(ImportedEntity),
1125 unwrapDI<DIFile>(File), Line, Elts));
1126}
1127
1130 LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements,
1131 unsigned NumElements) {
1132 auto Elts =
1133 (NumElements > 0)
1134 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1135 : nullptr;
1137 unwrapDI<DIScope>(Scope), unwrapDI<DIModule>(M), unwrapDI<DIFile>(File),
1138 Line, Elts));
1139}
1140
1143 LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen,
1144 LLVMMetadataRef *Elements, unsigned NumElements) {
1145 auto Elts =
1146 (NumElements > 0)
1147 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1148 : nullptr;
1149 return wrap(unwrap(Builder)->createImportedDeclaration(
1150 unwrapDI<DIScope>(Scope), unwrapDI<DINode>(Decl), unwrapDI<DIFile>(File),
1151 Line, {Name, NameLen}, Elts));
1152}
1153
1156 unsigned Column, LLVMMetadataRef Scope,
1157 LLVMMetadataRef InlinedAt) {
1158 return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
1159 unwrap(InlinedAt)));
1160}
1161
1163 return unwrapDI<DILocation>(Location)->getLine();
1164}
1165
1167 return unwrapDI<DILocation>(Location)->getColumn();
1168}
1169
1171 return wrap(unwrapDI<DILocation>(Location)->getScope());
1172}
1173
1175 return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
1176}
1177
1179 return wrap(unwrapDI<DIScope>(Scope)->getFile());
1180}
1181
1182const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) {
1183 auto Dir = unwrapDI<DIFile>(File)->getDirectory();
1184 *Len = Dir.size();
1185 return Dir.data();
1186}
1187
1188const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
1189 auto Name = unwrapDI<DIFile>(File)->getFilename();
1190 *Len = Name.size();
1191 return Name.data();
1192}
1193
1194const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
1195 if (auto Src = unwrapDI<DIFile>(File)->getSource()) {
1196 *Len = Src->size();
1197 return Src->data();
1198 }
1199 *Len = 0;
1200 return "";
1201}
1202
1204 LLVMMetadataRef ParentMacroFile,
1205 unsigned Line,
1207 const char *Name, size_t NameLen,
1208 const char *Value, size_t ValueLen) {
1209 return wrap(
1210 unwrap(Builder)->createMacro(unwrapDI<DIMacroFile>(ParentMacroFile), Line,
1211 static_cast<MacinfoRecordType>(RecordType),
1212 {Name, NameLen}, {Value, ValueLen}));
1213}
1214
1217 LLVMMetadataRef ParentMacroFile, unsigned Line,
1218 LLVMMetadataRef File) {
1219 return wrap(unwrap(Builder)->createTempMacroFile(
1220 unwrapDI<DIMacroFile>(ParentMacroFile), Line, unwrapDI<DIFile>(File)));
1221}
1222
1224 const char *Name, size_t NameLen,
1225 int64_t Value,
1226 LLVMBool IsUnsigned) {
1227 return wrap(unwrap(Builder)->createEnumerator({Name, NameLen}, Value,
1228 IsUnsigned != 0));
1229}
1230
1232 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1233 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1234 uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements,
1235 unsigned NumElements, LLVMMetadataRef ClassTy) {
1236auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1237 NumElements});
1238return wrap(unwrap(Builder)->createEnumerationType(
1239 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1240 LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
1241}
1242
1244 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1245 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1246 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1247 LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
1248 const char *UniqueId, size_t UniqueIdLen) {
1249 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1250 NumElements});
1251 return wrap(unwrap(Builder)->createUnionType(
1252 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1253 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1254 Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
1255}
1256
1257
1260 uint32_t AlignInBits, LLVMMetadataRef Ty,
1261 LLVMMetadataRef *Subscripts,
1262 unsigned NumSubscripts) {
1263 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1264 NumSubscripts});
1265 return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
1266 unwrapDI<DIType>(Ty), Subs));
1267}
1268
1271 uint32_t AlignInBits, LLVMMetadataRef Ty,
1272 LLVMMetadataRef *Subscripts,
1273 unsigned NumSubscripts) {
1274 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1275 NumSubscripts});
1276 return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
1277 unwrapDI<DIType>(Ty), Subs));
1278}
1279
1282 size_t NameLen, uint64_t SizeInBits,
1283 LLVMDWARFTypeEncoding Encoding,
1284 LLVMDIFlags Flags) {
1285 return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
1286 SizeInBits, Encoding,
1288}
1289
1291 LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
1292 uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,
1293 const char *Name, size_t NameLen) {
1294 return wrap(unwrap(Builder)->createPointerType(unwrapDI<DIType>(PointeeTy),
1295 SizeInBits, AlignInBits,
1296 AddressSpace, {Name, NameLen}));
1297}
1298
1300 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1301 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1302 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1303 LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
1304 unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
1305 const char *UniqueId, size_t UniqueIdLen) {
1306 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1307 NumElements});
1308 return wrap(unwrap(Builder)->createStructType(
1309 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1310 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1311 unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
1312 unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
1313}
1314
1316 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1317 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
1318 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1319 LLVMMetadataRef Ty) {
1320 return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope),
1321 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
1322 OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty)));
1323}
1324
1327 size_t NameLen) {
1328 return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
1329}
1330
1333 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1334 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1335 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
1336 uint32_t AlignInBits) {
1337 return wrap(unwrap(Builder)->createStaticMemberType(
1338 unwrapDI<DIScope>(Scope), {Name, NameLen},
1339 unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIType>(Type),
1340 map_from_llvmDIFlags(Flags), unwrap<Constant>(ConstantVal),
1341 AlignInBits));
1342}
1343
1346 const char *Name, size_t NameLen,
1347 LLVMMetadataRef File, unsigned LineNo,
1348 uint64_t SizeInBits, uint32_t AlignInBits,
1349 uint64_t OffsetInBits, LLVMDIFlags Flags,
1350 LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
1351 return wrap(unwrap(Builder)->createObjCIVar(
1352 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1353 SizeInBits, AlignInBits, OffsetInBits,
1354 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty),
1355 unwrapDI<MDNode>(PropertyNode)));
1356}
1357
1360 const char *Name, size_t NameLen,
1361 LLVMMetadataRef File, unsigned LineNo,
1362 const char *GetterName, size_t GetterNameLen,
1363 const char *SetterName, size_t SetterNameLen,
1364 unsigned PropertyAttributes,
1365 LLVMMetadataRef Ty) {
1366 return wrap(unwrap(Builder)->createObjCProperty(
1367 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1368 {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
1369 PropertyAttributes, unwrapDI<DIType>(Ty)));
1370}
1371
1375 return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
1376}
1377
1380 const char *Name, size_t NameLen,
1381 LLVMMetadataRef File, unsigned LineNo,
1382 LLVMMetadataRef Scope, uint32_t AlignInBits) {
1383 return wrap(unwrap(Builder)->createTypedef(
1384 unwrapDI<DIType>(Type), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1385 unwrapDI<DIScope>(Scope), AlignInBits));
1386}
1387
1391 uint64_t BaseOffset, uint32_t VBPtrOffset,
1392 LLVMDIFlags Flags) {
1393 return wrap(unwrap(Builder)->createInheritance(
1394 unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy),
1395 BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
1396}
1397
1400 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1401 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1402 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1403 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1404 return wrap(unwrap(Builder)->createForwardDecl(
1405 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1406 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1407 AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
1408}
1409
1412 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1413 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1414 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1415 LLVMDIFlags Flags, const char *UniqueIdentifier,
1416 size_t UniqueIdentifierLen) {
1417 return wrap(unwrap(Builder)->createReplaceableCompositeType(
1418 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1419 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1420 AlignInBits, map_from_llvmDIFlags(Flags),
1421 {UniqueIdentifier, UniqueIdentifierLen}));
1422}
1423
1427 return wrap(unwrap(Builder)->createQualifiedType(Tag,
1428 unwrapDI<DIType>(Type)));
1429}
1430
1434 return wrap(unwrap(Builder)->createReferenceType(Tag,
1435 unwrapDI<DIType>(Type)));
1436}
1437
1440 return wrap(unwrap(Builder)->createNullPtrType());
1441}
1442
1445 LLVMMetadataRef PointeeType,
1446 LLVMMetadataRef ClassType,
1447 uint64_t SizeInBits,
1448 uint32_t AlignInBits,
1449 LLVMDIFlags Flags) {
1450 return wrap(unwrap(Builder)->createMemberPointerType(
1451 unwrapDI<DIType>(PointeeType),
1452 unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
1454}
1455
1458 LLVMMetadataRef Scope,
1459 const char *Name, size_t NameLen,
1460 LLVMMetadataRef File, unsigned LineNumber,
1461 uint64_t SizeInBits,
1462 uint64_t OffsetInBits,
1463 uint64_t StorageOffsetInBits,
1465 return wrap(unwrap(Builder)->createBitFieldMemberType(
1466 unwrapDI<DIScope>(Scope), {Name, NameLen},
1467 unwrapDI<DIFile>(File), LineNumber,
1468 SizeInBits, OffsetInBits, StorageOffsetInBits,
1469 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type)));
1470}
1471
1473 LLVMMetadataRef Scope, const char *Name, size_t NameLen,
1474 LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
1475 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1476 LLVMMetadataRef DerivedFrom,
1477 LLVMMetadataRef *Elements, unsigned NumElements,
1478 LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode,
1479 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1480 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1481 NumElements});
1482 return wrap(unwrap(Builder)->createClassType(
1483 unwrapDI<DIScope>(Scope), {Name, NameLen},
1484 unwrapDI<DIFile>(File), LineNumber,
1485 SizeInBits, AlignInBits, OffsetInBits,
1486 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom),
1487 Elts, unwrapDI<DIType>(VTableHolder),
1488 unwrapDI<MDNode>(TemplateParamsNode),
1489 {UniqueIdentifier, UniqueIdentifierLen}));
1490}
1491
1495 return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
1496}
1497
1499 return unwrapDI<DINode>(MD)->getTag();
1500}
1501
1502const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
1503 StringRef Str = unwrap<DIType>(DType)->getName();
1504 *Length = Str.size();
1505 return Str.data();
1506}
1507
1509 return unwrapDI<DIType>(DType)->getSizeInBits();
1510}
1511
1513 return unwrapDI<DIType>(DType)->getOffsetInBits();
1514}
1515
1517 return unwrapDI<DIType>(DType)->getAlignInBits();
1518}
1519
1521 return unwrapDI<DIType>(DType)->getLine();
1522}
1523
1525 return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags());
1526}
1527
1529 LLVMMetadataRef *Types,
1530 size_t Length) {
1531 return wrap(
1532 unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
1533}
1534
1537 LLVMMetadataRef File,
1538 LLVMMetadataRef *ParameterTypes,
1539 unsigned NumParameterTypes,
1540 LLVMDIFlags Flags) {
1541 auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
1542 NumParameterTypes});
1543 return wrap(unwrap(Builder)->createSubroutineType(
1544 Elts, map_from_llvmDIFlags(Flags)));
1545}
1546
1548 uint64_t *Addr, size_t Length) {
1549 return wrap(
1550 unwrap(Builder)->createExpression(ArrayRef<uint64_t>(Addr, Length)));
1551}
1552
1555 uint64_t Value) {
1556 return wrap(unwrap(Builder)->createConstantValueExpression(Value));
1557}
1558
1560 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1561 size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File,
1562 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1563 LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) {
1564 return wrap(unwrap(Builder)->createGlobalVariableExpression(
1565 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
1566 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1567 true, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
1568 nullptr, AlignInBits));
1569}
1570
1572 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getVariable());
1573}
1574
1576 LLVMMetadataRef GVE) {
1577 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getExpression());
1578}
1579
1581 return wrap(unwrapDI<DIVariable>(Var)->getFile());
1582}
1583
1585 return wrap(unwrapDI<DIVariable>(Var)->getScope());
1586}
1587
1589 return unwrapDI<DIVariable>(Var)->getLine();
1590}
1591
1593 size_t Count) {
1594 return wrap(
1595 MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
1596}
1597
1599 MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode));
1600}
1601
1603 LLVMMetadataRef Replacement) {
1604 auto *Node = unwrapDI<MDNode>(TargetMetadata);
1605 Node->replaceAllUsesWith(unwrap(Replacement));
1607}
1608
1610 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1611 size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File,
1612 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1613 LLVMMetadataRef Decl, uint32_t AlignInBits) {
1614 return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
1615 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen},
1616 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1617 unwrapDI<MDNode>(Decl), nullptr, AlignInBits));
1618}
1619
1622 LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1624 return wrap(unwrap(Builder)->insertDeclare(
1625 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1626 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1627 unwrap<Instruction>(Instr)));
1628}
1629
1631 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1633 return wrap(unwrap(Builder)->insertDeclare(
1634 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1635 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1636 unwrap(Block)));
1637}
1638
1640 LLVMValueRef Val,
1641 LLVMMetadataRef VarInfo,
1642 LLVMMetadataRef Expr,
1644 LLVMValueRef Instr) {
1645 return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1646 unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1647 unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1648 unwrap<Instruction>(Instr)));
1649}
1650
1652 LLVMValueRef Val,
1653 LLVMMetadataRef VarInfo,
1654 LLVMMetadataRef Expr,
1657 return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1658 unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1659 unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1660 unwrap(Block)));
1661}
1662
1664 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1665 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1666 LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) {
1667 return wrap(unwrap(Builder)->createAutoVariable(
1668 unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File),
1669 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1670 map_from_llvmDIFlags(Flags), AlignInBits));
1671}
1672
1674 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1675 size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo,
1676 LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) {
1677 return wrap(unwrap(Builder)->createParameterVariable(
1678 unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File),
1679 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1681}
1682
1684 int64_t Lo, int64_t Count) {
1685 return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
1686}
1687
1690 size_t Length) {
1691 Metadata **DataValue = unwrap(Data);
1692 return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get());
1693}
1694
1696 return wrap(unwrap<Function>(Func)->getSubprogram());
1697}
1698
1700 unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
1701}
1702
1704 return unwrapDI<DISubprogram>(Subprogram)->getLine();
1705}
1706
1708 return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
1709}
1710
1712 if (Loc)
1713 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc)));
1714 else
1715 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
1716}
1717
1719 switch(unwrap(Metadata)->getMetadataID()) {
1720#define HANDLE_METADATA_LEAF(CLASS) \
1721 case Metadata::CLASS##Kind: \
1722 return (LLVMMetadataKind)LLVM##CLASS##MetadataKind;
1723#include "llvm/IR/Metadata.def"
1724 default:
1726 }
1727}
1728
1730 assert(ID && "Expected non-null ID");
1731 LLVMContext &Ctx = ID->getContext();
1732 auto &Map = Ctx.pImpl->AssignmentIDToInstrs;
1733
1734 auto MapIt = Map.find(ID);
1735 if (MapIt == Map.end())
1736 return make_range(nullptr, nullptr);
1737
1738 return make_range(MapIt->second.begin(), MapIt->second.end());
1739}
1740
1742 assert(ID && "Expected non-null ID");
1743 LLVMContext &Ctx = ID->getContext();
1744
1745 auto *IDAsValue = MetadataAsValue::getIfExists(Ctx, ID);
1746
1747 // The ID is only used wrapped in MetadataAsValue(ID), so lets check that
1748 // one of those already exists first.
1749 if (!IDAsValue)
1751
1752 return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
1753}
1754
1756 auto Range = getAssignmentMarkers(Inst);
1757 if (Range.empty())
1758 return;
1759 SmallVector<DbgAssignIntrinsic *> ToDelete(Range.begin(), Range.end());
1760 for (auto *DAI : ToDelete)
1761 DAI->eraseFromParent();
1762}
1763
1765 // Replace MetadataAsValue uses.
1766 if (auto *OldIDAsValue =
1768 auto *NewIDAsValue = MetadataAsValue::get(Old->getContext(), New);
1769 OldIDAsValue->replaceAllUsesWith(NewIDAsValue);
1770 }
1771
1772 // Replace attachments.
1773 AssignmentInstRange InstRange = getAssignmentInsts(Old);
1774 // Use intermediate storage for the instruction ptrs because the
1775 // getAssignmentInsts range iterators will be invalidated by adding and
1776 // removing DIAssignID attachments.
1777 SmallVector<Instruction *> InstVec(InstRange.begin(), InstRange.end());
1778 for (auto *I : InstVec)
1779 I->setMetadata(LLVMContext::MD_DIAssignID, New);
1780}
1781
1784 for (BasicBlock &BB : *F) {
1785 for (Instruction &I : BB) {
1786 if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
1787 ToDelete.push_back(DAI);
1788 else
1789 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
1790 }
1791 }
1792 for (auto *DAI : ToDelete)
1793 DAI->eraseFromParent();
1794}
1795
1796/// Collect constant properies (base, size, offset) of \p StoreDest.
1797/// Return std::nullopt if any properties are not constants.
1798static std::optional<AssignmentInfo>
1799getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest,
1800 uint64_t SizeInBits) {
1801 APInt GEPOffset(DL.getIndexTypeSizeInBits(StoreDest->getType()), 0);
1802 const Value *Base = StoreDest->stripAndAccumulateConstantOffsets(
1803 DL, GEPOffset, /*AllowNonInbounds*/ true);
1804 uint64_t OffsetInBytes = GEPOffset.getLimitedValue();
1805 // Check for overflow.
1806 if (OffsetInBytes == UINT64_MAX)
1807 return std::nullopt;
1808 if (const auto *Alloca = dyn_cast<AllocaInst>(Base))
1809 return AssignmentInfo(DL, Alloca, OffsetInBytes * 8, SizeInBits);
1810 return std::nullopt;
1811}
1812
1813std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
1814 const MemIntrinsic *I) {
1815 const Value *StoreDest = I->getRawDest();
1816 // Assume 8 bit bytes.
1817 auto *ConstLengthInBytes = dyn_cast<ConstantInt>(I->getLength());
1818 if (!ConstLengthInBytes)
1819 // We can't use a non-const size, bail.
1820 return std::nullopt;
1821 uint64_t SizeInBits = 8 * ConstLengthInBytes->getZExtValue();
1822 return getAssignmentInfoImpl(DL, StoreDest, SizeInBits);
1823}
1824
1825std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
1826 const StoreInst *SI) {
1827 const Value *StoreDest = SI->getPointerOperand();
1828 uint64_t SizeInBits = DL.getTypeSizeInBits(SI->getValueOperand()->getType());
1829 return getAssignmentInfoImpl(DL, StoreDest, SizeInBits);
1830}
1831
1832std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
1833 const AllocaInst *AI) {
1834 uint64_t SizeInBits = DL.getTypeSizeInBits(AI->getAllocatedType());
1835 return getAssignmentInfoImpl(DL, AI, SizeInBits);
1836}
1837
1839 Instruction &StoreLikeInst,
1840 const VarRecord &VarRec, DIBuilder &DIB) {
1841 auto *ID = StoreLikeInst.getMetadata(LLVMContext::MD_DIAssignID);
1842 assert(ID && "Store instruction must have DIAssignID metadata");
1843 (void)ID;
1844
1845 DIExpression *Expr =
1846 DIExpression::get(StoreLikeInst.getContext(), std::nullopt);
1847 if (!Info.StoreToWholeAlloca) {
1848 auto R = DIExpression::createFragmentExpression(Expr, Info.OffsetInBits,
1849 Info.SizeInBits);
1850 assert(R.has_value() && "failed to create fragment expression");
1851 Expr = *R;
1852 }
1853 DIExpression *AddrExpr =
1854 DIExpression::get(StoreLikeInst.getContext(), std::nullopt);
1855 return DIB.insertDbgAssign(&StoreLikeInst, Val, VarRec.Var, Expr, Dest,
1856 AddrExpr, VarRec.DL);
1857}
1858
1859#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).
1860#define DEBUG_TYPE "assignment-tracking"
1861
1863 const StorageToVarsMap &Vars, const DataLayout &DL,
1864 bool DebugPrints) {
1865 // Early-exit if there are no interesting variables.
1866 if (Vars.empty())
1867 return;
1868
1869 auto &Ctx = Start->getContext();
1870 auto &Module = *Start->getModule();
1871
1872 // Undef type doesn't matter, so long as it isn't void. Let's just use i1.
1873 auto *Undef = UndefValue::get(Type::getInt1Ty(Ctx));
1874 DIBuilder DIB(Module, /*AllowUnresolved*/ false);
1875
1876 // Scan the instructions looking for stores to local variables' storage.
1877 LLVM_DEBUG(errs() << "# Scanning instructions\n");
1878 for (auto BBI = Start; BBI != End; ++BBI) {
1879 for (Instruction &I : *BBI) {
1880
1881 std::optional<AssignmentInfo> Info;
1882 Value *ValueComponent = nullptr;
1883 Value *DestComponent = nullptr;
1884 if (auto *AI = dyn_cast<AllocaInst>(&I)) {
1885 // We want to track the variable's stack home from its alloca's
1886 // position onwards so we treat it as an assignment (where the stored
1887 // value is Undef).
1888 Info = getAssignmentInfo(DL, AI);
1889 ValueComponent = Undef;
1890 DestComponent = AI;
1891 } else if (auto *SI = dyn_cast<StoreInst>(&I)) {
1893 ValueComponent = SI->getValueOperand();
1894 DestComponent = SI->getPointerOperand();
1895 } else if (auto *MI = dyn_cast<MemTransferInst>(&I)) {
1897 // May not be able to represent this value easily.
1898 ValueComponent = Undef;
1899 DestComponent = MI->getOperand(0);
1900 } else if (auto *MI = dyn_cast<MemSetInst>(&I)) {
1902 // If we're zero-initing we can state the assigned value is zero,
1903 // otherwise use undef.
1904 auto *ConstValue = dyn_cast<ConstantInt>(MI->getOperand(1));
1905 if (ConstValue && ConstValue->isZero())
1906 ValueComponent = ConstValue;
1907 else
1908 ValueComponent = Undef;
1909 DestComponent = MI->getOperand(0);
1910 } else {
1911 // Not a store-like instruction.
1912 continue;
1913 }
1914
1915 assert(ValueComponent && DestComponent);
1916 LLVM_DEBUG(errs() << "SCAN: Found store-like: " << I << "\n");
1917
1918 // Check if getAssignmentInfo failed to understand this store.
1919 if (!Info.has_value()) {
1920 LLVM_DEBUG(
1921 errs()
1922 << " | SKIP: Untrackable store (e.g. through non-const gep)\n");
1923 continue;
1924 }
1925 LLVM_DEBUG(errs() << " | BASE: " << *Info->Base << "\n");
1926
1927 // Check if the store destination is a local variable with debug info.
1928 auto LocalIt = Vars.find(Info->Base);
1929 if (LocalIt == Vars.end()) {
1930 LLVM_DEBUG(
1931 errs()
1932 << " | SKIP: Base address not associated with local variable\n");
1933 continue;
1934 }
1935
1936 DIAssignID *ID =
1937 cast_or_null<DIAssignID>(I.getMetadata(LLVMContext::MD_DIAssignID));
1938 if (!ID) {
1940 I.setMetadata(LLVMContext::MD_DIAssignID, ID);
1941 }
1942
1943 for (const VarRecord &R : LocalIt->second) {
1944 auto *Assign =
1945 emitDbgAssign(*Info, ValueComponent, DestComponent, I, R, DIB);
1946 (void)Assign;
1947 LLVM_DEBUG(errs() << " > INSERT: " << *Assign << "\n");
1948 }
1949 }
1950 }
1951}
1952
1953bool AssignmentTrackingPass::runOnFunction(Function &F) {
1954 bool Changed = false;
1955 // Collect a map of {backing storage : dbg.declares} (currently "backing
1956 // storage" is limited to Allocas). We'll use this to find dbg.declares to
1957 // delete after running `trackAssignments`.
1959 // Create another similar map of {storage : variables} that we'll pass to
1960 // trackAssignments.
1961 StorageToVarsMap Vars;
1962 for (auto &BB : F) {
1963 for (auto &I : BB) {
1964 DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(&I);
1965 if (!DDI)
1966 continue;
1967 // FIXME: trackAssignments doesn't let you specify any modifiers to the
1968 // variable (e.g. fragment) or location (e.g. offset), so we have to
1969 // leave dbg.declares with non-empty expressions in place.
1970 if (DDI->getExpression()->getNumElements() != 0)
1971 continue;
1972 if (AllocaInst *Alloca =
1973 dyn_cast<AllocaInst>(DDI->getAddress()->stripPointerCasts())) {
1974 DbgDeclares[Alloca].insert(DDI);
1975 Vars[Alloca].insert(VarRecord(DDI));
1976 }
1977 }
1978 }
1979
1980 auto DL = std::make_unique<DataLayout>(F.getParent());
1981 // FIXME: Locals can be backed by caller allocas (sret, byval).
1982 // Note: trackAssignments doesn't respect dbg.declare's IR positions (as it
1983 // doesn't "understand" dbg.declares). However, this doesn't appear to break
1984 // any rules given this description of dbg.declare from
1985 // llvm/docs/SourceLevelDebugging.rst:
1986 //
1987 // It is not control-dependent, meaning that if a call to llvm.dbg.declare
1988 // exists and has a valid location argument, that address is considered to
1989 // be the true home of the variable across its entire lifetime.
1990 trackAssignments(F.begin(), F.end(), Vars, *DL);
1991
1992 // Delete dbg.declares for variables now tracked with assignment tracking.
1993 for (auto &P : DbgDeclares) {
1994 const AllocaInst *Alloca = P.first;
1995 auto Markers = at::getAssignmentMarkers(Alloca);
1996 (void)Markers;
1997 for (DbgDeclareInst *DDI : P.second) {
1998 // Assert that the alloca that DDI uses is now linked to a dbg.assign
1999 // describing the same variable (i.e. check that this dbg.declare
2000 // has been replaced by a dbg.assign).
2002 return DebugVariable(DAI) == DebugVariable(DDI);
2003 }));
2004 // Delete DDI because the variable location is now tracked using
2005 // assignment tracking.
2006 DDI->eraseFromParent();
2007 Changed = true;
2008 }
2009 }
2010 return Changed;
2011}
2012
2014 "debug-info-assignment-tracking";
2015
2019 ConstantInt::get(Type::getInt1Ty(M.getContext()), 1)));
2020}
2021
2023 Metadata *Value = M.getModuleFlag(AssignmentTrackingModuleFlag);
2024 return Value && !cast<ConstantAsMetadata>(Value)->getValue()->isZeroValue();
2025}
2026
2029}
2030
2033 if (!runOnFunction(F))
2034 return PreservedAnalyses::all();
2035
2036 // Record that this module uses assignment tracking. It doesn't matter that
2037 // some functons in the module may not use it - the debug info in those
2038 // functions will still be handled properly.
2039 setAssignmentTrackingModuleFlag(*F.getParent());
2040
2041 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2042 // return PreservedAnalyses::all()?
2045 return PA;
2046}
2047
2050 bool Changed = false;
2051 for (auto &F : M)
2052 Changed |= runOnFunction(F);
2053
2054 if (!Changed)
2055 return PreservedAnalyses::all();
2056
2057 // Record that this module uses assignment tracking.
2059
2060 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2061 // return PreservedAnalyses::all()?
2064 return PA;
2065}
2066
2067#undef DEBUG_TYPE
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
assume Assume Builder
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, DINodeArray Elements, SmallVectorImpl< TrackingMDNodeRef > &AllImportedModules)
Definition: DIBuilder.cpp:173
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
Definition: DIBuilder.cpp:837
static void setAssignmentTrackingModuleFlag(Module &M)
Definition: DebugInfo.cpp:2016
static std::optional< AssignmentInfo > getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest, uint64_t SizeInBits)
Collect constant properies (base, size, offset) of StoreDest.
Definition: DebugInfo.cpp:1799
static DISubprogram::DISPFlags pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized)
Definition: DebugInfo.cpp:984
static Metadata * stripLoopMDLoc(const SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
Definition: DebugInfo.cpp:435
static MDNode * updateLoopMetadataDebugLocationsImpl(MDNode *OrigLoopID, function_ref< Metadata *(Metadata *)> Updater)
Definition: DebugInfo.cpp:353
static MDNode * stripDebugLocFromLoopID(MDNode *N)
Definition: DebugInfo.cpp:472
static CallInst * emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest, Instruction &StoreLikeInst, const VarRecord &VarRec, DIBuilder &DIB)
Definition: DebugInfo.cpp:1838
static const char * AssignmentTrackingModuleFlag
Definition: DebugInfo.cpp:2013
static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags)
Definition: DebugInfo.cpp:975
static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang)
Definition: DebugInfo.cpp:960
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags)
Definition: DebugInfo.cpp:979
static bool getAssignmentTrackingModuleFlag(const Module &M)
Definition: DebugInfo.cpp:2022
static bool isAllDILocation(SmallPtrSetImpl< Metadata * > &Visited, SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
Definition: DebugInfo.cpp:409
static bool isDILocationReachable(SmallPtrSetImpl< Metadata * > &Visited, SmallPtrSetImpl< Metadata * > &Reachable, Metadata *MD)
Return true if a node is a DILocation or if a DILocation is indirectly referenced by one of the node'...
Definition: DebugInfo.cpp:388
DIT * unwrapDI(LLVMMetadataRef Ref)
Definition: DebugInfo.cpp:971
#define LLVM_DEBUG(X)
Definition: Debug.h:101
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
uint64_t Addr
std::string Name
uint64_t Size
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
#define P(N)
This header defines various interfaces for pass management in LLVM.
R600 Emit Clause Markers
@ SI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SPIRV::Scope::Scope getScope(SyncScope::ID Ord)
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.
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:27
@ Flags
Definition: TextStubV5.cpp:93
Class for arbitrary precision integers.
Definition: APInt.h:75
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:463
an instruction to allocate memory on the stack
Definition: Instructions.h:58
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:118
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: DebugInfo.cpp:2031
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
Represents analyses that only rely on functions' control flow.
Definition: PassManager.h:113
This class represents a function call, abstracting a target machine's calling convention.
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:419
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:888
Assignment ID.
static DIAssignID * getDistinct(LLVMContext &Context)
DbgAssignIntrinsic * insertDbgAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *SrcVar, DIExpression *ValExpr, Value *Addr, DIExpression *AddrExpr, const DILocation *DL)
Insert a new llvm.dbg.assign intrinsic call.
Definition: DIBuilder.cpp:961
DWARF expression.
unsigned getNumElements() const
static 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...
A pair of DIGlobalVariable and DIExpression.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
Debug location.
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Tagged DWARF-like metadata node.
DIFlags
Debug info flags.
Base class for scope-like contexts.
StringRef getName() const
DIFile * getFile() const
DIScope * getScope() const
Subprogram description.
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
DISPFlags
Debug info subprogram flags.
Type array for a subprogram.
Base class for types.
DIScope * getScope() const
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
This represents the llvm.dbg.assign instruction.
This represents the llvm.dbg.declare instruction.
Value * getAddress() const
This represents the llvm.dbg.value instruction.
This is the common base class for debug info intrinsics for variables.
DILocalVariable * getVariable() const
DIExpression * getExpression() const
void processVariable(const Module &M, const DbgVariableIntrinsic &DVI)
Process DbgVariableIntrinsic.
Definition: DebugInfo.cpp:284
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:195
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:151
void processSubprogram(DISubprogram *SP)
Process subprogram.
Definition: DebugInfo.cpp:261
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:204
void reset()
Clear all lists.
Definition: DebugInfo.cpp:142
A debug info location.
Definition: DebugLoc.h:33
MDNode * getScope() const
Definition: DebugLoc.cpp:34
DILocation * getInlinedAt() const
Definition: DebugLoc.cpp:39
Identifies a unique instance of a variable.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:202
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
bool empty() const
Definition: DenseMap.h:98
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
BasicBlockListType::iterator iterator
Definition: Function.h:65
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1625
void mergeDIAssignID(ArrayRef< const Instruction * > SourceInstructions)
Merge the DIAssignID metadata from this instruction and those attached to instructions in SourceInstr...
Definition: DebugInfo.cpp:888
void dropLocation()
Drop the instruction's debug location.
Definition: DebugInfo.cpp:919
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:358
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:74
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:275
void applyMergedLocation(const DILocation *LocA, const DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
Definition: DebugInfo.cpp:883
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1455
void updateLocationAfterHoist()
Updates the debug location given that the instruction has been hoisted from a block to a predecessor ...
Definition: DebugInfo.cpp:917
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:82
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:355
static bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
DenseMap< DIAssignID *, SmallVector< Instruction *, 1 > > AssignmentIDToInstrs
Map DIAssignID -> Instructions with that attachment.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:69
static LocalAsMetadata * getIfExists(Value *Local)
Definition: Metadata.h:449
Metadata node.
Definition: Metadata.h:943
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:968
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1407
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Definition: Metadata.cpp:940
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1291
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1399
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1297
bool isDistinct() const
Definition: Metadata.h:1126
LLVMContext & getContext() const
Definition: Metadata.h:1107
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:772
Metadata * get() const
Definition: Metadata.h:794
Tuple of metadata.
Definition: Metadata.h:1328
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1376
This is the common base class for memset/memcpy/memmove.
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:102
static MetadataAsValue * getIfExists(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:110
Root of the metadata hierarchy.
Definition: Metadata.h:61
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
@ Max
Takes the max of the two values, which are required to be integers.
Definition: Module.h:147
A tuple of MDNodes.
Definition: Metadata.h:1587
StringRef getName() const
Definition: Metadata.cpp:1232
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
void preserveSet()
Mark an analysis set as preserved.
Definition: PassManager.h:188
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:383
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
bool empty() const
Definition: SmallVector.h:94
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void reserve(size_type N)
Definition: SmallVector.h:667
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
An instruction for storing to memory.
Definition: Instructions.h:301
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition: TinyPtrVector.h:29
void push_back(EltTy NewVal)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static IntegerType * getInt1Ty(LLVMContext &C)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1731
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:685
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
user_iterator_impl< User > user_iterator
Definition: Value.h:390
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
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:97
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
IteratorT end() const
IteratorT begin() const
LLVMMetadataRef LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode)
Create debugging information entry for Objective-C instance variable.
Definition: DebugInfo.cpp:1345
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location)
Get the "inline at" location associated with this debug location.
Definition: DebugInfo.cpp:1174
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Insert a new llvm.dbg.value intrinsic call at the end of the given basic block.
Definition: DebugInfo.cpp:1651
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create an array of DI Nodes.
Definition: DebugInfo.cpp:1688
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef ClassTy)
Create debugging information entry for an enumeration.
Definition: DebugInfo.cpp:1231
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef M, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported module.
Definition: DebugInfo.cpp:1128
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set.
Definition: DebugInfo.cpp:1373
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType)
Get the size of this DIType in bits.
Definition: DebugInfo.cpp:1508
LLVMDWARFMacinfoRecordType
Describes the kind of macro declaration used for LLVMDIBuilderCreateMacro.
Definition: DebugInfo.h:196
LLVMMetadataRef LLVMDIBuilderCreateFunction(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *LinkageName, size_t LinkageNameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool IsLocalToUnit, LLVMBool IsDefinition, unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized)
Create a new descriptor for the specified subprogram.
Definition: DebugInfo.cpp:1070
LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Insert a new llvm.dbg.value intrinsic call before the given instruction.
Definition: DebugInfo.cpp:1639
LLVMMetadataRef LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Type)
Create debugging information entry for a bit field member.
Definition: DebugInfo.cpp:1457
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetVariable(LLVMMetadataRef GVE)
Retrieves the DIVariable associated with this global variable expression.
Definition: DebugInfo.cpp:1571
LLVMMetadataRef LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagArtificial set.
Definition: DebugInfo.cpp:1493
void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder)
Construct any deferred debug info descriptors.
Definition: DebugInfo.cpp:1012
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Discriminator)
Create a descriptor for a lexical block with a new file attached.
Definition: DebugInfo.cpp:1094
unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram)
Get the line associated with a given subprogram.
Definition: DebugInfo.cpp:1703
LLVMMetadataRef LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen)
Create a DWARF unspecified type.
Definition: DebugInfo.cpp:1326
LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, LLVMBool ExportSymbols)
Creates a new descriptor for a namespace with the specified parent scope.
Definition: DebugInfo.cpp:1062
LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt)
Creates a new DebugLocation that describes a source location.
Definition: DebugInfo.cpp:1155
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType)
Get the alignment of this DIType in bits.
Definition: DebugInfo.cpp:1516
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetExpression(LLVMMetadataRef GVE)
Retrieves the DIExpression associated with this global variable expression.
Definition: DebugInfo.cpp:1575
LLVMMetadataRef LLVMDIVariableGetScope(LLVMMetadataRef Var)
Get the metadata of the scope associated with a given variable.
Definition: DebugInfo.cpp:1584
LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst)
Get the debug location for the given instruction.
Definition: DebugInfo.cpp:1707
LLVMMetadataRef LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a c++ style reference or rvalue reference type.
Definition: DebugInfo.cpp:1432
LLVMMetadataRef LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, const char *ConfigMacros, size_t ConfigMacrosLen, const char *IncludePath, size_t IncludePathLen, const char *APINotesFile, size_t APINotesFileLen)
Creates a new descriptor for a module with the specified parent scope.
Definition: DebugInfo.cpp:1050
LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M)
Construct a builder for a module, and do not allow for unresolved nodes attached to the module.
Definition: DebugInfo.cpp:992
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP)
Set the subprogram attached to a function.
Definition: DebugInfo.cpp:1699
LLVMDWARFSourceLanguage
Source languages known by DWARF.
Definition: DebugInfo.h:78
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, int64_t LowerBound, int64_t Count)
Create a descriptor for a value range.
Definition: DebugInfo.cpp:1683
LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M)
Construct a builder for a module and collect unresolved nodes attached to the module in order to reso...
Definition: DebugInfo.cpp:996
void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode)
Deallocate a temporary node.
Definition: DebugInfo.cpp:1598
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location)
Get the local scope associated with this debug location.
Definition: DebugInfo.cpp:1170
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef NS, LLVMMetadataRef File, unsigned Line)
Create a descriptor for an imported namespace.
Definition: DebugInfo.cpp:1104
LLVMMetadataRef LLVMDIBuilderCreateTempMacroFile(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentMacroFile, unsigned Line, LLVMMetadataRef File)
Create debugging information temporary entry for a macro file.
Definition: DebugInfo.cpp:1216
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc)
Set the debug location for the given instruction.
Definition: DebugInfo.cpp:1711
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, int64_t Value, LLVMBool IsUnsigned)
Create debugging information entry for an enumerator.
Definition: DebugInfo.cpp:1223
LLVMValueRef LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Insert a new llvm.dbg.declare intrinsic call before the given instruction.
Definition: DebugInfo.cpp:1621
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, uint64_t *Addr, size_t Length)
Create a new descriptor for the specified variable which has a complex address expression for its add...
Definition: DebugInfo.cpp:1547
LLVMMetadataRef LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts)
Create debugging information entry for a vector type.
Definition: DebugInfo.cpp:1270
LLVMMetadataRef LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeType, LLVMMetadataRef ClassType, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags)
Create debugging information entry for a pointer to member.
Definition: DebugInfo.cpp:1444
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location)
Get the column number of this debug location.
Definition: DebugInfo.cpp:1166
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Insert a new llvm.dbg.declare intrinsic call at the end of the given basic block.
Definition: DebugInfo.cpp:1630
LLVMDIFlags
Debug info flags.
Definition: DebugInfo.h:34
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits)
Create a new descriptor for a local auto variable.
Definition: DebugInfo.cpp:1663
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, size_t NumElements)
Create a new temporary MDNode.
Definition: DebugInfo.cpp:1592
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType)
Get the flags associated with this DIType.
Definition: DebugInfo.cpp:1524
const char * LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len)
Get the directory of a given file.
Definition: DebugInfo.cpp:1182
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TempTargetMetadata, LLVMMetadataRef Replacement)
Replace all uses of temporary metadata.
Definition: DebugInfo.cpp:1602
const char * LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len)
Get the name of a given file.
Definition: DebugInfo.cpp:1188
unsigned LLVMDebugMetadataVersion(void)
The current debug metadata version number.
Definition: DebugInfo.cpp:988
unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef Module)
The version of debug metadata that's present in the provided Module.
Definition: DebugInfo.cpp:1000
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType)
Get the source line where this DIType is declared.
Definition: DebugInfo.cpp:1520
LLVMMetadataRef LLVMDIVariableGetFile(LLVMMetadataRef Var)
Get the metadata of the file associated with a given variable.
Definition: DebugInfo.cpp:1580
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported module that aliases another imported entity descriptor.
Definition: DebugInfo.cpp:1115
LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal, uint32_t AlignInBits)
Create debugging information entry for a C++ static data member.
Definition: DebugInfo.cpp:1332
uint16_t LLVMGetDINodeTag(LLVMMetadataRef MD)
Get the dwarf::Tag of a DINode.
Definition: DebugInfo.cpp:1498
LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits)
Create a new descriptor for the specified variable.
Definition: DebugInfo.cpp:1559
LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Decl, uint32_t AlignInBits)
Create a new descriptor for the specified global variable that is temporary and meant to be RAUWed.
Definition: DebugInfo.cpp:1609
LLVMMetadataRef LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a qualified type, e.g.
Definition: DebugInfo.cpp:1425
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata)
Obtain the enumerated type of a Metadata instance.
Definition: DebugInfo.cpp:1718
LLVMMetadataRef LLVMDIBuilderCreateUnionType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, const char *UniqueId, size_t UniqueIdLen)
Create debugging information entry for a union.
Definition: DebugInfo.cpp:1243
LLVMMetadataRef LLVMDIBuilderCreateForwardDecl(LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create a permanent forward-declared type.
Definition: DebugInfo.cpp:1399
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags)
Create a new descriptor for a function parameter variable.
Definition: DebugInfo.cpp:1673
LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, LLVMMetadataRef File, LLVMMetadataRef *ParameterTypes, unsigned NumParameterTypes, LLVMDIFlags Flags)
Create subroutine type.
Definition: DebugInfo.cpp:1536
LLVMMetadataRef LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, const char *GetterName, size_t GetterNameLen, const char *SetterName, size_t SetterNameLen, unsigned PropertyAttributes, LLVMMetadataRef Ty)
Create debugging information entry for Objective-C property.
Definition: DebugInfo.cpp:1359
LLVMMetadataRef LLVMDIBuilderCreateMacro(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentMacroFile, unsigned Line, LLVMDWARFMacinfoRecordType RecordType, const char *Name, size_t NameLen, const char *Value, size_t ValueLen)
Create debugging information entry for a macro.
Definition: DebugInfo.cpp:1203
LLVMDWARFEmissionKind
The amount of debug information to emit.
Definition: DebugInfo.h:137
LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts)
Create debugging information entry for an array.
Definition: DebugInfo.cpp:1259
LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope)
Get the metadata of the file associated with a given scope.
Definition: DebugInfo.cpp:1178
void LLVMDIBuilderFinalizeSubprogram(LLVMDIBuilderRef Builder, LLVMMetadataRef Subprogram)
Finalize a specific subprogram.
Definition: DebugInfo.cpp:1016
LLVMMetadataRef LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, uint64_t Value)
Create a new descriptor for the specified variable that does not have an address, but does have a con...
Definition: DebugInfo.cpp:1554
LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create debugging information entry for a class.
Definition: DebugInfo.cpp:1472
LLVMMetadataRef LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty)
Create debugging information entry for a member.
Definition: DebugInfo.cpp:1315
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location)
Get the line number of this debug location.
Definition: DebugInfo.cpp:1162
LLVMMetadataRef LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder)
Create C++11 nullptr type.
Definition: DebugInfo.cpp:1439
LLVMMetadataRef LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder, LLVMMetadataRef Ty, LLVMMetadataRef BaseTy, uint64_t BaseOffset, uint32_t VBPtrOffset, LLVMDIFlags Flags)
Create debugging information entry to establish inheritance relationship between two types.
Definition: DebugInfo.cpp:1389
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, LLVMBool isOptimized, const char *Flags, size_t FlagsLen, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen, const char *SDK, size_t SDKLen)
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
Definition: DebugInfo.cpp:1021
LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef Module)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:1004
LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, uint64_t SizeInBits, LLVMDWARFTypeEncoding Encoding, LLVMDIFlags Flags)
Create debugging information entry for a basic type.
Definition: DebugInfo.cpp:1281
unsigned LLVMDIVariableGetLine(LLVMMetadataRef Var)
Get the source line where this DIVariable is declared.
Definition: DebugInfo.cpp:1588
unsigned LLVMDWARFTypeEncoding
An LLVM DWARF type encoding.
Definition: DebugInfo.h:189
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned Column)
Create a descriptor for a lexical block with the specified parent context.
Definition: DebugInfo.cpp:1085
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create a type array.
Definition: DebugInfo.cpp:1528
LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create a temporary forward-declared type.
Definition: DebugInfo.cpp:1411
const char * LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len)
Get the source of a given file.
Definition: DebugInfo.cpp:1194
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType)
Get the offset of this DIType in bits.
Definition: DebugInfo.cpp:1512
LLVMMetadataRef LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef Decl, LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported function, type, or variable.
Definition: DebugInfo.cpp:1141
LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen, const char *Directory, size_t DirectoryLen)
Create a file descriptor to hold debugging information for a file.
Definition: DebugInfo.cpp:1042
const char * LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length)
Get the name of this DIType.
Definition: DebugInfo.cpp:1502
unsigned LLVMMetadataKind
Definition: DebugInfo.h:184
LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope, uint32_t AlignInBits)
Create debugging information entry for a typedef.
Definition: DebugInfo.cpp:1379
LLVMMetadataRef LLVMDIBuilderCreateStructType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder, const char *UniqueId, size_t UniqueIdLen)
Create debugging information entry for a struct.
Definition: DebugInfo.cpp:1299
void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder)
Deallocates the DIBuilder and everything it owns.
Definition: DebugInfo.cpp:1008
LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, const char *Name, size_t NameLen)
Create debugging information entry for a pointer.
Definition: DebugInfo.cpp:1290
LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func)
Get the metadata of the subprogram attached to a function.
Definition: DebugInfo.cpp:1695
@ LLVMGenericDINodeMetadataKind
Definition: DebugInfo.h:155
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:53
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
Definition: Types.h:82
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
Definition: Types.h:89
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
struct LLVMOpaqueDIBuilder * LLVMDIBuilderRef
Represents an LLVM debug info builder.
Definition: Types.h:117
#define UINT64_MAX
Definition: DataTypes.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Assignment Tracking (at).
Definition: DebugInfo.h:166
void deleteAll(Function *F)
Remove all Assignment Tracking related intrinsics and metadata from F.
Definition: DebugInfo.cpp:1782
AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
Definition: DebugInfo.cpp:1729
AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)
Return a range of dbg.assign intrinsics which use \ID as an operand.
Definition: DebugInfo.cpp:1741
void trackAssignments(Function::iterator Start, Function::iterator End, const StorageToVarsMap &Vars, const DataLayout &DL, bool DebugPrints=false)
Track assignments to Vars between Start and End.
Definition: DebugInfo.cpp:1862
void deleteAssignmentMarkers(const Instruction *Inst)
Delete the llvm.dbg.assign intrinsics linked to Inst.
Definition: DebugInfo.cpp:1755
std::optional< AssignmentInfo > getAssignmentInfo(const DataLayout &DL, const MemIntrinsic *I)
Definition: DebugInfo.cpp:1813
void RAUW(DIAssignID *Old, DIAssignID *New)
Replace all uses (and attachments) of Old with New.
Definition: DebugInfo.cpp:1764
MacinfoRecordType
Definition: Dwarf.h:462
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition: STLExtras.h:413
@ Length
Definition: DWP.cpp:406
TinyPtrVector< DbgDeclareInst * > FindDbgDeclareUses(Value *V)
Finds dbg.declare intrinsics declaring local variables as living in the memory that 'V' points to.
Definition: DebugInfo.cpp:46
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:1819
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:507
AddressSpace
Definition: NVPTXBaseInfo.h:21
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
@ Import
Import information from summary.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:748
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:1826
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: DebugInfo.cpp:93
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
bool stripNonLineTableDebugInfo(Module &M)
Downgrade the debug info in a module to contain only line table information.
Definition: DebugInfo.cpp:780
DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII)
Produce a DebugLoc to use for each dbg.declare that is promoted to a dbg.value.
Definition: DebugInfo.cpp:126
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: DebugInfo.cpp:67
unsigned getDebugMetadataVersionFromModule(const Module &M)
Return Debug Info Metadata Version by checking module flags.
Definition: DebugInfo.cpp:876
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:545
@ Ref
The access may reference the value stored in memory.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:290
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
Definition: DebugInfo.cpp:2027
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:2018
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:285
void updateLoopMetadataDebugLocations(Instruction &I, function_ref< Metadata *(Metadata *)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
Definition: DebugInfo.cpp:377
@ DEBUG_METADATA_VERSION
Definition: Metadata.h:51
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:120
#define N
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
Describes properties of a store that has a static size and offset into a some base storage.
Definition: DebugInfo.h:262
Helper struct for trackAssignments, below.
Definition: DebugInfo.h:233
DILocation * DL
Definition: DebugInfo.h:235
DILocalVariable * Var
Definition: DebugInfo.h:234