LLVM  13.0.0git
Debugify.cpp
Go to the documentation of this file.
1 //===- Debugify.cpp - Check debug info preservation in optimizations ------===//
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 In the `synthetic` mode, the `-debugify` attaches synthetic debug info
10 /// to everything. It can be used to create targeted tests for debug info
11 /// preservation. In addition, when using the `original` mode, it can check
12 /// original debug info preservation. The `synthetic` mode is default one.
13 ///
14 //===----------------------------------------------------------------------===//
15 
17 #include "llvm/ADT/BitVector.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/IR/DIBuilder.h"
20 #include "llvm/IR/DebugInfo.h"
21 #include "llvm/IR/InstIterator.h"
22 #include "llvm/IR/Instructions.h"
23 #include "llvm/IR/IntrinsicInst.h"
24 #include "llvm/IR/Module.h"
26 #include "llvm/Pass.h"
29 #include "llvm/Support/JSON.h"
30 
31 #define DEBUG_TYPE "debugify"
32 
33 using namespace llvm;
34 
35 namespace {
36 
37 cl::opt<bool> Quiet("debugify-quiet",
38  cl::desc("Suppress verbose debugify output"));
39 
40 enum class Level {
41  Locations,
42  LocationsAndVariables
43 };
44 
45 // Used for the synthetic mode only.
46 cl::opt<Level> DebugifyLevel(
47  "debugify-level", cl::desc("Kind of debug info to add"),
48  cl::values(clEnumValN(Level::Locations, "locations", "Locations only"),
49  clEnumValN(Level::LocationsAndVariables, "location+variables",
50  "Locations and Variables")),
51  cl::init(Level::LocationsAndVariables));
52 
53 raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
54 
55 uint64_t getAllocSizeInBits(Module &M, Type *Ty) {
56  return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0;
57 }
58 
59 bool isFunctionSkipped(Function &F) {
60  return F.isDeclaration() || !F.hasExactDefinition();
61 }
62 
63 /// Find the basic block's terminating instruction.
64 ///
65 /// Special care is needed to handle musttail and deopt calls, as these behave
66 /// like (but are in fact not) terminators.
67 Instruction *findTerminatingInstruction(BasicBlock &BB) {
68  if (auto *I = BB.getTerminatingMustTailCall())
69  return I;
70  if (auto *I = BB.getTerminatingDeoptimizeCall())
71  return I;
72  return BB.getTerminator();
73 }
74 } // end anonymous namespace
75 
78  std::function<bool(DIBuilder &DIB, Function &F)> ApplyToMF) {
79  // Skip modules with debug info.
80  if (M.getNamedMetadata("llvm.dbg.cu")) {
81  dbg() << Banner << "Skipping module with debug info\n";
82  return false;
83  }
84 
85  DIBuilder DIB(M);
86  LLVMContext &Ctx = M.getContext();
87  auto *Int32Ty = Type::getInt32Ty(Ctx);
88 
89  // Get a DIType which corresponds to Ty.
91  auto getCachedDIType = [&](Type *Ty) -> DIType * {
92  uint64_t Size = getAllocSizeInBits(M, Ty);
93  DIType *&DTy = TypeCache[Size];
94  if (!DTy) {
95  std::string Name = "ty" + utostr(Size);
96  DTy = DIB.createBasicType(Name, Size, dwarf::DW_ATE_unsigned);
97  }
98  return DTy;
99  };
100 
101  unsigned NextLine = 1;
102  unsigned NextVar = 1;
103  auto File = DIB.createFile(M.getName(), "/");
104  auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "debugify",
105  /*isOptimized=*/true, "", 0);
106 
107  // Visit each instruction.
108  for (Function &F : Functions) {
109  if (isFunctionSkipped(F))
110  continue;
111 
112  bool InsertedDbgVal = false;
113  auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
114  DISubprogram::DISPFlags SPFlags =
115  DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
116  if (F.hasPrivateLinkage() || F.hasInternalLinkage())
117  SPFlags |= DISubprogram::SPFlagLocalToUnit;
118  auto SP = DIB.createFunction(CU, F.getName(), F.getName(), File, NextLine,
119  SPType, NextLine, DINode::FlagZero, SPFlags);
120  F.setSubprogram(SP);
121 
122  // Helper that inserts a dbg.value before \p InsertBefore, copying the
123  // location (and possibly the type, if it's non-void) from \p TemplateInst.
124  auto insertDbgVal = [&](Instruction &TemplateInst,
125  Instruction *InsertBefore) {
126  std::string Name = utostr(NextVar++);
127  Value *V = &TemplateInst;
128  if (TemplateInst.getType()->isVoidTy())
129  V = ConstantInt::get(Int32Ty, 0);
130  const DILocation *Loc = TemplateInst.getDebugLoc().get();
131  auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
132  getCachedDIType(V->getType()),
133  /*AlwaysPreserve=*/true);
134  DIB.insertDbgValueIntrinsic(V, LocalVar, DIB.createExpression(), Loc,
135  InsertBefore);
136  };
137 
138  for (BasicBlock &BB : F) {
139  // Attach debug locations.
140  for (Instruction &I : BB)
141  I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
142 
143  if (DebugifyLevel < Level::LocationsAndVariables)
144  continue;
145 
146  // Inserting debug values into EH pads can break IR invariants.
147  if (BB.isEHPad())
148  continue;
149 
150  // Find the terminating instruction, after which no debug values are
151  // attached.
152  Instruction *LastInst = findTerminatingInstruction(BB);
153  assert(LastInst && "Expected basic block with a terminator");
154 
155  // Maintain an insertion point which can't be invalidated when updates
156  // are made.
157  BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();
158  assert(InsertPt != BB.end() && "Expected to find an insertion point");
159  Instruction *InsertBefore = &*InsertPt;
160 
161  // Attach debug values.
162  for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {
163  // Skip void-valued instructions.
164  if (I->getType()->isVoidTy())
165  continue;
166 
167  // Phis and EH pads must be grouped at the beginning of the block.
168  // Only advance the insertion point when we finish visiting these.
169  if (!isa<PHINode>(I) && !I->isEHPad())
170  InsertBefore = I->getNextNode();
171 
172  insertDbgVal(*I, InsertBefore);
173  InsertedDbgVal = true;
174  }
175  }
176  // Make sure we emit at least one dbg.value, otherwise MachineDebugify may
177  // not have anything to work with as it goes about inserting DBG_VALUEs.
178  // (It's common for MIR tests to be written containing skeletal IR with
179  // empty functions -- we're still interested in debugifying the MIR within
180  // those tests, and this helps with that.)
181  if (DebugifyLevel == Level::LocationsAndVariables && !InsertedDbgVal) {
182  auto *Term = findTerminatingInstruction(F.getEntryBlock());
183  insertDbgVal(*Term, Term);
184  }
185  if (ApplyToMF)
186  ApplyToMF(DIB, F);
187  DIB.finalizeSubprogram(SP);
188  }
189  DIB.finalize();
190 
191  // Track the number of distinct lines and variables.
192  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.debugify");
193  auto addDebugifyOperand = [&](unsigned N) {
194  NMD->addOperand(MDNode::get(
196  };
197  addDebugifyOperand(NextLine - 1); // Original number of lines.
198  addDebugifyOperand(NextVar - 1); // Original number of variables.
199  assert(NMD->getNumOperands() == 2 &&
200  "llvm.debugify should have exactly 2 operands!");
201 
202  // Claim that this synthetic debug info is valid.
203  StringRef DIVersionKey = "Debug Info Version";
204  if (!M.getModuleFlag(DIVersionKey))
205  M.addModuleFlag(Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
206 
207  return true;
208 }
209 
210 static bool
213  DebugInfoPerPassMap *DIPreservationMap = nullptr,
214  StringRef NameOfWrappedPass = "") {
215  Module &M = *F.getParent();
216  auto FuncIt = F.getIterator();
218  return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
219  "FunctionDebugify: ", /*ApplyToMF*/ nullptr);
220  assert(DIPreservationMap);
221  return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap,
222  "FunctionDebugify (original debuginfo)",
223  NameOfWrappedPass);
224 }
225 
226 static bool
229  DebugInfoPerPassMap *DIPreservationMap = nullptr,
230  StringRef NameOfWrappedPass = "") {
232  return applyDebugifyMetadata(M, M.functions(),
233  "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
234  return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap,
235  "ModuleDebugify (original debuginfo)",
236  NameOfWrappedPass);
237 }
238 
240  bool Changed = false;
241 
242  // Remove the llvm.debugify module-level named metadata.
243  NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify");
244  if (DebugifyMD) {
245  M.eraseNamedMetadata(DebugifyMD);
246  Changed = true;
247  }
248 
249  // Strip out all debug intrinsics and supporting metadata (subprograms, types,
250  // variables, etc).
251  Changed |= StripDebugInfo(M);
252 
253  // Strip out the dead dbg.value prototype.
254  Function *DbgValF = M.getFunction("llvm.dbg.value");
255  if (DbgValF) {
256  assert(DbgValF->isDeclaration() && DbgValF->use_empty() &&
257  "Not all debug info stripped?");
258  DbgValF->eraseFromParent();
259  Changed = true;
260  }
261 
262  // Strip out the module-level Debug Info Version metadata.
263  // FIXME: There must be an easier way to remove an operand from a NamedMDNode.
264  NamedMDNode *NMD = M.getModuleFlagsMetadata();
265  if (!NMD)
266  return Changed;
267  SmallVector<MDNode *, 4> Flags(NMD->operands());
268  NMD->clearOperands();
269  for (MDNode *Flag : Flags) {
270  MDString *Key = dyn_cast_or_null<MDString>(Flag->getOperand(1));
271  if (Key->getString() == "Debug Info Version") {
272  Changed = true;
273  continue;
274  }
275  NMD->addOperand(Flag);
276  }
277  // If we left it empty we might as well remove it.
278  if (NMD->getNumOperands() == 0)
279  NMD->eraseFromParent();
280 
281  return Changed;
282 }
283 
286  DebugInfoPerPassMap &DIPreservationMap,
287  StringRef Banner,
288  StringRef NameOfWrappedPass) {
289  LLVM_DEBUG(dbgs() << Banner << ": (before) " << NameOfWrappedPass << '\n');
290 
291  // Clear the map with the debug info before every single pass.
292  DIPreservationMap.clear();
293 
294  if (!M.getNamedMetadata("llvm.dbg.cu")) {
295  dbg() << Banner << ": Skipping module without debug info\n";
296  return false;
297  }
298 
299  // Visit each instruction.
300  for (Function &F : Functions) {
301  if (isFunctionSkipped(F))
302  continue;
303 
304  // Collect the DISubprogram.
305  auto *SP = F.getSubprogram();
306  DIPreservationMap[NameOfWrappedPass].DIFunctions.insert({F.getName(), SP});
307  if (SP) {
308  LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n');
309  for (const DINode *DN : SP->getRetainedNodes()) {
310  if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
311  DIPreservationMap[NameOfWrappedPass].DIVariables[DV] = 0;
312  }
313  }
314  }
315 
316  for (BasicBlock &BB : F) {
317  // Collect debug locations (!dbg) and debug variable intrinsics.
318  for (Instruction &I : BB) {
319  // Skip PHIs.
320  if (isa<PHINode>(I))
321  continue;
322 
323  // Collect dbg.values and dbg.declares.
324  if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I)) {
325  if (!SP)
326  continue;
327  // Skip inlined variables.
328  if (I.getDebugLoc().getInlinedAt())
329  continue;
330  // Skip undef values.
331  if (DVI->isUndef())
332  continue;
333 
334  auto *Var = DVI->getVariable();
335  DIPreservationMap[NameOfWrappedPass].DIVariables[Var]++;
336  continue;
337  }
338 
339  // Skip debug instructions other than dbg.value and dbg.declare.
340  if (isa<DbgInfoIntrinsic>(&I))
341  continue;
342 
343  LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n');
344  DIPreservationMap[NameOfWrappedPass].InstToDelete.insert({&I, &I});
345 
346  const DILocation *Loc = I.getDebugLoc().get();
347  bool HasLoc = Loc != nullptr;
348  DIPreservationMap[NameOfWrappedPass].DILocations.insert({&I, HasLoc});
349  }
350  }
351  }
352 
353  return true;
354 }
355 
356 // This checks the preservation of original debug info attached to functions.
357 static bool checkFunctions(const DebugFnMap &DIFunctionsBefore,
358  const DebugFnMap &DIFunctionsAfter,
359  StringRef NameOfWrappedPass,
360  StringRef FileNameFromCU, bool ShouldWriteIntoJSON,
361  llvm::json::Array &Bugs) {
362  bool Preserved = true;
363  for (const auto &F : DIFunctionsAfter) {
364  if (F.second)
365  continue;
366  auto SPIt = DIFunctionsBefore.find(F.first);
367  if (SPIt == DIFunctionsBefore.end()) {
368  if (ShouldWriteIntoJSON)
369  Bugs.push_back(llvm::json::Object({{"metadata", "DISubprogram"},
370  {"name", F.first},
371  {"action", "not-generate"}}));
372  else
373  dbg() << "ERROR: " << NameOfWrappedPass
374  << " did not generate DISubprogram for " << F.first << " from "
375  << FileNameFromCU << '\n';
376  Preserved = false;
377  } else {
378  auto SP = SPIt->second;
379  if (!SP)
380  continue;
381  // If the function had the SP attached before the pass, consider it as
382  // a debug info bug.
383  if (ShouldWriteIntoJSON)
384  Bugs.push_back(llvm::json::Object({{"metadata", "DISubprogram"},
385  {"name", F.first},
386  {"action", "drop"}}));
387  else
388  dbg() << "ERROR: " << NameOfWrappedPass << " dropped DISubprogram of "
389  << F.first << " from " << FileNameFromCU << '\n';
390  Preserved = false;
391  }
392  }
393 
394  return Preserved;
395 }
396 
397 // This checks the preservation of the original debug info attached to
398 // instructions.
399 static bool checkInstructions(const DebugInstMap &DILocsBefore,
400  const DebugInstMap &DILocsAfter,
401  const WeakInstValueMap &InstToDelete,
402  StringRef NameOfWrappedPass,
403  StringRef FileNameFromCU,
404  bool ShouldWriteIntoJSON,
405  llvm::json::Array &Bugs) {
406  bool Preserved = true;
407  for (const auto &L : DILocsAfter) {
408  if (L.second)
409  continue;
410  auto Instr = L.first;
411 
412  // In order to avoid pointer reuse/recycling, skip the values that might
413  // have been deleted during a pass.
414  auto WeakInstrPtr = InstToDelete.find(Instr);
415  if (WeakInstrPtr != InstToDelete.end() && !WeakInstrPtr->second)
416  continue;
417 
418  auto FnName = Instr->getFunction()->getName();
419  auto BB = Instr->getParent();
420  auto BBName = BB->hasName() ? BB->getName() : "no-name";
421  auto InstName = Instruction::getOpcodeName(Instr->getOpcode());
422 
423  auto InstrIt = DILocsBefore.find(Instr);
424  if (InstrIt == DILocsBefore.end()) {
425  if (ShouldWriteIntoJSON)
426  Bugs.push_back(llvm::json::Object({{"metadata", "DILocation"},
427  {"fn-name", FnName.str()},
428  {"bb-name", BBName.str()},
429  {"instr", InstName},
430  {"action", "not-generate"}}));
431  else
432  dbg() << "WARNING: " << NameOfWrappedPass
433  << " did not generate DILocation for " << *Instr
434  << " (BB: " << BBName << ", Fn: " << FnName
435  << ", File: " << FileNameFromCU << ")\n";
436  Preserved = false;
437  } else {
438  if (!InstrIt->second)
439  continue;
440  // If the instr had the !dbg attached before the pass, consider it as
441  // a debug info issue.
442  if (ShouldWriteIntoJSON)
443  Bugs.push_back(llvm::json::Object({{"metadata", "DILocation"},
444  {"fn-name", FnName.str()},
445  {"bb-name", BBName.str()},
446  {"instr", InstName},
447  {"action", "drop"}}));
448  else
449  dbg() << "WARNING: " << NameOfWrappedPass << " dropped DILocation of "
450  << *Instr << " (BB: " << BBName << ", Fn: " << FnName
451  << ", File: " << FileNameFromCU << ")\n";
452  Preserved = false;
453  }
454  }
455 
456  return Preserved;
457 }
458 
459 // This checks the preservation of original debug variable intrinsics.
460 static bool checkVars(const DebugVarMap &DIFunctionsBefore,
461  const DebugVarMap &DIFunctionsAfter,
462  StringRef NameOfWrappedPass, StringRef FileNameFromCU,
463  bool ShouldWriteIntoJSON, llvm::json::Array &Bugs) {
464  bool Preserved = true;
465  for (const auto &V : DIFunctionsBefore) {
466  auto VarIt = DIFunctionsAfter.find(V.first);
467  if (VarIt == DIFunctionsAfter.end())
468  continue;
469 
470  unsigned NumOfDbgValsAfter = VarIt->second;
471 
472  if (V.second > NumOfDbgValsAfter) {
473  if (ShouldWriteIntoJSON)
475  {{"metadata", "dbg-var-intrinsic"},
476  {"name", V.first->getName()},
477  {"fn-name", V.first->getScope()->getSubprogram()->getName()},
478  {"action", "drop"}}));
479  else
480  dbg() << "WARNING: " << NameOfWrappedPass
481  << " drops dbg.value()/dbg.declare() for " << V.first->getName()
482  << " from "
483  << "function " << V.first->getScope()->getSubprogram()->getName()
484  << " (file " << FileNameFromCU << ")\n";
485  Preserved = false;
486  }
487  }
488 
489  return Preserved;
490 }
491 
492 // Write the json data into the specifed file.
493 static void writeJSON(StringRef OrigDIVerifyBugsReportFilePath,
494  StringRef FileNameFromCU, StringRef NameOfWrappedPass,
495  llvm::json::Array &Bugs) {
496  std::error_code EC;
497  raw_fd_ostream OS_FILE{OrigDIVerifyBugsReportFilePath, EC,
499  if (EC) {
500  errs() << "Could not open file: " << EC.message() << ", "
501  << OrigDIVerifyBugsReportFilePath << '\n';
502  return;
503  }
504 
505  OS_FILE << "{\"file\":\"" << FileNameFromCU << "\", ";
506 
507  StringRef PassName = NameOfWrappedPass != "" ? NameOfWrappedPass : "no-name";
508  OS_FILE << "\"pass\":\"" << PassName << "\", ";
509 
510  llvm::json::Value BugsToPrint{std::move(Bugs)};
511  OS_FILE << "\"bugs\": " << BugsToPrint;
512 
513  OS_FILE << "}\n";
514 }
515 
518  DebugInfoPerPassMap &DIPreservationMap,
519  StringRef Banner, StringRef NameOfWrappedPass,
520  StringRef OrigDIVerifyBugsReportFilePath) {
521  LLVM_DEBUG(dbgs() << Banner << ": (after) " << NameOfWrappedPass << '\n');
522 
523  if (!M.getNamedMetadata("llvm.dbg.cu")) {
524  dbg() << Banner << ": Skipping module without debug info\n";
525  return false;
526  }
527 
528  // Map the debug info holding DIs after a pass.
529  DebugInfoPerPassMap DIPreservationAfter;
530 
531  // Visit each instruction.
532  for (Function &F : Functions) {
533  if (isFunctionSkipped(F))
534  continue;
535 
536  // TODO: Collect metadata other than DISubprograms.
537  // Collect the DISubprogram.
538  auto *SP = F.getSubprogram();
539  DIPreservationAfter[NameOfWrappedPass].DIFunctions.insert(
540  {F.getName(), SP});
541 
542  if (SP) {
543  LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n');
544  for (const DINode *DN : SP->getRetainedNodes()) {
545  if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
546  DIPreservationAfter[NameOfWrappedPass].DIVariables[DV] = 0;
547  }
548  }
549  }
550 
551  for (BasicBlock &BB : F) {
552  // Collect debug locations (!dbg) and debug variable intrinsics.
553  for (Instruction &I : BB) {
554  // Skip PHIs.
555  if (isa<PHINode>(I))
556  continue;
557 
558  // Collect dbg.values and dbg.declares.
559  if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I)) {
560  if (!SP)
561  continue;
562  // Skip inlined variables.
563  if (I.getDebugLoc().getInlinedAt())
564  continue;
565  // Skip undef values.
566  if (DVI->isUndef())
567  continue;
568 
569  auto *Var = DVI->getVariable();
570  DIPreservationAfter[NameOfWrappedPass].DIVariables[Var]++;
571  continue;
572  }
573 
574  // Skip debug instructions other than dbg.value and dbg.declare.
575  if (isa<DbgInfoIntrinsic>(&I))
576  continue;
577 
578  LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n');
579 
580  const DILocation *Loc = I.getDebugLoc().get();
581  bool HasLoc = Loc != nullptr;
582 
583  DIPreservationAfter[NameOfWrappedPass].DILocations.insert({&I, HasLoc});
584  }
585  }
586  }
587 
588  // TODO: The name of the module could be read better?
589  StringRef FileNameFromCU =
590  (cast<DICompileUnit>(M.getNamedMetadata("llvm.dbg.cu")->getOperand(0)))
591  ->getFilename();
592 
593  auto DIFunctionsBefore = DIPreservationMap[NameOfWrappedPass].DIFunctions;
594  auto DIFunctionsAfter = DIPreservationAfter[NameOfWrappedPass].DIFunctions;
595 
596  auto DILocsBefore = DIPreservationMap[NameOfWrappedPass].DILocations;
597  auto DILocsAfter = DIPreservationAfter[NameOfWrappedPass].DILocations;
598 
599  auto InstToDelete = DIPreservationAfter[NameOfWrappedPass].InstToDelete;
600 
601  auto DIVarsBefore = DIPreservationMap[NameOfWrappedPass].DIVariables;
602  auto DIVarsAfter = DIPreservationAfter[NameOfWrappedPass].DIVariables;
603 
604  bool ShouldWriteIntoJSON = !OrigDIVerifyBugsReportFilePath.empty();
605  llvm::json::Array Bugs;
606 
607  bool ResultForFunc =
608  checkFunctions(DIFunctionsBefore, DIFunctionsAfter, NameOfWrappedPass,
609  FileNameFromCU, ShouldWriteIntoJSON, Bugs);
610  bool ResultForInsts = checkInstructions(
611  DILocsBefore, DILocsAfter, InstToDelete, NameOfWrappedPass,
612  FileNameFromCU, ShouldWriteIntoJSON, Bugs);
613 
614  bool ResultForVars = checkVars(DIVarsBefore, DIVarsAfter, NameOfWrappedPass,
615  FileNameFromCU, ShouldWriteIntoJSON, Bugs);
616 
617  bool Result = ResultForFunc && ResultForInsts && ResultForVars;
618 
619  StringRef ResultBanner = NameOfWrappedPass != "" ? NameOfWrappedPass : Banner;
620  if (ShouldWriteIntoJSON && !Bugs.empty())
621  writeJSON(OrigDIVerifyBugsReportFilePath, FileNameFromCU, NameOfWrappedPass,
622  Bugs);
623 
624  if (Result)
625  dbg() << ResultBanner << ": PASS\n";
626  else
627  dbg() << ResultBanner << ": FAIL\n";
628 
629  LLVM_DEBUG(dbgs() << "\n\n");
630  return Result;
631 }
632 
633 namespace {
634 /// Return true if a mis-sized diagnostic is issued for \p DVI.
635 bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
636  // The size of a dbg.value's value operand should match the size of the
637  // variable it corresponds to.
638  //
639  // TODO: This, along with a check for non-null value operands, should be
640  // promoted to verifier failures.
641 
642  // For now, don't try to interpret anything more complicated than an empty
643  // DIExpression. Eventually we should try to handle OP_deref and fragments.
644  if (DVI->getExpression()->getNumElements())
645  return false;
646 
647  Value *V = DVI->getVariableLocationOp(0);
648  if (!V)
649  return false;
650 
651  Type *Ty = V->getType();
652  uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
653  Optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits();
654  if (!ValueOperandSize || !DbgVarSize)
655  return false;
656 
657  bool HasBadSize = false;
658  if (Ty->isIntegerTy()) {
659  auto Signedness = DVI->getVariable()->getSignedness();
660  if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
661  HasBadSize = ValueOperandSize < *DbgVarSize;
662  } else {
663  HasBadSize = ValueOperandSize != *DbgVarSize;
664  }
665 
666  if (HasBadSize) {
667  dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
668  << ", but its variable has size " << *DbgVarSize << ": ";
669  DVI->print(dbg());
670  dbg() << "\n";
671  }
672  return HasBadSize;
673 }
674 
675 bool checkDebugifyMetadata(Module &M,
677  StringRef NameOfWrappedPass, StringRef Banner,
678  bool Strip, DebugifyStatsMap *StatsMap) {
679  // Skip modules without debugify metadata.
680  NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
681  if (!NMD) {
682  dbg() << Banner << ": Skipping module without debugify metadata\n";
683  return false;
684  }
685 
686  auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
687  return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
688  ->getZExtValue();
689  };
690  assert(NMD->getNumOperands() == 2 &&
691  "llvm.debugify should have exactly 2 operands!");
692  unsigned OriginalNumLines = getDebugifyOperand(0);
693  unsigned OriginalNumVars = getDebugifyOperand(1);
694  bool HasErrors = false;
695 
696  // Track debug info loss statistics if able.
697  DebugifyStatistics *Stats = nullptr;
698  if (StatsMap && !NameOfWrappedPass.empty())
699  Stats = &StatsMap->operator[](NameOfWrappedPass);
700 
701  BitVector MissingLines{OriginalNumLines, true};
702  BitVector MissingVars{OriginalNumVars, true};
703  for (Function &F : Functions) {
704  if (isFunctionSkipped(F))
705  continue;
706 
707  // Find missing lines.
708  for (Instruction &I : instructions(F)) {
709  if (isa<DbgValueInst>(&I))
710  continue;
711 
712  auto DL = I.getDebugLoc();
713  if (DL && DL.getLine() != 0) {
714  MissingLines.reset(DL.getLine() - 1);
715  continue;
716  }
717 
718  if (!isa<PHINode>(&I) && !DL) {
719  dbg() << "WARNING: Instruction with empty DebugLoc in function ";
720  dbg() << F.getName() << " --";
721  I.print(dbg());
722  dbg() << "\n";
723  }
724  }
725 
726  // Find missing variables and mis-sized debug values.
727  for (Instruction &I : instructions(F)) {
728  auto *DVI = dyn_cast<DbgValueInst>(&I);
729  if (!DVI)
730  continue;
731 
732  unsigned Var = ~0U;
733  (void)to_integer(DVI->getVariable()->getName(), Var, 10);
734  assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
735  bool HasBadSize = diagnoseMisSizedDbgValue(M, DVI);
736  if (!HasBadSize)
737  MissingVars.reset(Var - 1);
738  HasErrors |= HasBadSize;
739  }
740  }
741 
742  // Print the results.
743  for (unsigned Idx : MissingLines.set_bits())
744  dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
745 
746  for (unsigned Idx : MissingVars.set_bits())
747  dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
748 
749  // Update DI loss statistics.
750  if (Stats) {
751  Stats->NumDbgLocsExpected += OriginalNumLines;
752  Stats->NumDbgLocsMissing += MissingLines.count();
753  Stats->NumDbgValuesExpected += OriginalNumVars;
754  Stats->NumDbgValuesMissing += MissingVars.count();
755  }
756 
757  dbg() << Banner;
758  if (!NameOfWrappedPass.empty())
759  dbg() << " [" << NameOfWrappedPass << "]";
760  dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
761 
762  // Strip debugify metadata if required.
763  if (Strip)
764  return stripDebugifyMetadata(M);
765 
766  return false;
767 }
768 
769 /// ModulePass for attaching synthetic debug info to everything, used with the
770 /// legacy module pass manager.
771 struct DebugifyModulePass : public ModulePass {
772  bool runOnModule(Module &M) override {
773  return applyDebugify(M, Mode, DIPreservationMap, NameOfWrappedPass);
774  }
775 
776  DebugifyModulePass(enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
777  StringRef NameOfWrappedPass = "",
778  DebugInfoPerPassMap *DIPreservationMap = nullptr)
779  : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
780  DIPreservationMap(DIPreservationMap), Mode(Mode) {}
781 
782  void getAnalysisUsage(AnalysisUsage &AU) const override {
783  AU.setPreservesAll();
784  }
785 
786  static char ID; // Pass identification.
787 
788 private:
789  StringRef NameOfWrappedPass;
790  DebugInfoPerPassMap *DIPreservationMap;
791  enum DebugifyMode Mode;
792 };
793 
794 /// FunctionPass for attaching synthetic debug info to instructions within a
795 /// single function, used with the legacy module pass manager.
796 struct DebugifyFunctionPass : public FunctionPass {
797  bool runOnFunction(Function &F) override {
798  return applyDebugify(F, Mode, DIPreservationMap, NameOfWrappedPass);
799  }
800 
801  DebugifyFunctionPass(
803  StringRef NameOfWrappedPass = "",
804  DebugInfoPerPassMap *DIPreservationMap = nullptr)
805  : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
806  DIPreservationMap(DIPreservationMap), Mode(Mode) {}
807 
808  void getAnalysisUsage(AnalysisUsage &AU) const override {
809  AU.setPreservesAll();
810  }
811 
812  static char ID; // Pass identification.
813 
814 private:
815  StringRef NameOfWrappedPass;
816  DebugInfoPerPassMap *DIPreservationMap;
817  enum DebugifyMode Mode;
818 };
819 
820 /// ModulePass for checking debug info inserted by -debugify, used with the
821 /// legacy module pass manager.
822 struct CheckDebugifyModulePass : public ModulePass {
823  bool runOnModule(Module &M) override {
825  return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
826  "CheckModuleDebugify", Strip, StatsMap);
827  return checkDebugInfoMetadata(
828  M, M.functions(), *DIPreservationMap,
829  "CheckModuleDebugify (original debuginfo)", NameOfWrappedPass,
830  OrigDIVerifyBugsReportFilePath);
831  }
832 
833  CheckDebugifyModulePass(
834  bool Strip = false, StringRef NameOfWrappedPass = "",
835  DebugifyStatsMap *StatsMap = nullptr,
837  DebugInfoPerPassMap *DIPreservationMap = nullptr,
838  StringRef OrigDIVerifyBugsReportFilePath = "")
839  : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
840  OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
841  StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode),
842  Strip(Strip) {}
843 
844  void getAnalysisUsage(AnalysisUsage &AU) const override {
845  AU.setPreservesAll();
846  }
847 
848  static char ID; // Pass identification.
849 
850 private:
851  StringRef NameOfWrappedPass;
852  StringRef OrigDIVerifyBugsReportFilePath;
853  DebugifyStatsMap *StatsMap;
854  DebugInfoPerPassMap *DIPreservationMap;
855  enum DebugifyMode Mode;
856  bool Strip;
857 };
858 
859 /// FunctionPass for checking debug info inserted by -debugify-function, used
860 /// with the legacy module pass manager.
861 struct CheckDebugifyFunctionPass : public FunctionPass {
862  bool runOnFunction(Function &F) override {
863  Module &M = *F.getParent();
864  auto FuncIt = F.getIterator();
866  return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
867  NameOfWrappedPass, "CheckFunctionDebugify",
868  Strip, StatsMap);
869  return checkDebugInfoMetadata(
870  M, make_range(FuncIt, std::next(FuncIt)), *DIPreservationMap,
871  "CheckFunctionDebugify (original debuginfo)", NameOfWrappedPass,
872  OrigDIVerifyBugsReportFilePath);
873  }
874 
875  CheckDebugifyFunctionPass(
876  bool Strip = false, StringRef NameOfWrappedPass = "",
877  DebugifyStatsMap *StatsMap = nullptr,
879  DebugInfoPerPassMap *DIPreservationMap = nullptr,
880  StringRef OrigDIVerifyBugsReportFilePath = "")
881  : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
882  OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
883  StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode),
884  Strip(Strip) {}
885 
886  void getAnalysisUsage(AnalysisUsage &AU) const override {
887  AU.setPreservesAll();
888  }
889 
890  static char ID; // Pass identification.
891 
892 private:
893  StringRef NameOfWrappedPass;
894  StringRef OrigDIVerifyBugsReportFilePath;
895  DebugifyStatsMap *StatsMap;
896  DebugInfoPerPassMap *DIPreservationMap;
897  enum DebugifyMode Mode;
898  bool Strip;
899 };
900 
901 } // end anonymous namespace
902 
904  std::error_code EC;
905  raw_fd_ostream OS{Path, EC};
906  if (EC) {
907  errs() << "Could not open file: " << EC.message() << ", " << Path << '\n';
908  return;
909  }
910 
911  OS << "Pass Name" << ',' << "# of missing debug values" << ','
912  << "# of missing locations" << ',' << "Missing/Expected value ratio" << ','
913  << "Missing/Expected location ratio" << '\n';
914  for (const auto &Entry : Map) {
915  StringRef Pass = Entry.first;
916  DebugifyStatistics Stats = Entry.second;
917 
918  OS << Pass << ',' << Stats.NumDbgValuesMissing << ','
919  << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ','
920  << Stats.getEmptyLocationRatio() << '\n';
921  }
922 }
923 
925  llvm::StringRef NameOfWrappedPass,
926  DebugInfoPerPassMap *DIPreservationMap) {
928  return new DebugifyModulePass();
929  assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
930  return new DebugifyModulePass(Mode, NameOfWrappedPass, DIPreservationMap);
931 }
932 
933 FunctionPass *
935  llvm::StringRef NameOfWrappedPass,
936  DebugInfoPerPassMap *DIPreservationMap) {
938  return new DebugifyFunctionPass();
939  assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
940  return new DebugifyFunctionPass(Mode, NameOfWrappedPass, DIPreservationMap);
941 }
942 
944  applyDebugifyMetadata(M, M.functions(),
945  "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
946  return PreservedAnalyses::all();
947 }
948 
950  bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
951  enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap,
952  StringRef OrigDIVerifyBugsReportFilePath) {
954  return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
955  assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
956  return new CheckDebugifyModulePass(false, NameOfWrappedPass, nullptr, Mode,
957  DIPreservationMap,
958  OrigDIVerifyBugsReportFilePath);
959 }
960 
962  bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
963  enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap,
964  StringRef OrigDIVerifyBugsReportFilePath) {
966  return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
967  assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
968  return new CheckDebugifyFunctionPass(false, NameOfWrappedPass, nullptr, Mode,
969  DIPreservationMap,
970  OrigDIVerifyBugsReportFilePath);
971 }
972 
975  checkDebugifyMetadata(M, M.functions(), "", "CheckModuleDebugify", false,
976  nullptr);
977  return PreservedAnalyses::all();
978 }
979 
980 static bool isIgnoredPass(StringRef PassID) {
981  return isSpecialPass(PassID, {"PassManager", "PassAdaptor",
982  "AnalysisManagerProxy", "PrintFunctionPass",
983  "PrintModulePass", "BitcodeWriterPass",
984  "ThinLTOBitcodeWriterPass", "VerifierPass"});
985 }
986 
990  if (isIgnoredPass(P))
991  return;
992  if (any_isa<const Function *>(IR))
993  applyDebugify(*const_cast<Function *>(any_cast<const Function *>(IR)));
994  else if (any_isa<const Module *>(IR))
995  applyDebugify(*const_cast<Module *>(any_cast<const Module *>(IR)));
996  });
998  const PreservedAnalyses &PassPA) {
999  if (isIgnoredPass(P))
1000  return;
1001  if (any_isa<const Function *>(IR)) {
1002  auto &F = *const_cast<Function *>(any_cast<const Function *>(IR));
1003  Module &M = *F.getParent();
1004  auto It = F.getIterator();
1005  checkDebugifyMetadata(M, make_range(It, std::next(It)), P,
1006  "CheckFunctionDebugify", /*Strip=*/true, &StatsMap);
1007  } else if (any_isa<const Module *>(IR)) {
1008  auto &M = *const_cast<Module *>(any_cast<const Module *>(IR));
1009  checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify",
1010  /*Strip=*/true, &StatsMap);
1011  }
1012  });
1013 }
1014 
1015 char DebugifyModulePass::ID = 0;
1016 static RegisterPass<DebugifyModulePass> DM("debugify",
1017  "Attach debug info to everything");
1018 
1021  CDM("check-debugify", "Check debug info from -debugify");
1022 
1023 char DebugifyFunctionPass::ID = 0;
1024 static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
1025  "Attach debug info to a function");
1026 
1029  CDF("check-debugify-function", "Check debug info from -debugify-function");
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::RegisterPass
RegisterPass<t> template - This template class is used to notify the system that a Pass is available ...
Definition: PassSupport.h:94
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
Int32Ty
IntegerType * Int32Ty
Definition: NVVMIntrRange.cpp:67
llvm::DbgVariableIntrinsic::getExpression
DIExpression * getExpression() const
Definition: IntrinsicInst.h:257
llvm::Type::isSized
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:272
CDF
static RegisterPass< CheckDebugifyFunctionPass > CDF("check-debugify-function", "Check debug info from -debugify-function")
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
llvm::StripDebugInfo
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:476
llvm::json::Value
A Value is an JSON value of unknown type.
Definition: JSON.h:289
llvm
Definition: AllocatorList.h:23
llvm::DIType
Base class for types.
Definition: DebugInfoMetadata.h:662
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::DIBuilder::getOrCreateTypeArray
DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata * > Elements)
Get a DITypeRefArray, create one if required.
Definition: DIBuilder.cpp:646
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
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:1386
llvm::DIBuilder::finalize
void finalize()
Construct any deferred debug info descriptors.
Definition: DIBuilder.cpp:69
DebugifyMode
DebugifyMode
Used to check whether we track synthetic or original debug info.
Definition: Debugify.h:94
FileSystem.h
llvm::NamedMDNode::getNumOperands
unsigned getNumOperands() const
Definition: Metadata.cpp:1114
llvm::BasicBlock::iterator
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:90
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
IntrinsicInst.h
llvm::DIBuilder
Definition: DIBuilder.h:41
InstIterator.h
Debugify.h
llvm::Function
Definition: Function.h:61
llvm::DIBuilder::finalizeSubprogram
void finalizeSubprogram(DISubprogram *SP)
Finalize a specific subprogram - no new variables may be added to this subprogram afterwards.
Definition: DIBuilder.cpp:49
llvm::json::Array::empty
bool empty() const
Definition: JSON.h:185
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
Pass.h
checkFunctions
static bool checkFunctions(const DebugFnMap &DIFunctionsBefore, const DebugFnMap &DIFunctionsAfter, StringRef NameOfWrappedPass, StringRef FileNameFromCU, bool ShouldWriteIntoJSON, llvm::json::Array &Bugs)
Definition: Debugify.cpp:357
DM
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
llvm::PassInstrumentationCallbacks::registerBeforeNonSkippedPassCallback
void registerBeforeNonSkippedPassCallback(CallableT C)
Definition: PassInstrumentation.h:106
llvm::lltok::LocalVar
@ LocalVar
Definition: LLToken.h:471
llvm::Function::eraseFromParent
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Function.cpp:371
llvm::MapVector::clear
void clear()
Definition: MapVector.h:88
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1167
llvm::collectDebugInfoMetadata
bool collectDebugInfoMetadata(Module &M, iterator_range< Module::iterator > Functions, DebugInfoPerPassMap &DIPreservationMap, StringRef Banner, StringRef NameOfWrappedPass)
Collect original debug information before a pass.
Definition: Debugify.cpp:284
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1562
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
Module.h
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
llvm::DbgVariableIntrinsic::getVariable
DILocalVariable * getVariable() const
Definition: IntrinsicInst.h:253
llvm::Optional< uint64_t >
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
NewPMDebugifyPass::run
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
Definition: Debugify.cpp:943
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::applyDebugifyMetadata
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::DIBuilder::createSubroutineType
DISubroutineType * createSubroutineType(DITypeRefArray ParameterTypes, DINode::DIFlags Flags=DINode::FlagZero, unsigned CC=0)
Create subroutine type.
Definition: DIBuilder.cpp:508
llvm::M68kBeads::Term
@ Term
Definition: M68kBaseInfo.h:71
checkInstructions
static bool checkInstructions(const DebugInstMap &DILocsBefore, const DebugInstMap &DILocsAfter, const WeakInstValueMap &InstToDelete, StringRef NameOfWrappedPass, StringRef FileNameFromCU, bool ShouldWriteIntoJSON, llvm::json::Array &Bugs)
Definition: Debugify.cpp:399
llvm::nulls
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
Definition: raw_ostream.cpp:899
llvm::json::Array::push_back
void push_back(const Value &E)
Definition: JSON.h:190
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:197
llvm::DbgVariableIntrinsic::getVariableLocationOp
Value * getVariableLocationOp(unsigned OpIdx) const
Definition: IntrinsicInst.cpp:60
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:122
llvm::DIBuilder::createFile
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
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1198
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
DebugifyMode::SyntheticDebugInfo
@ SyntheticDebugInfo
llvm::DIBuilder::createAutoVariable
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:754
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition: Metadata.cpp:1124
CommandLine.h
llvm::checkDebugInfoMetadata
bool checkDebugInfoMetadata(Module &M, iterator_range< Module::iterator > Functions, DebugInfoPerPassMap &DIPreservationMap, StringRef Banner, StringRef NameOfWrappedPass, StringRef OrigDIVerifyBugsReportFilePath)
Check original debug information after a pass.
Definition: Debugify.cpp:516
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:228
isIgnoredPass
static bool isIgnoredPass(StringRef PassID)
Definition: Debugify.cpp:980
llvm::DbgValueInst
This represents the llvm.dbg.value instruction.
Definition: IntrinsicInst.h:347
PassInstrumentation.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::DISubprogram::DISPFlags
DISPFlags
Debug info subprogram flags.
Definition: DebugInfoMetadata.h:1815
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::isSpecialPass
bool isSpecialPass(StringRef PassID, const std::vector< StringRef > &Specials)
Definition: PassInstrumentation.cpp:32
llvm::DIBuilder::createFunction
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:810
llvm::Instruction::getOpcodeName
const char * getOpcodeName() const
Definition: Instruction.h:162
llvm::Instruction
Definition: Instruction.h:45
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:146
llvm::NamedMDNode::eraseFromParent
void eraseFromParent()
Drop all references and remove the node from parent module.
Definition: Metadata.cpp:1131
llvm::json::Array
An Array is a JSON array, which contains heterogeneous JSON values.
Definition: JSON.h:156
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
BitVector.h
llvm::ConstantInt::get
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:898
checkVars
static bool checkVars(const DebugVarMap &DIFunctionsBefore, const DebugVarMap &DIFunctionsAfter, StringRef NameOfWrappedPass, StringRef FileNameFromCU, bool ShouldWriteIntoJSON, llvm::json::Array &Bugs)
Definition: Debugify.cpp:460
IR
Statically lint checks LLVM IR
Definition: Lint.cpp:744
JSON.h
llvm::exportDebugifyStats
void exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map)
Definition: Debugify.cpp:903
llvm::BitVector
Definition: BitVector.h:74
llvm::stripDebugifyMetadata
bool stripDebugifyMetadata(Module &M)
Strip out all of the metadata and debug info inserted by debugify.
Definition: Debugify.cpp:239
llvm::DEBUG_METADATA_VERSION
@ DEBUG_METADATA_VERSION
Definition: Metadata.h:52
llvm::None
const NoneType None
Definition: None.h:23
getFilename
static SmallString< 128 > getFilename(const DISubprogram *SP)
Extract a filename for a DISubprogram.
Definition: GCOVProfiling.cpp:266
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:345
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::DIBasicType::Signedness::Signed
@ Signed
llvm::sys::fs::OF_TextWithCRLF
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition: FileSystem.h:772
createCheckDebugifyFunctionPass
FunctionPass * createCheckDebugifyFunctionPass(bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap, enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap, StringRef OrigDIVerifyBugsReportFilePath)
Definition: Debugify.cpp:961
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:202
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1102
llvm::cl::opt< bool >
llvm::instructions
inst_range instructions(Function *F)
Definition: InstIterator.h:133
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:699
llvm::MapVector::find
iterator find(const KeyT &Key)
Definition: MapVector.h:147
createDebugifyModulePass
ModulePass * createDebugifyModulePass(enum DebugifyMode Mode, llvm::StringRef NameOfWrappedPass, DebugInfoPerPassMap *DIPreservationMap)
Definition: Debugify.cpp:924
applyDebugify
static bool applyDebugify(Function &F, enum DebugifyMode Mode=DebugifyMode::SyntheticDebugInfo, DebugInfoPerPassMap *DIPreservationMap=nullptr, StringRef NameOfWrappedPass="")
Definition: Debugify.cpp:211
llvm::DebugifyEachInstrumentation::StatsMap
DebugifyStatsMap StatsMap
Definition: Debugify.h:161
llvm::DIBuilder::createExpression
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:793
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::DenseMap
Definition: DenseMap.h:714
DebugInfo.h
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::DebugLoc::get
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:21
StringExtras.h
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
DIBuilder.h
llvm::Value::print
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:4623
createDebugifyFunctionPass
FunctionPass * createDebugifyFunctionPass(enum DebugifyMode Mode, llvm::StringRef NameOfWrappedPass, DebugInfoPerPassMap *DIPreservationMap)
Definition: Debugify.cpp:934
llvm::NamedMDNode::getOperand
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1118
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DebugifyStatistics
Track how much debugify information (in the synthetic mode only) has been lost.
Definition: Debugify.h:111
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:262
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
DebugifyMode::OriginalDebugInfo
@ OriginalDebugInfo
llvm::DIVariable::getName
StringRef getName() const
Definition: DebugInfoMetadata.h:2500
llvm::DIVariable::getSignedness
Optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or None if this type is neither signed nor unsigned.
Definition: DebugInfoMetadata.h:2510
createCheckDebugifyModulePass
ModulePass * createCheckDebugifyModulePass(bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap, enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap, StringRef OrigDIVerifyBugsReportFilePath)
Definition: Debugify.cpp:949
llvm::MapVector::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: MapVector.h:117
llvm::Module::Warning
@ Warning
Emits a warning if two values disagree.
Definition: Module.h:124
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::DINode
Tagged DWARF-like metadata node.
Definition: DebugInfoMetadata.h:127
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
clEnumValN
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:674
llvm::ValueAsMetadata::getConstant
static ConstantAsMetadata * getConstant(Value *C)
Definition: Metadata.h:366
llvm::PICLevel::Level
Level
Definition: CodeGen.h:33
llvm::DbgVariableIntrinsic::getFragmentSizeInBits
Optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
Definition: IntrinsicInst.cpp:138
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:294
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:432
llvm::NamedMDNode::operands
iterator_range< op_iterator > operands()
Definition: Metadata.h:1482
llvm::MapVector::end
iterator end()
Definition: MapVector.h:71
llvm::DIBuilder::createCompileUnit
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
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:69
llvm::Any
Definition: Any.h:26
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
Stats
block placement Basic Block Placement Stats
Definition: MachineBlockPlacement.cpp:3463
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
NewPMCheckDebugifyPass::run
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
Definition: Debugify.cpp:973
CDM
static RegisterPass< CheckDebugifyModulePass > CDM("check-debugify", "Check debug info from -debugify")
writeJSON
static void writeJSON(StringRef OrigDIVerifyBugsReportFilePath, StringRef FileNameFromCU, StringRef NameOfWrappedPass, llvm::json::Array &Bugs)
Definition: Debugify.cpp:493
llvm::PassInstrumentationCallbacks::registerAfterPassCallback
void registerAfterPassCallback(CallableT C)
Definition: PassInstrumentation.h:110
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
Instructions.h
llvm::Instruction::getDebugLoc
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:370
llvm::PassInstrumentationCallbacks
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Definition: PassInstrumentation.h:66
N
#define N
llvm::sys::fs::OF_Append
@ OF_Append
The file should be opened in append mode.
Definition: FileSystem.h:775
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
getSubprogram
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&... Args)
Definition: DIBuilder.cpp:804
llvm::DIExpression::getNumElements
unsigned getNumElements() const
Definition: DebugInfoMetadata.h:2580
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
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
llvm::DIBuilder::createBasicType
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
llvm::DebugifyEachInstrumentation::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC)
Definition: Debugify.cpp:987
llvm::cl::desc
Definition: CommandLine.h:414
llvm::json::Object
An Object is a JSON object, which maps strings to heterogenous JSON values.
Definition: JSON.h:90
llvm::NamedMDNode::clearOperands
void clearOperands()
Drop all references to this node's operands.
Definition: Metadata.cpp:1133
llvm::MDString
A single uniqued string.
Definition: Metadata.h:611
CU
Definition: AArch64AsmBackend.cpp:499
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:206
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:669
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38