1 //===- Debugify.h - Attach synthetic debug info to everything -------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// \file Interface to the `debugify` synthetic debug info testing utility. 10 /// 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_TRANSFORM_UTILS_DEBUGIFY_H 14 #define LLVM_TRANSFORM_UTILS_DEBUGIFY_H 15 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/ADT/MapVector.h" 18 #include "llvm/IR/PassManager.h" 19 20 namespace llvm { 21 class DIBuilder; 22 23 /// Add synthesized debug information to a module. 24 /// 25 /// \param M The module to add debug information to. 26 /// \param Functions A range of functions to add debug information to. 27 /// \param Banner A prefix string to add to debug/error messages. 28 /// \param ApplyToMF A call back that will add debug information to the 29 /// MachineFunction for a Function. If nullptr, then the 30 /// MachineFunction (if any) will not be modified. 31 bool applyDebugifyMetadata( 32 Module &M, iterator_range<Module::iterator> Functions, StringRef Banner, 33 std::function<bool(DIBuilder &, Function &)> ApplyToMF); 34 35 /// Strip out all of the metadata and debug info inserted by debugify. If no 36 /// llvm.debugify module-level named metadata is present, this is a no-op. 37 /// Returns true if any change was made. 38 bool stripDebugifyMetadata(Module &M); 39 40 } // namespace llvm 41 42 llvm::ModulePass *createDebugifyModulePass(); 43 llvm::FunctionPass *createDebugifyFunctionPass(); 44 45 struct NewPMDebugifyPass : public llvm::PassInfoMixin<NewPMDebugifyPass> { 46 llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM); 47 }; 48 49 /// Track how much `debugify` information has been lost. 50 struct DebugifyStatistics { 51 /// Number of missing dbg.values. 52 unsigned NumDbgValuesMissing = 0; 53 54 /// Number of dbg.values expected. 55 unsigned NumDbgValuesExpected = 0; 56 57 /// Number of instructions with empty debug locations. 58 unsigned NumDbgLocsMissing = 0; 59 60 /// Number of instructions expected to have debug locations. 61 unsigned NumDbgLocsExpected = 0; 62 63 /// Get the ratio of missing/expected dbg.values. 64 float getMissingValueRatio() const { 65 return float(NumDbgValuesMissing) / float(NumDbgLocsExpected); 66 } 67 68 /// Get the ratio of missing/expected instructions with locations. 69 float getEmptyLocationRatio() const { 70 return float(NumDbgLocsMissing) / float(NumDbgLocsExpected); 71 } 72 }; 73 74 /// Map pass names to a per-pass DebugifyStatistics instance. 75 using DebugifyStatsMap = llvm::MapVector<llvm::StringRef, DebugifyStatistics>; 76 77 llvm::ModulePass * 78 createCheckDebugifyModulePass(bool Strip = false, 79 llvm::StringRef NameOfWrappedPass = "", 80 DebugifyStatsMap *StatsMap = nullptr); 81 82 llvm::FunctionPass * 83 createCheckDebugifyFunctionPass(bool Strip = false, 84 llvm::StringRef NameOfWrappedPass = "", 85 DebugifyStatsMap *StatsMap = nullptr); 86 87 struct NewPMCheckDebugifyPass 88 : public llvm::PassInfoMixin<NewPMCheckDebugifyPass> { 89 llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM); 90 }; 91 92 #endif // LLVM_TRANSFORM_UTILS_DEBUGIFY_H 93