xref: /freebsd/contrib/llvm-project/llvm/include/llvm/IR/DroppedVariableStatsIR.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 ///===- DroppedVariableStatsIR.h - Opt Diagnostics -*- C++ -*--------------===//
2 ///
3 /// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4 /// Exceptions. See https://llvm.org/LICENSE.txt for license information.
5 /// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 ///
7 ///===---------------------------------------------------------------------===//
8 /// \file
9 /// Dropped Variable Statistics for Debug Information. Reports any number
10 /// of #dbg_value that get dropped due to an optimization pass.
11 ///
12 ///===---------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_DROPPEDVARIABLESTATSIR_H
15 #define LLVM_CODEGEN_DROPPEDVARIABLESTATSIR_H
16 
17 #include "llvm/IR/DroppedVariableStats.h"
18 #include "llvm/Support/Compiler.h"
19 
20 namespace llvm {
21 
22 class Any;
23 class StringRef;
24 class PassInstrumentationCallbacks;
25 class Function;
26 class Module;
27 class DILocation;
28 
29 /// A class to collect and print dropped debug information due to LLVM IR
30 /// optimization passes. After every LLVM IR pass is run, it will print how many
31 /// #dbg_values were dropped due to that pass.
32 class LLVM_ABI DroppedVariableStatsIR : public DroppedVariableStats {
33 public:
DroppedVariableStatsIR(bool DroppedVarStatsEnabled)34   DroppedVariableStatsIR(bool DroppedVarStatsEnabled)
35       : llvm::DroppedVariableStats(DroppedVarStatsEnabled) {}
36 
37   void runBeforePass(StringRef P, Any IR);
38 
39   void runAfterPass(StringRef P, Any IR);
40 
41   void registerCallbacks(PassInstrumentationCallbacks &PIC);
42 
43 private:
44   const Function *Func;
45 
46   void runAfterPassFunction(StringRef PassID, const Function *F);
47 
48   void runAfterPassModule(StringRef PassID, const Module *M);
49 
50   /// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
51   /// after a pass has run to facilitate dropped variable calculation for an
52   /// llvm::Function.
53   void runOnFunction(StringRef PassID, const Function *F, bool Before);
54 
55   /// Iterate over all Instructions in a Function and report any dropped debug
56   /// information.
57   void calculateDroppedVarStatsOnFunction(const Function *F, StringRef PassID,
58                                           StringRef FuncOrModName,
59                                           StringRef PassLevel);
60 
61   /// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
62   /// after a pass has run to facilitate dropped variable calculation for an
63   /// llvm::Module. Calls runOnFunction on every Function in the Module.
64   void runOnModule(StringRef PassID, const Module *M, bool Before);
65 
66   /// Iterate over all Functions in a Module and report any dropped debug
67   /// information. Will call calculateDroppedVarStatsOnFunction on every
68   /// Function.
69   void calculateDroppedVarStatsOnModule(const Module *M, StringRef PassID,
70                                         StringRef FuncOrModName,
71                                         StringRef PassLevel);
72 
73   /// Override base class method to run on an llvm::Function specifically.
74   virtual void
75   visitEveryInstruction(unsigned &DroppedCount,
76                         DenseMap<VarID, DILocation *> &InlinedAtsMap,
77                         VarID Var) override;
78 
79   /// Override base class method to run on #dbg_values specifically.
80   virtual void visitEveryDebugRecord(
81       DenseSet<VarID> &VarIDSet,
82       DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
83       StringRef FuncName, bool Before) override;
84 
85   template <typename IRUnitT> static const IRUnitT *unwrapIR(Any IR);
86 };
87 
88 } // namespace llvm
89 
90 #endif
91