LLVM  12.0.0git
Debugify.cpp
Go to the documentation of this file.
1 //===- Debugify.cpp - Attach synthetic debug info to everything -----------===//
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 /// \file This pass attaches synthetic debug info to everything. It can be used
10 /// to create targeted tests for debug info preservation.
11 ///
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/BitVector.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/IR/DIBuilder.h"
18 #include "llvm/IR/DebugInfo.h"
19 #include "llvm/IR/InstIterator.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/IntrinsicInst.h"
22 #include "llvm/IR/Module.h"
24 #include "llvm/Pass.h"
26 
27 using namespace llvm;
28 
29 namespace {
30 
31 cl::opt<bool> Quiet("debugify-quiet",
32  cl::desc("Suppress verbose debugify output"));
33 
34 enum class Level {
35  Locations,
36  LocationsAndVariables
37 };
38 cl::opt<Level> DebugifyLevel(
39  "debugify-level", cl::desc("Kind of debug info to add"),
40  cl::values(clEnumValN(Level::Locations, "locations", "Locations only"),
41  clEnumValN(Level::LocationsAndVariables, "location+variables",
42  "Locations and Variables")),
43  cl::init(Level::LocationsAndVariables));
44 
45 raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
46 
47 uint64_t getAllocSizeInBits(Module &M, Type *Ty) {
48  return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0;
49 }
50 
51 bool isFunctionSkipped(Function &F) {
52  return F.isDeclaration() || !F.hasExactDefinition();
53 }
54 
55 /// Find the basic block's terminating instruction.
56 ///
57 /// Special care is needed to handle musttail and deopt calls, as these behave
58 /// like (but are in fact not) terminators.
59 Instruction *findTerminatingInstruction(BasicBlock &BB) {
60  if (auto *I = BB.getTerminatingMustTailCall())
61  return I;
62  if (auto *I = BB.getTerminatingDeoptimizeCall())
63  return I;
64  return BB.getTerminator();
65 }
66 } // end anonymous namespace
67 
70  std::function<bool(DIBuilder &DIB, Function &F)> ApplyToMF) {
71  // Skip modules with debug info.
72  if (M.getNamedMetadata("llvm.dbg.cu")) {
73  dbg() << Banner << "Skipping module with debug info\n";
74  return false;
75  }
76 
77  DIBuilder DIB(M);
78  LLVMContext &Ctx = M.getContext();
79  auto *Int32Ty = Type::getInt32Ty(Ctx);
80 
81  // Get a DIType which corresponds to Ty.
83  auto getCachedDIType = [&](Type *Ty) -> DIType * {
84  uint64_t Size = getAllocSizeInBits(M, Ty);
85  DIType *&DTy = TypeCache[Size];
86  if (!DTy) {
87  std::string Name = "ty" + utostr(Size);
88  DTy = DIB.createBasicType(Name, Size, dwarf::DW_ATE_unsigned);
89  }
90  return DTy;
91  };
92 
93  unsigned NextLine = 1;
94  unsigned NextVar = 1;
95  auto File = DIB.createFile(M.getName(), "/");
96  auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "debugify",
97  /*isOptimized=*/true, "", 0);
98 
99  // Visit each instruction.
100  for (Function &F : Functions) {
101  if (isFunctionSkipped(F))
102  continue;
103 
104  bool InsertedDbgVal = false;
105  auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
106  DISubprogram::DISPFlags SPFlags =
107  DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
108  if (F.hasPrivateLinkage() || F.hasInternalLinkage())
109  SPFlags |= DISubprogram::SPFlagLocalToUnit;
110  auto SP = DIB.createFunction(CU, F.getName(), F.getName(), File, NextLine,
111  SPType, NextLine, DINode::FlagZero, SPFlags);
112  F.setSubprogram(SP);
113 
114  // Helper that inserts a dbg.value before \p InsertBefore, copying the
115  // location (and possibly the type, if it's non-void) from \p TemplateInst.
116  auto insertDbgVal = [&](Instruction &TemplateInst,
117  Instruction *InsertBefore) {
118  std::string Name = utostr(NextVar++);
119  Value *V = &TemplateInst;
120  if (TemplateInst.getType()->isVoidTy())
121  V = ConstantInt::get(Int32Ty, 0);
122  const DILocation *Loc = TemplateInst.getDebugLoc().get();
123  auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
124  getCachedDIType(V->getType()),
125  /*AlwaysPreserve=*/true);
126  DIB.insertDbgValueIntrinsic(V, LocalVar, DIB.createExpression(), Loc,
127  InsertBefore);
128  };
129 
130  for (BasicBlock &BB : F) {
131  // Attach debug locations.
132  for (Instruction &I : BB)
133  I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
134 
135  if (DebugifyLevel < Level::LocationsAndVariables)
136  continue;
137 
138  // Inserting debug values into EH pads can break IR invariants.
139  if (BB.isEHPad())
140  continue;
141 
142  // Find the terminating instruction, after which no debug values are
143  // attached.
144  Instruction *LastInst = findTerminatingInstruction(BB);
145  assert(LastInst && "Expected basic block with a terminator");
146 
147  // Maintain an insertion point which can't be invalidated when updates
148  // are made.
149  BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();
150  assert(InsertPt != BB.end() && "Expected to find an insertion point");
151  Instruction *InsertBefore = &*InsertPt;
152 
153  // Attach debug values.
154  for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {
155  // Skip void-valued instructions.
156  if (I->getType()->isVoidTy())
157  continue;
158 
159  // Phis and EH pads must be grouped at the beginning of the block.
160  // Only advance the insertion point when we finish visiting these.
161  if (!isa<PHINode>(I) && !I->isEHPad())
162  InsertBefore = I->getNextNode();
163 
164  insertDbgVal(*I, InsertBefore);
165  InsertedDbgVal = true;
166  }
167  }
168  // Make sure we emit at least one dbg.value, otherwise MachineDebugify may
169  // not have anything to work with as it goes about inserting DBG_VALUEs.
170  // (It's common for MIR tests to be written containing skeletal IR with
171  // empty functions -- we're still interested in debugifying the MIR within
172  // those tests, and this helps with that.)
173  if (DebugifyLevel == Level::LocationsAndVariables && !InsertedDbgVal) {
174  auto *Term = findTerminatingInstruction(F.getEntryBlock());
175  insertDbgVal(*Term, Term);
176  }
177  if (ApplyToMF)
178  ApplyToMF(DIB, F);
179  DIB.finalizeSubprogram(SP);
180  }
181  DIB.finalize();
182 
183  // Track the number of distinct lines and variables.
184  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.debugify");
185  auto addDebugifyOperand = [&](unsigned N) {
186  NMD->addOperand(MDNode::get(
188  };
189  addDebugifyOperand(NextLine - 1); // Original number of lines.
190  addDebugifyOperand(NextVar - 1); // Original number of variables.
191  assert(NMD->getNumOperands() == 2 &&
192  "llvm.debugify should have exactly 2 operands!");
193 
194  // Claim that this synthetic debug info is valid.
195  StringRef DIVersionKey = "Debug Info Version";
196  if (!M.getModuleFlag(DIVersionKey))
197  M.addModuleFlag(Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
198 
199  return true;
200 }
201 
202 static bool applyDebugify(Function &F) {
203  Module &M = *F.getParent();
204  auto FuncIt = F.getIterator();
205  return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
206  "FunctionDebugify: ", /*ApplyToMF=*/nullptr);
207 }
208 
209 static bool applyDebugify(Module &M) {
210  return applyDebugifyMetadata(M, M.functions(),
211  "ModuleDebugify: ", /*ApplyToMF=*/nullptr);
212 }
213 
215  bool Changed = false;
216 
217  // Remove the llvm.debugify module-level named metadata.
218  NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify");
219  if (DebugifyMD) {
220  M.eraseNamedMetadata(DebugifyMD);
221  Changed = true;
222  }
223 
224  // Strip out all debug intrinsics and supporting metadata (subprograms, types,
225  // variables, etc).
226  Changed |= StripDebugInfo(M);
227 
228  // Strip out the dead dbg.value prototype.
229  Function *DbgValF = M.getFunction("llvm.dbg.value");
230  if (DbgValF) {
231  assert(DbgValF->isDeclaration() && DbgValF->use_empty() &&
232  "Not all debug info stripped?");
233  DbgValF->eraseFromParent();
234  Changed = true;
235  }
236 
237  // Strip out the module-level Debug Info Version metadata.
238  // FIXME: There must be an easier way to remove an operand from a NamedMDNode.
239  NamedMDNode *NMD = M.getModuleFlagsMetadata();
240  if (!NMD)
241  return Changed;
243  for (MDNode *Flag : NMD->operands())
244  Flags.push_back(Flag);
245  NMD->clearOperands();
246  for (MDNode *Flag : Flags) {
247  MDString *Key = dyn_cast_or_null<MDString>(Flag->getOperand(1));
248  if (Key->getString() == "Debug Info Version") {
249  Changed = true;
250  continue;
251  }
252  NMD->addOperand(Flag);
253  }
254  // If we left it empty we might as well remove it.
255  if (NMD->getNumOperands() == 0)
256  NMD->eraseFromParent();
257 
258  return Changed;
259 }
260 
261 namespace {
262 /// Return true if a mis-sized diagnostic is issued for \p DVI.
263 bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
264  // The size of a dbg.value's value operand should match the size of the
265  // variable it corresponds to.
266  //
267  // TODO: This, along with a check for non-null value operands, should be
268  // promoted to verifier failures.
269  Value *V = DVI->getValue();
270  if (!V)
271  return false;
272 
273  // For now, don't try to interpret anything more complicated than an empty
274  // DIExpression. Eventually we should try to handle OP_deref and fragments.
275  if (DVI->getExpression()->getNumElements())
276  return false;
277 
278  Type *Ty = V->getType();
279  uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
280  Optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits();
281  if (!ValueOperandSize || !DbgVarSize)
282  return false;
283 
284  bool HasBadSize = false;
285  if (Ty->isIntegerTy()) {
286  auto Signedness = DVI->getVariable()->getSignedness();
287  if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
288  HasBadSize = ValueOperandSize < *DbgVarSize;
289  } else {
290  HasBadSize = ValueOperandSize != *DbgVarSize;
291  }
292 
293  if (HasBadSize) {
294  dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
295  << ", but its variable has size " << *DbgVarSize << ": ";
296  DVI->print(dbg());
297  dbg() << "\n";
298  }
299  return HasBadSize;
300 }
301 
302 bool checkDebugifyMetadata(Module &M,
304  StringRef NameOfWrappedPass, StringRef Banner,
305  bool Strip, DebugifyStatsMap *StatsMap) {
306  // Skip modules without debugify metadata.
307  NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
308  if (!NMD) {
309  dbg() << Banner << ": Skipping module without debugify metadata\n";
310  return false;
311  }
312 
313  auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
314  return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
315  ->getZExtValue();
316  };
317  assert(NMD->getNumOperands() == 2 &&
318  "llvm.debugify should have exactly 2 operands!");
319  unsigned OriginalNumLines = getDebugifyOperand(0);
320  unsigned OriginalNumVars = getDebugifyOperand(1);
321  bool HasErrors = false;
322 
323  // Track debug info loss statistics if able.
324  DebugifyStatistics *Stats = nullptr;
325  if (StatsMap && !NameOfWrappedPass.empty())
326  Stats = &StatsMap->operator[](NameOfWrappedPass);
327 
328  BitVector MissingLines{OriginalNumLines, true};
329  BitVector MissingVars{OriginalNumVars, true};
330  for (Function &F : Functions) {
331  if (isFunctionSkipped(F))
332  continue;
333 
334  // Find missing lines.
335  for (Instruction &I : instructions(F)) {
336  if (isa<DbgValueInst>(&I) || isa<PHINode>(&I))
337  continue;
338 
339  auto DL = I.getDebugLoc();
340  if (DL && DL.getLine() != 0) {
341  MissingLines.reset(DL.getLine() - 1);
342  continue;
343  }
344 
345  if (!DL) {
346  dbg() << "WARNING: Instruction with empty DebugLoc in function ";
347  dbg() << F.getName() << " --";
348  I.print(dbg());
349  dbg() << "\n";
350  }
351  }
352 
353  // Find missing variables and mis-sized debug values.
354  for (Instruction &I : instructions(F)) {
355  auto *DVI = dyn_cast<DbgValueInst>(&I);
356  if (!DVI)
357  continue;
358 
359  unsigned Var = ~0U;
360  (void)to_integer(DVI->getVariable()->getName(), Var, 10);
361  assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
362  bool HasBadSize = diagnoseMisSizedDbgValue(M, DVI);
363  if (!HasBadSize)
364  MissingVars.reset(Var - 1);
365  HasErrors |= HasBadSize;
366  }
367  }
368 
369  // Print the results.
370  for (unsigned Idx : MissingLines.set_bits())
371  dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
372 
373  for (unsigned Idx : MissingVars.set_bits())
374  dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
375 
376  // Update DI loss statistics.
377  if (Stats) {
378  Stats->NumDbgLocsExpected += OriginalNumLines;
379  Stats->NumDbgLocsMissing += MissingLines.count();
380  Stats->NumDbgValuesExpected += OriginalNumVars;
381  Stats->NumDbgValuesMissing += MissingVars.count();
382  }
383 
384  dbg() << Banner;
385  if (!NameOfWrappedPass.empty())
386  dbg() << " [" << NameOfWrappedPass << "]";
387  dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
388 
389  // Strip debugify metadata if required.
390  if (Strip)
391  return stripDebugifyMetadata(M);
392 
393  return false;
394 }
395 
396 /// ModulePass for attaching synthetic debug info to everything, used with the
397 /// legacy module pass manager.
398 struct DebugifyModulePass : public ModulePass {
399  bool runOnModule(Module &M) override { return applyDebugify(M); }
400 
401  DebugifyModulePass() : ModulePass(ID) {}
402 
403  void getAnalysisUsage(AnalysisUsage &AU) const override {
404  AU.setPreservesAll();
405  }
406 
407  static char ID; // Pass identification.
408 };
409 
410 /// FunctionPass for attaching synthetic debug info to instructions within a
411 /// single function, used with the legacy module pass manager.
412 struct DebugifyFunctionPass : public FunctionPass {
413  bool runOnFunction(Function &F) override { return applyDebugify(F); }
414 
415  DebugifyFunctionPass() : FunctionPass(ID) {}
416 
417  void getAnalysisUsage(AnalysisUsage &AU) const override {
418  AU.setPreservesAll();
419  }
420 
421  static char ID; // Pass identification.
422 };
423 
424 /// ModulePass for checking debug info inserted by -debugify, used with the
425 /// legacy module pass manager.
426 struct CheckDebugifyModulePass : public ModulePass {
427  bool runOnModule(Module &M) override {
428  return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
429  "CheckModuleDebugify", Strip, StatsMap);
430  }
431 
432  CheckDebugifyModulePass(bool Strip = false, StringRef NameOfWrappedPass = "",
433  DebugifyStatsMap *StatsMap = nullptr)
434  : ModulePass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
435  StatsMap(StatsMap) {}
436 
437  void getAnalysisUsage(AnalysisUsage &AU) const override {
438  AU.setPreservesAll();
439  }
440 
441  static char ID; // Pass identification.
442 
443 private:
444  bool Strip;
445  StringRef NameOfWrappedPass;
446  DebugifyStatsMap *StatsMap;
447 };
448 
449 /// FunctionPass for checking debug info inserted by -debugify-function, used
450 /// with the legacy module pass manager.
451 struct CheckDebugifyFunctionPass : public FunctionPass {
452  bool runOnFunction(Function &F) override {
453  Module &M = *F.getParent();
454  auto FuncIt = F.getIterator();
455  return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
456  NameOfWrappedPass, "CheckFunctionDebugify",
457  Strip, StatsMap);
458  }
459 
460  CheckDebugifyFunctionPass(bool Strip = false,
461  StringRef NameOfWrappedPass = "",
462  DebugifyStatsMap *StatsMap = nullptr)
463  : FunctionPass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
464  StatsMap(StatsMap) {}
465 
466  void getAnalysisUsage(AnalysisUsage &AU) const override {
467  AU.setPreservesAll();
468  }
469 
470  static char ID; // Pass identification.
471 
472 private:
473  bool Strip;
474  StringRef NameOfWrappedPass;
475  DebugifyStatsMap *StatsMap;
476 };
477 
478 } // end anonymous namespace
479 
481  std::error_code EC;
482  raw_fd_ostream OS{Path, EC};
483  if (EC) {
484  errs() << "Could not open file: " << EC.message() << ", " << Path << '\n';
485  return;
486  }
487 
488  OS << "Pass Name" << ',' << "# of missing debug values" << ','
489  << "# of missing locations" << ',' << "Missing/Expected value ratio" << ','
490  << "Missing/Expected location ratio" << '\n';
491  for (const auto &Entry : Map) {
492  StringRef Pass = Entry.first;
493  DebugifyStatistics Stats = Entry.second;
494 
495  OS << Pass << ',' << Stats.NumDbgValuesMissing << ','
496  << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ','
497  << Stats.getEmptyLocationRatio() << '\n';
498  }
499 }
500 
502  return new DebugifyModulePass();
503 }
504 
506  return new DebugifyFunctionPass();
507 }
508 
510  applyDebugifyMetadata(M, M.functions(),
511  "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
512  return PreservedAnalyses::all();
513 }
514 
516  StringRef NameOfWrappedPass,
517  DebugifyStatsMap *StatsMap) {
518  return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
519 }
520 
521 FunctionPass *
522 llvm::createCheckDebugifyFunctionPass(bool Strip, StringRef NameOfWrappedPass,
523  DebugifyStatsMap *StatsMap) {
524  return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
525 }
526 
529  checkDebugifyMetadata(M, M.functions(), "", "CheckModuleDebugify", false,
530  nullptr);
531  return PreservedAnalyses::all();
532 }
533 
534 static bool isIgnoredPass(StringRef PassID) {
535  return isSpecialPass(PassID, {"PassManager", "PassAdaptor",
536  "AnalysisManagerProxy", "PrintFunctionPass",
537  "PrintModulePass", "BitcodeWriterPass",
538  "ThinLTOBitcodeWriterPass", "VerifierPass"});
539 }
540 
544  if (isIgnoredPass(P))
545  return;
546  if (any_isa<const Function *>(IR))
547  applyDebugify(*const_cast<Function *>(any_cast<const Function *>(IR)));
548  else if (any_isa<const Module *>(IR))
549  applyDebugify(*const_cast<Module *>(any_cast<const Module *>(IR)));
550  });
552  const PreservedAnalyses &PassPA) {
553  if (isIgnoredPass(P))
554  return;
555  if (any_isa<const Function *>(IR)) {
556  auto &F = *const_cast<Function *>(any_cast<const Function *>(IR));
557  Module &M = *F.getParent();
558  auto It = F.getIterator();
559  checkDebugifyMetadata(M, make_range(It, std::next(It)), P,
560  "CheckFunctionDebugify", /*Strip=*/true, &StatsMap);
561  } else if (any_isa<const Module *>(IR)) {
562  auto &M = *const_cast<Module *>(any_cast<const Module *>(IR));
563  checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify",
564  /*Strip=*/true, &StatsMap);
565  }
566  });
567 }
568 
569 char DebugifyModulePass::ID = 0;
570 static RegisterPass<DebugifyModulePass> DM("debugify",
571  "Attach debug info to everything");
572 
575  CDM("check-debugify", "Check debug info from -debugify");
576 
577 char DebugifyFunctionPass::ID = 0;
578 static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
579  "Attach debug info to a function");
580 
583  CDF("check-debugify-function", "Check debug info from -debugify-function");
void finalize()
Construct any deferred debug info descriptors.
Definition: DIBuilder.cpp:69
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
const NoneType None
Definition: None.h:23
Definition: Any.h:26
RegisterPass<t> template - This template class is used to notify the system that a Pass is available ...
Definition: PassSupport.h:94
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:21
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1105
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
void clearOperands()
Drop all references to this node's operands.
Definition: Metadata.cpp:1120
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:154
void addOperand(MDNode *M)
Definition: Metadata.cpp:1111
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
Metadata node.
Definition: Metadata.h:870
Optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or None if this type is neither signed nor unsigned.
F(f)
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1075
DISubprogram * createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, DINode::DIFlags Flags=DINode::FlagZero, DISubprogram::DISPFlags SPFlags=DISubprogram::SPFlagZero, DITemplateParameterArray TParams=nullptr, DISubprogram *Decl=nullptr, DITypeArray ThrownTypes=nullptr)
Create a new descriptor for the specified subprogram.
Definition: DIBuilder.cpp:798
void registerBeforeNonSkippedPassCallback(CallableT C)
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:148
static RegisterPass< CheckDebugifyFunctionPass > CDF("check-debugify-function", "Check debug info from -debugify-function")
bool stripDebugifyMetadata(Module &M)
Strip out all of the metadata and debug info inserted by debugify.
Definition: Debugify.cpp:214
DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata * > Elements)
Get a DITypeRefArray, create one if required.
Definition: DIBuilder.cpp:634
Optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
static bool applyDebugify(Function &F)
Definition: Debugify.cpp:202
A tuple of MDNodes.
Definition: Metadata.h:1350
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:185
StringRef getName() const
void eraseFromParent()
Drop all references and remove the node from parent module.
Definition: Metadata.cpp:1118
DISubroutineType * createSubroutineType(DITypeRefArray ParameterTypes, DINode::DIFlags Flags=DINode::FlagZero, unsigned CC=0)
Create subroutine type.
Definition: DIBuilder.cpp:508
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:202
unsigned getNumOperands() const
Definition: Metadata.cpp:1101
block placement Basic Block Placement Stats
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
Key
PAL metadata keys.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
Track how much debugify information has been lost.
Definition: Debugify.h:51
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:358
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
Debug location.
iterator_range< op_iterator > operands()
Definition: Metadata.h:1442
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:272
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
Definition: Debugify.cpp:527
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:147
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
static bool runOnFunction(Function &F, bool PostInlining)
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:427
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
bool applyDebugifyMetadata(Module &M, iterator_range< Module::iterator > Functions, StringRef Banner, std::function< bool(DIBuilder &, Function &)> ApplyToMF)
Add synthesized debug information to a module.
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
static RegisterPass< CheckDebugifyModulePass > CDM("check-debugify", "Check debug info from -debugify")
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
static bool isIgnoredPass(StringRef PassID)
Definition: Debugify.cpp:534
Instrumentation for Order File
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:683
llvm::ModulePass * createCheckDebugifyModulePass(bool Strip=false, llvm::StringRef NameOfWrappedPass="", DebugifyStatsMap *StatsMap=nullptr)
Definition: Debugify.cpp:515
Value * getValue() const
void registerCallbacks(PassInstrumentationCallbacks &PIC)
Definition: Debugify.cpp:541
bool isSpecialPass(StringRef PassID, const std::vector< StringRef > &Specials)
DIExpression * getExpression() const
Represent the analysis usage information of a pass.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:4577
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::ModulePass * createDebugifyModulePass()
Definition: Debugify.cpp:501
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
Base class for types.
DIFile * createFile(StringRef Filename, StringRef Directory, Optional< DIFile::ChecksumInfo< StringRef >> Checksum=None, Optional< StringRef > Source=None)
Create a file descriptor to hold debugging information for a file.
Definition: DIBuilder.cpp:215
void exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map)
Definition: Debugify.cpp:480
static ConstantAsMetadata * getConstant(Value *C)
Definition: Metadata.h:361
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1116
Module.h This file contains the declarations for the Module class.
DIExpression * createExpression(ArrayRef< uint64_t > Addr=None)
Create a new descriptor for the specified variable which has a complex address expression for its add...
Definition: DIBuilder.cpp:781
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:867
A range adaptor for a pair of iterators.
Emits a warning if two values disagree.
Definition: Module.h:124
void setPreservesAll()
Set by analyses that do not transform their input at all.
unsigned getNumElements() const
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:658
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1171
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
Definition: Debugify.cpp:509
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:365
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:425
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:197
This represents the llvm.dbg.value instruction.
DILocalVariable * createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve=false, DINode::DIFlags Flags=DINode::FlagZero, uint32_t AlignInBits=0)
Create a new descriptor for an auto variable.
Definition: DIBuilder.cpp:742
#define I(x, y, z)
Definition: MD5.cpp:59
#define N
llvm::FunctionPass * createDebugifyFunctionPass()
Definition: Debugify.cpp:505
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
DILocalVariable * getVariable() const
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Function.cpp:317
DISPFlags
Debug info subprogram flags.
void finalizeSubprogram(DISubprogram *SP)
Finalize a specific subprogram - no new variables may be added to this subprogram afterwards.
Definition: DIBuilder.cpp:49
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:228
DIBasicType * createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding, DINode::DIFlags Flags=DINode::FlagZero)
Create debugging information entry for a basic type.
Definition: DIBuilder.cpp:262
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DICompileUnit * createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized, StringRef Flags, unsigned RV, StringRef SplitName=StringRef(), DICompileUnit::DebugEmissionKind Kind=DICompileUnit::DebugEmissionKind::FullDebug, uint64_t DWOId=0, bool SplitDebugInlining=true, bool DebugInfoForProfiling=false, DICompileUnit::DebugNameTableKind NameTableKind=DICompileUnit::DebugNameTableKind::Default, bool RangesBaseAddress=false, StringRef SysRoot={}, StringRef SDK={})
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
Definition: DIBuilder.cpp:138
LLVM Value Representation.
Definition: Value.h:75
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
inst_range instructions(Function *F)
Definition: InstIterator.h:133
A single uniqued string.
Definition: Metadata.h:602
A container for analyses that lazily runs them and caches their results.
bool use_empty() const
Definition: Value.h:347
Statically lint checks LLVM IR
Definition: Lint.cpp:742
IntegerType * Int32Ty
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Level
Definition: Debugify.cpp:34
llvm::FunctionPass * createCheckDebugifyFunctionPass(bool Strip=false, llvm::StringRef NameOfWrappedPass="", DebugifyStatsMap *StatsMap=nullptr)
Definition: Debugify.cpp:522