blob: 222cc702bc1f5da195fa85322b505067b8edc51a [file] [log] [blame]
Vedant Kumar195dfd12017-12-08 21:57:28 +00001//===- Debugify.cpp - Attach synthetic debug info to everything -----------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Vedant Kumar195dfd12017-12-08 21:57:28 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file This pass attaches synthetic debug info to everything. It can be used
10/// to create targeted tests for debug info preservation.
11///
12//===----------------------------------------------------------------------===//
13
Vedant Kumarca407c42018-07-24 00:41:28 +000014#include "Debugify.h"
Vedant Kumar195dfd12017-12-08 21:57:28 +000015#include "llvm/ADT/BitVector.h"
16#include "llvm/ADT/StringExtras.h"
17#include "llvm/IR/BasicBlock.h"
18#include "llvm/IR/Constants.h"
19#include "llvm/IR/DIBuilder.h"
20#include "llvm/IR/DebugInfo.h"
21#include "llvm/IR/Function.h"
22#include "llvm/IR/GlobalVariable.h"
23#include "llvm/IR/InstIterator.h"
24#include "llvm/IR/Instruction.h"
25#include "llvm/IR/Instructions.h"
26#include "llvm/IR/IntrinsicInst.h"
27#include "llvm/IR/Module.h"
28#include "llvm/IR/Type.h"
29#include "llvm/Pass.h"
30#include "llvm/Support/raw_ostream.h"
31#include "llvm/Transforms/IPO.h"
32
33using namespace llvm;
34
35namespace {
36
Vedant Kumara9e27312018-06-06 19:05:41 +000037cl::opt<bool> Quiet("debugify-quiet",
38 cl::desc("Suppress verbose debugify output"));
39
40raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
41
Vedant Kumarb9c1a232018-06-26 22:46:41 +000042uint64_t getAllocSizeInBits(Module &M, Type *Ty) {
43 return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0;
44}
45
Vedant Kumar17d8bba2018-02-15 21:28:38 +000046bool isFunctionSkipped(Function &F) {
47 return F.isDeclaration() || !F.hasExactDefinition();
48}
49
Vedant Kumar6d354ed2018-06-06 19:05:42 +000050/// Find the basic block's terminating instruction.
Vedant Kumar800255f2018-06-05 00:56:07 +000051///
Vedant Kumar6d354ed2018-06-06 19:05:42 +000052/// Special care is needed to handle musttail and deopt calls, as these behave
53/// like (but are in fact not) terminators.
54Instruction *findTerminatingInstruction(BasicBlock &BB) {
Vedant Kumar800255f2018-06-05 00:56:07 +000055 if (auto *I = BB.getTerminatingMustTailCall())
56 return I;
57 if (auto *I = BB.getTerminatingDeoptimizeCall())
58 return I;
59 return BB.getTerminator();
60}
61
Vedant Kumar595ba1d2018-05-15 00:29:27 +000062bool applyDebugifyMetadata(Module &M,
63 iterator_range<Module::iterator> Functions,
64 StringRef Banner) {
Vedant Kumar195dfd12017-12-08 21:57:28 +000065 // Skip modules with debug info.
66 if (M.getNamedMetadata("llvm.dbg.cu")) {
Vedant Kumara9e27312018-06-06 19:05:41 +000067 dbg() << Banner << "Skipping module with debug info\n";
Vedant Kumar195dfd12017-12-08 21:57:28 +000068 return false;
69 }
70
71 DIBuilder DIB(M);
72 LLVMContext &Ctx = M.getContext();
73
74 // Get a DIType which corresponds to Ty.
75 DenseMap<uint64_t, DIType *> TypeCache;
76 auto getCachedDIType = [&](Type *Ty) -> DIType * {
Vedant Kumarb9c1a232018-06-26 22:46:41 +000077 uint64_t Size = getAllocSizeInBits(M, Ty);
Vedant Kumar195dfd12017-12-08 21:57:28 +000078 DIType *&DTy = TypeCache[Size];
79 if (!DTy) {
80 std::string Name = "ty" + utostr(Size);
81 DTy = DIB.createBasicType(Name, Size, dwarf::DW_ATE_unsigned);
82 }
83 return DTy;
84 };
85
86 unsigned NextLine = 1;
87 unsigned NextVar = 1;
88 auto File = DIB.createFile(M.getName(), "/");
Vedant Kumarab112b82018-06-05 00:56:07 +000089 auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "debugify",
90 /*isOptimized=*/true, "", 0);
Vedant Kumar195dfd12017-12-08 21:57:28 +000091
92 // Visit each instruction.
Vedant Kumar595ba1d2018-05-15 00:29:27 +000093 for (Function &F : Functions) {
Vedant Kumar17d8bba2018-02-15 21:28:38 +000094 if (isFunctionSkipped(F))
Vedant Kumar195dfd12017-12-08 21:57:28 +000095 continue;
96
97 auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
Paul Robinsoncda54212018-11-19 18:29:28 +000098 DISubprogram::DISPFlags SPFlags =
99 DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
100 if (F.hasPrivateLinkage() || F.hasInternalLinkage())
101 SPFlags |= DISubprogram::SPFlagLocalToUnit;
102 auto SP = DIB.createFunction(CU, F.getName(), F.getName(), File, NextLine,
103 SPType, NextLine, DINode::FlagZero, SPFlags);
Vedant Kumar195dfd12017-12-08 21:57:28 +0000104 F.setSubprogram(SP);
105 for (BasicBlock &BB : F) {
106 // Attach debug locations.
107 for (Instruction &I : BB)
108 I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
109
Vedant Kumar77f4d4d2018-06-03 22:50:22 +0000110 // Inserting debug values into EH pads can break IR invariants.
111 if (BB.isEHPad())
112 continue;
113
Vedant Kumar6d354ed2018-06-06 19:05:42 +0000114 // Find the terminating instruction, after which no debug values are
115 // attached.
116 Instruction *LastInst = findTerminatingInstruction(BB);
117 assert(LastInst && "Expected basic block with a terminator");
118
119 // Maintain an insertion point which can't be invalidated when updates
120 // are made.
121 BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();
122 assert(InsertPt != BB.end() && "Expected to find an insertion point");
123 Instruction *InsertBefore = &*InsertPt;
Vedant Kumar7dda2212018-06-04 03:33:01 +0000124
Vedant Kumar195dfd12017-12-08 21:57:28 +0000125 // Attach debug values.
Vedant Kumar6d354ed2018-06-06 19:05:42 +0000126 for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {
Vedant Kumar195dfd12017-12-08 21:57:28 +0000127 // Skip void-valued instructions.
Vedant Kumar6d354ed2018-06-06 19:05:42 +0000128 if (I->getType()->isVoidTy())
Vedant Kumar195dfd12017-12-08 21:57:28 +0000129 continue;
130
Vedant Kumar6d354ed2018-06-06 19:05:42 +0000131 // Phis and EH pads must be grouped at the beginning of the block.
132 // Only advance the insertion point when we finish visiting these.
133 if (!isa<PHINode>(I) && !I->isEHPad())
134 InsertBefore = I->getNextNode();
Vedant Kumar195dfd12017-12-08 21:57:28 +0000135
136 std::string Name = utostr(NextVar++);
Vedant Kumar6d354ed2018-06-06 19:05:42 +0000137 const DILocation *Loc = I->getDebugLoc().get();
Vedant Kumar195dfd12017-12-08 21:57:28 +0000138 auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
Vedant Kumar6d354ed2018-06-06 19:05:42 +0000139 getCachedDIType(I->getType()),
Vedant Kumar195dfd12017-12-08 21:57:28 +0000140 /*AlwaysPreserve=*/true);
Vedant Kumar6d354ed2018-06-06 19:05:42 +0000141 DIB.insertDbgValueIntrinsic(I, LocalVar, DIB.createExpression(), Loc,
142 InsertBefore);
Vedant Kumar195dfd12017-12-08 21:57:28 +0000143 }
144 }
145 DIB.finalizeSubprogram(SP);
146 }
147 DIB.finalize();
148
149 // Track the number of distinct lines and variables.
150 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.debugify");
151 auto *IntTy = Type::getInt32Ty(Ctx);
152 auto addDebugifyOperand = [&](unsigned N) {
153 NMD->addOperand(MDNode::get(
154 Ctx, ValueAsMetadata::getConstant(ConstantInt::get(IntTy, N))));
155 };
156 addDebugifyOperand(NextLine - 1); // Original number of lines.
157 addDebugifyOperand(NextVar - 1); // Original number of variables.
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000158 assert(NMD->getNumOperands() == 2 &&
159 "llvm.debugify should have exactly 2 operands!");
Vedant Kumar4872535e2018-05-24 23:00:23 +0000160
161 // Claim that this synthetic debug info is valid.
162 StringRef DIVersionKey = "Debug Info Version";
163 if (!M.getModuleFlag(DIVersionKey))
164 M.addModuleFlag(Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
165
Vedant Kumar195dfd12017-12-08 21:57:28 +0000166 return true;
167}
168
Vedant Kumarb9c1a232018-06-26 22:46:41 +0000169/// Return true if a mis-sized diagnostic is issued for \p DVI.
170bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
171 // The size of a dbg.value's value operand should match the size of the
172 // variable it corresponds to.
173 //
174 // TODO: This, along with a check for non-null value operands, should be
175 // promoted to verifier failures.
176 Value *V = DVI->getValue();
177 if (!V)
178 return false;
179
180 // For now, don't try to interpret anything more complicated than an empty
181 // DIExpression. Eventually we should try to handle OP_deref and fragments.
182 if (DVI->getExpression()->getNumElements())
183 return false;
184
185 Type *Ty = V->getType();
186 uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
Vedant Kumard13536e2018-06-27 00:47:52 +0000187 Optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits();
188 if (!ValueOperandSize || !DbgVarSize)
189 return false;
190
Vedant Kumarba0c8762018-07-06 17:32:40 +0000191 bool HasBadSize = false;
192 if (Ty->isIntegerTy()) {
193 auto Signedness = DVI->getVariable()->getSignedness();
194 if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
195 HasBadSize = ValueOperandSize < *DbgVarSize;
196 } else {
197 HasBadSize = ValueOperandSize != *DbgVarSize;
198 }
199
Vedant Kumarb9c1a232018-06-26 22:46:41 +0000200 if (HasBadSize) {
201 dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
Vedant Kumard13536e2018-06-27 00:47:52 +0000202 << ", but its variable has size " << *DbgVarSize << ": ";
Vedant Kumarb9c1a232018-06-26 22:46:41 +0000203 DVI->print(dbg());
204 dbg() << "\n";
205 }
206 return HasBadSize;
207}
208
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000209bool checkDebugifyMetadata(Module &M,
210 iterator_range<Module::iterator> Functions,
Vedant Kumarab112b82018-06-05 00:56:07 +0000211 StringRef NameOfWrappedPass, StringRef Banner,
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000212 bool Strip, DebugifyStatsMap *StatsMap) {
Vedant Kumar195dfd12017-12-08 21:57:28 +0000213 // Skip modules without debugify metadata.
214 NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000215 if (!NMD) {
Vedant Kumara9e27312018-06-06 19:05:41 +0000216 dbg() << Banner << "Skipping module without debugify metadata\n";
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000217 return false;
218 }
Vedant Kumar195dfd12017-12-08 21:57:28 +0000219
220 auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
221 return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
222 ->getZExtValue();
223 };
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000224 assert(NMD->getNumOperands() == 2 &&
225 "llvm.debugify should have exactly 2 operands!");
Vedant Kumar195dfd12017-12-08 21:57:28 +0000226 unsigned OriginalNumLines = getDebugifyOperand(0);
227 unsigned OriginalNumVars = getDebugifyOperand(1);
228 bool HasErrors = false;
229
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000230 // Track debug info loss statistics if able.
231 DebugifyStatistics *Stats = nullptr;
232 if (StatsMap && !NameOfWrappedPass.empty())
233 Stats = &StatsMap->operator[](NameOfWrappedPass);
234
Vedant Kumar195dfd12017-12-08 21:57:28 +0000235 BitVector MissingLines{OriginalNumLines, true};
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000236 BitVector MissingVars{OriginalNumVars, true};
237 for (Function &F : Functions) {
Vedant Kumar17d8bba2018-02-15 21:28:38 +0000238 if (isFunctionSkipped(F))
239 continue;
240
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000241 // Find missing lines.
Vedant Kumar195dfd12017-12-08 21:57:28 +0000242 for (Instruction &I : instructions(F)) {
243 if (isa<DbgValueInst>(&I))
244 continue;
245
246 auto DL = I.getDebugLoc();
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000247 if (DL && DL.getLine() != 0) {
Vedant Kumar195dfd12017-12-08 21:57:28 +0000248 MissingLines.reset(DL.getLine() - 1);
249 continue;
250 }
251
Vedant Kumar197e73f2018-06-28 18:21:11 +0000252 if (!DL) {
253 dbg() << "ERROR: Instruction with empty DebugLoc in function ";
254 dbg() << F.getName() << " --";
255 I.print(dbg());
256 dbg() << "\n";
257 HasErrors = true;
258 }
Vedant Kumar195dfd12017-12-08 21:57:28 +0000259 }
Vedant Kumar195dfd12017-12-08 21:57:28 +0000260
Vedant Kumarb9c1a232018-06-26 22:46:41 +0000261 // Find missing variables and mis-sized debug values.
Vedant Kumar195dfd12017-12-08 21:57:28 +0000262 for (Instruction &I : instructions(F)) {
263 auto *DVI = dyn_cast<DbgValueInst>(&I);
264 if (!DVI)
265 continue;
266
267 unsigned Var = ~0U;
268 (void)to_integer(DVI->getVariable()->getName(), Var, 10);
269 assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
Vedant Kumarb9c1a232018-06-26 22:46:41 +0000270 bool HasBadSize = diagnoseMisSizedDbgValue(M, DVI);
271 if (!HasBadSize)
272 MissingVars.reset(Var - 1);
273 HasErrors |= HasBadSize;
Vedant Kumar195dfd12017-12-08 21:57:28 +0000274 }
275 }
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000276
277 // Print the results.
278 for (unsigned Idx : MissingLines.set_bits())
Vedant Kumara9e27312018-06-06 19:05:41 +0000279 dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000280
Vedant Kumar195dfd12017-12-08 21:57:28 +0000281 for (unsigned Idx : MissingVars.set_bits())
Vedant Kumar2e6c5f92018-06-26 18:54:10 +0000282 dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
Vedant Kumar195dfd12017-12-08 21:57:28 +0000283
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000284 // Update DI loss statistics.
285 if (Stats) {
286 Stats->NumDbgLocsExpected += OriginalNumLines;
287 Stats->NumDbgLocsMissing += MissingLines.count();
288 Stats->NumDbgValuesExpected += OriginalNumVars;
289 Stats->NumDbgValuesMissing += MissingVars.count();
290 }
291
Vedant Kumara9e27312018-06-06 19:05:41 +0000292 dbg() << Banner;
Vedant Kumarb70e3562018-05-24 23:00:22 +0000293 if (!NameOfWrappedPass.empty())
Vedant Kumara9e27312018-06-06 19:05:41 +0000294 dbg() << " [" << NameOfWrappedPass << "]";
295 dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000296
297 // Strip the Debugify Metadata if required.
298 if (Strip) {
299 StripDebugInfo(M);
300 M.eraseNamedMetadata(NMD);
301 return true;
302 }
303
304 return false;
Vedant Kumar195dfd12017-12-08 21:57:28 +0000305}
306
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000307/// ModulePass for attaching synthetic debug info to everything, used with the
308/// legacy module pass manager.
309struct DebugifyModulePass : public ModulePass {
310 bool runOnModule(Module &M) override {
311 return applyDebugifyMetadata(M, M.functions(), "ModuleDebugify: ");
312 }
Vedant Kumar195dfd12017-12-08 21:57:28 +0000313
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000314 DebugifyModulePass() : ModulePass(ID) {}
Vedant Kumar195dfd12017-12-08 21:57:28 +0000315
316 void getAnalysisUsage(AnalysisUsage &AU) const override {
317 AU.setPreservesAll();
318 }
319
320 static char ID; // Pass identification.
321};
322
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000323/// FunctionPass for attaching synthetic debug info to instructions within a
324/// single function, used with the legacy module pass manager.
325struct DebugifyFunctionPass : public FunctionPass {
326 bool runOnFunction(Function &F) override {
327 Module &M = *F.getParent();
328 auto FuncIt = F.getIterator();
329 return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
Vedant Kumarab112b82018-06-05 00:56:07 +0000330 "FunctionDebugify: ");
Vedant Kumar195dfd12017-12-08 21:57:28 +0000331 }
332
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000333 DebugifyFunctionPass() : FunctionPass(ID) {}
Vedant Kumar195dfd12017-12-08 21:57:28 +0000334
335 void getAnalysisUsage(AnalysisUsage &AU) const override {
336 AU.setPreservesAll();
337 }
338
339 static char ID; // Pass identification.
340};
341
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000342/// ModulePass for checking debug info inserted by -debugify, used with the
343/// legacy module pass manager.
344struct CheckDebugifyModulePass : public ModulePass {
345 bool runOnModule(Module &M) override {
Anastasis Grammenosb4344c62018-05-15 23:38:05 +0000346 return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000347 "CheckModuleDebugify", Strip, StatsMap);
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000348 }
349
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000350 CheckDebugifyModulePass(bool Strip = false, StringRef NameOfWrappedPass = "",
351 DebugifyStatsMap *StatsMap = nullptr)
352 : ModulePass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
353 StatsMap(StatsMap) {}
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000354
Vedant Kumarfb7c7682018-06-04 21:43:28 +0000355 void getAnalysisUsage(AnalysisUsage &AU) const override {
356 AU.setPreservesAll();
357 }
358
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000359 static char ID; // Pass identification.
360
361private:
362 bool Strip;
Anastasis Grammenosb4344c62018-05-15 23:38:05 +0000363 StringRef NameOfWrappedPass;
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000364 DebugifyStatsMap *StatsMap;
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000365};
366
367/// FunctionPass for checking debug info inserted by -debugify-function, used
368/// with the legacy module pass manager.
369struct CheckDebugifyFunctionPass : public FunctionPass {
370 bool runOnFunction(Function &F) override {
371 Module &M = *F.getParent();
372 auto FuncIt = F.getIterator();
373 return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
Vedant Kumar4872535e2018-05-24 23:00:23 +0000374 NameOfWrappedPass, "CheckFunctionDebugify",
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000375 Strip, StatsMap);
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000376 }
377
Vedant Kumar4872535e2018-05-24 23:00:23 +0000378 CheckDebugifyFunctionPass(bool Strip = false,
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000379 StringRef NameOfWrappedPass = "",
380 DebugifyStatsMap *StatsMap = nullptr)
381 : FunctionPass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
382 StatsMap(StatsMap) {}
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000383
384 void getAnalysisUsage(AnalysisUsage &AU) const override {
385 AU.setPreservesAll();
386 }
387
388 static char ID; // Pass identification.
389
390private:
391 bool Strip;
Anastasis Grammenosb4344c62018-05-15 23:38:05 +0000392 StringRef NameOfWrappedPass;
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000393 DebugifyStatsMap *StatsMap;
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000394};
395
Vedant Kumar195dfd12017-12-08 21:57:28 +0000396} // end anonymous namespace
397
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000398void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map) {
399 std::error_code EC;
400 raw_fd_ostream OS{Path, EC};
401 if (EC) {
402 errs() << "Could not open file: " << EC.message() << ", " << Path << '\n';
403 return;
404 }
405
406 OS << "Pass Name" << ',' << "# of missing debug values" << ','
407 << "# of missing locations" << ',' << "Missing/Expected value ratio" << ','
408 << "Missing/Expected location ratio" << '\n';
409 for (const auto &Entry : Map) {
410 StringRef Pass = Entry.first;
411 DebugifyStatistics Stats = Entry.second;
412
413 OS << Pass << ',' << Stats.NumDbgValuesMissing << ','
414 << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ','
415 << Stats.getEmptyLocationRatio() << '\n';
416 }
417}
418
Vedant Kumarab112b82018-06-05 00:56:07 +0000419ModulePass *createDebugifyModulePass() { return new DebugifyModulePass(); }
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000420
421FunctionPass *createDebugifyFunctionPass() {
422 return new DebugifyFunctionPass();
423}
Vedant Kumar92f7a622018-01-23 20:43:50 +0000424
Vedant Kumar775c7af2018-02-15 21:14:36 +0000425PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000426 applyDebugifyMetadata(M, M.functions(), "ModuleDebugify: ");
Vedant Kumar775c7af2018-02-15 21:14:36 +0000427 return PreservedAnalyses::all();
428}
429
Vedant Kumar36b89d42018-06-04 00:11:47 +0000430ModulePass *createCheckDebugifyModulePass(bool Strip,
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000431 StringRef NameOfWrappedPass,
432 DebugifyStatsMap *StatsMap) {
433 return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000434}
435
Vedant Kumar36b89d42018-06-04 00:11:47 +0000436FunctionPass *createCheckDebugifyFunctionPass(bool Strip,
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000437 StringRef NameOfWrappedPass,
438 DebugifyStatsMap *StatsMap) {
439 return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000440}
Vedant Kumar92f7a622018-01-23 20:43:50 +0000441
Vedant Kumar775c7af2018-02-15 21:14:36 +0000442PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
443 ModuleAnalysisManager &) {
Vedant Kumard6ff43c2018-07-24 00:41:29 +0000444 checkDebugifyMetadata(M, M.functions(), "", "CheckModuleDebugify", false,
445 nullptr);
Vedant Kumar775c7af2018-02-15 21:14:36 +0000446 return PreservedAnalyses::all();
447}
448
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000449char DebugifyModulePass::ID = 0;
450static RegisterPass<DebugifyModulePass> DM("debugify",
Vedant Kumar36b89d42018-06-04 00:11:47 +0000451 "Attach debug info to everything");
Vedant Kumar195dfd12017-12-08 21:57:28 +0000452
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000453char CheckDebugifyModulePass::ID = 0;
Vedant Kumar36b89d42018-06-04 00:11:47 +0000454static RegisterPass<CheckDebugifyModulePass>
455 CDM("check-debugify", "Check debug info from -debugify");
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000456
457char DebugifyFunctionPass::ID = 0;
458static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
Vedant Kumar36b89d42018-06-04 00:11:47 +0000459 "Attach debug info to a function");
Vedant Kumar595ba1d2018-05-15 00:29:27 +0000460
461char CheckDebugifyFunctionPass::ID = 0;
Vedant Kumar36b89d42018-06-04 00:11:47 +0000462static RegisterPass<CheckDebugifyFunctionPass>
463 CDF("check-debugify-function", "Check debug info from -debugify-function");