11a2b3536SDjordje Todorovic //===- Debugify.cpp - Check debug info preservation in optimizations ------===//
225ee8613SDaniel Sanders //
325ee8613SDaniel Sanders // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
425ee8613SDaniel Sanders // See https://llvm.org/LICENSE.txt for license information.
525ee8613SDaniel Sanders // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
625ee8613SDaniel Sanders //
725ee8613SDaniel Sanders //===----------------------------------------------------------------------===//
825ee8613SDaniel Sanders ///
91a2b3536SDjordje Todorovic /// \file In the `synthetic` mode, the `-debugify` attaches synthetic debug info
101a2b3536SDjordje Todorovic /// to everything. It can be used to create targeted tests for debug info
111a2b3536SDjordje Todorovic /// preservation. In addition, when using the `original` mode, it can check
121a2b3536SDjordje Todorovic /// original debug info preservation. The `synthetic` mode is default one.
1325ee8613SDaniel Sanders ///
1425ee8613SDaniel Sanders //===----------------------------------------------------------------------===//
1525ee8613SDaniel Sanders 
164c1a1d3cSReid Kleckner #include "llvm/Transforms/Utils/Debugify.h"
1725ee8613SDaniel Sanders #include "llvm/ADT/BitVector.h"
1825ee8613SDaniel Sanders #include "llvm/ADT/StringExtras.h"
1925ee8613SDaniel Sanders #include "llvm/IR/DIBuilder.h"
2025ee8613SDaniel Sanders #include "llvm/IR/DebugInfo.h"
2125ee8613SDaniel Sanders #include "llvm/IR/InstIterator.h"
2225ee8613SDaniel Sanders #include "llvm/IR/Instructions.h"
2325ee8613SDaniel Sanders #include "llvm/IR/IntrinsicInst.h"
240128b950SSimon Pilgrim #include "llvm/IR/Module.h"
257de6dcd2SArthur Eubanks #include "llvm/IR/PassInstrumentation.h"
2625ee8613SDaniel Sanders #include "llvm/Pass.h"
274c1a1d3cSReid Kleckner #include "llvm/Support/CommandLine.h"
289f41c03fSDjordje Todorovic #include "llvm/Support/JSON.h"
2925ee8613SDaniel Sanders 
301a2b3536SDjordje Todorovic #define DEBUG_TYPE "debugify"
311a2b3536SDjordje Todorovic 
3225ee8613SDaniel Sanders using namespace llvm;
3325ee8613SDaniel Sanders 
3425ee8613SDaniel Sanders namespace {
3525ee8613SDaniel Sanders 
3625ee8613SDaniel Sanders cl::opt<bool> Quiet("debugify-quiet",
3725ee8613SDaniel Sanders                     cl::desc("Suppress verbose debugify output"));
3825ee8613SDaniel Sanders 
3915f7bc78SDaniel Sanders enum class Level {
4015f7bc78SDaniel Sanders   Locations,
4115f7bc78SDaniel Sanders   LocationsAndVariables
4215f7bc78SDaniel Sanders };
431a2b3536SDjordje Todorovic 
441a2b3536SDjordje Todorovic // Used for the synthetic mode only.
4515f7bc78SDaniel Sanders cl::opt<Level> DebugifyLevel(
4615f7bc78SDaniel Sanders     "debugify-level", cl::desc("Kind of debug info to add"),
4715f7bc78SDaniel Sanders     cl::values(clEnumValN(Level::Locations, "locations", "Locations only"),
4815f7bc78SDaniel Sanders                clEnumValN(Level::LocationsAndVariables, "location+variables",
4915f7bc78SDaniel Sanders                           "Locations and Variables")),
5015f7bc78SDaniel Sanders     cl::init(Level::LocationsAndVariables));
5115f7bc78SDaniel Sanders 
5225ee8613SDaniel Sanders raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
5325ee8613SDaniel Sanders 
5425ee8613SDaniel Sanders uint64_t getAllocSizeInBits(Module &M, Type *Ty) {
5525ee8613SDaniel Sanders   return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0;
5625ee8613SDaniel Sanders }
5725ee8613SDaniel Sanders 
5825ee8613SDaniel Sanders bool isFunctionSkipped(Function &F) {
5925ee8613SDaniel Sanders   return F.isDeclaration() || !F.hasExactDefinition();
6025ee8613SDaniel Sanders }
6125ee8613SDaniel Sanders 
6225ee8613SDaniel Sanders /// Find the basic block's terminating instruction.
6325ee8613SDaniel Sanders ///
6425ee8613SDaniel Sanders /// Special care is needed to handle musttail and deopt calls, as these behave
6525ee8613SDaniel Sanders /// like (but are in fact not) terminators.
6625ee8613SDaniel Sanders Instruction *findTerminatingInstruction(BasicBlock &BB) {
6725ee8613SDaniel Sanders   if (auto *I = BB.getTerminatingMustTailCall())
6825ee8613SDaniel Sanders     return I;
6925ee8613SDaniel Sanders   if (auto *I = BB.getTerminatingDeoptimizeCall())
7025ee8613SDaniel Sanders     return I;
7125ee8613SDaniel Sanders   return BB.getTerminator();
7225ee8613SDaniel Sanders }
731adeeabbSDaniel Sanders } // end anonymous namespace
7425ee8613SDaniel Sanders 
751adeeabbSDaniel Sanders bool llvm::applyDebugifyMetadata(
761adeeabbSDaniel Sanders     Module &M, iterator_range<Module::iterator> Functions, StringRef Banner,
771adeeabbSDaniel Sanders     std::function<bool(DIBuilder &DIB, Function &F)> ApplyToMF) {
7825ee8613SDaniel Sanders   // Skip modules with debug info.
7925ee8613SDaniel Sanders   if (M.getNamedMetadata("llvm.dbg.cu")) {
8025ee8613SDaniel Sanders     dbg() << Banner << "Skipping module with debug info\n";
8125ee8613SDaniel Sanders     return false;
8225ee8613SDaniel Sanders   }
8325ee8613SDaniel Sanders 
8425ee8613SDaniel Sanders   DIBuilder DIB(M);
8525ee8613SDaniel Sanders   LLVMContext &Ctx = M.getContext();
86a852ee19SNico Weber   auto *Int32Ty = Type::getInt32Ty(Ctx);
8725ee8613SDaniel Sanders 
8825ee8613SDaniel Sanders   // Get a DIType which corresponds to Ty.
8925ee8613SDaniel Sanders   DenseMap<uint64_t, DIType *> TypeCache;
9025ee8613SDaniel Sanders   auto getCachedDIType = [&](Type *Ty) -> DIType * {
9125ee8613SDaniel Sanders     uint64_t Size = getAllocSizeInBits(M, Ty);
9225ee8613SDaniel Sanders     DIType *&DTy = TypeCache[Size];
9325ee8613SDaniel Sanders     if (!DTy) {
9425ee8613SDaniel Sanders       std::string Name = "ty" + utostr(Size);
9525ee8613SDaniel Sanders       DTy = DIB.createBasicType(Name, Size, dwarf::DW_ATE_unsigned);
9625ee8613SDaniel Sanders     }
9725ee8613SDaniel Sanders     return DTy;
9825ee8613SDaniel Sanders   };
9925ee8613SDaniel Sanders 
10025ee8613SDaniel Sanders   unsigned NextLine = 1;
10125ee8613SDaniel Sanders   unsigned NextVar = 1;
10225ee8613SDaniel Sanders   auto File = DIB.createFile(M.getName(), "/");
10325ee8613SDaniel Sanders   auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "debugify",
10425ee8613SDaniel Sanders                                   /*isOptimized=*/true, "", 0);
10525ee8613SDaniel Sanders 
10625ee8613SDaniel Sanders   // Visit each instruction.
10725ee8613SDaniel Sanders   for (Function &F : Functions) {
10825ee8613SDaniel Sanders     if (isFunctionSkipped(F))
10925ee8613SDaniel Sanders       continue;
11025ee8613SDaniel Sanders 
111a852ee19SNico Weber     bool InsertedDbgVal = false;
11225ee8613SDaniel Sanders     auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
11325ee8613SDaniel Sanders     DISubprogram::DISPFlags SPFlags =
11425ee8613SDaniel Sanders         DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
11525ee8613SDaniel Sanders     if (F.hasPrivateLinkage() || F.hasInternalLinkage())
11625ee8613SDaniel Sanders       SPFlags |= DISubprogram::SPFlagLocalToUnit;
11725ee8613SDaniel Sanders     auto SP = DIB.createFunction(CU, F.getName(), F.getName(), File, NextLine,
11825ee8613SDaniel Sanders                                  SPType, NextLine, DINode::FlagZero, SPFlags);
11925ee8613SDaniel Sanders     F.setSubprogram(SP);
120a852ee19SNico Weber 
121a852ee19SNico Weber     // Helper that inserts a dbg.value before \p InsertBefore, copying the
122a852ee19SNico Weber     // location (and possibly the type, if it's non-void) from \p TemplateInst.
123a852ee19SNico Weber     auto insertDbgVal = [&](Instruction &TemplateInst,
124a852ee19SNico Weber                             Instruction *InsertBefore) {
125a852ee19SNico Weber       std::string Name = utostr(NextVar++);
126a852ee19SNico Weber       Value *V = &TemplateInst;
127a852ee19SNico Weber       if (TemplateInst.getType()->isVoidTy())
128a852ee19SNico Weber         V = ConstantInt::get(Int32Ty, 0);
129a852ee19SNico Weber       const DILocation *Loc = TemplateInst.getDebugLoc().get();
130a852ee19SNico Weber       auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
131a852ee19SNico Weber                                              getCachedDIType(V->getType()),
132a852ee19SNico Weber                                              /*AlwaysPreserve=*/true);
133a852ee19SNico Weber       DIB.insertDbgValueIntrinsic(V, LocalVar, DIB.createExpression(), Loc,
134a852ee19SNico Weber                                   InsertBefore);
135a852ee19SNico Weber     };
136a852ee19SNico Weber 
13725ee8613SDaniel Sanders     for (BasicBlock &BB : F) {
13825ee8613SDaniel Sanders       // Attach debug locations.
13925ee8613SDaniel Sanders       for (Instruction &I : BB)
14025ee8613SDaniel Sanders         I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
14125ee8613SDaniel Sanders 
14215f7bc78SDaniel Sanders       if (DebugifyLevel < Level::LocationsAndVariables)
14315f7bc78SDaniel Sanders         continue;
14415f7bc78SDaniel Sanders 
14525ee8613SDaniel Sanders       // Inserting debug values into EH pads can break IR invariants.
14625ee8613SDaniel Sanders       if (BB.isEHPad())
14725ee8613SDaniel Sanders         continue;
14825ee8613SDaniel Sanders 
14925ee8613SDaniel Sanders       // Find the terminating instruction, after which no debug values are
15025ee8613SDaniel Sanders       // attached.
15125ee8613SDaniel Sanders       Instruction *LastInst = findTerminatingInstruction(BB);
15225ee8613SDaniel Sanders       assert(LastInst && "Expected basic block with a terminator");
15325ee8613SDaniel Sanders 
15425ee8613SDaniel Sanders       // Maintain an insertion point which can't be invalidated when updates
15525ee8613SDaniel Sanders       // are made.
15625ee8613SDaniel Sanders       BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();
15725ee8613SDaniel Sanders       assert(InsertPt != BB.end() && "Expected to find an insertion point");
15825ee8613SDaniel Sanders       Instruction *InsertBefore = &*InsertPt;
15925ee8613SDaniel Sanders 
16025ee8613SDaniel Sanders       // Attach debug values.
16125ee8613SDaniel Sanders       for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {
16225ee8613SDaniel Sanders         // Skip void-valued instructions.
16325ee8613SDaniel Sanders         if (I->getType()->isVoidTy())
16425ee8613SDaniel Sanders           continue;
16525ee8613SDaniel Sanders 
16625ee8613SDaniel Sanders         // Phis and EH pads must be grouped at the beginning of the block.
16725ee8613SDaniel Sanders         // Only advance the insertion point when we finish visiting these.
16825ee8613SDaniel Sanders         if (!isa<PHINode>(I) && !I->isEHPad())
16925ee8613SDaniel Sanders           InsertBefore = I->getNextNode();
17025ee8613SDaniel Sanders 
171a852ee19SNico Weber         insertDbgVal(*I, InsertBefore);
172a852ee19SNico Weber         InsertedDbgVal = true;
17325ee8613SDaniel Sanders       }
17425ee8613SDaniel Sanders     }
175a852ee19SNico Weber     // Make sure we emit at least one dbg.value, otherwise MachineDebugify may
176a852ee19SNico Weber     // not have anything to work with as it goes about inserting DBG_VALUEs.
177a852ee19SNico Weber     // (It's common for MIR tests to be written containing skeletal IR with
178a852ee19SNico Weber     // empty functions -- we're still interested in debugifying the MIR within
179a852ee19SNico Weber     // those tests, and this helps with that.)
180a852ee19SNico Weber     if (DebugifyLevel == Level::LocationsAndVariables && !InsertedDbgVal) {
181a852ee19SNico Weber       auto *Term = findTerminatingInstruction(F.getEntryBlock());
182a852ee19SNico Weber       insertDbgVal(*Term, Term);
183a852ee19SNico Weber     }
1841adeeabbSDaniel Sanders     if (ApplyToMF)
1851adeeabbSDaniel Sanders       ApplyToMF(DIB, F);
18625ee8613SDaniel Sanders     DIB.finalizeSubprogram(SP);
18725ee8613SDaniel Sanders   }
18825ee8613SDaniel Sanders   DIB.finalize();
18925ee8613SDaniel Sanders 
19025ee8613SDaniel Sanders   // Track the number of distinct lines and variables.
19125ee8613SDaniel Sanders   NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.debugify");
19225ee8613SDaniel Sanders   auto addDebugifyOperand = [&](unsigned N) {
19325ee8613SDaniel Sanders     NMD->addOperand(MDNode::get(
194a852ee19SNico Weber         Ctx, ValueAsMetadata::getConstant(ConstantInt::get(Int32Ty, N))));
19525ee8613SDaniel Sanders   };
19625ee8613SDaniel Sanders   addDebugifyOperand(NextLine - 1); // Original number of lines.
19725ee8613SDaniel Sanders   addDebugifyOperand(NextVar - 1);  // Original number of variables.
19825ee8613SDaniel Sanders   assert(NMD->getNumOperands() == 2 &&
19925ee8613SDaniel Sanders          "llvm.debugify should have exactly 2 operands!");
20025ee8613SDaniel Sanders 
20125ee8613SDaniel Sanders   // Claim that this synthetic debug info is valid.
20225ee8613SDaniel Sanders   StringRef DIVersionKey = "Debug Info Version";
20325ee8613SDaniel Sanders   if (!M.getModuleFlag(DIVersionKey))
20425ee8613SDaniel Sanders     M.addModuleFlag(Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
20525ee8613SDaniel Sanders 
20625ee8613SDaniel Sanders   return true;
20725ee8613SDaniel Sanders }
20825ee8613SDaniel Sanders 
2091a2b3536SDjordje Todorovic static bool
2101a2b3536SDjordje Todorovic applyDebugify(Function &F,
2111a2b3536SDjordje Todorovic               enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
2121a2b3536SDjordje Todorovic               DebugInfoPerPassMap *DIPreservationMap = nullptr,
2131a2b3536SDjordje Todorovic               StringRef NameOfWrappedPass = "") {
21498b93385SFangrui Song   Module &M = *F.getParent();
21598b93385SFangrui Song   auto FuncIt = F.getIterator();
2161a2b3536SDjordje Todorovic   if (Mode == DebugifyMode::SyntheticDebugInfo)
21798b93385SFangrui Song     return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
2181a2b3536SDjordje Todorovic                                  "FunctionDebugify: ", /*ApplyToMF*/ nullptr);
2191a2b3536SDjordje Todorovic   assert(DIPreservationMap);
2201a2b3536SDjordje Todorovic   return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap,
2211a2b3536SDjordje Todorovic                                   "FunctionDebugify (original debuginfo)",
2221a2b3536SDjordje Todorovic                                   NameOfWrappedPass);
22398b93385SFangrui Song }
22498b93385SFangrui Song 
2251a2b3536SDjordje Todorovic static bool
2261a2b3536SDjordje Todorovic applyDebugify(Module &M,
2271a2b3536SDjordje Todorovic               enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
2281a2b3536SDjordje Todorovic               DebugInfoPerPassMap *DIPreservationMap = nullptr,
2291a2b3536SDjordje Todorovic               StringRef NameOfWrappedPass = "") {
2301a2b3536SDjordje Todorovic   if (Mode == DebugifyMode::SyntheticDebugInfo)
23198b93385SFangrui Song     return applyDebugifyMetadata(M, M.functions(),
2321a2b3536SDjordje Todorovic                                  "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
2331a2b3536SDjordje Todorovic   return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap,
2341a2b3536SDjordje Todorovic                                   "ModuleDebugify (original debuginfo)",
2351a2b3536SDjordje Todorovic                                   NameOfWrappedPass);
23698b93385SFangrui Song }
23798b93385SFangrui Song 
238122a6bfbSVedant Kumar bool llvm::stripDebugifyMetadata(Module &M) {
239122a6bfbSVedant Kumar   bool Changed = false;
240122a6bfbSVedant Kumar 
241122a6bfbSVedant Kumar   // Remove the llvm.debugify module-level named metadata.
242122a6bfbSVedant Kumar   NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify");
243122a6bfbSVedant Kumar   if (DebugifyMD) {
244122a6bfbSVedant Kumar     M.eraseNamedMetadata(DebugifyMD);
245122a6bfbSVedant Kumar     Changed = true;
246122a6bfbSVedant Kumar   }
247122a6bfbSVedant Kumar 
248122a6bfbSVedant Kumar   // Strip out all debug intrinsics and supporting metadata (subprograms, types,
249122a6bfbSVedant Kumar   // variables, etc).
250122a6bfbSVedant Kumar   Changed |= StripDebugInfo(M);
251122a6bfbSVedant Kumar 
252122a6bfbSVedant Kumar   // Strip out the dead dbg.value prototype.
253122a6bfbSVedant Kumar   Function *DbgValF = M.getFunction("llvm.dbg.value");
254122a6bfbSVedant Kumar   if (DbgValF) {
255122a6bfbSVedant Kumar     assert(DbgValF->isDeclaration() && DbgValF->use_empty() &&
256122a6bfbSVedant Kumar            "Not all debug info stripped?");
257122a6bfbSVedant Kumar     DbgValF->eraseFromParent();
258122a6bfbSVedant Kumar     Changed = true;
259122a6bfbSVedant Kumar   }
260122a6bfbSVedant Kumar 
261122a6bfbSVedant Kumar   // Strip out the module-level Debug Info Version metadata.
262122a6bfbSVedant Kumar   // FIXME: There must be an easier way to remove an operand from a NamedMDNode.
263122a6bfbSVedant Kumar   NamedMDNode *NMD = M.getModuleFlagsMetadata();
2642fa656cdSVedant Kumar   if (!NMD)
2652fa656cdSVedant Kumar     return Changed;
26619aacdb7SKazu Hirata   SmallVector<MDNode *, 4> Flags(NMD->operands());
267122a6bfbSVedant Kumar   NMD->clearOperands();
268122a6bfbSVedant Kumar   for (MDNode *Flag : Flags) {
269122a6bfbSVedant Kumar     MDString *Key = dyn_cast_or_null<MDString>(Flag->getOperand(1));
270122a6bfbSVedant Kumar     if (Key->getString() == "Debug Info Version") {
271122a6bfbSVedant Kumar       Changed = true;
272122a6bfbSVedant Kumar       continue;
273122a6bfbSVedant Kumar     }
274122a6bfbSVedant Kumar     NMD->addOperand(Flag);
275122a6bfbSVedant Kumar   }
276122a6bfbSVedant Kumar   // If we left it empty we might as well remove it.
277122a6bfbSVedant Kumar   if (NMD->getNumOperands() == 0)
278122a6bfbSVedant Kumar     NMD->eraseFromParent();
279122a6bfbSVedant Kumar 
280122a6bfbSVedant Kumar   return Changed;
281122a6bfbSVedant Kumar }
282122a6bfbSVedant Kumar 
2831a2b3536SDjordje Todorovic bool llvm::collectDebugInfoMetadata(Module &M,
2841a2b3536SDjordje Todorovic                                     iterator_range<Module::iterator> Functions,
2851a2b3536SDjordje Todorovic                                     DebugInfoPerPassMap &DIPreservationMap,
2861a2b3536SDjordje Todorovic                                     StringRef Banner,
2871a2b3536SDjordje Todorovic                                     StringRef NameOfWrappedPass) {
2881a2b3536SDjordje Todorovic   LLVM_DEBUG(dbgs() << Banner << ": (before) " << NameOfWrappedPass << '\n');
2891a2b3536SDjordje Todorovic 
2901a2b3536SDjordje Todorovic   // Clear the map with the debug info before every single pass.
2911a2b3536SDjordje Todorovic   DIPreservationMap.clear();
2921a2b3536SDjordje Todorovic 
2931a2b3536SDjordje Todorovic   if (!M.getNamedMetadata("llvm.dbg.cu")) {
2941a2b3536SDjordje Todorovic     dbg() << Banner << ": Skipping module without debug info\n";
2951a2b3536SDjordje Todorovic     return false;
2961a2b3536SDjordje Todorovic   }
2971a2b3536SDjordje Todorovic 
2981a2b3536SDjordje Todorovic   // Visit each instruction.
2991a2b3536SDjordje Todorovic   for (Function &F : Functions) {
3001a2b3536SDjordje Todorovic     if (isFunctionSkipped(F))
3011a2b3536SDjordje Todorovic       continue;
3021a2b3536SDjordje Todorovic 
3031a2b3536SDjordje Todorovic     // Collect the DISubprogram.
3041a2b3536SDjordje Todorovic     auto *SP = F.getSubprogram();
3051a2b3536SDjordje Todorovic     DIPreservationMap[NameOfWrappedPass].DIFunctions.insert({F.getName(), SP});
3061a2b3536SDjordje Todorovic     if (SP)
3071a2b3536SDjordje Todorovic       LLVM_DEBUG(dbgs() << "  Collecting subprogram: " << *SP << '\n');
3081a2b3536SDjordje Todorovic 
3091a2b3536SDjordje Todorovic     for (BasicBlock &BB : F) {
3101a2b3536SDjordje Todorovic       // Collect debug locations (!dbg).
3111a2b3536SDjordje Todorovic       // TODO: Collect dbg.values.
3121a2b3536SDjordje Todorovic       for (Instruction &I : BB) {
3131a2b3536SDjordje Todorovic         // Skip PHIs.
3141a2b3536SDjordje Todorovic         if (isa<PHINode>(I))
3151a2b3536SDjordje Todorovic           continue;
3161a2b3536SDjordje Todorovic 
3171a2b3536SDjordje Todorovic         // Skip debug instructions.
3181a2b3536SDjordje Todorovic         if (isa<DbgInfoIntrinsic>(&I))
3191a2b3536SDjordje Todorovic           continue;
3201a2b3536SDjordje Todorovic 
3211a2b3536SDjordje Todorovic         LLVM_DEBUG(dbgs() << "  Collecting info for inst: " << I << '\n');
3221a2b3536SDjordje Todorovic         DIPreservationMap[NameOfWrappedPass].InstToDelete.insert({&I, &I});
3231a2b3536SDjordje Todorovic 
3241a2b3536SDjordje Todorovic         const DILocation *Loc = I.getDebugLoc().get();
3251a2b3536SDjordje Todorovic         bool HasLoc = Loc != nullptr;
3261a2b3536SDjordje Todorovic         DIPreservationMap[NameOfWrappedPass].DILocations.insert({&I, HasLoc});
3271a2b3536SDjordje Todorovic       }
3281a2b3536SDjordje Todorovic     }
3291a2b3536SDjordje Todorovic   }
3301a2b3536SDjordje Todorovic 
3311a2b3536SDjordje Todorovic   return true;
3321a2b3536SDjordje Todorovic }
3331a2b3536SDjordje Todorovic 
3341a2b3536SDjordje Todorovic // This checks the preservation of original debug info attached to functions.
3351a2b3536SDjordje Todorovic static bool checkFunctions(const DebugFnMap &DIFunctionsBefore,
3361a2b3536SDjordje Todorovic                            const DebugFnMap &DIFunctionsAfter,
3371a2b3536SDjordje Todorovic                            StringRef NameOfWrappedPass,
3389f41c03fSDjordje Todorovic                            StringRef FileNameFromCU, bool ShouldWriteIntoJSON,
3399f41c03fSDjordje Todorovic                            llvm::json::Array &Bugs) {
3401a2b3536SDjordje Todorovic   bool Preserved = true;
3411a2b3536SDjordje Todorovic   for (const auto &F : DIFunctionsAfter) {
3421a2b3536SDjordje Todorovic     if (F.second)
3431a2b3536SDjordje Todorovic       continue;
3441a2b3536SDjordje Todorovic     auto SPIt = DIFunctionsBefore.find(F.first);
3451a2b3536SDjordje Todorovic     if (SPIt == DIFunctionsBefore.end()) {
3469f41c03fSDjordje Todorovic       if (ShouldWriteIntoJSON)
3479f41c03fSDjordje Todorovic         Bugs.push_back(llvm::json::Object({{"metadata", "DISubprogram"},
3489f41c03fSDjordje Todorovic                                            {"name", F.first},
3499f41c03fSDjordje Todorovic                                            {"action", "not-generate"}}));
3509f41c03fSDjordje Todorovic       else
3511a2b3536SDjordje Todorovic         dbg() << "ERROR: " << NameOfWrappedPass
3521a2b3536SDjordje Todorovic               << " did not generate DISubprogram for " << F.first << " from "
3531a2b3536SDjordje Todorovic               << FileNameFromCU << '\n';
3541a2b3536SDjordje Todorovic       Preserved = false;
3551a2b3536SDjordje Todorovic     } else {
3561a2b3536SDjordje Todorovic       auto SP = SPIt->second;
3571a2b3536SDjordje Todorovic       if (!SP)
3581a2b3536SDjordje Todorovic         continue;
3591a2b3536SDjordje Todorovic       // If the function had the SP attached before the pass, consider it as
3601a2b3536SDjordje Todorovic       // a debug info bug.
3619f41c03fSDjordje Todorovic       if (ShouldWriteIntoJSON)
3629f41c03fSDjordje Todorovic         Bugs.push_back(llvm::json::Object({{"metadata", "DISubprogram"},
3639f41c03fSDjordje Todorovic                                            {"name", F.first},
3649f41c03fSDjordje Todorovic                                            {"action", "drop"}}));
3659f41c03fSDjordje Todorovic       else
3661a2b3536SDjordje Todorovic         dbg() << "ERROR: " << NameOfWrappedPass << " dropped DISubprogram of "
3671a2b3536SDjordje Todorovic               << F.first << " from " << FileNameFromCU << '\n';
3681a2b3536SDjordje Todorovic       Preserved = false;
3691a2b3536SDjordje Todorovic     }
3701a2b3536SDjordje Todorovic   }
3711a2b3536SDjordje Todorovic 
3721a2b3536SDjordje Todorovic   return Preserved;
3731a2b3536SDjordje Todorovic }
3741a2b3536SDjordje Todorovic 
3751a2b3536SDjordje Todorovic // This checks the preservation of the original debug info attached to
3761a2b3536SDjordje Todorovic // instructions.
3771a2b3536SDjordje Todorovic static bool checkInstructions(const DebugInstMap &DILocsBefore,
3781a2b3536SDjordje Todorovic                               const DebugInstMap &DILocsAfter,
3791a2b3536SDjordje Todorovic                               const WeakInstValueMap &InstToDelete,
3801a2b3536SDjordje Todorovic                               StringRef NameOfWrappedPass,
3819f41c03fSDjordje Todorovic                               StringRef FileNameFromCU,
3829f41c03fSDjordje Todorovic                               bool ShouldWriteIntoJSON,
3839f41c03fSDjordje Todorovic                               llvm::json::Array &Bugs) {
3841a2b3536SDjordje Todorovic   bool Preserved = true;
3851a2b3536SDjordje Todorovic   for (const auto &L : DILocsAfter) {
3861a2b3536SDjordje Todorovic     if (L.second)
3871a2b3536SDjordje Todorovic       continue;
3881a2b3536SDjordje Todorovic     auto Instr = L.first;
3891a2b3536SDjordje Todorovic 
3901a2b3536SDjordje Todorovic     // In order to avoid pointer reuse/recycling, skip the values that might
3911a2b3536SDjordje Todorovic     // have been deleted during a pass.
3921a2b3536SDjordje Todorovic     auto WeakInstrPtr = InstToDelete.find(Instr);
3931a2b3536SDjordje Todorovic     if (WeakInstrPtr != InstToDelete.end() && !WeakInstrPtr->second)
3941a2b3536SDjordje Todorovic       continue;
3951a2b3536SDjordje Todorovic 
3961a2b3536SDjordje Todorovic     auto FnName = Instr->getFunction()->getName();
3971a2b3536SDjordje Todorovic     auto BB = Instr->getParent();
3981a2b3536SDjordje Todorovic     auto BBName = BB->hasName() ? BB->getName() : "no-name";
3999f41c03fSDjordje Todorovic     auto InstName = Instruction::getOpcodeName(Instr->getOpcode());
4001a2b3536SDjordje Todorovic 
4011a2b3536SDjordje Todorovic     auto InstrIt = DILocsBefore.find(Instr);
4021a2b3536SDjordje Todorovic     if (InstrIt == DILocsBefore.end()) {
4039f41c03fSDjordje Todorovic       if (ShouldWriteIntoJSON)
4049f41c03fSDjordje Todorovic         Bugs.push_back(llvm::json::Object({{"metadata", "DILocation"},
4059f41c03fSDjordje Todorovic                                            {"fn-name", FnName.str()},
4069f41c03fSDjordje Todorovic                                            {"bb-name", BBName.str()},
4079f41c03fSDjordje Todorovic                                            {"instr", InstName},
4089f41c03fSDjordje Todorovic                                            {"action", "not-generate"}}));
4099f41c03fSDjordje Todorovic       else
4101a2b3536SDjordje Todorovic         dbg() << "WARNING: " << NameOfWrappedPass
4111a2b3536SDjordje Todorovic               << " did not generate DILocation for " << *Instr
4121a2b3536SDjordje Todorovic               << " (BB: " << BBName << ", Fn: " << FnName
4131a2b3536SDjordje Todorovic               << ", File: " << FileNameFromCU << ")\n";
4141a2b3536SDjordje Todorovic       Preserved = false;
4151a2b3536SDjordje Todorovic     } else {
4161a2b3536SDjordje Todorovic       if (!InstrIt->second)
4171a2b3536SDjordje Todorovic         continue;
4181a2b3536SDjordje Todorovic       // If the instr had the !dbg attached before the pass, consider it as
4191a2b3536SDjordje Todorovic       // a debug info issue.
4209f41c03fSDjordje Todorovic       if (ShouldWriteIntoJSON)
4219f41c03fSDjordje Todorovic         Bugs.push_back(llvm::json::Object({{"metadata", "DILocation"},
4229f41c03fSDjordje Todorovic                                            {"fn-name", FnName.str()},
4239f41c03fSDjordje Todorovic                                            {"bb-name", BBName.str()},
4249f41c03fSDjordje Todorovic                                            {"instr", InstName},
4259f41c03fSDjordje Todorovic                                            {"action", "drop"}}));
4269f41c03fSDjordje Todorovic       else
4271a2b3536SDjordje Todorovic         dbg() << "WARNING: " << NameOfWrappedPass << " dropped DILocation of "
4281a2b3536SDjordje Todorovic               << *Instr << " (BB: " << BBName << ", Fn: " << FnName
4291a2b3536SDjordje Todorovic               << ", File: " << FileNameFromCU << ")\n";
4301a2b3536SDjordje Todorovic       Preserved = false;
4311a2b3536SDjordje Todorovic     }
4321a2b3536SDjordje Todorovic   }
4331a2b3536SDjordje Todorovic 
4341a2b3536SDjordje Todorovic   return Preserved;
4351a2b3536SDjordje Todorovic }
4361a2b3536SDjordje Todorovic 
4379f41c03fSDjordje Todorovic // Write the json data into the specifed file.
4389f41c03fSDjordje Todorovic static void writeJSON(StringRef OrigDIVerifyBugsReportFilePath,
4399f41c03fSDjordje Todorovic                       StringRef FileNameFromCU, StringRef NameOfWrappedPass,
4409f41c03fSDjordje Todorovic                       llvm::json::Array &Bugs) {
4419f41c03fSDjordje Todorovic   std::error_code EC;
4429f41c03fSDjordje Todorovic   raw_fd_ostream OS_FILE{OrigDIVerifyBugsReportFilePath, EC,
4439f41c03fSDjordje Todorovic                          sys::fs::OF_Append | sys::fs::OF_Text};
4449f41c03fSDjordje Todorovic   if (EC) {
4459f41c03fSDjordje Todorovic     errs() << "Could not open file: " << EC.message() << ", "
4469f41c03fSDjordje Todorovic            << OrigDIVerifyBugsReportFilePath << '\n';
4479f41c03fSDjordje Todorovic     return;
4489f41c03fSDjordje Todorovic   }
4499f41c03fSDjordje Todorovic 
4509f41c03fSDjordje Todorovic   OS_FILE << "{\"file\":\"" << FileNameFromCU << "\", ";
4519f41c03fSDjordje Todorovic 
4529f41c03fSDjordje Todorovic   StringRef PassName = NameOfWrappedPass != "" ? NameOfWrappedPass : "no-name";
4539f41c03fSDjordje Todorovic   OS_FILE << "\"pass\":\"" << PassName << "\", ";
4549f41c03fSDjordje Todorovic 
4559f41c03fSDjordje Todorovic   llvm::json::Value BugsToPrint{std::move(Bugs)};
4569f41c03fSDjordje Todorovic   OS_FILE << "\"bugs\": " << BugsToPrint;
4579f41c03fSDjordje Todorovic 
4589f41c03fSDjordje Todorovic   OS_FILE << "}\n";
4599f41c03fSDjordje Todorovic }
4609f41c03fSDjordje Todorovic 
4611a2b3536SDjordje Todorovic bool llvm::checkDebugInfoMetadata(Module &M,
4621a2b3536SDjordje Todorovic                                   iterator_range<Module::iterator> Functions,
4631a2b3536SDjordje Todorovic                                   DebugInfoPerPassMap &DIPreservationMap,
4649f41c03fSDjordje Todorovic                                   StringRef Banner, StringRef NameOfWrappedPass,
4659f41c03fSDjordje Todorovic                                   StringRef OrigDIVerifyBugsReportFilePath) {
4661a2b3536SDjordje Todorovic   LLVM_DEBUG(dbgs() << Banner << ": (after) " << NameOfWrappedPass << '\n');
4671a2b3536SDjordje Todorovic 
4681a2b3536SDjordje Todorovic   if (!M.getNamedMetadata("llvm.dbg.cu")) {
4691a2b3536SDjordje Todorovic     dbg() << Banner << ": Skipping module without debug info\n";
4701a2b3536SDjordje Todorovic     return false;
4711a2b3536SDjordje Todorovic   }
4721a2b3536SDjordje Todorovic 
4731a2b3536SDjordje Todorovic   // Map the debug info holding DIs after a pass.
4741a2b3536SDjordje Todorovic   DebugInfoPerPassMap DIPreservationAfter;
4751a2b3536SDjordje Todorovic 
4761a2b3536SDjordje Todorovic   // Visit each instruction.
4771a2b3536SDjordje Todorovic   for (Function &F : Functions) {
4781a2b3536SDjordje Todorovic     if (isFunctionSkipped(F))
4791a2b3536SDjordje Todorovic       continue;
4801a2b3536SDjordje Todorovic 
4811a2b3536SDjordje Todorovic     // TODO: Collect metadata other than DISubprograms.
4821a2b3536SDjordje Todorovic     // Collect the DISubprogram.
4831a2b3536SDjordje Todorovic     auto *SP = F.getSubprogram();
4849f41c03fSDjordje Todorovic     DIPreservationAfter[NameOfWrappedPass].DIFunctions.insert(
4859f41c03fSDjordje Todorovic         {F.getName(), SP});
4861a2b3536SDjordje Todorovic     if (SP)
4871a2b3536SDjordje Todorovic       LLVM_DEBUG(dbgs() << "  Collecting subprogram: " << *SP << '\n');
4881a2b3536SDjordje Todorovic 
4891a2b3536SDjordje Todorovic     for (BasicBlock &BB : F) {
4901a2b3536SDjordje Todorovic       // Collect debug locations (!dbg attachments).
4911a2b3536SDjordje Todorovic       // TODO: Collect dbg.values.
4921a2b3536SDjordje Todorovic       for (Instruction &I : BB) {
4931a2b3536SDjordje Todorovic         // Skip PHIs.
4941a2b3536SDjordje Todorovic         if (isa<PHINode>(I))
4951a2b3536SDjordje Todorovic           continue;
4961a2b3536SDjordje Todorovic 
4971a2b3536SDjordje Todorovic         // Skip debug instructions.
4981a2b3536SDjordje Todorovic         if (isa<DbgInfoIntrinsic>(&I))
4991a2b3536SDjordje Todorovic           continue;
5001a2b3536SDjordje Todorovic 
5011a2b3536SDjordje Todorovic         LLVM_DEBUG(dbgs() << "  Collecting info for inst: " << I << '\n');
5021a2b3536SDjordje Todorovic 
5031a2b3536SDjordje Todorovic         const DILocation *Loc = I.getDebugLoc().get();
5041a2b3536SDjordje Todorovic         bool HasLoc = Loc != nullptr;
5051a2b3536SDjordje Todorovic 
5061a2b3536SDjordje Todorovic         DIPreservationAfter[NameOfWrappedPass].DILocations.insert({&I, HasLoc});
5071a2b3536SDjordje Todorovic       }
5081a2b3536SDjordje Todorovic     }
5091a2b3536SDjordje Todorovic   }
5101a2b3536SDjordje Todorovic 
5111a2b3536SDjordje Todorovic   // TODO: The name of the module could be read better?
5121a2b3536SDjordje Todorovic   StringRef FileNameFromCU =
5131a2b3536SDjordje Todorovic       (cast<DICompileUnit>(M.getNamedMetadata("llvm.dbg.cu")->getOperand(0)))
5141a2b3536SDjordje Todorovic           ->getFilename();
5151a2b3536SDjordje Todorovic 
5161a2b3536SDjordje Todorovic   auto DIFunctionsBefore = DIPreservationMap[NameOfWrappedPass].DIFunctions;
5171a2b3536SDjordje Todorovic   auto DIFunctionsAfter = DIPreservationAfter[NameOfWrappedPass].DIFunctions;
5181a2b3536SDjordje Todorovic 
5191a2b3536SDjordje Todorovic   auto DILocsBefore = DIPreservationMap[NameOfWrappedPass].DILocations;
5201a2b3536SDjordje Todorovic   auto DILocsAfter = DIPreservationAfter[NameOfWrappedPass].DILocations;
5211a2b3536SDjordje Todorovic 
5221a2b3536SDjordje Todorovic   auto InstToDelete = DIPreservationAfter[NameOfWrappedPass].InstToDelete;
5231a2b3536SDjordje Todorovic 
5249f41c03fSDjordje Todorovic   bool ShouldWriteIntoJSON = !OrigDIVerifyBugsReportFilePath.empty();
5259f41c03fSDjordje Todorovic   llvm::json::Array Bugs;
5269f41c03fSDjordje Todorovic 
5279f41c03fSDjordje Todorovic   bool ResultForFunc =
5289f41c03fSDjordje Todorovic       checkFunctions(DIFunctionsBefore, DIFunctionsAfter, NameOfWrappedPass,
5299f41c03fSDjordje Todorovic                      FileNameFromCU, ShouldWriteIntoJSON, Bugs);
5309f41c03fSDjordje Todorovic   bool ResultForInsts = checkInstructions(
5319f41c03fSDjordje Todorovic       DILocsBefore, DILocsAfter, InstToDelete, NameOfWrappedPass,
5329f41c03fSDjordje Todorovic       FileNameFromCU, ShouldWriteIntoJSON, Bugs);
5331a2b3536SDjordje Todorovic   bool Result = ResultForFunc && ResultForInsts;
5341a2b3536SDjordje Todorovic 
5351a2b3536SDjordje Todorovic   StringRef ResultBanner = NameOfWrappedPass != "" ? NameOfWrappedPass : Banner;
5369f41c03fSDjordje Todorovic   if (ShouldWriteIntoJSON && !Bugs.empty())
5379f41c03fSDjordje Todorovic     writeJSON(OrigDIVerifyBugsReportFilePath, FileNameFromCU, NameOfWrappedPass,
5389f41c03fSDjordje Todorovic               Bugs);
5399f41c03fSDjordje Todorovic 
5401a2b3536SDjordje Todorovic   if (Result)
5411a2b3536SDjordje Todorovic     dbg() << ResultBanner << ": PASS\n";
5421a2b3536SDjordje Todorovic   else
5431a2b3536SDjordje Todorovic     dbg() << ResultBanner << ": FAIL\n";
5441a2b3536SDjordje Todorovic 
5451a2b3536SDjordje Todorovic   LLVM_DEBUG(dbgs() << "\n\n");
5461a2b3536SDjordje Todorovic   return Result;
5471a2b3536SDjordje Todorovic }
5481a2b3536SDjordje Todorovic 
5491adeeabbSDaniel Sanders namespace {
55025ee8613SDaniel Sanders /// Return true if a mis-sized diagnostic is issued for \p DVI.
55125ee8613SDaniel Sanders bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
55225ee8613SDaniel Sanders   // The size of a dbg.value's value operand should match the size of the
55325ee8613SDaniel Sanders   // variable it corresponds to.
55425ee8613SDaniel Sanders   //
55525ee8613SDaniel Sanders   // TODO: This, along with a check for non-null value operands, should be
55625ee8613SDaniel Sanders   // promoted to verifier failures.
55725ee8613SDaniel Sanders 
55825ee8613SDaniel Sanders   // For now, don't try to interpret anything more complicated than an empty
55925ee8613SDaniel Sanders   // DIExpression. Eventually we should try to handle OP_deref and fragments.
56025ee8613SDaniel Sanders   if (DVI->getExpression()->getNumElements())
56125ee8613SDaniel Sanders     return false;
56225ee8613SDaniel Sanders 
563*3bfddc25SStephen Tozer   Value *V = DVI->getVariableLocationOp(0);
564*3bfddc25SStephen Tozer   if (!V)
565*3bfddc25SStephen Tozer     return false;
566*3bfddc25SStephen Tozer 
56725ee8613SDaniel Sanders   Type *Ty = V->getType();
56825ee8613SDaniel Sanders   uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
56925ee8613SDaniel Sanders   Optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits();
57025ee8613SDaniel Sanders   if (!ValueOperandSize || !DbgVarSize)
57125ee8613SDaniel Sanders     return false;
57225ee8613SDaniel Sanders 
57325ee8613SDaniel Sanders   bool HasBadSize = false;
57425ee8613SDaniel Sanders   if (Ty->isIntegerTy()) {
57525ee8613SDaniel Sanders     auto Signedness = DVI->getVariable()->getSignedness();
57625ee8613SDaniel Sanders     if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
57725ee8613SDaniel Sanders       HasBadSize = ValueOperandSize < *DbgVarSize;
57825ee8613SDaniel Sanders   } else {
57925ee8613SDaniel Sanders     HasBadSize = ValueOperandSize != *DbgVarSize;
58025ee8613SDaniel Sanders   }
58125ee8613SDaniel Sanders 
58225ee8613SDaniel Sanders   if (HasBadSize) {
58325ee8613SDaniel Sanders     dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
58425ee8613SDaniel Sanders           << ", but its variable has size " << *DbgVarSize << ": ";
58525ee8613SDaniel Sanders     DVI->print(dbg());
58625ee8613SDaniel Sanders     dbg() << "\n";
58725ee8613SDaniel Sanders   }
58825ee8613SDaniel Sanders   return HasBadSize;
58925ee8613SDaniel Sanders }
59025ee8613SDaniel Sanders 
59125ee8613SDaniel Sanders bool checkDebugifyMetadata(Module &M,
59225ee8613SDaniel Sanders                            iterator_range<Module::iterator> Functions,
59325ee8613SDaniel Sanders                            StringRef NameOfWrappedPass, StringRef Banner,
59425ee8613SDaniel Sanders                            bool Strip, DebugifyStatsMap *StatsMap) {
59525ee8613SDaniel Sanders   // Skip modules without debugify metadata.
59625ee8613SDaniel Sanders   NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
59725ee8613SDaniel Sanders   if (!NMD) {
59865030821SDjordje Todorovic     dbg() << Banner << ": Skipping module without debugify metadata\n";
59925ee8613SDaniel Sanders     return false;
60025ee8613SDaniel Sanders   }
60125ee8613SDaniel Sanders 
60225ee8613SDaniel Sanders   auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
60325ee8613SDaniel Sanders     return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
60425ee8613SDaniel Sanders         ->getZExtValue();
60525ee8613SDaniel Sanders   };
60625ee8613SDaniel Sanders   assert(NMD->getNumOperands() == 2 &&
60725ee8613SDaniel Sanders          "llvm.debugify should have exactly 2 operands!");
60825ee8613SDaniel Sanders   unsigned OriginalNumLines = getDebugifyOperand(0);
60925ee8613SDaniel Sanders   unsigned OriginalNumVars = getDebugifyOperand(1);
61025ee8613SDaniel Sanders   bool HasErrors = false;
61125ee8613SDaniel Sanders 
61225ee8613SDaniel Sanders   // Track debug info loss statistics if able.
61325ee8613SDaniel Sanders   DebugifyStatistics *Stats = nullptr;
61425ee8613SDaniel Sanders   if (StatsMap && !NameOfWrappedPass.empty())
61525ee8613SDaniel Sanders     Stats = &StatsMap->operator[](NameOfWrappedPass);
61625ee8613SDaniel Sanders 
61725ee8613SDaniel Sanders   BitVector MissingLines{OriginalNumLines, true};
61825ee8613SDaniel Sanders   BitVector MissingVars{OriginalNumVars, true};
61925ee8613SDaniel Sanders   for (Function &F : Functions) {
62025ee8613SDaniel Sanders     if (isFunctionSkipped(F))
62125ee8613SDaniel Sanders       continue;
62225ee8613SDaniel Sanders 
62325ee8613SDaniel Sanders     // Find missing lines.
62425ee8613SDaniel Sanders     for (Instruction &I : instructions(F)) {
625f64e457cSPierre-vh       if (isa<DbgValueInst>(&I) || isa<PHINode>(&I))
62625ee8613SDaniel Sanders         continue;
62725ee8613SDaniel Sanders 
62825ee8613SDaniel Sanders       auto DL = I.getDebugLoc();
62925ee8613SDaniel Sanders       if (DL && DL.getLine() != 0) {
63025ee8613SDaniel Sanders         MissingLines.reset(DL.getLine() - 1);
63125ee8613SDaniel Sanders         continue;
63225ee8613SDaniel Sanders       }
63325ee8613SDaniel Sanders 
63425ee8613SDaniel Sanders       if (!DL) {
635c1cad151SVedant Kumar         dbg() << "WARNING: Instruction with empty DebugLoc in function ";
63625ee8613SDaniel Sanders         dbg() << F.getName() << " --";
63725ee8613SDaniel Sanders         I.print(dbg());
63825ee8613SDaniel Sanders         dbg() << "\n";
63925ee8613SDaniel Sanders       }
64025ee8613SDaniel Sanders     }
64125ee8613SDaniel Sanders 
64225ee8613SDaniel Sanders     // Find missing variables and mis-sized debug values.
64325ee8613SDaniel Sanders     for (Instruction &I : instructions(F)) {
64425ee8613SDaniel Sanders       auto *DVI = dyn_cast<DbgValueInst>(&I);
64525ee8613SDaniel Sanders       if (!DVI)
64625ee8613SDaniel Sanders         continue;
64725ee8613SDaniel Sanders 
64825ee8613SDaniel Sanders       unsigned Var = ~0U;
64925ee8613SDaniel Sanders       (void)to_integer(DVI->getVariable()->getName(), Var, 10);
65025ee8613SDaniel Sanders       assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
65125ee8613SDaniel Sanders       bool HasBadSize = diagnoseMisSizedDbgValue(M, DVI);
65225ee8613SDaniel Sanders       if (!HasBadSize)
65325ee8613SDaniel Sanders         MissingVars.reset(Var - 1);
65425ee8613SDaniel Sanders       HasErrors |= HasBadSize;
65525ee8613SDaniel Sanders     }
65625ee8613SDaniel Sanders   }
65725ee8613SDaniel Sanders 
65825ee8613SDaniel Sanders   // Print the results.
65925ee8613SDaniel Sanders   for (unsigned Idx : MissingLines.set_bits())
66025ee8613SDaniel Sanders     dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
66125ee8613SDaniel Sanders 
66225ee8613SDaniel Sanders   for (unsigned Idx : MissingVars.set_bits())
66325ee8613SDaniel Sanders     dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
66425ee8613SDaniel Sanders 
66525ee8613SDaniel Sanders   // Update DI loss statistics.
66625ee8613SDaniel Sanders   if (Stats) {
66725ee8613SDaniel Sanders     Stats->NumDbgLocsExpected += OriginalNumLines;
66825ee8613SDaniel Sanders     Stats->NumDbgLocsMissing += MissingLines.count();
66925ee8613SDaniel Sanders     Stats->NumDbgValuesExpected += OriginalNumVars;
67025ee8613SDaniel Sanders     Stats->NumDbgValuesMissing += MissingVars.count();
67125ee8613SDaniel Sanders   }
67225ee8613SDaniel Sanders 
67325ee8613SDaniel Sanders   dbg() << Banner;
67425ee8613SDaniel Sanders   if (!NameOfWrappedPass.empty())
67525ee8613SDaniel Sanders     dbg() << " [" << NameOfWrappedPass << "]";
67625ee8613SDaniel Sanders   dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
67725ee8613SDaniel Sanders 
678122a6bfbSVedant Kumar   // Strip debugify metadata if required.
679122a6bfbSVedant Kumar   if (Strip)
680122a6bfbSVedant Kumar     return stripDebugifyMetadata(M);
68125ee8613SDaniel Sanders 
68225ee8613SDaniel Sanders   return false;
68325ee8613SDaniel Sanders }
68425ee8613SDaniel Sanders 
68525ee8613SDaniel Sanders /// ModulePass for attaching synthetic debug info to everything, used with the
68625ee8613SDaniel Sanders /// legacy module pass manager.
68725ee8613SDaniel Sanders struct DebugifyModulePass : public ModulePass {
6888ee7c7e0SDjordje Todorovic   bool runOnModule(Module &M) override {
6891a2b3536SDjordje Todorovic     return applyDebugify(M, Mode, DIPreservationMap, NameOfWrappedPass);
6908ee7c7e0SDjordje Todorovic   }
6918ee7c7e0SDjordje Todorovic 
6921a2b3536SDjordje Todorovic   DebugifyModulePass(enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
6931a2b3536SDjordje Todorovic                      StringRef NameOfWrappedPass = "",
6941a2b3536SDjordje Todorovic                      DebugInfoPerPassMap *DIPreservationMap = nullptr)
6951a2b3536SDjordje Todorovic       : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
6961a2b3536SDjordje Todorovic         DIPreservationMap(DIPreservationMap), Mode(Mode) {}
6978ee7c7e0SDjordje Todorovic 
6988ee7c7e0SDjordje Todorovic   void getAnalysisUsage(AnalysisUsage &AU) const override {
6998ee7c7e0SDjordje Todorovic     AU.setPreservesAll();
7008ee7c7e0SDjordje Todorovic   }
7018ee7c7e0SDjordje Todorovic 
7028ee7c7e0SDjordje Todorovic   static char ID; // Pass identification.
7038ee7c7e0SDjordje Todorovic 
7048ee7c7e0SDjordje Todorovic private:
7051a2b3536SDjordje Todorovic   StringRef NameOfWrappedPass;
7061a2b3536SDjordje Todorovic   DebugInfoPerPassMap *DIPreservationMap;
7071a2b3536SDjordje Todorovic   enum DebugifyMode Mode;
7081a2b3536SDjordje Todorovic };
7091a2b3536SDjordje Todorovic 
7101a2b3536SDjordje Todorovic /// FunctionPass for attaching synthetic debug info to instructions within a
7111a2b3536SDjordje Todorovic /// single function, used with the legacy module pass manager.
7121a2b3536SDjordje Todorovic struct DebugifyFunctionPass : public FunctionPass {
7131a2b3536SDjordje Todorovic   bool runOnFunction(Function &F) override {
7141a2b3536SDjordje Todorovic     return applyDebugify(F, Mode, DIPreservationMap, NameOfWrappedPass);
7151a2b3536SDjordje Todorovic   }
7161a2b3536SDjordje Todorovic 
7171a2b3536SDjordje Todorovic   DebugifyFunctionPass(
7181a2b3536SDjordje Todorovic       enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
7191a2b3536SDjordje Todorovic       StringRef NameOfWrappedPass = "",
7201a2b3536SDjordje Todorovic       DebugInfoPerPassMap *DIPreservationMap = nullptr)
7211a2b3536SDjordje Todorovic       : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
7221a2b3536SDjordje Todorovic         DIPreservationMap(DIPreservationMap), Mode(Mode) {}
7231a2b3536SDjordje Todorovic 
7241a2b3536SDjordje Todorovic   void getAnalysisUsage(AnalysisUsage &AU) const override {
7251a2b3536SDjordje Todorovic     AU.setPreservesAll();
7261a2b3536SDjordje Todorovic   }
7271a2b3536SDjordje Todorovic 
7281a2b3536SDjordje Todorovic   static char ID; // Pass identification.
7291a2b3536SDjordje Todorovic 
7301a2b3536SDjordje Todorovic private:
7311a2b3536SDjordje Todorovic   StringRef NameOfWrappedPass;
7321a2b3536SDjordje Todorovic   DebugInfoPerPassMap *DIPreservationMap;
7331a2b3536SDjordje Todorovic   enum DebugifyMode Mode;
7341a2b3536SDjordje Todorovic };
7351a2b3536SDjordje Todorovic 
7361a2b3536SDjordje Todorovic /// ModulePass for checking debug info inserted by -debugify, used with the
7371a2b3536SDjordje Todorovic /// legacy module pass manager.
7381a2b3536SDjordje Todorovic struct CheckDebugifyModulePass : public ModulePass {
7391a2b3536SDjordje Todorovic   bool runOnModule(Module &M) override {
7401a2b3536SDjordje Todorovic     if (Mode == DebugifyMode::SyntheticDebugInfo)
7411a2b3536SDjordje Todorovic       return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
7421a2b3536SDjordje Todorovic                                    "CheckModuleDebugify", Strip, StatsMap);
7431a2b3536SDjordje Todorovic     return checkDebugInfoMetadata(
7441a2b3536SDjordje Todorovic         M, M.functions(), *DIPreservationMap,
7459f41c03fSDjordje Todorovic         "CheckModuleDebugify (original debuginfo)", NameOfWrappedPass,
7469f41c03fSDjordje Todorovic         OrigDIVerifyBugsReportFilePath);
7471a2b3536SDjordje Todorovic   }
7481a2b3536SDjordje Todorovic 
7491a2b3536SDjordje Todorovic   CheckDebugifyModulePass(
7501a2b3536SDjordje Todorovic       bool Strip = false, StringRef NameOfWrappedPass = "",
7511a2b3536SDjordje Todorovic       DebugifyStatsMap *StatsMap = nullptr,
7521a2b3536SDjordje Todorovic       enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
7539f41c03fSDjordje Todorovic       DebugInfoPerPassMap *DIPreservationMap = nullptr,
7549f41c03fSDjordje Todorovic       StringRef OrigDIVerifyBugsReportFilePath = "")
7551a2b3536SDjordje Todorovic       : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
7569f41c03fSDjordje Todorovic         OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
7571a2b3536SDjordje Todorovic         StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode),
7581a2b3536SDjordje Todorovic         Strip(Strip) {}
7591a2b3536SDjordje Todorovic 
7601a2b3536SDjordje Todorovic   void getAnalysisUsage(AnalysisUsage &AU) const override {
7611a2b3536SDjordje Todorovic     AU.setPreservesAll();
7621a2b3536SDjordje Todorovic   }
7631a2b3536SDjordje Todorovic 
7641a2b3536SDjordje Todorovic   static char ID; // Pass identification.
7651a2b3536SDjordje Todorovic 
7661a2b3536SDjordje Todorovic private:
76725ee8613SDaniel Sanders   StringRef NameOfWrappedPass;
7689f41c03fSDjordje Todorovic   StringRef OrigDIVerifyBugsReportFilePath;
76925ee8613SDaniel Sanders   DebugifyStatsMap *StatsMap;
7701a2b3536SDjordje Todorovic   DebugInfoPerPassMap *DIPreservationMap;
7711a2b3536SDjordje Todorovic   enum DebugifyMode Mode;
7721a2b3536SDjordje Todorovic   bool Strip;
77325ee8613SDaniel Sanders };
77425ee8613SDaniel Sanders 
77525ee8613SDaniel Sanders /// FunctionPass for checking debug info inserted by -debugify-function, used
77625ee8613SDaniel Sanders /// with the legacy module pass manager.
77725ee8613SDaniel Sanders struct CheckDebugifyFunctionPass : public FunctionPass {
77825ee8613SDaniel Sanders   bool runOnFunction(Function &F) override {
77925ee8613SDaniel Sanders     Module &M = *F.getParent();
78025ee8613SDaniel Sanders     auto FuncIt = F.getIterator();
7811a2b3536SDjordje Todorovic     if (Mode == DebugifyMode::SyntheticDebugInfo)
78225ee8613SDaniel Sanders       return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
78325ee8613SDaniel Sanders                                    NameOfWrappedPass, "CheckFunctionDebugify",
78425ee8613SDaniel Sanders                                    Strip, StatsMap);
7851a2b3536SDjordje Todorovic     return checkDebugInfoMetadata(
7861a2b3536SDjordje Todorovic         M, make_range(FuncIt, std::next(FuncIt)), *DIPreservationMap,
7879f41c03fSDjordje Todorovic         "CheckFunctionDebugify (original debuginfo)", NameOfWrappedPass,
7889f41c03fSDjordje Todorovic         OrigDIVerifyBugsReportFilePath);
78925ee8613SDaniel Sanders   }
79025ee8613SDaniel Sanders 
7911a2b3536SDjordje Todorovic   CheckDebugifyFunctionPass(
7921a2b3536SDjordje Todorovic       bool Strip = false, StringRef NameOfWrappedPass = "",
7931a2b3536SDjordje Todorovic       DebugifyStatsMap *StatsMap = nullptr,
7941a2b3536SDjordje Todorovic       enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
7959f41c03fSDjordje Todorovic       DebugInfoPerPassMap *DIPreservationMap = nullptr,
7969f41c03fSDjordje Todorovic       StringRef OrigDIVerifyBugsReportFilePath = "")
7971a2b3536SDjordje Todorovic       : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
7989f41c03fSDjordje Todorovic         OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
7991a2b3536SDjordje Todorovic         StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode),
8001a2b3536SDjordje Todorovic         Strip(Strip) {}
80125ee8613SDaniel Sanders 
80225ee8613SDaniel Sanders   void getAnalysisUsage(AnalysisUsage &AU) const override {
80325ee8613SDaniel Sanders     AU.setPreservesAll();
80425ee8613SDaniel Sanders   }
80525ee8613SDaniel Sanders 
80625ee8613SDaniel Sanders   static char ID; // Pass identification.
80725ee8613SDaniel Sanders 
80825ee8613SDaniel Sanders private:
80925ee8613SDaniel Sanders   StringRef NameOfWrappedPass;
8109f41c03fSDjordje Todorovic   StringRef OrigDIVerifyBugsReportFilePath;
81125ee8613SDaniel Sanders   DebugifyStatsMap *StatsMap;
8121a2b3536SDjordje Todorovic   DebugInfoPerPassMap *DIPreservationMap;
8131a2b3536SDjordje Todorovic   enum DebugifyMode Mode;
8141a2b3536SDjordje Todorovic   bool Strip;
81525ee8613SDaniel Sanders };
81625ee8613SDaniel Sanders 
81725ee8613SDaniel Sanders } // end anonymous namespace
81825ee8613SDaniel Sanders 
81939856d5dSFangrui Song void llvm::exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map) {
82039856d5dSFangrui Song   std::error_code EC;
82139856d5dSFangrui Song   raw_fd_ostream OS{Path, EC};
82239856d5dSFangrui Song   if (EC) {
82339856d5dSFangrui Song     errs() << "Could not open file: " << EC.message() << ", " << Path << '\n';
82439856d5dSFangrui Song     return;
82539856d5dSFangrui Song   }
82625ee8613SDaniel Sanders 
82739856d5dSFangrui Song   OS << "Pass Name" << ',' << "# of missing debug values" << ','
82839856d5dSFangrui Song      << "# of missing locations" << ',' << "Missing/Expected value ratio" << ','
82939856d5dSFangrui Song      << "Missing/Expected location ratio" << '\n';
83039856d5dSFangrui Song   for (const auto &Entry : Map) {
83139856d5dSFangrui Song     StringRef Pass = Entry.first;
83239856d5dSFangrui Song     DebugifyStatistics Stats = Entry.second;
83339856d5dSFangrui Song 
83439856d5dSFangrui Song     OS << Pass << ',' << Stats.NumDbgValuesMissing << ','
83539856d5dSFangrui Song        << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ','
83639856d5dSFangrui Song        << Stats.getEmptyLocationRatio() << '\n';
83739856d5dSFangrui Song   }
83839856d5dSFangrui Song }
83939856d5dSFangrui Song 
8401a2b3536SDjordje Todorovic ModulePass *createDebugifyModulePass(enum DebugifyMode Mode,
8411a2b3536SDjordje Todorovic                                      llvm::StringRef NameOfWrappedPass,
8421a2b3536SDjordje Todorovic                                      DebugInfoPerPassMap *DIPreservationMap) {
8431a2b3536SDjordje Todorovic   if (Mode == DebugifyMode::SyntheticDebugInfo)
84439856d5dSFangrui Song     return new DebugifyModulePass();
8451a2b3536SDjordje Todorovic   assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
8461a2b3536SDjordje Todorovic   return new DebugifyModulePass(Mode, NameOfWrappedPass, DIPreservationMap);
84739856d5dSFangrui Song }
84839856d5dSFangrui Song 
8491a2b3536SDjordje Todorovic FunctionPass *
8501a2b3536SDjordje Todorovic createDebugifyFunctionPass(enum DebugifyMode Mode,
8511a2b3536SDjordje Todorovic                            llvm::StringRef NameOfWrappedPass,
8521a2b3536SDjordje Todorovic                            DebugInfoPerPassMap *DIPreservationMap) {
8531a2b3536SDjordje Todorovic   if (Mode == DebugifyMode::SyntheticDebugInfo)
85425ee8613SDaniel Sanders     return new DebugifyFunctionPass();
8551a2b3536SDjordje Todorovic   assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
8561a2b3536SDjordje Todorovic   return new DebugifyFunctionPass(Mode, NameOfWrappedPass, DIPreservationMap);
85725ee8613SDaniel Sanders }
85825ee8613SDaniel Sanders 
85925ee8613SDaniel Sanders PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
8601adeeabbSDaniel Sanders   applyDebugifyMetadata(M, M.functions(),
8611adeeabbSDaniel Sanders                         "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
86225ee8613SDaniel Sanders   return PreservedAnalyses::all();
86325ee8613SDaniel Sanders }
86425ee8613SDaniel Sanders 
8651a2b3536SDjordje Todorovic ModulePass *createCheckDebugifyModulePass(
8661a2b3536SDjordje Todorovic     bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
8679f41c03fSDjordje Todorovic     enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap,
8689f41c03fSDjordje Todorovic     StringRef OrigDIVerifyBugsReportFilePath) {
8691a2b3536SDjordje Todorovic   if (Mode == DebugifyMode::SyntheticDebugInfo)
87025ee8613SDaniel Sanders     return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
8711a2b3536SDjordje Todorovic   assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
8721a2b3536SDjordje Todorovic   return new CheckDebugifyModulePass(false, NameOfWrappedPass, nullptr, Mode,
8739f41c03fSDjordje Todorovic                                      DIPreservationMap,
8749f41c03fSDjordje Todorovic                                      OrigDIVerifyBugsReportFilePath);
87525ee8613SDaniel Sanders }
87625ee8613SDaniel Sanders 
8771a2b3536SDjordje Todorovic FunctionPass *createCheckDebugifyFunctionPass(
8781a2b3536SDjordje Todorovic     bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
8799f41c03fSDjordje Todorovic     enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap,
8809f41c03fSDjordje Todorovic     StringRef OrigDIVerifyBugsReportFilePath) {
8811a2b3536SDjordje Todorovic   if (Mode == DebugifyMode::SyntheticDebugInfo)
88225ee8613SDaniel Sanders     return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
8831a2b3536SDjordje Todorovic   assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
8841a2b3536SDjordje Todorovic   return new CheckDebugifyFunctionPass(false, NameOfWrappedPass, nullptr, Mode,
8859f41c03fSDjordje Todorovic                                        DIPreservationMap,
8869f41c03fSDjordje Todorovic                                        OrigDIVerifyBugsReportFilePath);
88725ee8613SDaniel Sanders }
88825ee8613SDaniel Sanders 
88925ee8613SDaniel Sanders PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
89025ee8613SDaniel Sanders                                               ModuleAnalysisManager &) {
89125ee8613SDaniel Sanders   checkDebugifyMetadata(M, M.functions(), "", "CheckModuleDebugify", false,
89225ee8613SDaniel Sanders                         nullptr);
89325ee8613SDaniel Sanders   return PreservedAnalyses::all();
89425ee8613SDaniel Sanders }
89525ee8613SDaniel Sanders 
8967de6dcd2SArthur Eubanks static bool isIgnoredPass(StringRef PassID) {
8977de6dcd2SArthur Eubanks   return isSpecialPass(PassID, {"PassManager", "PassAdaptor",
8987de6dcd2SArthur Eubanks                                 "AnalysisManagerProxy", "PrintFunctionPass",
8997de6dcd2SArthur Eubanks                                 "PrintModulePass", "BitcodeWriterPass",
9007de6dcd2SArthur Eubanks                                 "ThinLTOBitcodeWriterPass", "VerifierPass"});
9017de6dcd2SArthur Eubanks }
9027de6dcd2SArthur Eubanks 
90398b93385SFangrui Song void DebugifyEachInstrumentation::registerCallbacks(
90498b93385SFangrui Song     PassInstrumentationCallbacks &PIC) {
90598b93385SFangrui Song   PIC.registerBeforeNonSkippedPassCallback([](StringRef P, Any IR) {
9067de6dcd2SArthur Eubanks     if (isIgnoredPass(P))
9077de6dcd2SArthur Eubanks       return;
90898b93385SFangrui Song     if (any_isa<const Function *>(IR))
90998b93385SFangrui Song       applyDebugify(*const_cast<Function *>(any_cast<const Function *>(IR)));
91098b93385SFangrui Song     else if (any_isa<const Module *>(IR))
91198b93385SFangrui Song       applyDebugify(*const_cast<Module *>(any_cast<const Module *>(IR)));
91298b93385SFangrui Song   });
91398b93385SFangrui Song   PIC.registerAfterPassCallback([this](StringRef P, Any IR,
91498b93385SFangrui Song                                        const PreservedAnalyses &PassPA) {
9157de6dcd2SArthur Eubanks     if (isIgnoredPass(P))
9167de6dcd2SArthur Eubanks       return;
91798b93385SFangrui Song     if (any_isa<const Function *>(IR)) {
91898b93385SFangrui Song       auto &F = *const_cast<Function *>(any_cast<const Function *>(IR));
91998b93385SFangrui Song       Module &M = *F.getParent();
92098b93385SFangrui Song       auto It = F.getIterator();
92198b93385SFangrui Song       checkDebugifyMetadata(M, make_range(It, std::next(It)), P,
92298b93385SFangrui Song                             "CheckFunctionDebugify", /*Strip=*/true, &StatsMap);
92398b93385SFangrui Song     } else if (any_isa<const Module *>(IR)) {
92498b93385SFangrui Song       auto &M = *const_cast<Module *>(any_cast<const Module *>(IR));
92598b93385SFangrui Song       checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify",
92698b93385SFangrui Song                             /*Strip=*/true, &StatsMap);
92798b93385SFangrui Song     }
92898b93385SFangrui Song   });
92998b93385SFangrui Song }
93098b93385SFangrui Song 
93125ee8613SDaniel Sanders char DebugifyModulePass::ID = 0;
93225ee8613SDaniel Sanders static RegisterPass<DebugifyModulePass> DM("debugify",
93325ee8613SDaniel Sanders                                            "Attach debug info to everything");
93425ee8613SDaniel Sanders 
93525ee8613SDaniel Sanders char CheckDebugifyModulePass::ID = 0;
93625ee8613SDaniel Sanders static RegisterPass<CheckDebugifyModulePass>
93725ee8613SDaniel Sanders     CDM("check-debugify", "Check debug info from -debugify");
93825ee8613SDaniel Sanders 
93925ee8613SDaniel Sanders char DebugifyFunctionPass::ID = 0;
94025ee8613SDaniel Sanders static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
94125ee8613SDaniel Sanders                                              "Attach debug info to a function");
94225ee8613SDaniel Sanders 
94325ee8613SDaniel Sanders char CheckDebugifyFunctionPass::ID = 0;
94425ee8613SDaniel Sanders static RegisterPass<CheckDebugifyFunctionPass>
94525ee8613SDaniel Sanders     CDF("check-debugify-function", "Check debug info from -debugify-function");
946