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