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 20llvm::ModulePass *createDebugifyModulePass(); 21llvm::FunctionPass *createDebugifyFunctionPass(); 22 23struct NewPMDebugifyPass : public llvm::PassInfoMixin<NewPMDebugifyPass> { 24 llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM); 25}; 26 27/// Track how much `debugify` information has been lost. 28struct DebugifyStatistics { 29 /// Number of missing dbg.values. 30 unsigned NumDbgValuesMissing = 0; 31 32 /// Number of dbg.values expected. 33 unsigned NumDbgValuesExpected = 0; 34 35 /// Number of instructions with empty debug locations. 36 unsigned NumDbgLocsMissing = 0; 37 38 /// Number of instructions expected to have debug locations. 39 unsigned NumDbgLocsExpected = 0; 40 41 /// Get the ratio of missing/expected dbg.values. 42 float getMissingValueRatio() const { 43 return float(NumDbgValuesMissing) / float(NumDbgLocsExpected); 44 } 45 46 /// Get the ratio of missing/expected instructions with locations. 47 float getEmptyLocationRatio() const { 48 return float(NumDbgLocsMissing) / float(NumDbgLocsExpected); 49 } 50}; 51 52/// Map pass names to a per-pass DebugifyStatistics instance. 53using DebugifyStatsMap = llvm::MapVector<llvm::StringRef, DebugifyStatistics>; 54 55llvm::ModulePass * 56createCheckDebugifyModulePass(bool Strip = false, 57 llvm::StringRef NameOfWrappedPass = "", 58 DebugifyStatsMap *StatsMap = nullptr); 59 60llvm::FunctionPass * 61createCheckDebugifyFunctionPass(bool Strip = false, 62 llvm::StringRef NameOfWrappedPass = "", 63 DebugifyStatsMap *StatsMap = nullptr); 64 65struct NewPMCheckDebugifyPass 66 : public llvm::PassInfoMixin<NewPMCheckDebugifyPass> { 67 llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM); 68}; 69 70#endif // LLVM_TRANSFORM_UTILS_DEBUGIFY_H 71