LLVM  8.0.1
DebugInfo.cpp
Go to the documentation of this file.
1 //===- DebugInfo.cpp - Debug Information Helper Classes -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the helper classes used to build and interpret debug
11 // information in LLVM IR form.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm-c/DebugInfo.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/DenseSet.h"
18 #include "llvm/ADT/None.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/IR/BasicBlock.h"
24 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DebugLoc.h"
27 #include "llvm/IR/DebugInfo.h"
28 #include "llvm/IR/DIBuilder.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/GVMaterializer.h"
31 #include "llvm/IR/Instruction.h"
32 #include "llvm/IR/IntrinsicInst.h"
33 #include "llvm/IR/LLVMContext.h"
34 #include "llvm/IR/Metadata.h"
35 #include "llvm/IR/Module.h"
36 #include "llvm/Support/Casting.h"
37 #include <algorithm>
38 #include <cassert>
39 #include <utility>
40 
41 using namespace llvm;
42 using namespace llvm::dwarf;
43 
45  if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
46  return LocalScope->getSubprogram();
47  return nullptr;
48 }
49 
50 //===----------------------------------------------------------------------===//
51 // DebugInfoFinder implementations.
52 //===----------------------------------------------------------------------===//
53 
55  CUs.clear();
56  SPs.clear();
57  GVs.clear();
58  TYs.clear();
59  Scopes.clear();
60  NodesSeen.clear();
61 }
62 
64  for (auto *CU : M.debug_compile_units())
65  processCompileUnit(CU);
66  for (auto &F : M.functions()) {
67  if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
68  processSubprogram(SP);
69  // There could be subprograms from inlined functions referenced from
70  // instructions only. Walk the function to find them.
71  for (const BasicBlock &BB : F)
72  for (const Instruction &I : BB)
73  processInstruction(M, I);
74  }
75 }
76 
77 void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) {
78  if (!addCompileUnit(CU))
79  return;
80  for (auto DIG : CU->getGlobalVariables()) {
81  if (!addGlobalVariable(DIG))
82  continue;
83  auto *GV = DIG->getVariable();
84  processScope(GV->getScope());
85  processType(GV->getType().resolve());
86  }
87  for (auto *ET : CU->getEnumTypes())
88  processType(ET);
89  for (auto *RT : CU->getRetainedTypes())
90  if (auto *T = dyn_cast<DIType>(RT))
91  processType(T);
92  else
93  processSubprogram(cast<DISubprogram>(RT));
94  for (auto *Import : CU->getImportedEntities()) {
95  auto *Entity = Import->getEntity().resolve();
96  if (auto *T = dyn_cast<DIType>(Entity))
97  processType(T);
98  else if (auto *SP = dyn_cast<DISubprogram>(Entity))
99  processSubprogram(SP);
100  else if (auto *NS = dyn_cast<DINamespace>(Entity))
101  processScope(NS->getScope());
102  else if (auto *M = dyn_cast<DIModule>(Entity))
103  processScope(M->getScope());
104  }
105 }
106 
108  const Instruction &I) {
109  if (auto *DDI = dyn_cast<DbgDeclareInst>(&I))
110  processDeclare(M, DDI);
111  else if (auto *DVI = dyn_cast<DbgValueInst>(&I))
112  processValue(M, DVI);
113 
114  if (auto DbgLoc = I.getDebugLoc())
115  processLocation(M, DbgLoc.get());
116 }
117 
119  if (!Loc)
120  return;
121  processScope(Loc->getScope());
122  processLocation(M, Loc->getInlinedAt());
123 }
124 
125 void DebugInfoFinder::processType(DIType *DT) {
126  if (!addType(DT))
127  return;
128  processScope(DT->getScope().resolve());
129  if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
130  for (DITypeRef Ref : ST->getTypeArray())
131  processType(Ref.resolve());
132  return;
133  }
134  if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
135  processType(DCT->getBaseType().resolve());
136  for (Metadata *D : DCT->getElements()) {
137  if (auto *T = dyn_cast<DIType>(D))
138  processType(T);
139  else if (auto *SP = dyn_cast<DISubprogram>(D))
140  processSubprogram(SP);
141  }
142  return;
143  }
144  if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
145  processType(DDT->getBaseType().resolve());
146  }
147 }
148 
149 void DebugInfoFinder::processScope(DIScope *Scope) {
150  if (!Scope)
151  return;
152  if (auto *Ty = dyn_cast<DIType>(Scope)) {
153  processType(Ty);
154  return;
155  }
156  if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
157  addCompileUnit(CU);
158  return;
159  }
160  if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
161  processSubprogram(SP);
162  return;
163  }
164  if (!addScope(Scope))
165  return;
166  if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
167  processScope(LB->getScope());
168  } else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
169  processScope(NS->getScope());
170  } else if (auto *M = dyn_cast<DIModule>(Scope)) {
171  processScope(M->getScope());
172  }
173 }
174 
175 void DebugInfoFinder::processSubprogram(DISubprogram *SP) {
176  if (!addSubprogram(SP))
177  return;
178  processScope(SP->getScope().resolve());
179  // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
180  // ValueMap containing identity mappings for all of the DICompileUnit's, not
181  // just DISubprogram's, referenced from anywhere within the Function being
182  // cloned prior to calling MapMetadata / RemapInstruction to avoid their
183  // duplication later as DICompileUnit's are also directly referenced by
184  // llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well.
185  // Also, DICompileUnit's may reference DISubprogram's too and therefore need
186  // to be at least looked through.
187  processCompileUnit(SP->getUnit());
188  processType(SP->getType());
189  for (auto *Element : SP->getTemplateParams()) {
190  if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
191  processType(TType->getType().resolve());
192  } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
193  processType(TVal->getType().resolve());
194  }
195  }
196 }
197 
199  const DbgDeclareInst *DDI) {
200  auto *N = dyn_cast<MDNode>(DDI->getVariable());
201  if (!N)
202  return;
203 
204  auto *DV = dyn_cast<DILocalVariable>(N);
205  if (!DV)
206  return;
207 
208  if (!NodesSeen.insert(DV).second)
209  return;
210  processScope(DV->getScope());
211  processType(DV->getType().resolve());
212 }
213 
215  auto *N = dyn_cast<MDNode>(DVI->getVariable());
216  if (!N)
217  return;
218 
219  auto *DV = dyn_cast<DILocalVariable>(N);
220  if (!DV)
221  return;
222 
223  if (!NodesSeen.insert(DV).second)
224  return;
225  processScope(DV->getScope());
226  processType(DV->getType().resolve());
227 }
228 
229 bool DebugInfoFinder::addType(DIType *DT) {
230  if (!DT)
231  return false;
232 
233  if (!NodesSeen.insert(DT).second)
234  return false;
235 
236  TYs.push_back(const_cast<DIType *>(DT));
237  return true;
238 }
239 
240 bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
241  if (!CU)
242  return false;
243  if (!NodesSeen.insert(CU).second)
244  return false;
245 
246  CUs.push_back(CU);
247  return true;
248 }
249 
250 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) {
251  if (!NodesSeen.insert(DIG).second)
252  return false;
253 
254  GVs.push_back(DIG);
255  return true;
256 }
257 
258 bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
259  if (!SP)
260  return false;
261 
262  if (!NodesSeen.insert(SP).second)
263  return false;
264 
265  SPs.push_back(SP);
266  return true;
267 }
268 
269 bool DebugInfoFinder::addScope(DIScope *Scope) {
270  if (!Scope)
271  return false;
272  // FIXME: Ocaml binding generates a scope with no content, we treat it
273  // as null for now.
274  if (Scope->getNumOperands() == 0)
275  return false;
276  if (!NodesSeen.insert(Scope).second)
277  return false;
278  Scopes.push_back(Scope);
279  return true;
280 }
281 
283  assert(!empty(N->operands()) && "Missing self reference?");
284 
285  // if there is no debug location, we do not have to rewrite this MDNode.
286  if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
287  return isa<DILocation>(Op.get());
288  }))
289  return N;
290 
291  // If there is only the debug location without any actual loop metadata, we
292  // can remove the metadata.
293  if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
294  return !isa<DILocation>(Op.get());
295  }))
296  return nullptr;
297 
299  // Reserve operand 0 for loop id self reference.
300  auto TempNode = MDNode::getTemporary(N->getContext(), None);
301  Args.push_back(TempNode.get());
302  // Add all non-debug location operands back.
303  for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) {
304  if (!isa<DILocation>(*Op))
305  Args.push_back(*Op);
306  }
307 
308  // Set the first operand to itself.
309  MDNode *LoopID = MDNode::get(N->getContext(), Args);
310  LoopID->replaceOperandWith(0, LoopID);
311  return LoopID;
312 }
313 
315  bool Changed = false;
317  Changed = true;
318  F.setSubprogram(nullptr);
319  }
320 
321  DenseMap<MDNode*, MDNode*> LoopIDsMap;
322  for (BasicBlock &BB : F) {
323  for (auto II = BB.begin(), End = BB.end(); II != End;) {
324  Instruction &I = *II++; // We may delete the instruction, increment now.
325  if (isa<DbgInfoIntrinsic>(&I)) {
326  I.eraseFromParent();
327  Changed = true;
328  continue;
329  }
330  if (I.getDebugLoc()) {
331  Changed = true;
332  I.setDebugLoc(DebugLoc());
333  }
334  }
335 
336  auto *TermInst = BB.getTerminator();
337  if (!TermInst)
338  // This is invalid IR, but we may not have run the verifier yet
339  continue;
340  if (auto *LoopID = TermInst->getMetadata(LLVMContext::MD_loop)) {
341  auto *NewLoopID = LoopIDsMap.lookup(LoopID);
342  if (!NewLoopID)
343  NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
344  if (NewLoopID != LoopID)
345  TermInst->setMetadata(LLVMContext::MD_loop, NewLoopID);
346  }
347  }
348  return Changed;
349 }
350 
352  bool Changed = false;
353 
355  NME = M.named_metadata_end(); NMI != NME;) {
356  NamedMDNode *NMD = &*NMI;
357  ++NMI;
358 
359  // We're stripping debug info, and without them, coverage information
360  // doesn't quite make sense.
361  if (NMD->getName().startswith("llvm.dbg.") ||
362  NMD->getName() == "llvm.gcov") {
363  NMD->eraseFromParent();
364  Changed = true;
365  }
366  }
367 
368  for (Function &F : M)
369  Changed |= stripDebugInfo(F);
370 
371  for (auto &GV : M.globals()) {
372  Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
373  }
374 
375  if (GVMaterializer *Materializer = M.getMaterializer())
376  Materializer->setStripDebugInfo();
377 
378  return Changed;
379 }
380 
381 namespace {
382 
383 /// Helper class to downgrade -g metadata to -gline-tables-only metadata.
384 class DebugTypeInfoRemoval {
386 
387 public:
388  /// The (void)() type.
389  MDNode *EmptySubroutineType;
390 
391 private:
392  /// Remember what linkage name we originally had before stripping. If we end
393  /// up making two subprograms identical who originally had different linkage
394  /// names, then we need to make one of them distinct, to avoid them getting
395  /// uniqued. Maps the new node to the old linkage name.
396  DenseMap<DISubprogram *, StringRef> NewToLinkageName;
397 
398  // TODO: Remember the distinct subprogram we created for a given linkage name,
399  // so that we can continue to unique whenever possible. Map <newly created
400  // node, old linkage name> to the first (possibly distinct) mdsubprogram
401  // created for that combination. This is not strictly needed for correctness,
402  // but can cut down on the number of MDNodes and let us diff cleanly with the
403  // output of -gline-tables-only.
404 
405 public:
406  DebugTypeInfoRemoval(LLVMContext &C)
407  : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0,
408  MDNode::get(C, {}))) {}
409 
410  Metadata *map(Metadata *M) {
411  if (!M)
412  return nullptr;
413  auto Replacement = Replacements.find(M);
414  if (Replacement != Replacements.end())
415  return Replacement->second;
416 
417  return M;
418  }
419  MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); }
420 
421  /// Recursively remap N and all its referenced children. Does a DF post-order
422  /// traversal, so as to remap bottoms up.
423  void traverseAndRemap(MDNode *N) { traverse(N); }
424 
425 private:
426  // Create a new DISubprogram, to replace the one given.
427  DISubprogram *getReplacementSubprogram(DISubprogram *MDS) {
428  auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile()));
429  StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
430  DISubprogram *Declaration = nullptr;
431  auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
432  DITypeRef ContainingType(map(MDS->getContainingType()));
433  auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
434  auto Variables = nullptr;
435  auto TemplateParams = nullptr;
436 
437  // Make a distinct DISubprogram, for situations that warrent it.
438  auto distinctMDSubprogram = [&]() {
440  MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
441  FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(),
442  ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(),
443  MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration,
444  Variables);
445  };
446 
447  if (MDS->isDistinct())
448  return distinctMDSubprogram();
449 
450  auto *NewMDS = DISubprogram::get(
451  MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
452  FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType,
453  MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(),
454  MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables);
455 
456  StringRef OldLinkageName = MDS->getLinkageName();
457 
458  // See if we need to make a distinct one.
459  auto OrigLinkage = NewToLinkageName.find(NewMDS);
460  if (OrigLinkage != NewToLinkageName.end()) {
461  if (OrigLinkage->second == OldLinkageName)
462  // We're good.
463  return NewMDS;
464 
465  // Otherwise, need to make a distinct one.
466  // TODO: Query the map to see if we already have one.
467  return distinctMDSubprogram();
468  }
469 
470  NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
471  return NewMDS;
472  }
473 
474  /// Create a new compile unit, to replace the one given
475  DICompileUnit *getReplacementCU(DICompileUnit *CU) {
476  // Drop skeleton CUs.
477  if (CU->getDWOId())
478  return nullptr;
479 
480  auto *File = cast_or_null<DIFile>(map(CU->getFile()));
481  MDTuple *EnumTypes = nullptr;
482  MDTuple *RetainedTypes = nullptr;
483  MDTuple *GlobalVariables = nullptr;
484  MDTuple *ImportedEntities = nullptr;
486  CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(),
487  CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
489  RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
490  CU->getDWOId(), CU->getSplitDebugInlining(),
492  CU->getRangesBaseAddress());
493  }
494 
495  DILocation *getReplacementMDLocation(DILocation *MLD) {
496  auto *Scope = map(MLD->getScope());
497  auto *InlinedAt = map(MLD->getInlinedAt());
498  if (MLD->isDistinct())
499  return DILocation::getDistinct(MLD->getContext(), MLD->getLine(),
500  MLD->getColumn(), Scope, InlinedAt);
501  return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(),
502  Scope, InlinedAt);
503  }
504 
505  /// Create a new generic MDNode, to replace the one given
506  MDNode *getReplacementMDNode(MDNode *N) {
508  Ops.reserve(N->getNumOperands());
509  for (auto &I : N->operands())
510  if (I)
511  Ops.push_back(map(I));
512  auto *Ret = MDNode::get(N->getContext(), Ops);
513  return Ret;
514  }
515 
516  /// Attempt to re-map N to a newly created node.
517  void remap(MDNode *N) {
518  if (Replacements.count(N))
519  return;
520 
521  auto doRemap = [&](MDNode *N) -> MDNode * {
522  if (!N)
523  return nullptr;
524  if (auto *MDSub = dyn_cast<DISubprogram>(N)) {
525  remap(MDSub->getUnit());
526  return getReplacementSubprogram(MDSub);
527  }
528  if (isa<DISubroutineType>(N))
529  return EmptySubroutineType;
530  if (auto *CU = dyn_cast<DICompileUnit>(N))
531  return getReplacementCU(CU);
532  if (isa<DIFile>(N))
533  return N;
534  if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N))
535  // Remap to our referenced scope (recursively).
536  return mapNode(MDLB->getScope());
537  if (auto *MLD = dyn_cast<DILocation>(N))
538  return getReplacementMDLocation(MLD);
539 
540  // Otherwise, if we see these, just drop them now. Not strictly necessary,
541  // but this speeds things up a little.
542  if (isa<DINode>(N))
543  return nullptr;
544 
545  return getReplacementMDNode(N);
546  };
547  Replacements[N] = doRemap(N);
548  }
549 
550  /// Do the remapping traversal.
551  void traverse(MDNode *);
552 };
553 
554 } // end anonymous namespace
555 
556 void DebugTypeInfoRemoval::traverse(MDNode *N) {
557  if (!N || Replacements.count(N))
558  return;
559 
560  // To avoid cycles, as well as for efficiency sake, we will sometimes prune
561  // parts of the graph.
562  auto prune = [](MDNode *Parent, MDNode *Child) {
563  if (auto *MDS = dyn_cast<DISubprogram>(Parent))
564  return Child == MDS->getRetainedNodes().get();
565  return false;
566  };
567 
569  DenseSet<MDNode *> Opened;
570 
571  // Visit each node starting at N in post order, and map them.
572  ToVisit.push_back(N);
573  while (!ToVisit.empty()) {
574  auto *N = ToVisit.back();
575  if (!Opened.insert(N).second) {
576  // Close it.
577  remap(N);
578  ToVisit.pop_back();
579  continue;
580  }
581  for (auto &I : N->operands())
582  if (auto *MDN = dyn_cast_or_null<MDNode>(I))
583  if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) &&
584  !isa<DICompileUnit>(MDN))
585  ToVisit.push_back(MDN);
586  }
587 }
588 
590  bool Changed = false;
591 
592  // First off, delete the debug intrinsics.
593  auto RemoveUses = [&](StringRef Name) {
594  if (auto *DbgVal = M.getFunction(Name)) {
595  while (!DbgVal->use_empty())
596  cast<Instruction>(DbgVal->user_back())->eraseFromParent();
597  DbgVal->eraseFromParent();
598  Changed = true;
599  }
600  };
601  RemoveUses("llvm.dbg.declare");
602  RemoveUses("llvm.dbg.value");
603 
604  // Delete non-CU debug info named metadata nodes.
605  for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
606  NMI != NME;) {
607  NamedMDNode *NMD = &*NMI;
608  ++NMI;
609  // Specifically keep dbg.cu around.
610  if (NMD->getName() == "llvm.dbg.cu")
611  continue;
612  }
613 
614  // Drop all dbg attachments from global variables.
615  for (auto &GV : M.globals())
616  GV.eraseMetadata(LLVMContext::MD_dbg);
617 
618  DebugTypeInfoRemoval Mapper(M.getContext());
619  auto remap = [&](MDNode *Node) -> MDNode * {
620  if (!Node)
621  return nullptr;
622  Mapper.traverseAndRemap(Node);
623  auto *NewNode = Mapper.mapNode(Node);
624  Changed |= Node != NewNode;
625  Node = NewNode;
626  return NewNode;
627  };
628 
629  // Rewrite the DebugLocs to be equivalent to what
630  // -gline-tables-only would have created.
631  for (auto &F : M) {
632  if (auto *SP = F.getSubprogram()) {
633  Mapper.traverseAndRemap(SP);
634  auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
635  Changed |= SP != NewSP;
636  F.setSubprogram(NewSP);
637  }
638  for (auto &BB : F) {
639  for (auto &I : BB) {
640  auto remapDebugLoc = [&](DebugLoc DL) -> DebugLoc {
641  auto *Scope = DL.getScope();
642  MDNode *InlinedAt = DL.getInlinedAt();
643  Scope = remap(Scope);
644  InlinedAt = remap(InlinedAt);
645  return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt);
646  };
647 
648  if (I.getDebugLoc() != DebugLoc())
649  I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
650 
651  // Remap DILocations in untyped MDNodes (e.g., llvm.loop).
653  I.getAllMetadata(MDs);
654  for (auto Attachment : MDs)
655  if (auto *T = dyn_cast_or_null<MDTuple>(Attachment.second))
656  for (unsigned N = 0; N < T->getNumOperands(); ++N)
657  if (auto *Loc = dyn_cast_or_null<DILocation>(T->getOperand(N)))
658  if (Loc != DebugLoc())
659  T->replaceOperandWith(N, remapDebugLoc(Loc));
660  }
661  }
662  }
663 
664  // Create a new llvm.dbg.cu, which is equivalent to the one
665  // -gline-tables-only would have created.
666  for (auto &NMD : M.getNamedMDList()) {
668  for (MDNode *Op : NMD.operands())
669  Ops.push_back(remap(Op));
670 
671  if (!Changed)
672  continue;
673 
674  NMD.clearOperands();
675  for (auto *Op : Ops)
676  if (Op)
677  NMD.addOperand(Op);
678  }
679  return Changed;
680 }
681 
683  if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
684  M.getModuleFlag("Debug Info Version")))
685  return Val->getZExtValue();
686  return 0;
687 }
688 
690  const DILocation *LocB) {
691  setDebugLoc(DILocation::getMergedLocation(LocA, LocB));
692 }
693 
694 //===----------------------------------------------------------------------===//
695 // LLVM C API implementations.
696 //===----------------------------------------------------------------------===//
697 
699  switch (lang) {
700 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
701  case LLVMDWARFSourceLanguage##NAME: \
702  return ID;
703 #include "llvm/BinaryFormat/Dwarf.def"
704 #undef HANDLE_DW_LANG
705  }
706  llvm_unreachable("Unhandled Tag");
707 }
708 
709 template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) {
710  return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
711 }
712 
714  return static_cast<DINode::DIFlags>(Flags);
715 }
716 
718  return static_cast<LLVMDIFlags>(Flags);
719 }
720 
722 pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) {
723  return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized);
724 }
725 
727  return DEBUG_METADATA_VERSION;
728 }
729 
731  return wrap(new DIBuilder(*unwrap(M), false));
732 }
733 
735  return wrap(new DIBuilder(*unwrap(M)));
736 }
737 
740 }
741 
743  return StripDebugInfo(*unwrap(M));
744 }
745 
747  delete unwrap(Builder);
748 }
749 
751  unwrap(Builder)->finalize();
752 }
753 
756  LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
757  LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
758  unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
759  LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
760  LLVMBool DebugInfoForProfiling) {
761  auto File = unwrapDI<DIFile>(FileRef);
762 
763  return wrap(unwrap(Builder)->createCompileUnit(
765  StringRef(Producer, ProducerLen), isOptimized,
766  StringRef(Flags, FlagsLen), RuntimeVer,
767  StringRef(SplitName, SplitNameLen),
768  static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
769  SplitDebugInlining, DebugInfoForProfiling));
770 }
771 
773 LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
774  size_t FilenameLen, const char *Directory,
775  size_t DirectoryLen) {
776  return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
777  StringRef(Directory, DirectoryLen)));
778 }
779 
782  const char *Name, size_t NameLen,
783  const char *ConfigMacros, size_t ConfigMacrosLen,
784  const char *IncludePath, size_t IncludePathLen,
785  const char *ISysRoot, size_t ISysRootLen) {
786  return wrap(unwrap(Builder)->createModule(
787  unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
788  StringRef(ConfigMacros, ConfigMacrosLen),
789  StringRef(IncludePath, IncludePathLen),
790  StringRef(ISysRoot, ISysRootLen)));
791 }
792 
794  LLVMMetadataRef ParentScope,
795  const char *Name, size_t NameLen,
796  LLVMBool ExportSymbols) {
797  return wrap(unwrap(Builder)->createNameSpace(
798  unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols));
799 }
800 
802  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
803  size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
804  LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
805  LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
806  unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
807  return wrap(unwrap(Builder)->createFunction(
808  unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
809  unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine,
810  map_from_llvmDIFlags(Flags),
811  pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr,
812  nullptr, nullptr));
813 }
814 
815 
817  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
818  LLVMMetadataRef File, unsigned Line, unsigned Col) {
819  return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope),
820  unwrapDI<DIFile>(File),
821  Line, Col));
822 }
823 
826  LLVMMetadataRef Scope,
828  unsigned Discriminator) {
829  return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope),
830  unwrapDI<DIFile>(File),
831  Discriminator));
832 }
833 
836  LLVMMetadataRef Scope,
837  LLVMMetadataRef NS,
839  unsigned Line) {
840  return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
841  unwrapDI<DINamespace>(NS),
842  unwrapDI<DIFile>(File),
843  Line));
844 }
845 
848  LLVMMetadataRef Scope,
849  LLVMMetadataRef ImportedEntity,
851  unsigned Line) {
852  return wrap(unwrap(Builder)->createImportedModule(
853  unwrapDI<DIScope>(Scope),
854  unwrapDI<DIImportedEntity>(ImportedEntity),
855  unwrapDI<DIFile>(File), Line));
856 }
857 
860  LLVMMetadataRef Scope,
861  LLVMMetadataRef M,
863  unsigned Line) {
864  return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
865  unwrapDI<DIModule>(M),
866  unwrapDI<DIFile>(File),
867  Line));
868 }
869 
872  LLVMMetadataRef Scope,
873  LLVMMetadataRef Decl,
875  unsigned Line,
876  const char *Name, size_t NameLen) {
877  return wrap(unwrap(Builder)->createImportedDeclaration(
878  unwrapDI<DIScope>(Scope),
879  unwrapDI<DINode>(Decl),
880  unwrapDI<DIFile>(File), Line, {Name, NameLen}));
881 }
882 
885  unsigned Column, LLVMMetadataRef Scope,
886  LLVMMetadataRef InlinedAt) {
887  return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
888  unwrap(InlinedAt)));
889 }
890 
892  return unwrapDI<DILocation>(Location)->getLine();
893 }
894 
896  return unwrapDI<DILocation>(Location)->getColumn();
897 }
898 
900  return wrap(unwrapDI<DILocation>(Location)->getScope());
901 }
902 
904  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
905  size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
906  uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements,
907  unsigned NumElements, LLVMMetadataRef ClassTy) {
908 auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
909  NumElements});
910 return wrap(unwrap(Builder)->createEnumerationType(
911  unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
912  LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
913 }
914 
916  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
917  size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
918  uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
919  LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
920  const char *UniqueId, size_t UniqueIdLen) {
921  auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
922  NumElements});
923  return wrap(unwrap(Builder)->createUnionType(
924  unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
925  LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
926  Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
927 }
928 
929 
932  uint32_t AlignInBits, LLVMMetadataRef Ty,
933  LLVMMetadataRef *Subscripts,
934  unsigned NumSubscripts) {
935  auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
936  NumSubscripts});
937  return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
938  unwrapDI<DIType>(Ty), Subs));
939 }
940 
943  uint32_t AlignInBits, LLVMMetadataRef Ty,
944  LLVMMetadataRef *Subscripts,
945  unsigned NumSubscripts) {
946  auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
947  NumSubscripts});
948  return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
949  unwrapDI<DIType>(Ty), Subs));
950 }
951 
954  size_t NameLen, uint64_t SizeInBits,
955  LLVMDWARFTypeEncoding Encoding,
956  LLVMDIFlags Flags) {
957  return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
958  SizeInBits, Encoding,
959  map_from_llvmDIFlags(Flags)));
960 }
961 
963  LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
964  uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,
965  const char *Name, size_t NameLen) {
966  return wrap(unwrap(Builder)->createPointerType(unwrapDI<DIType>(PointeeTy),
967  SizeInBits, AlignInBits,
968  AddressSpace, {Name, NameLen}));
969 }
970 
972  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
973  size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
974  uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
975  LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
976  unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
977  const char *UniqueId, size_t UniqueIdLen) {
978  auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
979  NumElements});
980  return wrap(unwrap(Builder)->createStructType(
981  unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
982  LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
983  unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
984  unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
985 }
986 
988  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
989  size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
990  uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
991  LLVMMetadataRef Ty) {
992  return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope),
993  {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
994  OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty)));
995 }
996 
999  size_t NameLen) {
1000  return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
1001 }
1002 
1005  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1006  size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1007  LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
1008  uint32_t AlignInBits) {
1009  return wrap(unwrap(Builder)->createStaticMemberType(
1010  unwrapDI<DIScope>(Scope), {Name, NameLen},
1011  unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIType>(Type),
1012  map_from_llvmDIFlags(Flags), unwrap<Constant>(ConstantVal),
1013  AlignInBits));
1014 }
1015 
1018  const char *Name, size_t NameLen,
1019  LLVMMetadataRef File, unsigned LineNo,
1020  uint64_t SizeInBits, uint32_t AlignInBits,
1021  uint64_t OffsetInBits, LLVMDIFlags Flags,
1022  LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
1023  return wrap(unwrap(Builder)->createObjCIVar(
1024  {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1025  SizeInBits, AlignInBits, OffsetInBits,
1026  map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty),
1027  unwrapDI<MDNode>(PropertyNode)));
1028 }
1029 
1032  const char *Name, size_t NameLen,
1033  LLVMMetadataRef File, unsigned LineNo,
1034  const char *GetterName, size_t GetterNameLen,
1035  const char *SetterName, size_t SetterNameLen,
1036  unsigned PropertyAttributes,
1037  LLVMMetadataRef Ty) {
1038  return wrap(unwrap(Builder)->createObjCProperty(
1039  {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1040  {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
1041  PropertyAttributes, unwrapDI<DIType>(Ty)));
1042 }
1043 
1047  return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
1048 }
1049 
1052  const char *Name, size_t NameLen,
1053  LLVMMetadataRef File, unsigned LineNo,
1054  LLVMMetadataRef Scope) {
1055  return wrap(unwrap(Builder)->createTypedef(
1056  unwrapDI<DIType>(Type), {Name, NameLen},
1057  unwrapDI<DIFile>(File), LineNo,
1058  unwrapDI<DIScope>(Scope)));
1059 }
1060 
1063  LLVMMetadataRef Ty, LLVMMetadataRef BaseTy,
1064  uint64_t BaseOffset, uint32_t VBPtrOffset,
1065  LLVMDIFlags Flags) {
1066  return wrap(unwrap(Builder)->createInheritance(
1067  unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy),
1068  BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
1069 }
1070 
1073  LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1074  size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1075  unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1076  const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1077  return wrap(unwrap(Builder)->createForwardDecl(
1078  Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1079  unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1080  AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
1081 }
1082 
1085  LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
1086  size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
1087  unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
1088  LLVMDIFlags Flags, const char *UniqueIdentifier,
1089  size_t UniqueIdentifierLen) {
1090  return wrap(unwrap(Builder)->createReplaceableCompositeType(
1091  Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
1092  unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1093  AlignInBits, map_from_llvmDIFlags(Flags),
1094  {UniqueIdentifier, UniqueIdentifierLen}));
1095 }
1096 
1100  return wrap(unwrap(Builder)->createQualifiedType(Tag,
1101  unwrapDI<DIType>(Type)));
1102 }
1103 
1107  return wrap(unwrap(Builder)->createReferenceType(Tag,
1108  unwrapDI<DIType>(Type)));
1109 }
1110 
1113  return wrap(unwrap(Builder)->createNullPtrType());
1114 }
1115 
1118  LLVMMetadataRef PointeeType,
1119  LLVMMetadataRef ClassType,
1120  uint64_t SizeInBits,
1121  uint32_t AlignInBits,
1122  LLVMDIFlags Flags) {
1123  return wrap(unwrap(Builder)->createMemberPointerType(
1124  unwrapDI<DIType>(PointeeType),
1125  unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
1126  map_from_llvmDIFlags(Flags)));
1127 }
1128 
1131  LLVMMetadataRef Scope,
1132  const char *Name, size_t NameLen,
1133  LLVMMetadataRef File, unsigned LineNumber,
1134  uint64_t SizeInBits,
1135  uint64_t OffsetInBits,
1136  uint64_t StorageOffsetInBits,
1137  LLVMDIFlags Flags, LLVMMetadataRef Type) {
1138  return wrap(unwrap(Builder)->createBitFieldMemberType(
1139  unwrapDI<DIScope>(Scope), {Name, NameLen},
1140  unwrapDI<DIFile>(File), LineNumber,
1141  SizeInBits, OffsetInBits, StorageOffsetInBits,
1142  map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type)));
1143 }
1144 
1146  LLVMMetadataRef Scope, const char *Name, size_t NameLen,
1147  LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
1148  uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1149  LLVMMetadataRef DerivedFrom,
1150  LLVMMetadataRef *Elements, unsigned NumElements,
1151  LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode,
1152  const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
1153  auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
1154  NumElements});
1155  return wrap(unwrap(Builder)->createClassType(
1156  unwrapDI<DIScope>(Scope), {Name, NameLen},
1157  unwrapDI<DIFile>(File), LineNumber,
1158  SizeInBits, AlignInBits, OffsetInBits,
1159  map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom),
1160  Elts, unwrapDI<DIType>(VTableHolder),
1161  unwrapDI<MDNode>(TemplateParamsNode),
1162  {UniqueIdentifier, UniqueIdentifierLen}));
1163 }
1164 
1168  return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
1169 }
1170 
1171 const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
1172  StringRef Str = unwrap<DIType>(DType)->getName();
1173  *Length = Str.size();
1174  return Str.data();
1175 }
1176 
1178  return unwrapDI<DIType>(DType)->getSizeInBits();
1179 }
1180 
1182  return unwrapDI<DIType>(DType)->getOffsetInBits();
1183 }
1184 
1186  return unwrapDI<DIType>(DType)->getAlignInBits();
1187 }
1188 
1190  return unwrapDI<DIType>(DType)->getLine();
1191 }
1192 
1194  return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags());
1195 }
1196 
1198  LLVMMetadataRef *Types,
1199  size_t Length) {
1200  return wrap(
1201  unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
1202 }
1203 
1207  LLVMMetadataRef *ParameterTypes,
1208  unsigned NumParameterTypes,
1209  LLVMDIFlags Flags) {
1210  auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
1211  NumParameterTypes});
1212  return wrap(unwrap(Builder)->createSubroutineType(
1213  Elts, map_from_llvmDIFlags(Flags)));
1214 }
1215 
1217  int64_t *Addr, size_t Length) {
1218  return wrap(unwrap(Builder)->createExpression(ArrayRef<int64_t>(Addr,
1219  Length)));
1220 }
1221 
1224  int64_t Value) {
1225  return wrap(unwrap(Builder)->createConstantValueExpression(Value));
1226 }
1227 
1229  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1230  size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File,
1231  unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1232  LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) {
1233  return wrap(unwrap(Builder)->createGlobalVariableExpression(
1234  unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
1235  unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1236  unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
1237  nullptr, AlignInBits));
1238 }
1239 
1241  size_t Count) {
1242  return wrap(
1243  MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
1244 }
1245 
1247  MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode));
1248 }
1249 
1251  LLVMMetadataRef Replacement) {
1252  auto *Node = unwrapDI<MDNode>(TargetMetadata);
1253  Node->replaceAllUsesWith(unwrap<Metadata>(Replacement));
1255 }
1256 
1258  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1259  size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File,
1260  unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
1261  LLVMMetadataRef Decl, uint32_t AlignInBits) {
1262  return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
1263  unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen},
1264  unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1265  unwrapDI<MDNode>(Decl), nullptr, AlignInBits));
1266 }
1267 
1270  LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1271  LLVMMetadataRef DL, LLVMValueRef Instr) {
1272  return wrap(unwrap(Builder)->insertDeclare(
1273  unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1274  unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1275  unwrap<Instruction>(Instr)));
1276 }
1277 
1279  LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1281  return wrap(unwrap(Builder)->insertDeclare(
1282  unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1283  unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1284  unwrap(Block)));
1285 }
1286 
1288  LLVMValueRef Val,
1289  LLVMMetadataRef VarInfo,
1290  LLVMMetadataRef Expr,
1292  LLVMValueRef Instr) {
1293  return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1294  unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1295  unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1296  unwrap<Instruction>(Instr)));
1297 }
1298 
1300  LLVMValueRef Val,
1301  LLVMMetadataRef VarInfo,
1302  LLVMMetadataRef Expr,
1304  LLVMBasicBlockRef Block) {
1305  return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1306  unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1307  unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1308  unwrap(Block)));
1309 }
1310 
1312  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1313  size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1314  LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) {
1315  return wrap(unwrap(Builder)->createAutoVariable(
1316  unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File),
1317  LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1318  map_from_llvmDIFlags(Flags), AlignInBits));
1319 }
1320 
1322  LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1323  size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo,
1324  LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) {
1325  return wrap(unwrap(Builder)->createParameterVariable(
1326  unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File),
1327  LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1328  map_from_llvmDIFlags(Flags)));
1329 }
1330 
1332  int64_t Lo, int64_t Count) {
1333  return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
1334 }
1335 
1337  LLVMMetadataRef *Data,
1338  size_t Length) {
1339  Metadata **DataValue = unwrap(Data);
1340  return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get());
1341 }
1342 
1344  return wrap(unwrap<Function>(Func)->getSubprogram());
1345 }
1346 
1348  unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
1349 }
1350 
1352  switch(unwrap(Metadata)->getMetadataID()) {
1353 #define HANDLE_METADATA_LEAF(CLASS) \
1354  case Metadata::CLASS##Kind: \
1355  return (LLVMMetadataKind)LLVM##CLASS##MetadataKind;
1356 #include "llvm/IR/Metadata.def"
1357  default:
1359  }
1360 }
const NoneType None
Definition: None.h:24
uint64_t CallInst * C
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:68
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
Definition: DebugInfo.cpp:118
LLVMMetadataRef LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen)
Create a DWARF unspecified type.
Definition: DebugInfo.cpp:998
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Definition: Metadata.cpp:831
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:711
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:915
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set.
Definition: DebugInfo.cpp:1045
bool isDistinct() const
Definition: Metadata.h:943
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:22
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:1257
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:931
This class represents lattice values for constants.
Definition: AllocatorList.h:24
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:62
unsigned getRuntimeVersion() const
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Types, size_t Length)
Create a type array.
Definition: DebugInfo.cpp:1197
unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef M)
The version of debug metadata that&#39;s present in the provided Module.
Definition: DebugInfo.cpp:738
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:859
void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode)
Deallocate a temporary node.
Definition: DebugInfo.cpp:1246
Implements a dense probed hash-table based set.
Definition: DenseSet.h:250
DIFile * getFile() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata)
Obtain the enumerated type of a Metadata instance.
Definition: DebugInfo.cpp:1351
named_metadata_iterator named_metadata_end()
Definition: Module.h:712
static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags)
Definition: DebugInfo.cpp:713
This file contains the declarations for metadata subclasses.
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:801
unsigned getDebugMetadataVersionFromModule(const Module &M)
Return Debug Info Metadata Version by checking module flags.
Definition: DebugInfo.cpp:682
DICompositeTypeArray getEnumTypes() const
void reset()
Clear all lists.
Definition: DebugInfo.cpp:54
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line)
Create a descriptor for an imported module that aliases another imported entity descriptor.
Definition: DebugInfo.cpp:847
uint64_t getDWOId() const
struct LLVMOpaqueDIBuilder * LLVMDIBuilderRef
Represents an LLVM debug info builder.
Definition: Types.h:118
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:864
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Insert a new llvm.dbg.value intrinsic call at the end of the given basic block.
Definition: DebugInfo.cpp:1299
F(f)
bool stripDebugInfo(Function &F)
Definition: DebugInfo.cpp:314
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType)
Get the offset of this DIType in bits.
Definition: DebugInfo.cpp:1181
StringRef getProducer() const
void reserve(size_type N)
Definition: SmallVector.h:376
bool getDebugInfoForProfiling() const
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:987
op_iterator op_end() const
Definition: Metadata.h:1063
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:953
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
void processModule(const Module &M)
Process entire module and collect debug info anchors.
Definition: DebugInfo.cpp:63
Tuple of metadata.
Definition: Metadata.h:1106
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, SmallVectorImpl< TrackingMDNodeRef > &AllImportedModules)
Definition: DIBuilder.cpp:164
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)
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
Definition: DebugInfo.cpp:754
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:221
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location)
Get the column number of this debug location.
Definition: DebugInfo.cpp:895
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:1031
LLVMDWARFEmissionKind
The amount of debug information to emit.
Definition: DebugInfo.h:124
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:1145
StringRef getSplitDebugFilename() const
A tuple of MDNodes.
Definition: Metadata.h:1326
amdgpu Simplify well known AMD library false Value Value const Twine & Name
StringRef getFlags() const
unsigned LLVMDWARFTypeEncoding
An LLVM DWARF type encoding.
Definition: DebugInfo.h:171
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
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:903
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:1321
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:244
void eraseFromParent()
Drop all references and remove the node from parent module.
Definition: Metadata.cpp:1094
LLVMMetadataRef LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, int64_t Value)
Create a new descriptor for the specified variable that does not have an address, but does have a con...
Definition: DebugInfo.cpp:1223
The access may reference the value stored in memory.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1200
static StringRef getName(Value *V)
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location)
Get the line number of this debug location.
Definition: DebugInfo.cpp:891
bool getRangesBaseAddress() const
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1178
bool stripNonLineTableDebugInfo(Module &M)
Downgrade the debug info in a module to contain only line table information.
Definition: DebugInfo.cpp:589
Holds a subclass of DINode.
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:44
op_iterator op_begin() const
Definition: Metadata.h:1059
static Optional< DebugNameTableKind > getNameTableKind(StringRef Str)
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:1130
Subprogram description.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
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:793
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:734
LLVMMetadataRef LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a c++ style reference or rvalue reference type.
Definition: DebugInfo.cpp:1105
op_range operands() const
Definition: Metadata.h:1067
LLVMContext & getContext() const
Definition: Metadata.h:924
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:54
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:351
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
LLVMMetadataRef LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagArtificial set.
Definition: DebugInfo.cpp:1166
Debug location.
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:962
LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M)
Construct a builder for a module, and do not allow for unresolved nodes attached to the module...
Definition: DebugInfo.cpp:730
DIMacroNodeArray getMacros() const
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Return a temporary node.
Definition: Metadata.h:1153
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1166
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual)
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
Definition: Metadata.cpp:1504
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType)
Get the flags associated with this DIType.
Definition: DebugInfo.cpp:1193
iterator_range< iterator > functions()
Definition: Module.h:606
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:308
LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt)
Creates a new DebugLocation that describes a source location.
Definition: DebugInfo.cpp:884
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block)
Insert a new llvm.dbg.declare intrinsic call at the end of the given basic block. ...
Definition: DebugInfo.cpp:1278
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef NS, LLVMMetadataRef File, unsigned Line)
Create a descriptor for an imported namespace.
Definition: DebugInfo.cpp:835
Import information from summary.
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:312
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:1084
struct UnitT Unit
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1174
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned LLVMDebugMetadataVersion()
The current debug metadata version number.
Definition: DebugInfo.cpp:726
LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func)
Get the metadata of the subprogram attached to a function.
Definition: DebugInfo.cpp:1343
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned Col)
Create a descriptor for a lexical block with the specified parent context.
Definition: DebugInfo.cpp:816
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType)
Get the source line where this DIType is declared.
Definition: DebugInfo.cpp:1189
A pair of DIGlobalVariable and DIExpression.
DIImportedEntityArray getImportedEntities() const
LLVMDWARFSourceLanguage
Source languages known by DWARF.
Definition: DebugInfo.h:74
void processValue(const Module &M, const DbgValueInst *DVI)
Process DbgValueInst.
Definition: DebugInfo.cpp:214
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, int64_t Lo, int64_t Count)
Create a descriptor for a value range.
Definition: DebugInfo.cpp:1331
int LLVMBool
Definition: Types.h:29
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&... Args)
Definition: DIBuilder.cpp:746
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, size_t Count)
Create a new temporary MDNode.
Definition: DebugInfo.cpp:1240
static DISubprogram::DISPFlags pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized)
Definition: DebugInfo.cpp:722
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVMValueRef LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr)
Insert a new llvm.dbg.declare intrinsic call before the given instruction.
Definition: DebugInfo.cpp:1269
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:107
Base class for scope-like contexts.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:210
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata, LLVMMetadataRef Replacement)
Replace all uses of temporary metadata.
Definition: DebugInfo.cpp:1250
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 *ISysRoot, size_t ISysRootLen)
Creates a new descriptor for a module with the specified parent scope.
Definition: DebugInfo.cpp:781
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:1117
LLVMMetadataRef LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder)
Create C++11 nullptr type.
Definition: DebugInfo.cpp:1112
DIT * unwrapDI(LLVMMetadataRef Ref)
Definition: DebugInfo.cpp:709
Iterator for intrusive lists based on ilist_node.
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:773
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef M, LLVMMetadataRef File, unsigned Line)
Create a descriptor for an imported module.
Definition: DebugInfo.cpp:859
Base class for types.
StringRef getName() const
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Module.h This file contains the declarations for the Module class.
AddressSpace
Definition: NVPTXBaseInfo.h:22
LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Insert a new llvm.dbg.value intrinsic call before the given instruction.
Definition: DebugInfo.cpp:1287
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
Definition: Types.h:83
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:1311
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
void applyMergedLocation(const DILocation *LocA, const DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
Definition: DebugInfo.cpp:689
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location)
Get the local scope associated with this debug location.
Definition: DebugInfo.cpp:899
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t Length)
Create an array of DI Nodes.
Definition: DebugInfo.cpp:1336
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:176
unsigned getSourceLanguage() const
void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder)
Construct any deferred debug info descriptors.
Definition: DebugInfo.cpp:750
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType)
Get the alignment of this DIType in bits.
Definition: DebugInfo.cpp:1185
StringRef getName() const
Definition: Metadata.cpp:1098
DIGlobalVariableExpressionArray getGlobalVariables() const
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:971
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType)
Get the size of this DIType in bits.
Definition: DebugInfo.cpp:1177
bool getSplitDebugInlining() const
DIFlags
Debug info flags.
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags)
Definition: DebugInfo.cpp:717
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:311
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:190
LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, LLVMMetadataRef File, LLVMMetadataRef *ParameterTypes, unsigned NumParameterTypes, LLVMDIFlags Flags)
Create subroutine type.
Definition: DebugInfo.cpp:1205
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:56
void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder)
Deallocates the DIBuilder and everything it owns.
Definition: DebugInfo.cpp:746
This represents the llvm.dbg.value instruction.
void processDeclare(const Module &M, const DbgDeclareInst *DDI)
Process DbgDeclareInst.
Definition: DebugInfo.cpp:198
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP)
Set the subprogram attached to a function.
Definition: DebugInfo.cpp:1347
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
iterator_range< debug_compile_units_iterator > debug_compile_units() const
Return an iterator for all DICompileUnits listed in this Module&#39;s llvm.dbg.cu named metadata node and...
Definition: Module.h:778
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
uint32_t Size
Definition: Profile.cpp:47
static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang)
Definition: DebugInfo.cpp:698
DILocalVariable * getVariable() const
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:92
LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:742
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:171
DISPFlags
Debug info subprogram flags.
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:1004
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:1228
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:211
LLVMDIFlags
This file declares the C API endpoints for generating DWARF Debug Info.
Definition: DebugInfo.h:29
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:1062
DIScopeArray getRetainedTypes() const
const unsigned Kind
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:825
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
Definition: Types.h:90
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static MDNode * stripDebugLocFromLoopID(MDNode *N)
Definition: DebugInfo.cpp:282
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, int64_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:1216
LLVM Value Representation.
Definition: Value.h:73
DIScopeRef getScope() const
unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
bool hasMetadata() const
Check if this has any metadata.
Definition: GlobalObject.h:106
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:1017
iterator_range< global_iterator > globals()
Definition: Module.h:584
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
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:1072
LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope)
Create debugging information entry for a typedef.
Definition: DebugInfo.cpp:1051
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1075
const char * LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length)
Get the name of this DIType.
Definition: DebugInfo.cpp:1171
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:942
This represents the llvm.dbg.declare instruction.
unsigned LLVMMetadataKind
Definition: DebugInfo.h:166
Root of the metadata hierarchy.
Definition: Metadata.h:58
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
LLVMMetadataRef LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a qualified type, e.g.
Definition: DebugInfo.cpp:1098
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:76
named_metadata_iterator named_metadata_begin()
Definition: Module.h:707
LLVMMetadataRef LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef Decl, LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen)
Create a descriptor for an imported function, type, or variable.
Definition: DebugInfo.cpp:871
DIScopeRef getScope() const