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"
23 #include "llvm/Pass.h"
25 
26 using namespace llvm;
27 
28 namespace {
29 
30 cl::opt<bool> Quiet("debugify-quiet",
31  cl::desc("Suppress verbose debugify output"));
32 
33 enum class Level {
34  Locations,
35  LocationsAndVariables
36 };
37 cl::opt<Level> DebugifyLevel(
38  "debugify-level", cl::desc("Kind of debug info to add"),
39  cl::values(clEnumValN(Level::Locations, "locations", "Locations only"),
40  clEnumValN(Level::LocationsAndVariables, "location+variables",
41  "Locations and Variables")),
42  cl::init(Level::LocationsAndVariables));
43 
44 raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
45 
46 uint64_t getAllocSizeInBits(Module &M, Type *Ty) {
47  return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0;
48 }
49 
50 bool isFunctionSkipped(Function &F) {
51  return F.isDeclaration() || !F.hasExactDefinition();
52 }
53 
54 /// Find the basic block's terminating instruction.
55 ///
56 /// Special care is needed to handle musttail and deopt calls, as these behave
57 /// like (but are in fact not) terminators.
58 Instruction *findTerminatingInstruction(BasicBlock &BB) {
59  if (auto *I = BB.getTerminatingMustTailCall())
60  return I;
61  if (auto *I = BB.getTerminatingDeoptimizeCall())
62  return I;
63  return BB.getTerminator();
64 }
65 } // end anonymous namespace
66 
69  std::function<bool(DIBuilder &DIB, Function &F)> ApplyToMF) {
70  // Skip modules with debug info.
71  if (M.getNamedMetadata("llvm.dbg.cu")) {
72  dbg() << Banner << "Skipping module with debug info\n";
73  return false;
74  }
75 
76  DIBuilder DIB(M);
77  LLVMContext &Ctx = M.getContext();
78  auto *Int32Ty = Type::getInt32Ty(Ctx);
79 
80  // Get a DIType which corresponds to Ty.
82  auto getCachedDIType = [&](Type *Ty) -> DIType * {
83  uint64_t Size = getAllocSizeInBits(M, Ty);
84  DIType *&DTy = TypeCache[Size];
85  if (!DTy) {
86  std::string Name = "ty" + utostr(Size);
87  DTy = DIB.createBasicType(Name, Size, dwarf::DW_ATE_unsigned);
88  }
89  return DTy;
90  };
91 
92  unsigned NextLine = 1;
93  unsigned NextVar = 1;
94  auto File = DIB.createFile(M.getName(), "/");
95  auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "debugify",
96  /*isOptimized=*/true, "", 0);
97 
98  // Visit each instruction.
99  for (Function &F : Functions) {
100  if (isFunctionSkipped(F))
101  continue;
102 
103  bool InsertedDbgVal = false;
104  auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
105  DISubprogram::DISPFlags SPFlags =
106  DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
107  if (F.hasPrivateLinkage() || F.hasInternalLinkage())
108  SPFlags |= DISubprogram::SPFlagLocalToUnit;
109  auto SP = DIB.createFunction(CU, F.getName(), F.getName(), File, NextLine,
110  SPType, NextLine, DINode::FlagZero, SPFlags);
111  F.setSubprogram(SP);
112 
113  // Helper that inserts a dbg.value before \p InsertBefore, copying the
114  // location (and possibly the type, if it's non-void) from \p TemplateInst.
115  auto insertDbgVal = [&](Instruction &TemplateInst,
116  Instruction *InsertBefore) {
117  std::string Name = utostr(NextVar++);
118  Value *V = &TemplateInst;
119  if (TemplateInst.getType()->isVoidTy())
120  V = ConstantInt::get(Int32Ty, 0);
121  const DILocation *Loc = TemplateInst.getDebugLoc().get();
122  auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
123  getCachedDIType(V->getType()),
124  /*AlwaysPreserve=*/true);
125  DIB.insertDbgValueIntrinsic(V, LocalVar, DIB.createExpression(), Loc,
126  InsertBefore);
127  };
128 
129  for (BasicBlock &BB : F) {
130  // Attach debug locations.
131  for (Instruction &I : BB)
132  I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
133 
134  if (DebugifyLevel < Level::LocationsAndVariables)
135  continue;
136 
137  // Inserting debug values into EH pads can break IR invariants.
138  if (BB.isEHPad())
139  continue;
140 
141  // Find the terminating instruction, after which no debug values are
142  // attached.
143  Instruction *LastInst = findTerminatingInstruction(BB);
144  assert(LastInst && "Expected basic block with a terminator");
145 
146  // Maintain an insertion point which can't be invalidated when updates
147  // are made.
148  BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();
149  assert(InsertPt != BB.end() && "Expected to find an insertion point");
150  Instruction *InsertBefore = &*InsertPt;
151 
152  // Attach debug values.
153  for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {
154  // Skip void-valued instructions.
155  if (I->getType()->isVoidTy())
156  continue;
157 
158  // Phis and EH pads must be grouped at the beginning of the block.
159  // Only advance the insertion point when we finish visiting these.
160  if (!isa<PHINode>(I) && !I->isEHPad())
161  InsertBefore = I->getNextNode();
162 
163  insertDbgVal(*I, InsertBefore);
164  InsertedDbgVal = true;
165  }
166  }
167  // Make sure we emit at least one dbg.value, otherwise MachineDebugify may
168  // not have anything to work with as it goes about inserting DBG_VALUEs.
169  // (It's common for MIR tests to be written containing skeletal IR with
170  // empty functions -- we're still interested in debugifying the MIR within
171  // those tests, and this helps with that.)
172  if (DebugifyLevel == Level::LocationsAndVariables && !InsertedDbgVal) {
173  auto *Term = findTerminatingInstruction(F.getEntryBlock());
174  insertDbgVal(*Term, Term);
175  }
176  if (ApplyToMF)
177  ApplyToMF(DIB, F);
178  DIB.finalizeSubprogram(SP);
179  }
180  DIB.finalize();
181 
182  // Track the number of distinct lines and variables.
183  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.debugify");
184  auto addDebugifyOperand = [&](unsigned N) {
185  NMD->addOperand(MDNode::get(
187  };
188  addDebugifyOperand(NextLine - 1); // Original number of lines.
189  addDebugifyOperand(NextVar - 1); // Original number of variables.
190  assert(NMD->getNumOperands() == 2 &&
191  "llvm.debugify should have exactly 2 operands!");
192 
193  // Claim that this synthetic debug info is valid.
194  StringRef DIVersionKey = "Debug Info Version";
195  if (!M.getModuleFlag(DIVersionKey))
197 
198  return true;
199 }
200 
202  bool Changed = false;
203 
204  // Remove the llvm.debugify module-level named metadata.
205  NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify");
206  if (DebugifyMD) {
207  M.eraseNamedMetadata(DebugifyMD);
208  Changed = true;
209  }
210 
211  // Strip out all debug intrinsics and supporting metadata (subprograms, types,
212  // variables, etc).
213  Changed |= StripDebugInfo(M);
214 
215  // Strip out the dead dbg.value prototype.
216  Function *DbgValF = M.getFunction("llvm.dbg.value");
217  if (DbgValF) {
218  assert(DbgValF->isDeclaration() && DbgValF->use_empty() &&
219  "Not all debug info stripped?");
220  DbgValF->eraseFromParent();
221  Changed = true;
222  }
223 
224  // Strip out the module-level Debug Info Version metadata.
225  // FIXME: There must be an easier way to remove an operand from a NamedMDNode.
227  if (!NMD)
228  return Changed;
230  for (MDNode *Flag : NMD->operands())
231  Flags.push_back(Flag);
232  NMD->clearOperands();
233  for (MDNode *Flag : Flags) {
234  MDString *Key = dyn_cast_or_null<MDString>(Flag->getOperand(1));
235  if (Key->getString() == "Debug Info Version") {
236  Changed = true;
237  continue;
238  }
239  NMD->addOperand(Flag);
240  }
241  // If we left it empty we might as well remove it.
242  if (NMD->getNumOperands() == 0)
243  NMD->eraseFromParent();
244 
245  return Changed;
246 }
247 
248 namespace {
249 /// Return true if a mis-sized diagnostic is issued for \p DVI.
250 bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
251  // The size of a dbg.value's value operand should match the size of the
252  // variable it corresponds to.
253  //
254  // TODO: This, along with a check for non-null value operands, should be
255  // promoted to verifier failures.
256  Value *V = DVI->getValue();
257  if (!V)
258  return false;
259 
260  // For now, don't try to interpret anything more complicated than an empty
261  // DIExpression. Eventually we should try to handle OP_deref and fragments.
262  if (DVI->getExpression()->getNumElements())
263  return false;
264 
265  Type *Ty = V->getType();
266  uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
267  Optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits();
268  if (!ValueOperandSize || !DbgVarSize)
269  return false;
270 
271  bool HasBadSize = false;
272  if (Ty->isIntegerTy()) {
273  auto Signedness = DVI->getVariable()->getSignedness();
274  if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
275  HasBadSize = ValueOperandSize < *DbgVarSize;
276  } else {
277  HasBadSize = ValueOperandSize != *DbgVarSize;
278  }
279 
280  if (HasBadSize) {
281  dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
282  << ", but its variable has size " << *DbgVarSize << ": ";
283  DVI->print(dbg());
284  dbg() << "\n";
285  }
286  return HasBadSize;
287 }
288 
289 bool checkDebugifyMetadata(Module &M,
291  StringRef NameOfWrappedPass, StringRef Banner,
292  bool Strip, DebugifyStatsMap *StatsMap) {
293  // Skip modules without debugify metadata.
294  NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
295  if (!NMD) {
296  dbg() << Banner << ": Skipping module without debugify metadata\n";
297  return false;
298  }
299 
300  auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
301  return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
302  ->getZExtValue();
303  };
304  assert(NMD->getNumOperands() == 2 &&
305  "llvm.debugify should have exactly 2 operands!");
306  unsigned OriginalNumLines = getDebugifyOperand(0);
307  unsigned OriginalNumVars = getDebugifyOperand(1);
308  bool HasErrors = false;
309 
310  // Track debug info loss statistics if able.
311  DebugifyStatistics *Stats = nullptr;
312  if (StatsMap && !NameOfWrappedPass.empty())
313  Stats = &StatsMap->operator[](NameOfWrappedPass);
314 
315  BitVector MissingLines{OriginalNumLines, true};
316  BitVector MissingVars{OriginalNumVars, true};
317  for (Function &F : Functions) {
318  if (isFunctionSkipped(F))
319  continue;
320 
321  // Find missing lines.
322  for (Instruction &I : instructions(F)) {
323  if (isa<DbgValueInst>(&I) || isa<PHINode>(&I))
324  continue;
325 
326  auto DL = I.getDebugLoc();
327  if (DL && DL.getLine() != 0) {
328  MissingLines.reset(DL.getLine() - 1);
329  continue;
330  }
331 
332  if (!DL) {
333  dbg() << "WARNING: Instruction with empty DebugLoc in function ";
334  dbg() << F.getName() << " --";
335  I.print(dbg());
336  dbg() << "\n";
337  }
338  }
339 
340  // Find missing variables and mis-sized debug values.
341  for (Instruction &I : instructions(F)) {
342  auto *DVI = dyn_cast<DbgValueInst>(&I);
343  if (!DVI)
344  continue;
345 
346  unsigned Var = ~0U;
347  (void)to_integer(DVI->getVariable()->getName(), Var, 10);
348  assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
349  bool HasBadSize = diagnoseMisSizedDbgValue(M, DVI);
350  if (!HasBadSize)
351  MissingVars.reset(Var - 1);
352  HasErrors |= HasBadSize;
353  }
354  }
355 
356  // Print the results.
357  for (unsigned Idx : MissingLines.set_bits())
358  dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
359 
360  for (unsigned Idx : MissingVars.set_bits())
361  dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
362 
363  // Update DI loss statistics.
364  if (Stats) {
365  Stats->NumDbgLocsExpected += OriginalNumLines;
366  Stats->NumDbgLocsMissing += MissingLines.count();
367  Stats->NumDbgValuesExpected += OriginalNumVars;
368  Stats->NumDbgValuesMissing += MissingVars.count();
369  }
370 
371  dbg() << Banner;
372  if (!NameOfWrappedPass.empty())
373  dbg() << " [" << NameOfWrappedPass << "]";
374  dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
375 
376  // Strip debugify metadata if required.
377  if (Strip)
378  return stripDebugifyMetadata(M);
379 
380  return false;
381 }
382 
383 /// ModulePass for attaching synthetic debug info to everything, used with the
384 /// legacy module pass manager.
385 struct DebugifyModulePass : public ModulePass {
386  bool runOnModule(Module &M) override {
387  return applyDebugifyMetadata(M, M.functions(),
388  "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
389  }
390 
391  DebugifyModulePass() : ModulePass(ID) {}
392 
393  void getAnalysisUsage(AnalysisUsage &AU) const override {
394  AU.setPreservesAll();
395  }
396 
397  static char ID; // Pass identification.
398 };
399 
400 /// FunctionPass for attaching synthetic debug info to instructions within a
401 /// single function, used with the legacy module pass manager.
402 struct DebugifyFunctionPass : public FunctionPass {
403  bool runOnFunction(Function &F) override {
404  Module &M = *F.getParent();
405  auto FuncIt = F.getIterator();
406  return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
407  "FunctionDebugify: ", /*ApplyToMF*/ nullptr);
408  }
409 
410  DebugifyFunctionPass() : FunctionPass(ID) {}
411 
412  void getAnalysisUsage(AnalysisUsage &AU) const override {
413  AU.setPreservesAll();
414  }
415 
416  static char ID; // Pass identification.
417 };
418 
419 /// ModulePass for checking debug info inserted by -debugify, used with the
420 /// legacy module pass manager.
421 struct CheckDebugifyModulePass : public ModulePass {
422  bool runOnModule(Module &M) override {
423  return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
424  "CheckModuleDebugify", Strip, StatsMap);
425  }
426 
427  CheckDebugifyModulePass(bool Strip = false, StringRef NameOfWrappedPass = "",
428  DebugifyStatsMap *StatsMap = nullptr)
429  : ModulePass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
430  StatsMap(StatsMap) {}
431 
432  void getAnalysisUsage(AnalysisUsage &AU) const override {
433  AU.setPreservesAll();
434  }
435 
436  static char ID; // Pass identification.
437 
438 private:
439  bool Strip;
440  StringRef NameOfWrappedPass;
441  DebugifyStatsMap *StatsMap;
442 };
443 
444 /// FunctionPass for checking debug info inserted by -debugify-function, used
445 /// with the legacy module pass manager.
446 struct CheckDebugifyFunctionPass : public FunctionPass {
447  bool runOnFunction(Function &F) override {
448  Module &M = *F.getParent();
449  auto FuncIt = F.getIterator();
450  return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
451  NameOfWrappedPass, "CheckFunctionDebugify",
452  Strip, StatsMap);
453  }
454 
455  CheckDebugifyFunctionPass(bool Strip = false,
456  StringRef NameOfWrappedPass = "",
457  DebugifyStatsMap *StatsMap = nullptr)
458  : FunctionPass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
459  StatsMap(StatsMap) {}
460 
461  void getAnalysisUsage(AnalysisUsage &AU) const override {
462  AU.setPreservesAll();
463  }
464 
465  static char ID; // Pass identification.
466 
467 private:
468  bool Strip;
469  StringRef NameOfWrappedPass;
470  DebugifyStatsMap *StatsMap;
471 };
472 
473 } // end anonymous namespace
474 
475 ModulePass *createDebugifyModulePass() { return new DebugifyModulePass(); }
476 
478  return new DebugifyFunctionPass();
479 }
480 
483  "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
484  return PreservedAnalyses::all();
485 }
486 
488  StringRef NameOfWrappedPass,
489  DebugifyStatsMap *StatsMap) {
490  return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
491 }
492 
494  StringRef NameOfWrappedPass,
495  DebugifyStatsMap *StatsMap) {
496  return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
497 }
498 
501  checkDebugifyMetadata(M, M.functions(), "", "CheckModuleDebugify", false,
502  nullptr);
503  return PreservedAnalyses::all();
504 }
505 
506 char DebugifyModulePass::ID = 0;
507 static RegisterPass<DebugifyModulePass> DM("debugify",
508  "Attach debug info to everything");
509 
512  CDM("check-debugify", "Check debug info from -debugify");
513 
514 char DebugifyFunctionPass::ID = 0;
515 static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
516  "Attach debug info to a function");
517 
520  CDF("check-debugify-function", "Check debug info from -debugify-function");
void finalize()
Construct any deferred debug info descriptors.
Definition: DIBuilder.cpp:69
LLVM_NODISCARD std::enable_if_t< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition: Casting.h:334
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:1082
bool hasPrivateLinkage() const
Definition: GlobalValue.h:444
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Track how much debugify information has been lost.
Definition: Debugify.h:50
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base.
Definition: StringExtras.h:201
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:268
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void clearOperands()
Drop all references to this node&#39;s operands.
Definition: Metadata.cpp:1097
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked &#39;musttail&#39; prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:156
void addOperand(MDNode *M)
Definition: Metadata.cpp:1088
unsigned NumDbgValuesMissing
Number of missing dbg.values.
Definition: Debugify.h:52
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:259
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:37
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
Metadata node.
Definition: Metadata.h:870
StringRef getName() const
Get a short "name" for the module.
Definition: Module.h:236
Optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable&#39;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:768
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:150
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:201
FunctionPass * createCheckDebugifyFunctionPass(bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap)
Definition: Debugify.cpp:493
Optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
Definition: Debugify.cpp:481
A tuple of MDNodes.
Definition: Metadata.h:1330
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:187
StringRef getName() const
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:397
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
Definition: Module.cpp:271
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:253
void eraseFromParent()
Drop all references and remove the node from parent module.
Definition: Metadata.cpp:1095
DISubroutineType * createSubroutineType(DITypeRefArray ParameterTypes, DINode::DIFlags Flags=DINode::FlagZero, unsigned CC=0)
Create subroutine type.
Definition: DIBuilder.cpp:502
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:198
unsigned getNumOperands() const
Definition: Metadata.cpp:1078
block placement Basic Block Placement Stats
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
unsigned NumDbgLocsMissing
Number of instructions with empty debug locations.
Definition: Debugify.h:58
Key
PAL metadata keys.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:244
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:358
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:250
FunctionPass * createDebugifyFunctionPass()
Definition: Debugify.cpp:477
Debug location.
iterator_range< op_iterator > operands()
Definition: Metadata.h:1422
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:138
DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata *> Elements)
Get a DITypeRefArray, create one if required.
Definition: DIBuilder.cpp:616
StringRef getString() const
Definition: Metadata.cpp:463
bool isVoidTy() const
Return true if this is &#39;void&#39;.
Definition: Type.h:138
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1172
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:434
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
Definition: Metadata.cpp:1524
void getModuleFlagsMetadata(SmallVectorImpl< ModuleFlagEntry > &Flags) const
Returns the module flags in the provided vector.
Definition: Module.cpp:303
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
iterator_range< iterator > functions()
Definition: Module.h:621
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
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:321
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:690
Value * getValue() const
unsigned NumDbgLocsExpected
Number of instructions expected to have debug locations.
Definition: Debugify.h:61
unsigned NumDbgValuesExpected
Number of dbg.values expected.
Definition: Debugify.h:55
DIExpression * getExpression() const
Represent the analysis usage information of a pass.
bool hasInternalLinkage() const
Definition: GlobalValue.h:443
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition: Module.cpp:348
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:4460
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
self_iterator getIterator()
Definition: ilist_node.h:81
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:160
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
static ConstantAsMetadata * getConstant(Value *C)
Definition: Metadata.h:361
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:883
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:751
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:786
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:231
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:174
A range adaptor for a pair of iterators.
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
Definition: Debugify.cpp:499
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:665
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:363
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:186
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:712
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:270
bool hasExactDefinition() const
Return true if this global has an exact defintion.
Definition: GlobalValue.h:415
#define I(x, y, z)
Definition: MD5.cpp:59
ModulePass * createCheckDebugifyModulePass(bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap)
Definition: Debugify.cpp:487
#define N
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
uint32_t Size
Definition: Profile.cpp:46
DILocalVariable * getVariable() const
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Function.cpp:273
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition: DataLayout.h:503
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:227
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
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:572
LLVM Value Representation.
Definition: Value.h:74
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:46
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.
ModulePass * createDebugifyModulePass()
Definition: Debugify.cpp:475
bool use_empty() const
Definition: Value.h:341
IntegerType * Int32Ty
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Level
Definition: Debugify.cpp:33