LLVM 20.0.0git
DroppedVariableStatsIR.h
Go to the documentation of this file.
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
18#include "llvm/IR/Module.h"
20
21namespace llvm {
22
23/// A class to collect and print dropped debug information due to LLVM IR
24/// optimization passes. After every LLVM IR pass is run, it will print how many
25/// #dbg_values were dropped due to that pass.
27public:
28 DroppedVariableStatsIR(bool DroppedVarStatsEnabled)
29 : llvm::DroppedVariableStats(DroppedVarStatsEnabled) {}
30
32 setup();
33 if (const auto *M = unwrapIR<Module>(IR))
34 return this->runOnModule(M, true);
35 if (const auto *F = unwrapIR<Function>(IR))
36 return this->runOnFunction(F, true);
37 }
38
40 if (const auto *M = unwrapIR<Module>(IR))
41 runAfterPassModule(P, M);
42 else if (const auto *F = unwrapIR<Function>(IR))
43 runAfterPassFunction(P, F);
44 cleanup();
45 }
46
48
49private:
50 const Function *Func;
51
52 void runAfterPassFunction(StringRef PassID, const Function *F) {
53 runOnFunction(F, false);
54 calculateDroppedVarStatsOnFunction(F, PassID, F->getName().str(),
55 "Function");
56 }
57
58 void runAfterPassModule(StringRef PassID, const Module *M) {
59 runOnModule(M, false);
60 calculateDroppedVarStatsOnModule(M, PassID, M->getName().str(), "Module");
61 }
62 /// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
63 /// after a pass has run to facilitate dropped variable calculation for an
64 /// llvm::Function.
65 void runOnFunction(const Function *F, bool Before);
66 /// Iterate over all Instructions in a Function and report any dropped debug
67 /// information.
68 void calculateDroppedVarStatsOnFunction(const Function *F, StringRef PassID,
69 StringRef FuncOrModName,
70 StringRef PassLevel);
71 /// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
72 /// after a pass has run to facilitate dropped variable calculation for an
73 /// llvm::Module. Calls runOnFunction on every Function in the Module.
74 void runOnModule(const Module *M, bool Before);
75 /// Iterate over all Functions in a Module and report any dropped debug
76 /// information. Will call calculateDroppedVarStatsOnFunction on every
77 /// Function.
78 void calculateDroppedVarStatsOnModule(const Module *M, StringRef PassID,
79 StringRef FuncOrModName,
80 StringRef PassLevel);
81 /// Override base class method to run on an llvm::Function specifically.
82 virtual void
83 visitEveryInstruction(unsigned &DroppedCount,
84 DenseMap<VarID, DILocation *> &InlinedAtsMap,
85 VarID Var) override;
86
87 /// Override base class method to run on #dbg_values specifically.
88 virtual void visitEveryDebugRecord(
89 DenseSet<VarID> &VarIDSet,
90 DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
91 StringRef FuncName, bool Before) override;
92
93 template <typename IRUnitT> static const IRUnitT *unwrapIR(Any IR) {
94 const IRUnitT **IRPtr = llvm::any_cast<const IRUnitT *>(&IR);
95 return IRPtr ? *IRPtr : nullptr;
96 }
97};
98
99} // namespace llvm
100
101#endif
===- DroppedVariableStats.h - Opt Diagnostics -*- C++ -*-------------—===//
Module.h This file contains the declarations for the Module class.
Legalize the Machine IR a function s Machine IR
Definition: Legalizer.cpp:80
#define F(x, y, z)
Definition: MD5.cpp:55
#define P(N)
PassInstrumentationCallbacks PIC
Definition: Any.h:28
A class to collect and print dropped debug information due to LLVM IR optimization passes.
void registerCallbacks(PassInstrumentationCallbacks &PIC)
DroppedVariableStatsIR(bool DroppedVarStatsEnabled)
void runAfterPass(StringRef P, Any IR)
A base class to collect and print dropped debug information variable statistics.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...