LLVM 19.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"
29#include "llvm/IR/Function.h"
31#include "llvm/IR/Instruction.h"
33#include "llvm/IR/LLVMContext.h"
34#include "llvm/IR/Metadata.h"
35#include "llvm/IR/Module.h"
36#include "llvm/IR/PassManager.h"
38#include <algorithm>
39#include <cassert>
40#include <optional>
41#include <utility>
42
43using namespace llvm;
44using namespace llvm::at;
45using namespace llvm::dwarf;
46
48 // This function is hot. Check whether the value has any metadata to avoid a
49 // DenseMap lookup.
50 if (!V->isUsedByMetadata())
51 return {};
53 if (!L)
54 return {};
55 auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
56 if (!MDV)
57 return {};
58
60 for (User *U : MDV->users())
61 if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
62 Declares.push_back(DDI);
63
64 return Declares;
65}
67 // This function is hot. Check whether the value has any metadata to avoid a
68 // DenseMap lookup.
69 if (!V->isUsedByMetadata())
70 return {};
72 if (!L)
73 return {};
74
76 for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers())
77 if (DVR->getType() == DbgVariableRecord::LocationType::Declare)
78 Declares.push_back(DVR);
79
80 return Declares;
81}
82
83template <typename IntrinsicT, DbgVariableRecord::LocationType Type =
84 DbgVariableRecord::LocationType::Any>
85static void
87 SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
88 // This function is hot. Check whether the value has any metadata to avoid a
89 // DenseMap lookup.
90 if (!V->isUsedByMetadata())
91 return;
92
93 LLVMContext &Ctx = V->getContext();
94 // TODO: If this value appears multiple times in a DIArgList, we should still
95 // only add the owning DbgValueInst once; use this set to track ArgListUsers.
96 // This behaviour can be removed when we can automatically remove duplicates.
97 // V will also appear twice in a dbg.assign if its used in the both the value
98 // and address components.
99 SmallPtrSet<IntrinsicT *, 4> EncounteredIntrinsics;
100 SmallPtrSet<DbgVariableRecord *, 4> EncounteredDbgVariableRecords;
101
102 /// Append IntrinsicT users of MetadataAsValue(MD).
103 auto AppendUsers = [&Ctx, &EncounteredIntrinsics,
104 &EncounteredDbgVariableRecords, &Result,
105 DbgVariableRecords](Metadata *MD) {
106 if (auto *MDV = MetadataAsValue::getIfExists(Ctx, MD)) {
107 for (User *U : MDV->users())
108 if (IntrinsicT *DVI = dyn_cast<IntrinsicT>(U))
109 if (EncounteredIntrinsics.insert(DVI).second)
110 Result.push_back(DVI);
111 }
112 if (!DbgVariableRecords)
113 return;
114 // Get DbgVariableRecords that use this as a single value.
115 if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
116 for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers()) {
117 if (Type == DbgVariableRecord::LocationType::Any ||
118 DVR->getType() == Type)
119 if (EncounteredDbgVariableRecords.insert(DVR).second)
120 DbgVariableRecords->push_back(DVR);
121 }
122 }
123 };
124
125 if (auto *L = LocalAsMetadata::getIfExists(V)) {
126 AppendUsers(L);
127 for (Metadata *AL : L->getAllArgListUsers()) {
128 AppendUsers(AL);
129 if (!DbgVariableRecords)
130 continue;
131 DIArgList *DI = cast<DIArgList>(AL);
133 if (Type == DbgVariableRecord::LocationType::Any ||
134 DVR->getType() == Type)
135 if (EncounteredDbgVariableRecords.insert(DVR).second)
136 DbgVariableRecords->push_back(DVR);
137 }
138 }
139}
140
143 SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
144 findDbgIntrinsics<DbgValueInst, DbgVariableRecord::LocationType::Value>(
145 DbgValues, V, DbgVariableRecords);
146}
147
150 SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
151 findDbgIntrinsics<DbgVariableIntrinsic, DbgVariableRecord::LocationType::Any>(
152 DbgUsers, V, DbgVariableRecords);
153}
154
156 if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
157 return LocalScope->getSubprogram();
158 return nullptr;
159}
160
162 // Original dbg.declare must have a location.
163 const DebugLoc &DeclareLoc = DII->getDebugLoc();
164 MDNode *Scope = DeclareLoc.getScope();
165 DILocation *InlinedAt = DeclareLoc.getInlinedAt();
166 // Because no machine insts can come from debug intrinsics, only the scope
167 // and inlinedAt is significant. Zero line numbers are used in case this
168 // DebugLoc leaks into any adjacent instructions. Produce an unknown location
169 // with the correct scope / inlinedAt fields.
170 return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
171}
172
174 // Original dbg.declare must have a location.
175 const DebugLoc &DeclareLoc = DVR->getDebugLoc();
176 MDNode *Scope = DeclareLoc.getScope();
177 DILocation *InlinedAt = DeclareLoc.getInlinedAt();
178 // Because no machine insts can come from debug intrinsics, only the scope
179 // and inlinedAt is significant. Zero line numbers are used in case this
180 // DebugLoc leaks into any adjacent instructions. Produce an unknown location
181 // with the correct scope / inlinedAt fields.
182 return DILocation::get(DVR->getContext(), 0, 0, Scope, InlinedAt);
183}
184
185//===----------------------------------------------------------------------===//
186// DebugInfoFinder implementations.
187//===----------------------------------------------------------------------===//
188
190 CUs.clear();
191 SPs.clear();
192 GVs.clear();
193 TYs.clear();
194 Scopes.clear();
195 NodesSeen.clear();
196}
197
199 for (auto *CU : M.debug_compile_units())
200 processCompileUnit(CU);
201 for (auto &F : M.functions()) {
202 if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
204 // There could be subprograms from inlined functions referenced from
205 // instructions only. Walk the function to find them.
206 for (const BasicBlock &BB : F)
207 for (const Instruction &I : BB)
209 }
210}
211
212void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) {
213 if (!addCompileUnit(CU))
214 return;
215 for (auto *DIG : CU->getGlobalVariables()) {
216 if (!addGlobalVariable(DIG))
217 continue;
218 auto *GV = DIG->getVariable();
219 processScope(GV->getScope());
220 processType(GV->getType());
221 }
222 for (auto *ET : CU->getEnumTypes())
223 processType(ET);
224 for (auto *RT : CU->getRetainedTypes())
225 if (auto *T = dyn_cast<DIType>(RT))
226 processType(T);
227 else
228 processSubprogram(cast<DISubprogram>(RT));
229 for (auto *Import : CU->getImportedEntities()) {
230 auto *Entity = Import->getEntity();
231 if (auto *T = dyn_cast<DIType>(Entity))
232 processType(T);
233 else if (auto *SP = dyn_cast<DISubprogram>(Entity))
235 else if (auto *NS = dyn_cast<DINamespace>(Entity))
236 processScope(NS->getScope());
237 else if (auto *M = dyn_cast<DIModule>(Entity))
238 processScope(M->getScope());
239 }
240}
241
243 const Instruction &I) {
244 if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
245 processVariable(M, DVI->getVariable());
246
247 if (auto DbgLoc = I.getDebugLoc())
248 processLocation(M, DbgLoc.get());
249
250 for (const DbgRecord &DPR : I.getDbgRecordRange())
251 processDbgRecord(M, DPR);
252}
253
255 if (!Loc)
256 return;
257 processScope(Loc->getScope());
258 processLocation(M, Loc->getInlinedAt());
259}
260
262 if (const DbgVariableRecord *DVR = dyn_cast<const DbgVariableRecord>(&DR))
263 processVariable(M, DVR->getVariable());
265}
266
267void DebugInfoFinder::processType(DIType *DT) {
268 if (!addType(DT))
269 return;
270 processScope(DT->getScope());
271 if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
272 for (DIType *Ref : ST->getTypeArray())
273 processType(Ref);
274 return;
275 }
276 if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
277 processType(DCT->getBaseType());
278 for (Metadata *D : DCT->getElements()) {
279 if (auto *T = dyn_cast<DIType>(D))
280 processType(T);
281 else if (auto *SP = dyn_cast<DISubprogram>(D))
283 }
284 return;
285 }
286 if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
287 processType(DDT->getBaseType());
288 }
289}
290
291void DebugInfoFinder::processScope(DIScope *Scope) {
292 if (!Scope)
293 return;
294 if (auto *Ty = dyn_cast<DIType>(Scope)) {
295 processType(Ty);
296 return;
297 }
298 if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
299 addCompileUnit(CU);
300 return;
301 }
302 if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
304 return;
305 }
306 if (!addScope(Scope))
307 return;
308 if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
309 processScope(LB->getScope());
310 } else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
311 processScope(NS->getScope());
312 } else if (auto *M = dyn_cast<DIModule>(Scope)) {
313 processScope(M->getScope());
314 }
315}
316
318 if (!addSubprogram(SP))
319 return;
320 processScope(SP->getScope());
321 // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
322 // ValueMap containing identity mappings for all of the DICompileUnit's, not
323 // just DISubprogram's, referenced from anywhere within the Function being
324 // cloned prior to calling MapMetadata / RemapInstruction to avoid their
325 // duplication later as DICompileUnit's are also directly referenced by
326 // llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well.
327 // Also, DICompileUnit's may reference DISubprogram's too and therefore need
328 // to be at least looked through.
329 processCompileUnit(SP->getUnit());
330 processType(SP->getType());
331 for (auto *Element : SP->getTemplateParams()) {
332 if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
333 processType(TType->getType());
334 } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
335 processType(TVal->getType());
336 }
337 }
338}
339
341 const DILocalVariable *DV) {
342 if (!NodesSeen.insert(DV).second)
343 return;
344 processScope(DV->getScope());
345 processType(DV->getType());
346}
347
348bool DebugInfoFinder::addType(DIType *DT) {
349 if (!DT)
350 return false;
351
352 if (!NodesSeen.insert(DT).second)
353 return false;
354
355 TYs.push_back(const_cast<DIType *>(DT));
356 return true;
357}
358
359bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
360 if (!CU)
361 return false;
362 if (!NodesSeen.insert(CU).second)
363 return false;
364
365 CUs.push_back(CU);
366 return true;
367}
368
369bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) {
370 if (!NodesSeen.insert(DIG).second)
371 return false;
372
373 GVs.push_back(DIG);
374 return true;
375}
376
377bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
378 if (!SP)
379 return false;
380
381 if (!NodesSeen.insert(SP).second)
382 return false;
383
384 SPs.push_back(SP);
385 return true;
386}
387
388bool DebugInfoFinder::addScope(DIScope *Scope) {
389 if (!Scope)
390 return false;
391 // FIXME: Ocaml binding generates a scope with no content, we treat it
392 // as null for now.
393 if (Scope->getNumOperands() == 0)
394 return false;
395 if (!NodesSeen.insert(Scope).second)
396 return false;
397 Scopes.push_back(Scope);
398 return true;
399}
400
402 MDNode *OrigLoopID, function_ref<Metadata *(Metadata *)> Updater) {
403 assert(OrigLoopID && OrigLoopID->getNumOperands() > 0 &&
404 "Loop ID needs at least one operand");
405 assert(OrigLoopID && OrigLoopID->getOperand(0).get() == OrigLoopID &&
406 "Loop ID should refer to itself");
407
408 // Save space for the self-referential LoopID.
409 SmallVector<Metadata *, 4> MDs = {nullptr};
410
411 for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) {
412 Metadata *MD = OrigLoopID->getOperand(i);
413 if (!MD)
414 MDs.push_back(nullptr);
415 else if (Metadata *NewMD = Updater(MD))
416 MDs.push_back(NewMD);
417 }
418
419 MDNode *NewLoopID = MDNode::getDistinct(OrigLoopID->getContext(), MDs);
420 // Insert the self-referential LoopID.
421 NewLoopID->replaceOperandWith(0, NewLoopID);
422 return NewLoopID;
423}
424
426 Instruction &I, function_ref<Metadata *(Metadata *)> Updater) {
427 MDNode *OrigLoopID = I.getMetadata(LLVMContext::MD_loop);
428 if (!OrigLoopID)
429 return;
430 MDNode *NewLoopID = updateLoopMetadataDebugLocationsImpl(OrigLoopID, Updater);
431 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
432}
433
434/// Return true if a node is a DILocation or if a DILocation is
435/// indirectly referenced by one of the node's children.
438 Metadata *MD) {
439 MDNode *N = dyn_cast_or_null<MDNode>(MD);
440 if (!N)
441 return false;
442 if (isa<DILocation>(N) || Reachable.count(N))
443 return true;
444 if (!Visited.insert(N).second)
445 return false;
446 for (auto &OpIt : N->operands()) {
447 Metadata *Op = OpIt.get();
448 if (isDILocationReachable(Visited, Reachable, Op)) {
449 // Don't return just yet as we want to visit all MD's children to
450 // initialize DILocationReachable in stripDebugLocFromLoopID
451 Reachable.insert(N);
452 }
453 }
454 return Reachable.count(N);
455}
456
458 SmallPtrSetImpl<Metadata *> &AllDILocation,
459 const SmallPtrSetImpl<Metadata *> &DIReachable,
460 Metadata *MD) {
461 MDNode *N = dyn_cast_or_null<MDNode>(MD);
462 if (!N)
463 return false;
464 if (isa<DILocation>(N) || AllDILocation.count(N))
465 return true;
466 if (!DIReachable.count(N))
467 return false;
468 if (!Visited.insert(N).second)
469 return false;
470 for (auto &OpIt : N->operands()) {
471 Metadata *Op = OpIt.get();
472 if (Op == MD)
473 continue;
474 if (!isAllDILocation(Visited, AllDILocation, DIReachable, Op)) {
475 return false;
476 }
477 }
478 AllDILocation.insert(N);
479 return true;
480}
481
482static Metadata *
484 const SmallPtrSetImpl<Metadata *> &DIReachable, Metadata *MD) {
485 if (isa<DILocation>(MD) || AllDILocation.count(MD))
486 return nullptr;
487
488 if (!DIReachable.count(MD))
489 return MD;
490
491 MDNode *N = dyn_cast_or_null<MDNode>(MD);
492 if (!N)
493 return MD;
494
496 bool HasSelfRef = false;
497 for (unsigned i = 0; i < N->getNumOperands(); ++i) {
498 Metadata *A = N->getOperand(i);
499 if (!A) {
500 Args.push_back(nullptr);
501 } else if (A == MD) {
502 assert(i == 0 && "expected i==0 for self-reference");
503 HasSelfRef = true;
504 Args.push_back(nullptr);
505 } else if (Metadata *NewArg =
506 stripLoopMDLoc(AllDILocation, DIReachable, A)) {
507 Args.push_back(NewArg);
508 }
509 }
510 if (Args.empty() || (HasSelfRef && Args.size() == 1))
511 return nullptr;
512
513 MDNode *NewMD = N->isDistinct() ? MDNode::getDistinct(N->getContext(), Args)
514 : MDNode::get(N->getContext(), Args);
515 if (HasSelfRef)
516 NewMD->replaceOperandWith(0, NewMD);
517 return NewMD;
518}
519
521 assert(!N->operands().empty() && "Missing self reference?");
522 SmallPtrSet<Metadata *, 8> Visited, DILocationReachable, AllDILocation;
523 // If we already visited N, there is nothing to do.
524 if (!Visited.insert(N).second)
525 return N;
526
527 // If there is no debug location, we do not have to rewrite this
528 // MDNode. This loop also initializes DILocationReachable, later
529 // needed by updateLoopMetadataDebugLocationsImpl; the use of
530 // count_if avoids an early exit.
531 if (!llvm::count_if(llvm::drop_begin(N->operands()),
532 [&Visited, &DILocationReachable](const MDOperand &Op) {
533 return isDILocationReachable(
534 Visited, DILocationReachable, Op.get());
535 }))
536 return N;
537
538 Visited.clear();
539 // If there is only the debug location without any actual loop metadata, we
540 // can remove the metadata.
541 if (llvm::all_of(llvm::drop_begin(N->operands()),
542 [&Visited, &AllDILocation,
543 &DILocationReachable](const MDOperand &Op) {
544 return isAllDILocation(Visited, AllDILocation,
545 DILocationReachable, Op.get());
546 }))
547 return nullptr;
548
550 N, [&AllDILocation, &DILocationReachable](Metadata *MD) -> Metadata * {
551 return stripLoopMDLoc(AllDILocation, DILocationReachable, MD);
552 });
553}
554
556 bool Changed = false;
557 if (F.hasMetadata(LLVMContext::MD_dbg)) {
558 Changed = true;
559 F.setSubprogram(nullptr);
560 }
561
563 for (BasicBlock &BB : F) {
565 if (isa<DbgInfoIntrinsic>(&I)) {
566 I.eraseFromParent();
567 Changed = true;
568 continue;
569 }
570 if (I.getDebugLoc()) {
571 Changed = true;
572 I.setDebugLoc(DebugLoc());
573 }
574 if (auto *LoopID = I.getMetadata(LLVMContext::MD_loop)) {
575 auto *NewLoopID = LoopIDsMap.lookup(LoopID);
576 if (!NewLoopID)
577 NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
578 if (NewLoopID != LoopID)
579 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
580 }
581 // Strip other attachments that are or use debug info.
582 if (I.hasMetadataOtherThanDebugLoc()) {
583 // Heapallocsites point into the DIType system.
584 I.setMetadata("heapallocsite", nullptr);
585 // DIAssignID are debug info metadata primitives.
586 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
587 }
588 I.dropDbgRecords();
589 }
590 }
591 return Changed;
592}
593
595 bool Changed = false;
596
597 for (NamedMDNode &NMD : llvm::make_early_inc_range(M.named_metadata())) {
598 // We're stripping debug info, and without them, coverage information
599 // doesn't quite make sense.
600 if (NMD.getName().starts_with("llvm.dbg.") ||
601 NMD.getName() == "llvm.gcov") {
602 NMD.eraseFromParent();
603 Changed = true;
604 }
605 }
606
607 for (Function &F : M)
608 Changed |= stripDebugInfo(F);
609
610 for (auto &GV : M.globals()) {
611 Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
612 }
613
614 if (GVMaterializer *Materializer = M.getMaterializer())
615 Materializer->setStripDebugInfo();
616
617 return Changed;
618}
619
620namespace {
621
622/// Helper class to downgrade -g metadata to -gline-tables-only metadata.
623class DebugTypeInfoRemoval {
625
626public:
627 /// The (void)() type.
628 MDNode *EmptySubroutineType;
629
630private:
631 /// Remember what linkage name we originally had before stripping. If we end
632 /// up making two subprograms identical who originally had different linkage
633 /// names, then we need to make one of them distinct, to avoid them getting
634 /// uniqued. Maps the new node to the old linkage name.
636
637 // TODO: Remember the distinct subprogram we created for a given linkage name,
638 // so that we can continue to unique whenever possible. Map <newly created
639 // node, old linkage name> to the first (possibly distinct) mdsubprogram
640 // created for that combination. This is not strictly needed for correctness,
641 // but can cut down on the number of MDNodes and let us diff cleanly with the
642 // output of -gline-tables-only.
643
644public:
645 DebugTypeInfoRemoval(LLVMContext &C)
646 : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0,
647 MDNode::get(C, {}))) {}
648
649 Metadata *map(Metadata *M) {
650 if (!M)
651 return nullptr;
652 auto Replacement = Replacements.find(M);
653 if (Replacement != Replacements.end())
654 return Replacement->second;
655
656 return M;
657 }
658 MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); }
659
660 /// Recursively remap N and all its referenced children. Does a DF post-order
661 /// traversal, so as to remap bottoms up.
662 void traverseAndRemap(MDNode *N) { traverse(N); }
663
664private:
665 // Create a new DISubprogram, to replace the one given.
666 DISubprogram *getReplacementSubprogram(DISubprogram *MDS) {
667 auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile()));
668 StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
669 DISubprogram *Declaration = nullptr;
670 auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
671 DIType *ContainingType =
672 cast_or_null<DIType>(map(MDS->getContainingType()));
673 auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
674 auto Variables = nullptr;
675 auto TemplateParams = nullptr;
676
677 // Make a distinct DISubprogram, for situations that warrent it.
678 auto distinctMDSubprogram = [&]() {
679 return DISubprogram::getDistinct(
680 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
681 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(),
682 ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(),
683 MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration,
684 Variables);
685 };
686
687 if (MDS->isDistinct())
688 return distinctMDSubprogram();
689
690 auto *NewMDS = DISubprogram::get(
691 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
692 FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType,
693 MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(),
694 MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables);
695
696 StringRef OldLinkageName = MDS->getLinkageName();
697
698 // See if we need to make a distinct one.
699 auto OrigLinkage = NewToLinkageName.find(NewMDS);
700 if (OrigLinkage != NewToLinkageName.end()) {
701 if (OrigLinkage->second == OldLinkageName)
702 // We're good.
703 return NewMDS;
704
705 // Otherwise, need to make a distinct one.
706 // TODO: Query the map to see if we already have one.
707 return distinctMDSubprogram();
708 }
709
710 NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
711 return NewMDS;
712 }
713
714 /// Create a new compile unit, to replace the one given
715 DICompileUnit *getReplacementCU(DICompileUnit *CU) {
716 // Drop skeleton CUs.
717 if (CU->getDWOId())
718 return nullptr;
719
720 auto *File = cast_or_null<DIFile>(map(CU->getFile()));
721 MDTuple *EnumTypes = nullptr;
722 MDTuple *RetainedTypes = nullptr;
723 MDTuple *GlobalVariables = nullptr;
724 MDTuple *ImportedEntities = nullptr;
725 return DICompileUnit::getDistinct(
726 CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(),
727 CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
728 CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
729 RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
730 CU->getDWOId(), CU->getSplitDebugInlining(),
731 CU->getDebugInfoForProfiling(), CU->getNameTableKind(),
732 CU->getRangesBaseAddress(), CU->getSysRoot(), CU->getSDK());
733 }
734
735 DILocation *getReplacementMDLocation(DILocation *MLD) {
736 auto *Scope = map(MLD->getScope());
737 auto *InlinedAt = map(MLD->getInlinedAt());
738 if (MLD->isDistinct())
739 return DILocation::getDistinct(MLD->getContext(), MLD->getLine(),
740 MLD->getColumn(), Scope, InlinedAt);
741 return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(),
742 Scope, InlinedAt);
743 }
744
745 /// Create a new generic MDNode, to replace the one given
746 MDNode *getReplacementMDNode(MDNode *N) {
748 Ops.reserve(N->getNumOperands());
749 for (auto &I : N->operands())
750 if (I)
751 Ops.push_back(map(I));
752 auto *Ret = MDNode::get(N->getContext(), Ops);
753 return Ret;
754 }
755
756 /// Attempt to re-map N to a newly created node.
757 void remap(MDNode *N) {
758 if (Replacements.count(N))
759 return;
760
761 auto doRemap = [&](MDNode *N) -> MDNode * {
762 if (!N)
763 return nullptr;
764 if (auto *MDSub = dyn_cast<DISubprogram>(N)) {
765 remap(MDSub->getUnit());
766 return getReplacementSubprogram(MDSub);
767 }
768 if (isa<DISubroutineType>(N))
769 return EmptySubroutineType;
770 if (auto *CU = dyn_cast<DICompileUnit>(N))
771 return getReplacementCU(CU);
772 if (isa<DIFile>(N))
773 return N;
774 if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N))
775 // Remap to our referenced scope (recursively).
776 return mapNode(MDLB->getScope());
777 if (auto *MLD = dyn_cast<DILocation>(N))
778 return getReplacementMDLocation(MLD);
779
780 // Otherwise, if we see these, just drop them now. Not strictly necessary,
781 // but this speeds things up a little.
782 if (isa<DINode>(N))
783 return nullptr;
784
785 return getReplacementMDNode(N);
786 };
787 Replacements[N] = doRemap(N);
788 }
789
790 /// Do the remapping traversal.
791 void traverse(MDNode *);
792};
793
794} // end anonymous namespace
795
796void DebugTypeInfoRemoval::traverse(MDNode *N) {
797 if (!N || Replacements.count(N))
798 return;
799
800 // To avoid cycles, as well as for efficiency sake, we will sometimes prune
801 // parts of the graph.
802 auto prune = [](MDNode *Parent, MDNode *Child) {
803 if (auto *MDS = dyn_cast<DISubprogram>(Parent))
804 return Child == MDS->getRetainedNodes().get();
805 return false;
806 };
807
809 DenseSet<MDNode *> Opened;
810
811 // Visit each node starting at N in post order, and map them.
812 ToVisit.push_back(N);
813 while (!ToVisit.empty()) {
814 auto *N = ToVisit.back();
815 if (!Opened.insert(N).second) {
816 // Close it.
817 remap(N);
818 ToVisit.pop_back();
819 continue;
820 }
821 for (auto &I : N->operands())
822 if (auto *MDN = dyn_cast_or_null<MDNode>(I))
823 if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) &&
824 !isa<DICompileUnit>(MDN))
825 ToVisit.push_back(MDN);
826 }
827}
828
830 bool Changed = false;
831
832 // First off, delete the debug intrinsics.
833 auto RemoveUses = [&](StringRef Name) {
834 if (auto *DbgVal = M.getFunction(Name)) {
835 while (!DbgVal->use_empty())
836 cast<Instruction>(DbgVal->user_back())->eraseFromParent();
837 DbgVal->eraseFromParent();
838 Changed = true;
839 }
840 };
841 RemoveUses("llvm.dbg.declare");
842 RemoveUses("llvm.dbg.label");
843 RemoveUses("llvm.dbg.value");
844
845 // Delete non-CU debug info named metadata nodes.
846 for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
847 NMI != NME;) {
848 NamedMDNode *NMD = &*NMI;
849 ++NMI;
850 // Specifically keep dbg.cu around.
851 if (NMD->getName() == "llvm.dbg.cu")
852 continue;
853 }
854
855 // Drop all dbg attachments from global variables.
856 for (auto &GV : M.globals())
857 GV.eraseMetadata(LLVMContext::MD_dbg);
858
859 DebugTypeInfoRemoval Mapper(M.getContext());
860 auto remap = [&](MDNode *Node) -> MDNode * {
861 if (!Node)
862 return nullptr;
863 Mapper.traverseAndRemap(Node);
864 auto *NewNode = Mapper.mapNode(Node);
865 Changed |= Node != NewNode;
866 Node = NewNode;
867 return NewNode;
868 };
869
870 // Rewrite the DebugLocs to be equivalent to what
871 // -gline-tables-only would have created.
872 for (auto &F : M) {
873 if (auto *SP = F.getSubprogram()) {
874 Mapper.traverseAndRemap(SP);
875 auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
876 Changed |= SP != NewSP;
877 F.setSubprogram(NewSP);
878 }
879 for (auto &BB : F) {
880 for (auto &I : BB) {
881 auto remapDebugLoc = [&](const DebugLoc &DL) -> DebugLoc {
882 auto *Scope = DL.getScope();
883 MDNode *InlinedAt = DL.getInlinedAt();
884 Scope = remap(Scope);
885 InlinedAt = remap(InlinedAt);
886 return DILocation::get(M.getContext(), DL.getLine(), DL.getCol(),
887 Scope, InlinedAt);
888 };
889
890 if (I.getDebugLoc() != DebugLoc())
891 I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
892
893 // Remap DILocations in llvm.loop attachments.
895 if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
896 return remapDebugLoc(Loc).get();
897 return MD;
898 });
899
900 // Strip heapallocsite attachments, they point into the DIType system.
901 if (I.hasMetadataOtherThanDebugLoc())
902 I.setMetadata("heapallocsite", nullptr);
903
904 // Strip any DbgRecords attached.
905 I.dropDbgRecords();
906 }
907 }
908 }
909
910 // Create a new llvm.dbg.cu, which is equivalent to the one
911 // -gline-tables-only would have created.
912 for (auto &NMD : M.named_metadata()) {
914 for (MDNode *Op : NMD.operands())
915 Ops.push_back(remap(Op));
916
917 if (!Changed)
918 continue;
919
920 NMD.clearOperands();
921 for (auto *Op : Ops)
922 if (Op)
923 NMD.addOperand(Op);
924 }
925 return Changed;
926}
927
929 if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
930 M.getModuleFlag("Debug Info Version")))
931 return Val->getZExtValue();
932 return 0;
933}
934
937}
938
940 ArrayRef<const Instruction *> SourceInstructions) {
941 // Replace all uses (and attachments) of all the DIAssignIDs
942 // on SourceInstructions with a single merged value.
943 assert(getFunction() && "Uninserted instruction merged");
944 // Collect up the DIAssignID tags.
946 for (const Instruction *I : SourceInstructions) {
947 if (auto *MD = I->getMetadata(LLVMContext::MD_DIAssignID))
948 IDs.push_back(cast<DIAssignID>(MD));
949 assert(getFunction() == I->getFunction() &&
950 "Merging with instruction from another function not allowed");
951 }
952
953 // Add this instruction's DIAssignID too, if it has one.
954 if (auto *MD = getMetadata(LLVMContext::MD_DIAssignID))
955 IDs.push_back(cast<DIAssignID>(MD));
956
957 if (IDs.empty())
958 return; // No DIAssignID tags to process.
959
960 DIAssignID *MergeID = IDs[0];
961 for (auto It = std::next(IDs.begin()), End = IDs.end(); It != End; ++It) {
962 if (*It != MergeID)
963 at::RAUW(*It, MergeID);
964 }
965 setMetadata(LLVMContext::MD_DIAssignID, MergeID);
966}
967
969
971 const DebugLoc &DL = getDebugLoc();
972 if (!DL)
973 return;
974
975 // If this isn't a call, drop the location to allow a location from a
976 // preceding instruction to propagate.
977 bool MayLowerToCall = false;
978 if (isa<CallBase>(this)) {
979 auto *II = dyn_cast<IntrinsicInst>(this);
980 MayLowerToCall =
981 !II || IntrinsicInst::mayLowerToFunctionCall(II->getIntrinsicID());
982 }
983
984 if (!MayLowerToCall) {
986 return;
987 }
988
989 // Set a line 0 location for calls to preserve scope information in case
990 // inlining occurs.
992 if (SP)
993 // If a function scope is available, set it on the line 0 location. When
994 // hoisting a call to a predecessor block, using the function scope avoids
995 // making it look like the callee was reached earlier than it should be.
997 else
998 // The parent function has no scope. Go ahead and drop the location. If
999 // the parent function is inlined, and the callee has a subprogram, the
1000 // inliner will attach a location to the call.
1001 //
1002 // One alternative is to set a line 0 location with the existing scope and
1003 // inlinedAt info. The location might be sensitive to when inlining occurs.
1005}
1006
1007//===----------------------------------------------------------------------===//
1008// LLVM C API implementations.
1009//===----------------------------------------------------------------------===//
1010
1012 switch (lang) {
1013#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
1014 case LLVMDWARFSourceLanguage##NAME: \
1015 return ID;
1016#include "llvm/BinaryFormat/Dwarf.def"
1017#undef HANDLE_DW_LANG
1018 }
1019 llvm_unreachable("Unhandled Tag");
1020}
1021
1022template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) {
1023 return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
1024}
1025
1027 return static_cast<DINode::DIFlags>(Flags);
1028}
1029
1031 return static_cast<LLVMDIFlags>(Flags);
1032}
1033
1035pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) {
1036 return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized);
1037}
1038
1041}
1042
1044 return wrap(new DIBuilder(*unwrap(M), false));
1045}
1046
1048 return wrap(new DIBuilder(*unwrap(M)));
1049}
1050
1053}
1054
1056 return StripDebugInfo(*unwrap(M));
1057}
1058
1060 delete unwrap(Builder);
1061}
1062
1064 unwrap(Builder)->finalize();
1065}
1066
1068 LLVMMetadataRef subprogram) {
1069 unwrap(Builder)->finalizeSubprogram(unwrapDI<DISubprogram>(subprogram));
1070}
1071
1074 LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
1075 LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
1076 unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
1077 LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
1078 LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
1079 const char *SDK, size_t SDKLen) {
1080 auto File = unwrapDI<DIFile>(FileRef);
1081
1082 return wrap(unwrap(Builder)->createCompileUnit(
1084 StringRef(Producer, ProducerLen), isOptimized, StringRef(Flags, FlagsLen),
1085 RuntimeVer, StringRef(SplitName, SplitNameLen),
1086 static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
1087 SplitDebugInlining, DebugInfoForProfiling,
1089 StringRef(SysRoot, SysRootLen), StringRef(SDK, SDKLen)));
1090}
1091
1093LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
1094 size_t FilenameLen, const char *Directory,
1095 size_t DirectoryLen) {
1096 return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
1097 StringRef(Directory, DirectoryLen)));
1098}
1099
1102 const char *Name, size_t NameLen,
1103 const char *ConfigMacros, size_t ConfigMacrosLen,
1104 const char *IncludePath, size_t IncludePathLen,
1105 const char *APINotesFile, size_t APINotesFileLen) {
1106 return wrap(unwrap(Builder)->createModule(
1107 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
1108 StringRef(ConfigMacros, ConfigMacrosLen),
1109 StringRef(IncludePath, IncludePathLen),
1110 StringRef(APINotesFile, APINotesFileLen)));
1111}
1112
1114 LLVMMetadataRef ParentScope,
1115 const char *Name, size_t NameLen,
1116 LLVMBool ExportSymbols) {
1117 return wrap(unwrap(Builder)->createNameSpace(
1118 unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols));
1119}
1120
1122 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1123 size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
1124 LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1125 LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
1126 unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
1127 return wrap(unwrap(Builder)->createFunction(
1128 unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
1129 unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine,
1130 map_from_llvmDIFlags(Flags),
1131 pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr,
1132 nullptr, nullptr));
1133}
1134
1135
1137 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1138 LLVMMetadataRef File, unsigned Line, unsigned Col) {
1139 return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope),
1140 unwrapDI<DIFile>(File),
1141 Line, Col));
1142}
1143
1146 LLVMMetadataRef Scope,
1147 LLVMMetadataRef File,
1148 unsigned Discriminator) {
1149 return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope),
1150 unwrapDI<DIFile>(File),
1151 Discriminator));
1152}
1153
1156 LLVMMetadataRef Scope,
1157 LLVMMetadataRef NS,
1158 LLVMMetadataRef File,
1159 unsigned Line) {
1160 return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
1161 unwrapDI<DINamespace>(NS),
1162 unwrapDI<DIFile>(File),
1163 Line));
1164}
1165
1167 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
1168 LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line,
1169 LLVMMetadataRef *Elements, unsigned NumElements) {
1170 auto Elts =
1171 (NumElements > 0)
1172 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1173 : nullptr;
1174 return wrap(unwrap(Builder)->createImportedModule(
1175 unwrapDI<DIScope>(Scope), unwrapDI<DIImportedEntity>(ImportedEntity),
1176 unwrapDI<DIFile>(File), Line, Elts));
1177}
1178
1181 LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements,
1182 unsigned NumElements) {
1183 auto Elts =
1184 (NumElements > 0)
1185 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1186 : nullptr;
1187 return wrap(unwrap(Builder)->createImportedModule(
1188 unwrapDI<DIScope>(Scope), unwrapDI<DIModule>(M), unwrapDI<DIFile>(File),
1189 Line, Elts));
1190}
1191
1194 LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen,
1195 LLVMMetadataRef *Elements, unsigned NumElements) {
1196 auto Elts =
1197 (NumElements > 0)
1198 ? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
1199 : nullptr;
1200 return wrap(unwrap(Builder)->createImportedDeclaration(
1201 unwrapDI<DIScope>(Scope), unwrapDI<DINode>(Decl), unwrapDI<DIFile>(File),
1202 Line, {Name, NameLen}, Elts));
1203}
1204
1207 unsigned Column, LLVMMetadataRef Scope,
1208 LLVMMetadataRef InlinedAt) {
1209 return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
1210 unwrap(InlinedAt)));
1211}
1212
1214 return unwrapDI<DILocation>(Location)->getLine();
1215}
1216
1218 return unwrapDI<DILocation>(Location)->getColumn();
1219}
1220
1222 return wrap(unwrapDI<DILocation>(Location)->getScope());
1223}
1224
1226 return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
1227}
1228
1230 return wrap(unwrapDI<DIScope>(Scope)->getFile());
1231}
1232
1233const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) {
1234 auto Dir = unwrapDI<DIFile>(File)->getDirectory();
1235 *Len = Dir.size();
1236 return Dir.data();
1237}
1238
1239const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
1240 auto Name = unwrapDI<DIFile>(File)->getFilename();
1241 *Len = Name.size();
1242 return Name.data();
1243}
1244
1245const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
1246 if (auto Src = unwrapDI<DIFile>(File)->getSource()) {
1247 *Len = Src->size();
1248 return Src->data();
1249 }
1250 *Len = 0;
1251 return "";
1252}
1253
1255 LLVMMetadataRef ParentMacroFile,
1256 unsigned Line,
1258 const char *Name, size_t NameLen,
1259 const char *Value, size_t ValueLen) {
1260 return wrap(
1261 unwrap(Builder)->createMacro(unwrapDI<DIMacroFile>(ParentMacroFile), Line,
1262 static_cast<MacinfoRecordType>(RecordType),
1263 {Name, NameLen}, {Value, ValueLen}));
1264}
1265
1268 LLVMMetadataRef ParentMacroFile, unsigned Line,
1269 LLVMMetadataRef File) {
1270 return wrap(unwrap(Builder)->createTempMacroFile(
1271 unwrapDI<DIMacroFile>(ParentMacroFile), Line, unwrapDI<DIFile>(File)));
1272}
1273
1275 const char *Name, size_t NameLen,
1276 int64_t Value,
1277 LLVMBool IsUnsigned) {
1278 return wrap(unwrap(Builder)->createEnumerator({Name, NameLen}, Value,
1279 IsUnsigned != 0));
1280}
1281
1283 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1284 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1285 uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements,
1286 unsigned NumElements, LLVMMetadataRef ClassTy) {
1287auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1288 NumElements});
1289return wrap(unwrap(Builder)->createEnumerationType(
1290 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1291 LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
1292}
1293
1295 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1296 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1297 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1298 LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
1299 const char *UniqueId, size_t UniqueIdLen) {
1300 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1301 NumElements});
1302 return wrap(unwrap(Builder)->createUnionType(
1303 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1304 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1305 Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
1306}
1307
1308
1311 uint32_t AlignInBits, LLVMMetadataRef Ty,
1312 LLVMMetadataRef *Subscripts,
1313 unsigned NumSubscripts) {
1314 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1315 NumSubscripts});
1316 return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
1317 unwrapDI<DIType>(Ty), Subs));
1318}
1319
1322 uint32_t AlignInBits, LLVMMetadataRef Ty,
1323 LLVMMetadataRef *Subscripts,
1324 unsigned NumSubscripts) {
1325 auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
1326 NumSubscripts});
1327 return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
1328 unwrapDI<DIType>(Ty), Subs));
1329}
1330
1333 size_t NameLen, uint64_t SizeInBits,
1334 LLVMDWARFTypeEncoding Encoding,
1335 LLVMDIFlags Flags) {
1336 return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
1337 SizeInBits, Encoding,
1338 map_from_llvmDIFlags(Flags)));
1339}
1340
1342 LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
1343 uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,
1344 const char *Name, size_t NameLen) {
1345 return wrap(unwrap(Builder)->createPointerType(
1346 unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, AddressSpace,
1347 {Name, NameLen}));
1348}
1349
1351 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1352 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1353 uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1354 LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
1355 unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
1356 const char *UniqueId, size_t UniqueIdLen) {
1357 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1358 NumElements});
1359 return wrap(unwrap(Builder)->createStructType(
1360 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1361 LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
1362 unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
1363 unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
1364}
1365
1367 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1368 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
1369 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1370 LLVMMetadataRef Ty) {
1371 return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope),
1372 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
1373 OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty)));
1374}
1375
1378 size_t NameLen) {
1379 return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
1380}
1381
1383 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1384 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1385 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
1386 uint32_t AlignInBits) {
1387 return wrap(unwrap(Builder)->createStaticMemberType(
1388 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1389 LineNumber, unwrapDI<DIType>(Type), map_from_llvmDIFlags(Flags),
1390 unwrap<Constant>(ConstantVal), DW_TAG_member, AlignInBits));
1391}
1392
1395 const char *Name, size_t NameLen,
1396 LLVMMetadataRef File, unsigned LineNo,
1397 uint64_t SizeInBits, uint32_t AlignInBits,
1398 uint64_t OffsetInBits, LLVMDIFlags Flags,
1399 LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
1400 return wrap(unwrap(Builder)->createObjCIVar(
1401 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1402 SizeInBits, AlignInBits, OffsetInBits,
1403 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty),
1404 unwrapDI<MDNode>(PropertyNode)));
1405}
1406
1409 const char *Name, size_t NameLen,
1410 LLVMMetadataRef File, unsigned LineNo,
1411 const char *GetterName, size_t GetterNameLen,
1412 const char *SetterName, size_t SetterNameLen,
1413 unsigned PropertyAttributes,
1414 LLVMMetadataRef Ty) {
1415 return wrap(unwrap(Builder)->createObjCProperty(
1416 {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1417 {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
1418 PropertyAttributes, unwrapDI<DIType>(Ty)));
1419}
1420
1424 return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
1425}
1426
1429 const char *Name, size_t NameLen,
1430 LLVMMetadataRef File, unsigned LineNo,
1431 LLVMMetadataRef Scope, uint32_t AlignInBits) {
1432 return wrap(unwrap(Builder)->createTypedef(
1433 unwrapDI<DIType>(Type), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1434 unwrapDI<DIScope>(Scope), AlignInBits));
1435}
1436
1440 uint64_t BaseOffset, uint32_t VBPtrOffset,
1441 LLVMDIFlags Flags) {
1442 return wrap(unwrap(Builder)->createInheritance(
1443 unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy),
1444 BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
1445}
1446
1449 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1450 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1451 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1452 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1453 return wrap(unwrap(Builder)->createForwardDecl(
1454 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1455 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1456 AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
1457}
1458
1461 LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1462 size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1463 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1464 LLVMDIFlags Flags, const char *UniqueIdentifier,
1465 size_t UniqueIdentifierLen) {
1466 return wrap(unwrap(Builder)->createReplaceableCompositeType(
1467 Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1468 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1469 AlignInBits, map_from_llvmDIFlags(Flags),
1470 {UniqueIdentifier, UniqueIdentifierLen}));
1471}
1472
1476 return wrap(unwrap(Builder)->createQualifiedType(Tag,
1477 unwrapDI<DIType>(Type)));
1478}
1479
1483 return wrap(unwrap(Builder)->createReferenceType(Tag,
1484 unwrapDI<DIType>(Type)));
1485}
1486
1489 return wrap(unwrap(Builder)->createNullPtrType());
1490}
1491
1494 LLVMMetadataRef PointeeType,
1495 LLVMMetadataRef ClassType,
1496 uint64_t SizeInBits,
1497 uint32_t AlignInBits,
1498 LLVMDIFlags Flags) {
1499 return wrap(unwrap(Builder)->createMemberPointerType(
1500 unwrapDI<DIType>(PointeeType),
1501 unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
1502 map_from_llvmDIFlags(Flags)));
1503}
1504
1507 LLVMMetadataRef Scope,
1508 const char *Name, size_t NameLen,
1509 LLVMMetadataRef File, unsigned LineNumber,
1510 uint64_t SizeInBits,
1511 uint64_t OffsetInBits,
1512 uint64_t StorageOffsetInBits,
1514 return wrap(unwrap(Builder)->createBitFieldMemberType(
1515 unwrapDI<DIScope>(Scope), {Name, NameLen},
1516 unwrapDI<DIFile>(File), LineNumber,
1517 SizeInBits, OffsetInBits, StorageOffsetInBits,
1518 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type)));
1519}
1520
1522 LLVMMetadataRef Scope, const char *Name, size_t NameLen,
1523 LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
1524 uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1525 LLVMMetadataRef DerivedFrom,
1526 LLVMMetadataRef *Elements, unsigned NumElements,
1527 LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode,
1528 const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1529 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1530 NumElements});
1531 return wrap(unwrap(Builder)->createClassType(
1532 unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
1533 LineNumber, SizeInBits, AlignInBits, OffsetInBits,
1534 map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom), Elts,
1535 /*RunTimeLang=*/0, unwrapDI<DIType>(VTableHolder),
1536 unwrapDI<MDNode>(TemplateParamsNode),
1537 {UniqueIdentifier, UniqueIdentifierLen}));
1538}
1539
1543 return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
1544}
1545
1547 return unwrapDI<DINode>(MD)->getTag();
1548}
1549
1550const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
1551 StringRef Str = unwrapDI<DIType>(DType)->getName();
1552 *Length = Str.size();
1553 return Str.data();
1554}
1555
1557 return unwrapDI<DIType>(DType)->getSizeInBits();
1558}
1559
1561 return unwrapDI<DIType>(DType)->getOffsetInBits();
1562}
1563
1565 return unwrapDI<DIType>(DType)->getAlignInBits();
1566}
1567
1569 return unwrapDI<DIType>(DType)->getLine();
1570}
1571
1573 return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags());
1574}
1575
1577 LLVMMetadataRef *Types,
1578 size_t Length) {
1579 return wrap(
1580 unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
1581}
1582
1585 LLVMMetadataRef File,
1586 LLVMMetadataRef *ParameterTypes,
1587 unsigned NumParameterTypes,
1588 LLVMDIFlags Flags) {
1589 auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
1590 NumParameterTypes});
1591 return wrap(unwrap(Builder)->createSubroutineType(
1592 Elts, map_from_llvmDIFlags(Flags)));
1593}
1594
1596 uint64_t *Addr, size_t Length) {
1597 return wrap(
1598 unwrap(Builder)->createExpression(ArrayRef<uint64_t>(Addr, Length)));
1599}
1600
1603 uint64_t Value) {
1604 return wrap(unwrap(Builder)->createConstantValueExpression(Value));
1605}
1606
1608 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1609 size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File,
1610 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1611 LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) {
1612 return wrap(unwrap(Builder)->createGlobalVariableExpression(
1613 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
1614 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1615 true, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
1616 nullptr, AlignInBits));
1617}
1618
1620 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getVariable());
1621}
1622
1624 LLVMMetadataRef GVE) {
1625 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getExpression());
1626}
1627
1629 return wrap(unwrapDI<DIVariable>(Var)->getFile());
1630}
1631
1633 return wrap(unwrapDI<DIVariable>(Var)->getScope());
1634}
1635
1637 return unwrapDI<DIVariable>(Var)->getLine();
1638}
1639
1641 size_t Count) {
1642 return wrap(
1643 MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
1644}
1645
1647 MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode));
1648}
1649
1651 LLVMMetadataRef Replacement) {
1652 auto *Node = unwrapDI<MDNode>(TargetMetadata);
1653 Node->replaceAllUsesWith(unwrap(Replacement));
1655}
1656
1658 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1659 size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File,
1660 unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1661 LLVMMetadataRef Decl, uint32_t AlignInBits) {
1662 return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
1663 unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen},
1664 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1665 unwrapDI<MDNode>(Decl), nullptr, AlignInBits));
1666}
1667
1670 LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1672 return LLVMDIBuilderInsertDeclareRecordBefore(Builder, Storage, VarInfo, Expr,
1673 DL, Instr);
1674}
1676 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1678 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1679 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1680 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1681 unwrap<Instruction>(Instr));
1682 // This assert will fail if the module is in the new debug info format.
1683 // This function should only be called if the module is in the old
1684 // debug info format.
1685 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1686 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1687 assert(isa<Instruction *>(DbgInst) &&
1688 "Function unexpectedly in new debug info format");
1689 return wrap(cast<Instruction *>(DbgInst));
1690}
1692 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1694 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1695 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1696 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1697 unwrap<Instruction>(Instr));
1698 // This assert will fail if the module is in the old debug info format.
1699 // This function should only be called if the module is in the new
1700 // debug info format.
1701 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1702 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1703 assert(isa<DbgRecord *>(DbgInst) &&
1704 "Function unexpectedly in old debug info format");
1705 return wrap(cast<DbgRecord *>(DbgInst));
1706}
1707
1710 LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1712 return LLVMDIBuilderInsertDeclareRecordAtEnd(Builder, Storage, VarInfo, Expr,
1713 DL, Block);
1714}
1716 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1718 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1719 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1720 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block));
1721 // This assert will fail if the module is in the new debug info format.
1722 // This function should only be called if the module is in the old
1723 // debug info format.
1724 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1725 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1726 assert(isa<Instruction *>(DbgInst) &&
1727 "Function unexpectedly in new debug info format");
1728 return wrap(cast<Instruction *>(DbgInst));
1729}
1731 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1733 DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
1734 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1735 unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block));
1736 // This assert will fail if the module is in the old debug info format.
1737 // This function should only be called if the module is in the new
1738 // debug info format.
1739 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1740 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1741 assert(isa<DbgRecord *>(DbgInst) &&
1742 "Function unexpectedly in old debug info format");
1743 return wrap(cast<DbgRecord *>(DbgInst));
1744}
1745
1747 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1749 return LLVMDIBuilderInsertDbgValueRecordBefore(Builder, Val, VarInfo, Expr,
1750 DebugLoc, Instr);
1751}
1753 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1755 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1756 unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1757 unwrap<DILocation>(DebugLoc), unwrap<Instruction>(Instr));
1758 // This assert will fail if the module is in the new debug info format.
1759 // This function should only be called if the module is in the old
1760 // debug info format.
1761 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1762 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1763 assert(isa<Instruction *>(DbgInst) &&
1764 "Function unexpectedly in new debug info format");
1765 return wrap(cast<Instruction *>(DbgInst));
1766}
1768 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1770 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1771 unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1772 unwrap<DILocation>(DebugLoc), unwrap<Instruction>(Instr));
1773 // This assert will fail if the module is in the old debug info format.
1774 // This function should only be called if the module is in the new
1775 // debug info format.
1776 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1777 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1778 assert(isa<DbgRecord *>(DbgInst) &&
1779 "Function unexpectedly in old debug info format");
1780 return wrap(cast<DbgRecord *>(DbgInst));
1781}
1782
1784 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1786 return LLVMDIBuilderInsertDbgValueRecordAtEnd(Builder, Val, VarInfo, Expr,
1787 DebugLoc, Block);
1788}
1790 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1792 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1793 unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1794 unwrap<DILocation>(DebugLoc), unwrap(Block));
1795 // This assert will fail if the module is in the new debug info format.
1796 // This function should only be called if the module is in the old
1797 // debug info format.
1798 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1799 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1800 assert(isa<Instruction *>(DbgInst) &&
1801 "Function unexpectedly in new debug info format");
1802 return wrap(cast<Instruction *>(DbgInst));
1803}
1805 LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1807 DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
1808 unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1809 unwrap<DILocation>(DebugLoc), unwrap(Block));
1810 // This assert will fail if the module is in the old debug info format.
1811 // This function should only be called if the module is in the new
1812 // debug info format.
1813 // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1814 // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1815 assert(isa<DbgRecord *>(DbgInst) &&
1816 "Function unexpectedly in old debug info format");
1817 return wrap(cast<DbgRecord *>(DbgInst));
1818}
1819
1821 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1822 size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1823 LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) {
1824 return wrap(unwrap(Builder)->createAutoVariable(
1825 unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File),
1826 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1827 map_from_llvmDIFlags(Flags), AlignInBits));
1828}
1829
1831 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1832 size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo,
1833 LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) {
1834 return wrap(unwrap(Builder)->createParameterVariable(
1835 unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File),
1836 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1837 map_from_llvmDIFlags(Flags)));
1838}
1839
1841 int64_t Lo, int64_t Count) {
1842 return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
1843}
1844
1847 size_t Length) {
1848 Metadata **DataValue = unwrap(Data);
1849 return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get());
1850}
1851
1853 return wrap(unwrap<Function>(Func)->getSubprogram());
1854}
1855
1857 unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
1858}
1859
1861 return unwrapDI<DISubprogram>(Subprogram)->getLine();
1862}
1863
1865 return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
1866}
1867
1869 if (Loc)
1870 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc)));
1871 else
1872 unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
1873}
1874
1876 switch(unwrap(Metadata)->getMetadataID()) {
1877#define HANDLE_METADATA_LEAF(CLASS) \
1878 case Metadata::CLASS##Kind: \
1879 return (LLVMMetadataKind)LLVM##CLASS##MetadataKind;
1880#include "llvm/IR/Metadata.def"
1881 default:
1883 }
1884}
1885
1887 assert(ID && "Expected non-null ID");
1888 LLVMContext &Ctx = ID->getContext();
1889 auto &Map = Ctx.pImpl->AssignmentIDToInstrs;
1890
1891 auto MapIt = Map.find(ID);
1892 if (MapIt == Map.end())
1893 return make_range(nullptr, nullptr);
1894
1895 return make_range(MapIt->second.begin(), MapIt->second.end());
1896}
1897
1899 assert(ID && "Expected non-null ID");
1900 LLVMContext &Ctx = ID->getContext();
1901
1902 auto *IDAsValue = MetadataAsValue::getIfExists(Ctx, ID);
1903
1904 // The ID is only used wrapped in MetadataAsValue(ID), so lets check that
1905 // one of those already exists first.
1906 if (!IDAsValue)
1908
1909 return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
1910}
1911
1913 auto Range = getAssignmentMarkers(Inst);
1915 if (Range.empty() && DVRAssigns.empty())
1916 return;
1917 SmallVector<DbgAssignIntrinsic *> ToDelete(Range.begin(), Range.end());
1918 for (auto *DAI : ToDelete)
1919 DAI->eraseFromParent();
1920 for (auto *DVR : DVRAssigns)
1921 DVR->eraseFromParent();
1922}
1923
1925 // Replace attachments.
1926 AssignmentInstRange InstRange = getAssignmentInsts(Old);
1927 // Use intermediate storage for the instruction ptrs because the
1928 // getAssignmentInsts range iterators will be invalidated by adding and
1929 // removing DIAssignID attachments.
1930 SmallVector<Instruction *> InstVec(InstRange.begin(), InstRange.end());
1931 for (auto *I : InstVec)
1932 I->setMetadata(LLVMContext::MD_DIAssignID, New);
1933
1934 Old->replaceAllUsesWith(New);
1935}
1936
1940 for (BasicBlock &BB : *F) {
1941 for (Instruction &I : BB) {
1942 for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
1943 if (DVR.isDbgAssign())
1944 DPToDelete.push_back(&DVR);
1945 if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
1946 ToDelete.push_back(DAI);
1947 else
1948 I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
1949 }
1950 }
1951 for (auto *DAI : ToDelete)
1952 DAI->eraseFromParent();
1953 for (auto *DVR : DPToDelete)
1954 DVR->eraseFromParent();
1955}
1956
1957/// Get the FragmentInfo for the variable if it exists, otherwise return a
1958/// FragmentInfo that covers the entire variable if the variable size is
1959/// known, otherwise return a zero-sized fragment.
1962 DIExpression::FragmentInfo VariableSlice(0, 0);
1963 // Get the fragment or variable size, or zero.
1964 if (auto Sz = DVR->getFragmentSizeInBits())
1965 VariableSlice.SizeInBits = *Sz;
1966 if (auto Frag = DVR->getExpression()->getFragmentInfo())
1967 VariableSlice.OffsetInBits = Frag->OffsetInBits;
1968 return VariableSlice;
1969}
1970
1973 DIExpression::FragmentInfo VariableSlice(0, 0);
1974 // Get the fragment or variable size, or zero.
1975 if (auto Sz = DVI->getFragmentSizeInBits())
1976 VariableSlice.SizeInBits = *Sz;
1977 if (auto Frag = DVI->getExpression()->getFragmentInfo())
1978 VariableSlice.OffsetInBits = Frag->OffsetInBits;
1979 return VariableSlice;
1980}
1981template <typename T>
1983 const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
1984 uint64_t SliceSizeInBits, const T *AssignRecord,
1985 std::optional<DIExpression::FragmentInfo> &Result) {
1986 // There are multiple offsets at play in this function, so let's break it
1987 // down. Starting with how variables may be stored in allocas:
1988 //
1989 // 1 Simplest case: variable is alloca sized and starts at offset 0.
1990 // 2 Variable is larger than the alloca: the alloca holds just a part of it.
1991 // 3 Variable is smaller than the alloca: the alloca may hold multiple
1992 // variables.
1993 //
1994 // Imagine we have a store to the entire alloca. In case (3) the store
1995 // affects bits outside of the bounds of each variable. In case (2), where
1996 // the alloca holds the Xth bit to the Yth bit of a variable, the
1997 // zero-offset store doesn't represent an assignment at offset zero to the
1998 // variable. It is an assignment to offset X.
1999 //
2000 // # Example 1
2001 // Obviously, not all stores are alloca-sized and have zero offset. Imagine
2002 // the lower 32 bits of this store are dead and are going to be DSEd:
2003 //
2004 // store i64 %v, ptr %dest, !DIAssignID !1
2005 // dbg.assign(..., !DIExpression(fragment, 128, 32), !1, %dest,
2006 // !DIExpression(DW_OP_plus_uconst, 4))
2007 //
2008 // Goal: Given our dead bits at offset:0 size:32 for the store, determine the
2009 // part of the variable, which fits in the fragment expressed by the
2010 // dbg.assign, that has been killed, if any.
2011 //
2012 // calculateFragmentIntersect(..., SliceOffsetInBits=0,
2013 // SliceSizeInBits=32, Dest=%dest, Assign=dbg.assign)
2014 //
2015 // Drawing the store (s) in memory followed by the shortened version ($),
2016 // then the dbg.assign (d), with the fragment information on a seperate scale
2017 // underneath:
2018 //
2019 // Memory
2020 // offset
2021 // from
2022 // dest 0 63
2023 // | |
2024 // s[######] - Original stores 64 bits to Dest.
2025 // $----[##] - DSE says the lower 32 bits are dead, to be removed.
2026 // d [##] - Assign's address-modifying expression adds 4 bytes to
2027 // dest.
2028 // Variable | |
2029 // Fragment 128|
2030 // Offsets 159
2031 //
2032 // The answer is achieved in a few steps:
2033 // 1. Add the fragment offset to the store offset:
2034 // SliceOffsetInBits:0 + VarFrag.OffsetInBits:128 = 128
2035 //
2036 // 2. Subtract the address-modifying expression offset plus difference
2037 // between d.address and dest:
2038 // 128 - (expression_offset:32 + (d.address - dest):0) = 96
2039 //
2040 // 3. That offset along with the store size (32) represents the bits of the
2041 // variable that'd be affected by the store. Call it SliceOfVariable.
2042 // Intersect that with Assign's fragment info:
2043 // SliceOfVariable ∩ Assign_fragment = none
2044 //
2045 // In this case: none of the dead bits of the store affect Assign.
2046 //
2047 // # Example 2
2048 // Similar example with the same goal. This time the upper 16 bits
2049 // of the store are going to be DSE'd.
2050 //
2051 // store i64 %v, ptr %dest, !DIAssignID !1
2052 // dbg.assign(..., !DIExpression(fragment, 128, 32), !1, %dest,
2053 // !DIExpression(DW_OP_plus_uconst, 4))
2054 //
2055 // calculateFragmentIntersect(..., SliceOffsetInBits=48,
2056 // SliceSizeInBits=16, Dest=%dest, Assign=dbg.assign)
2057 //
2058 // Memory
2059 // offset
2060 // from
2061 // dest 0 63
2062 // | |
2063 // s[######] - Original stores 64 bits to Dest.
2064 // $[####]-- - DSE says the upper 16 bits are dead, to be removed.
2065 // d [##] - Assign's address-modifying expression adds 4 bytes to
2066 // dest.
2067 // Variable | |
2068 // Fragment 128|
2069 // Offsets 159
2070 //
2071 // Using the same steps in the first example:
2072 // 1. SliceOffsetInBits:48 + VarFrag.OffsetInBits:128 = 176
2073 // 2. 176 - (expression_offset:32 + (d.address - dest):0) = 144
2074 // 3. SliceOfVariable offset = 144, size = 16:
2075 // SliceOfVariable ∩ Assign_fragment = (offset: 144, size: 16)
2076 // SliceOfVariable tells us the bits of the variable described by Assign that
2077 // are affected by the DSE.
2078 if (AssignRecord->isKillAddress())
2079 return false;
2080
2082 getFragmentOrEntireVariable(AssignRecord);
2083 if (VarFrag.SizeInBits == 0)
2084 return false; // Variable size is unknown.
2085
2086 // Calculate the difference between Dest and the dbg.assign address +
2087 // address-modifying expression.
2088 int64_t PointerOffsetInBits;
2089 {
2090 auto DestOffsetInBytes =
2091 AssignRecord->getAddress()->getPointerOffsetFrom(Dest, DL);
2092 if (!DestOffsetInBytes)
2093 return false; // Can't calculate difference in addresses.
2094
2095 int64_t ExprOffsetInBytes;
2096 if (!AssignRecord->getAddressExpression()->extractIfOffset(
2097 ExprOffsetInBytes))
2098 return false;
2099
2100 int64_t PointerOffsetInBytes = *DestOffsetInBytes + ExprOffsetInBytes;
2101 PointerOffsetInBits = PointerOffsetInBytes * 8;
2102 }
2103
2104 // Adjust the slice offset so that we go from describing the a slice
2105 // of memory to a slice of the variable.
2106 int64_t NewOffsetInBits =
2107 SliceOffsetInBits + VarFrag.OffsetInBits - PointerOffsetInBits;
2108 if (NewOffsetInBits < 0)
2109 return false; // Fragment offsets can only be positive.
2110 DIExpression::FragmentInfo SliceOfVariable(SliceSizeInBits, NewOffsetInBits);
2111 // Intersect the variable slice with AssignRecord's fragment to trim it down
2112 // to size.
2113 DIExpression::FragmentInfo TrimmedSliceOfVariable =
2114 DIExpression::FragmentInfo::intersect(SliceOfVariable, VarFrag);
2115 if (TrimmedSliceOfVariable == VarFrag)
2116 Result = std::nullopt;
2117 else
2118 Result = TrimmedSliceOfVariable;
2119 return true;
2120}
2122 const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
2123 uint64_t SliceSizeInBits, const DbgAssignIntrinsic *DbgAssign,
2124 std::optional<DIExpression::FragmentInfo> &Result) {
2125 return calculateFragmentIntersectImpl(DL, Dest, SliceOffsetInBits,
2126 SliceSizeInBits, DbgAssign, Result);
2127}
2129 const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
2130 uint64_t SliceSizeInBits, const DbgVariableRecord *DVRAssign,
2131 std::optional<DIExpression::FragmentInfo> &Result) {
2132 return calculateFragmentIntersectImpl(DL, Dest, SliceOffsetInBits,
2133 SliceSizeInBits, DVRAssign, Result);
2134}
2135
2136/// Collect constant properies (base, size, offset) of \p StoreDest.
2137/// Return std::nullopt if any properties are not constants or the
2138/// offset from the base pointer is negative.
2139static std::optional<AssignmentInfo>
2140getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest,
2141 TypeSize SizeInBits) {
2142 if (SizeInBits.isScalable())
2143 return std::nullopt;
2144 APInt GEPOffset(DL.getIndexTypeSizeInBits(StoreDest->getType()), 0);
2145 const Value *Base = StoreDest->stripAndAccumulateConstantOffsets(
2146 DL, GEPOffset, /*AllowNonInbounds*/ true);
2147
2148 if (GEPOffset.isNegative())
2149 return std::nullopt;
2150
2151 uint64_t OffsetInBytes = GEPOffset.getLimitedValue();
2152 // Check for overflow.
2153 if (OffsetInBytes == UINT64_MAX)
2154 return std::nullopt;
2155 if (const auto *Alloca = dyn_cast<AllocaInst>(Base))
2156 return AssignmentInfo(DL, Alloca, OffsetInBytes * 8, SizeInBits);
2157 return std::nullopt;
2158}
2159
2160std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2161 const MemIntrinsic *I) {
2162 const Value *StoreDest = I->getRawDest();
2163 // Assume 8 bit bytes.
2164 auto *ConstLengthInBytes = dyn_cast<ConstantInt>(I->getLength());
2165 if (!ConstLengthInBytes)
2166 // We can't use a non-const size, bail.
2167 return std::nullopt;
2168 uint64_t SizeInBits = 8 * ConstLengthInBytes->getZExtValue();
2169 return getAssignmentInfoImpl(DL, StoreDest, TypeSize::getFixed(SizeInBits));
2170}
2171
2172std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2173 const StoreInst *SI) {
2174 TypeSize SizeInBits = DL.getTypeSizeInBits(SI->getValueOperand()->getType());
2175 return getAssignmentInfoImpl(DL, SI->getPointerOperand(), SizeInBits);
2176}
2177
2178std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
2179 const AllocaInst *AI) {
2180 TypeSize SizeInBits = DL.getTypeSizeInBits(AI->getAllocatedType());
2181 return getAssignmentInfoImpl(DL, AI, SizeInBits);
2182}
2183
2184/// Returns nullptr if the assignment shouldn't be attributed to this variable.
2185static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
2186 Instruction &StoreLikeInst, const VarRecord &VarRec,
2187 DIBuilder &DIB) {
2188 auto *ID = StoreLikeInst.getMetadata(LLVMContext::MD_DIAssignID);
2189 assert(ID && "Store instruction must have DIAssignID metadata");
2190 (void)ID;
2191
2192 const uint64_t StoreStartBit = Info.OffsetInBits;
2193 const uint64_t StoreEndBit = Info.OffsetInBits + Info.SizeInBits;
2194
2195 uint64_t FragStartBit = StoreStartBit;
2196 uint64_t FragEndBit = StoreEndBit;
2197
2198 bool StoreToWholeVariable = Info.StoreToWholeAlloca;
2199 if (auto Size = VarRec.Var->getSizeInBits()) {
2200 // NOTE: trackAssignments doesn't understand base expressions yet, so all
2201 // variables that reach here are guaranteed to start at offset 0 in the
2202 // alloca.
2203 const uint64_t VarStartBit = 0;
2204 const uint64_t VarEndBit = *Size;
2205
2206 // FIXME: trim FragStartBit when nonzero VarStartBit is supported.
2207 FragEndBit = std::min(FragEndBit, VarEndBit);
2208
2209 // Discard stores to bits outside this variable.
2210 if (FragStartBit >= FragEndBit)
2211 return;
2212
2213 StoreToWholeVariable = FragStartBit <= VarStartBit && FragEndBit >= *Size;
2214 }
2215
2216 DIExpression *Expr =
2217 DIExpression::get(StoreLikeInst.getContext(), std::nullopt);
2218 if (!StoreToWholeVariable) {
2219 auto R = DIExpression::createFragmentExpression(Expr, FragStartBit,
2220 FragEndBit - FragStartBit);
2221 assert(R.has_value() && "failed to create fragment expression");
2222 Expr = *R;
2223 }
2224 DIExpression *AddrExpr =
2225 DIExpression::get(StoreLikeInst.getContext(), std::nullopt);
2226 if (StoreLikeInst.getParent()->IsNewDbgInfoFormat) {
2228 &StoreLikeInst, Val, VarRec.Var, Expr, Dest, AddrExpr, VarRec.DL);
2229 (void)Assign;
2230 LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
2231 return;
2232 }
2233 auto Assign = DIB.insertDbgAssign(&StoreLikeInst, Val, VarRec.Var, Expr, Dest,
2234 AddrExpr, VarRec.DL);
2235 (void)Assign;
2236 LLVM_DEBUG(if (!Assign.isNull()) {
2237 if (Assign.is<DbgRecord *>())
2238 errs() << " > INSERT: " << *Assign.get<DbgRecord *>() << "\n";
2239 else
2240 errs() << " > INSERT: " << *Assign.get<Instruction *>() << "\n";
2241 });
2242}
2243
2244#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).
2245#define DEBUG_TYPE "assignment-tracking"
2246
2248 const StorageToVarsMap &Vars, const DataLayout &DL,
2249 bool DebugPrints) {
2250 // Early-exit if there are no interesting variables.
2251 if (Vars.empty())
2252 return;
2253
2254 auto &Ctx = Start->getContext();
2255 auto &Module = *Start->getModule();
2256
2257 // Undef type doesn't matter, so long as it isn't void. Let's just use i1.
2258 auto *Undef = UndefValue::get(Type::getInt1Ty(Ctx));
2259 DIBuilder DIB(Module, /*AllowUnresolved*/ false);
2260
2261 // Scan the instructions looking for stores to local variables' storage.
2262 LLVM_DEBUG(errs() << "# Scanning instructions\n");
2263 for (auto BBI = Start; BBI != End; ++BBI) {
2264 for (Instruction &I : *BBI) {
2265
2266 std::optional<AssignmentInfo> Info;
2267 Value *ValueComponent = nullptr;
2268 Value *DestComponent = nullptr;
2269 if (auto *AI = dyn_cast<AllocaInst>(&I)) {
2270 // We want to track the variable's stack home from its alloca's
2271 // position onwards so we treat it as an assignment (where the stored
2272 // value is Undef).
2273 Info = getAssignmentInfo(DL, AI);
2274 ValueComponent = Undef;
2275 DestComponent = AI;
2276 } else if (auto *SI = dyn_cast<StoreInst>(&I)) {
2277 Info = getAssignmentInfo(DL, SI);
2278 ValueComponent = SI->getValueOperand();
2279 DestComponent = SI->getPointerOperand();
2280 } else if (auto *MI = dyn_cast<MemTransferInst>(&I)) {
2282 // May not be able to represent this value easily.
2283 ValueComponent = Undef;
2284 DestComponent = MI->getOperand(0);
2285 } else if (auto *MI = dyn_cast<MemSetInst>(&I)) {
2287 // If we're zero-initing we can state the assigned value is zero,
2288 // otherwise use undef.
2289 auto *ConstValue = dyn_cast<ConstantInt>(MI->getOperand(1));
2290 if (ConstValue && ConstValue->isZero())
2291 ValueComponent = ConstValue;
2292 else
2293 ValueComponent = Undef;
2294 DestComponent = MI->getOperand(0);
2295 } else {
2296 // Not a store-like instruction.
2297 continue;
2298 }
2299
2300 assert(ValueComponent && DestComponent);
2301 LLVM_DEBUG(errs() << "SCAN: Found store-like: " << I << "\n");
2302
2303 // Check if getAssignmentInfo failed to understand this store.
2304 if (!Info.has_value()) {
2305 LLVM_DEBUG(
2306 errs()
2307 << " | SKIP: Untrackable store (e.g. through non-const gep)\n");
2308 continue;
2309 }
2310 LLVM_DEBUG(errs() << " | BASE: " << *Info->Base << "\n");
2311
2312 // Check if the store destination is a local variable with debug info.
2313 auto LocalIt = Vars.find(Info->Base);
2314 if (LocalIt == Vars.end()) {
2315 LLVM_DEBUG(
2316 errs()
2317 << " | SKIP: Base address not associated with local variable\n");
2318 continue;
2319 }
2320
2321 DIAssignID *ID =
2322 cast_or_null<DIAssignID>(I.getMetadata(LLVMContext::MD_DIAssignID));
2323 if (!ID) {
2325 I.setMetadata(LLVMContext::MD_DIAssignID, ID);
2326 }
2327
2328 for (const VarRecord &R : LocalIt->second)
2329 emitDbgAssign(*Info, ValueComponent, DestComponent, I, R, DIB);
2330 }
2331 }
2332}
2333
2334bool AssignmentTrackingPass::runOnFunction(Function &F) {
2335 // No value in assignment tracking without optimisations.
2336 if (F.hasFnAttribute(Attribute::OptimizeNone))
2337 return /*Changed*/ false;
2338
2339 bool Changed = false;
2340 auto *DL = &F.getParent()->getDataLayout();
2341 // Collect a map of {backing storage : dbg.declares} (currently "backing
2342 // storage" is limited to Allocas). We'll use this to find dbg.declares to
2343 // delete after running `trackAssignments`.
2346 // Create another similar map of {storage : variables} that we'll pass to
2347 // trackAssignments.
2348 StorageToVarsMap Vars;
2349 auto ProcessDeclare = [&](auto *Declare, auto &DeclareList) {
2350 // FIXME: trackAssignments doesn't let you specify any modifiers to the
2351 // variable (e.g. fragment) or location (e.g. offset), so we have to
2352 // leave dbg.declares with non-empty expressions in place.
2353 if (Declare->getExpression()->getNumElements() != 0)
2354 return;
2355 if (!Declare->getAddress())
2356 return;
2357 if (AllocaInst *Alloca =
2358 dyn_cast<AllocaInst>(Declare->getAddress()->stripPointerCasts())) {
2359 // FIXME: Skip VLAs for now (let these variables use dbg.declares).
2360 if (!Alloca->isStaticAlloca())
2361 return;
2362 // Similarly, skip scalable vectors (use dbg.declares instead).
2363 if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
2364 return;
2365 DeclareList[Alloca].insert(Declare);
2366 Vars[Alloca].insert(VarRecord(Declare));
2367 }
2368 };
2369 for (auto &BB : F) {
2370 for (auto &I : BB) {
2371 for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
2372 if (DVR.isDbgDeclare())
2373 ProcessDeclare(&DVR, DVRDeclares);
2374 }
2375 if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(&I))
2376 ProcessDeclare(DDI, DbgDeclares);
2377 }
2378 }
2379
2380 // FIXME: Locals can be backed by caller allocas (sret, byval).
2381 // Note: trackAssignments doesn't respect dbg.declare's IR positions (as it
2382 // doesn't "understand" dbg.declares). However, this doesn't appear to break
2383 // any rules given this description of dbg.declare from
2384 // llvm/docs/SourceLevelDebugging.rst:
2385 //
2386 // It is not control-dependent, meaning that if a call to llvm.dbg.declare
2387 // exists and has a valid location argument, that address is considered to
2388 // be the true home of the variable across its entire lifetime.
2389 trackAssignments(F.begin(), F.end(), Vars, *DL);
2390
2391 // Delete dbg.declares for variables now tracked with assignment tracking.
2392 auto DeleteSubsumedDeclare = [&](const auto &Markers, auto &Declares) {
2393 (void)Markers;
2394 for (auto *Declare : Declares) {
2395 // Assert that the alloca that Declare uses is now linked to a dbg.assign
2396 // describing the same variable (i.e. check that this dbg.declare has
2397 // been replaced by a dbg.assign). Use DebugVariableAggregate to Discard
2398 // the fragment part because trackAssignments may alter the
2399 // fragment. e.g. if the alloca is smaller than the variable, then
2400 // trackAssignments will create an alloca-sized fragment for the
2401 // dbg.assign.
2402 assert(llvm::any_of(Markers, [Declare](auto *Assign) {
2403 return DebugVariableAggregate(Assign) ==
2404 DebugVariableAggregate(Declare);
2405 }));
2406 // Delete Declare because the variable location is now tracked using
2407 // assignment tracking.
2408 Declare->eraseFromParent();
2409 Changed = true;
2410 }
2411 };
2412 for (auto &P : DbgDeclares)
2413 DeleteSubsumedDeclare(at::getAssignmentMarkers(P.first), P.second);
2414 for (auto &P : DVRDeclares)
2415 DeleteSubsumedDeclare(at::getDVRAssignmentMarkers(P.first), P.second);
2416 return Changed;
2417}
2418
2420 "debug-info-assignment-tracking";
2421
2425 ConstantInt::get(Type::getInt1Ty(M.getContext()), 1)));
2426}
2427
2429 Metadata *Value = M.getModuleFlag(AssignmentTrackingModuleFlag);
2430 return Value && !cast<ConstantAsMetadata>(Value)->getValue()->isZeroValue();
2431}
2432
2435}
2436
2439 if (!runOnFunction(F))
2440 return PreservedAnalyses::all();
2441
2442 // Record that this module uses assignment tracking. It doesn't matter that
2443 // some functons in the module may not use it - the debug info in those
2444 // functions will still be handled properly.
2445 setAssignmentTrackingModuleFlag(*F.getParent());
2446
2447 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2448 // return PreservedAnalyses::all()?
2451 return PA;
2452}
2453
2456 bool Changed = false;
2457 for (auto &F : M)
2458 Changed |= runOnFunction(F);
2459
2460 if (!Changed)
2461 return PreservedAnalyses::all();
2462
2463 // Record that this module uses assignment tracking.
2465
2466 // Q: Can we return a less conservative set than just CFGAnalyses? Can we
2467 // return PreservedAnalyses::all()?
2470 return PA;
2471}
2472
2473#undef DEBUG_TYPE
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
Definition: DIBuilder.cpp:849
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, DINodeArray Elements, SmallVectorImpl< TrackingMDNodeRef > &ImportedModules)
Definition: DIBuilder.cpp:162
static void setAssignmentTrackingModuleFlag(Module &M)
Definition: DebugInfo.cpp:2422
static DISubprogram::DISPFlags pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized)
Definition: DebugInfo.cpp:1035
static Metadata * stripLoopMDLoc(const SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
Definition: DebugInfo.cpp:483
static MDNode * updateLoopMetadataDebugLocationsImpl(MDNode *OrigLoopID, function_ref< Metadata *(Metadata *)> Updater)
Definition: DebugInfo.cpp:401
static MDNode * stripDebugLocFromLoopID(MDNode *N)
Definition: DebugInfo.cpp:520
bool calculateFragmentIntersectImpl(const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const T *AssignRecord, std::optional< DIExpression::FragmentInfo > &Result)
Definition: DebugInfo.cpp:1982
static const char * AssignmentTrackingModuleFlag
Definition: DebugInfo.cpp:2419
static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags)
Definition: DebugInfo.cpp:1026
static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang)
Definition: DebugInfo.cpp:1011
static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest, Instruction &StoreLikeInst, const VarRecord &VarRec, DIBuilder &DIB)
Returns nullptr if the assignment shouldn't be attributed to this variable.
Definition: DebugInfo.cpp:2185
static DIExpression::FragmentInfo getFragmentOrEntireVariable(const DbgVariableRecord *DVR)
Get the FragmentInfo for the variable if it exists, otherwise return a FragmentInfo that covers the e...
Definition: DebugInfo.cpp:1961
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags)
Definition: DebugInfo.cpp:1030
static void findDbgIntrinsics(SmallVectorImpl< IntrinsicT * > &Result, Value *V, SmallVectorImpl< DbgVariableRecord * > *DbgVariableRecords)
Definition: DebugInfo.cpp:86
static bool getAssignmentTrackingModuleFlag(const Module &M)
Definition: DebugInfo.cpp:2428
static bool isAllDILocation(SmallPtrSetImpl< Metadata * > &Visited, SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
Definition: DebugInfo.cpp:457
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:436
DIT * unwrapDI(LLVMMetadataRef Ref)
Definition: DebugInfo.cpp:1022
static std::optional< AssignmentInfo > getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest, TypeSize SizeInBits)
Collect constant properies (base, size, offset) of StoreDest.
Definition: DebugInfo.cpp:2140
#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
bool End
Definition: ELF_riscv.cpp:480
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SPIRV::Scope::Scope getScope(SyncScope::ID Ord, SPIRVMachineModuleInfo *MMI)
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
Class for arbitrary precision integers.
Definition: APInt.h:76
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:307
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:453
an instruction to allocate memory on the stack
Definition: Instructions.h:59
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:125
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:321
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:2437
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
bool IsNewDbgInfoFormat
Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...
Definition: BasicBlock.h:65
Represents analyses that only rely on functions' control flow.
Definition: Analysis.h:70
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:528
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
Assignment ID.
static DIAssignID * getDistinct(LLVMContext &Context)
DbgInstPtr 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:971
DWARF expression.
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
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.
DILocalScope * getScope() const
Get the local scope for this variable.
Debug location.
static DILocation * getMergedLocation(DILocation *LocA, 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
std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
DIType * getType() const
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
This represents the llvm.dbg.assign instruction.
This represents the llvm.dbg.declare instruction.
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
This is the common base class for debug info intrinsics for variables.
std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
DIExpression * getExpression() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
DIExpression * getExpression() const
static DbgVariableRecord * createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable, DIExpression *Expression, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:242
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:198
void processVariable(const Module &M, const DILocalVariable *DVI)
Process a DILocalVariable.
Definition: DebugInfo.cpp:340
void processSubprogram(DISubprogram *SP)
Process subprogram.
Definition: DebugInfo.cpp:317
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:254
void reset()
Clear all lists.
Definition: DebugInfo.cpp:189
void processDbgRecord(const Module &M, const DbgRecord &DR)
Process a DbgRecord (e.g, treat a DbgVariableRecord like a DbgVariableIntrinsic).
Definition: DebugInfo.cpp:261
A debug info location.
Definition: DebugLoc.h:33
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:20
MDNode * getScope() const
Definition: DebugLoc.cpp:34
DILocation * getInlinedAt() const
Definition: DebugLoc.cpp:39
Identifies a unique instance of a whole variable (discards/ignores fragment information).
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h: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:67
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1831
void mergeDIAssignID(ArrayRef< const Instruction * > SourceInstructions)
Merge the DIAssignID metadata from this instruction and those attached to instructions in SourceInstr...
Definition: DebugInfo.cpp:939
void dropLocation()
Drop the instruction's debug location.
Definition: DebugInfo.cpp:970
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:454
const BasicBlock * getParent() const
Definition: Instruction.h:152
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:86
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:359
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1636
void updateLocationAfterHoist()
Updates the debug location given that the instruction has been hoisted from a block to a predecessor ...
Definition: DebugInfo.cpp:968
void applyMergedLocation(DILocation *LocA, DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
Definition: DebugInfo.cpp:935
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:451
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:558
Metadata node.
Definition: Metadata.h:1067
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:1071
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1549
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition: Metadata.h:1264
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Definition: Metadata.cpp:1043
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1428
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1541
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1434
bool isDistinct() const
Definition: Metadata.h:1250
LLVMContext & getContext() const
Definition: Metadata.h:1231
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:889
Metadata * get() const
Definition: Metadata.h:918
Tuple of metadata.
Definition: Metadata.h:1470
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1518
This is the common base class for memset/memcpy/memmove.
static MetadataAsValue * getIfExists(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:111
Root of the metadata hierarchy.
Definition: Metadata.h:62
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:1729
StringRef getName() const
Definition: Metadata.cpp:1399
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
void preserveSet()
Mark an analysis set as preserved.
Definition: Analysis.h:144
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:321
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:360
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:342
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
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:586
void reserve(size_type N)
Definition: SmallVector.h:676
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
An instruction for storing to memory.
Definition: Instructions.h:317
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)
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition: TypeSize.h:330
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:1808
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.
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1074
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
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
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:1394
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location)
Get the "inline at" location associated with this debug location.
Definition: DebugInfo.cpp:1225
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Definition: DebugInfo.cpp:1669
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create an array of DI Nodes.
Definition: DebugInfo.cpp:1845
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:1282
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:1179
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set.
Definition: DebugInfo.cpp:1422
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType)
Get the size of this DIType in bits.
Definition: DebugInfo.cpp:1556
LLVMDWARFMacinfoRecordType
Describes the kind of macro declaration used for LLVMDIBuilderCreateMacro.
Definition: DebugInfo.h:197
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:1121
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Soon to be deprecated.
Definition: DebugInfo.cpp:1730
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Insert a new Value DbgRecord before the given instruction.
Definition: DebugInfo.cpp:1746
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Insert a new Value DbgRecord at the end of the given basic block.
Definition: DebugInfo.cpp:1783
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:1506
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetVariable(LLVMMetadataRef GVE)
Retrieves the DIVariable associated with this global variable expression.
Definition: DebugInfo.cpp:1619
LLVMMetadataRef LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagArtificial set.
Definition: DebugInfo.cpp:1541
void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder)
Construct any deferred debug info descriptors.
Definition: DebugInfo.cpp:1063
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:1145
unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram)
Get the line associated with a given subprogram.
Definition: DebugInfo.cpp:1860
LLVMMetadataRef LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen)
Create a DWARF unspecified type.
Definition: DebugInfo.cpp:1377
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:1113
LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt)
Creates a new DebugLocation that describes a source location.
Definition: DebugInfo.cpp:1206
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType)
Get the alignment of this DIType in bits.
Definition: DebugInfo.cpp:1564
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetExpression(LLVMMetadataRef GVE)
Retrieves the DIExpression associated with this global variable expression.
Definition: DebugInfo.cpp:1623
LLVMMetadataRef LLVMDIVariableGetScope(LLVMMetadataRef Var)
Get the metadata of the scope associated with a given variable.
Definition: DebugInfo.cpp:1632
LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst)
Get the debug location for the given instruction.
Definition: DebugInfo.cpp:1864
LLVMMetadataRef LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a c++ style reference or rvalue reference type.
Definition: DebugInfo.cpp:1481
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:1101
LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M)
Construct a builder for a module, and do not allow for unresolved nodes attached to the module.
Definition: DebugInfo.cpp:1043
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP)
Set the subprogram attached to a function.
Definition: DebugInfo.cpp:1856
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:1840
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:1047
void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode)
Deallocate a temporary node.
Definition: DebugInfo.cpp:1646
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location)
Get the local scope associated with this debug location.
Definition: DebugInfo.cpp:1221
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef NS, LLVMMetadataRef File, unsigned Line)
Create a descriptor for an imported namespace.
Definition: DebugInfo.cpp:1155
LLVMMetadataRef LLVMDIBuilderCreateTempMacroFile(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentMacroFile, unsigned Line, LLVMMetadataRef File)
Create debugging information temporary entry for a macro file.
Definition: DebugInfo.cpp:1267
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc)
Set the debug location for the given instruction.
Definition: DebugInfo.cpp:1868
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:1274
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:1595
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:1321
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:1493
LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Soon to be deprecated.
Definition: DebugInfo.cpp:1675
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location)
Get the column number of this debug location.
Definition: DebugInfo.cpp:1217
LLVMDIFlags
Debug info flags.
Definition: DebugInfo.h:34
LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Soon to be deprecated.
Definition: DebugInfo.cpp:1789
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:1820
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, size_t NumElements)
Create a new temporary MDNode.
Definition: DebugInfo.cpp:1640
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType)
Get the flags associated with this DIType.
Definition: DebugInfo.cpp:1572
const char * LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len)
Get the directory of a given file.
Definition: DebugInfo.cpp:1233
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TempTargetMetadata, LLVMMetadataRef Replacement)
Replace all uses of temporary metadata.
Definition: DebugInfo.cpp:1650
const char * LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len)
Get the name of a given file.
Definition: DebugInfo.cpp:1239
unsigned LLVMDebugMetadataVersion(void)
The current debug metadata version number.
Definition: DebugInfo.cpp:1039
unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef Module)
The version of debug metadata that's present in the provided Module.
Definition: DebugInfo.cpp:1051
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType)
Get the source line where this DIType is declared.
Definition: DebugInfo.cpp:1568
LLVMMetadataRef LLVMDIVariableGetFile(LLVMMetadataRef Var)
Get the metadata of the file associated with a given variable.
Definition: DebugInfo.cpp:1628
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:1166
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:1382
uint16_t LLVMGetDINodeTag(LLVMMetadataRef MD)
Get the dwarf::Tag of a DINode.
Definition: DebugInfo.cpp:1546
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:1607
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:1657
LLVMMetadataRef LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a qualified type, e.g.
Definition: DebugInfo.cpp:1474
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata)
Obtain the enumerated type of a Metadata instance.
Definition: DebugInfo.cpp:1875
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:1294
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:1448
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:1830
LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, LLVMMetadataRef File, LLVMMetadataRef *ParameterTypes, unsigned NumParameterTypes, LLVMDIFlags Flags)
Create subroutine type.
Definition: DebugInfo.cpp:1584
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:1408
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:1254
LLVMDWARFEmissionKind
The amount of debug information to emit.
Definition: DebugInfo.h:138
LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Soon to be deprecated.
Definition: DebugInfo.cpp:1715
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:1310
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Soon to be deprecated.
Definition: DebugInfo.cpp:1804
LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope)
Get the metadata of the file associated with a given scope.
Definition: DebugInfo.cpp:1229
void LLVMDIBuilderFinalizeSubprogram(LLVMDIBuilderRef Builder, LLVMMetadataRef Subprogram)
Finalize a specific subprogram.
Definition: DebugInfo.cpp:1067
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:1602
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:1521
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:1366
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location)
Get the line number of this debug location.
Definition: DebugInfo.cpp:1213
LLVMMetadataRef LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder)
Create C++11 nullptr type.
Definition: DebugInfo.cpp:1488
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:1438
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Insert a new Declare DbgRecord at the end of the given basic block.
Definition: DebugInfo.cpp:1709
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:1072
LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef Module)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:1055
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Soon to be deprecated.
Definition: DebugInfo.cpp:1691
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:1332
unsigned LLVMDIVariableGetLine(LLVMMetadataRef Var)
Get the source line where this DIVariable is declared.
Definition: DebugInfo.cpp:1636
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Soon to be deprecated.
Definition: DebugInfo.cpp:1767
unsigned LLVMDWARFTypeEncoding
An LLVM DWARF type encoding.
Definition: DebugInfo.h:190
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:1136
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create a type array.
Definition: DebugInfo.cpp:1576
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:1460
LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Soon to be deprecated.
Definition: DebugInfo.cpp:1752
const char * LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len)
Get the source of a given file.
Definition: DebugInfo.cpp:1245
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType)
Get the offset of this DIType in bits.
Definition: DebugInfo.cpp:1560
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:1192
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:1093
const char * LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length)
Get the name of this DIType.
Definition: DebugInfo.cpp:1550
unsigned LLVMMetadataKind
Definition: DebugInfo.h:185
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:1428
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:1350
void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder)
Deallocates the DIBuilder and everything it owns.
Definition: DebugInfo.cpp:1059
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:1341
LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func)
Get the metadata of the subprogram attached to a function.
Definition: DebugInfo.cpp:1852
@ LLVMGenericDINodeMetadataKind
Definition: DebugInfo.h:156
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
struct LLVMOpaqueDbgRecord * LLVMDbgRecordRef
Definition: Types.h:175
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:53
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
Definition: Types.h:82
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
Definition: Types.h:89
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
struct LLVMOpaqueDIBuilder * LLVMDIBuilderRef
Represents an LLVM debug info builder.
Definition: Types.h:117
#define UINT64_MAX
Definition: DataTypes.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Assignment Tracking (at).
Definition: DebugInfo.h:179
void deleteAll(Function *F)
Remove all Assignment Tracking related intrinsics and metadata from F.
Definition: DebugInfo.cpp:1937
AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
Definition: DebugInfo.cpp:1886
AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)
Return a range of dbg.assign intrinsics which use \ID as an operand.
Definition: DebugInfo.cpp:1898
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:2247
SmallVector< DbgVariableRecord * > getDVRAssignmentMarkers(const Instruction *Inst)
Definition: DebugInfo.h:238
void deleteAssignmentMarkers(const Instruction *Inst)
Delete the llvm.dbg.assign intrinsics linked to Inst.
Definition: DebugInfo.cpp:1912
std::optional< AssignmentInfo > getAssignmentInfo(const DataLayout &DL, const MemIntrinsic *I)
Definition: DebugInfo.cpp:2160
bool calculateFragmentIntersect(const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const DbgAssignIntrinsic *DbgAssign, std::optional< DIExpression::FragmentInfo > &Result)
Calculate the fragment of the variable in DAI covered from (Dest + SliceOffsetInBits) to to (Dest + S...
Definition: DebugInfo.cpp:2121
void RAUW(DIAssignID *Old, DIAssignID *New)
Replace all uses (and attachments) of Old with New.
Definition: DebugInfo.cpp:1924
Calculates the starting offsets for various sections within the .debug_names section.
Definition: Dwarf.h:34
MacinfoRecordType
Definition: Dwarf.h:470
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:329
@ Length
Definition: DWP.cpp:456
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:1722
TinyPtrVector< DbgDeclareInst * > findDbgDeclares(Value *V)
Finds dbg.declare intrinsics declaring local variables as living in the memory that 'V' points to.
Definition: DebugInfo.cpp:47
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:555
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V, SmallVectorImpl< DbgVariableRecord * > *DbgVariableRecords=nullptr)
Finds the debug info intrinsics describing a value.
Definition: DebugInfo.cpp:148
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:656
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V, SmallVectorImpl< DbgVariableRecord * > *DbgVariableRecords=nullptr)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: DebugInfo.cpp:141
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:1729
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:829
DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII)
Produce a DebugLoc to use for each dbg.declare that is promoted to a dbg.value.
Definition: DebugInfo.cpp:161
unsigned getDebugMetadataVersionFromModule(const Module &M)
Return Debug Info Metadata Version by checking module flags.
Definition: DebugInfo.cpp:928
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:594
@ Ref
The access may reference the value stored in memory.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:303
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
Definition: DebugInfo.cpp:2433
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:1921
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:298
TinyPtrVector< DbgVariableRecord * > findDVRDeclares(Value *V)
As above, for DVRDeclares.
Definition: DebugInfo.cpp:66
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
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:425
@ DEBUG_METADATA_VERSION
Definition: Metadata.h:52
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:155
#define N
Holds the characteristics of one fragment of a larger variable.
static DIExpression::FragmentInfo intersect(DIExpression::FragmentInfo A, DIExpression::FragmentInfo B)
Returns a zero-sized fragment if A and B don't intersect.
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:332
Helper struct for trackAssignments, below.
Definition: DebugInfo.h:277
DILocation * DL
Definition: DebugInfo.h:279
DILocalVariable * Var
Definition: DebugInfo.h:278