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