LLVM 24.0.0git
DroppedVariableStatsMIR.cpp
Go to the documentation of this file.
1///===- DroppedVariableStatsMIR.cpp ---------------------------------------===//
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_VALUEs that get dropped due to an optimization pass.
11///
12///===---------------------------------------------------------------------===//
13
16
17using namespace llvm;
18
20 MachineFunction *MF) {
21 if (PassID == "Debug Variable Analysis")
22 return;
23 setup();
24 return runOnMachineFunction(MF, true);
25}
26
28 MachineFunction *MF) {
29 if (PassID == "Debug Variable Analysis")
30 return;
31 runOnMachineFunction(MF, false);
32 calculateDroppedVarStatsOnMachineFunction(MF, PassID, MF->getName().str());
33 cleanup();
34}
35
36void DroppedVariableStatsMIR::runOnMachineFunction(const MachineFunction *MF,
37 bool Before) {
38 auto &DebugVariables = DebugVariablesStack.back()[&MF->getFunction()];
39 MFunc = MF;
40 run(DebugVariables, Before);
41}
42
43void DroppedVariableStatsMIR::calculateDroppedVarStatsOnMachineFunction(
44 const MachineFunction *MF, StringRef PassID, StringRef FuncOrModName) {
45 MFunc = MF;
46 const Function *Func = &MF->getFunction();
47 DebugVariables &DbgVariables = DebugVariablesStack.back()[Func];
48 calculateDroppedStatsAndPrint(DbgVariables, PassID, FuncOrModName,
49 "MachineFunction", Func);
50}
51
52void DroppedVariableStatsMIR::visitEveryInstruction(unsigned &DroppedCount,
53 VarID Var) {
54 unsigned PrevDroppedCount = DroppedCount;
55 for (const auto &MBB : *MFunc) {
56 for (const auto &MI : MBB) {
57 if (!MI.isDebugInstr()) {
58 auto *DbgLoc = MI.getDebugLoc().get();
59 if (!DbgLoc)
60 continue;
61
62 if (updateDroppedCount(DbgLoc, Var, DroppedCount))
63 break;
64 }
65 }
66 if (PrevDroppedCount != DroppedCount) {
67 PrevDroppedCount = DroppedCount;
68 break;
69 }
70 }
71}
72
73void DroppedVariableStatsMIR::visitEveryDebugRecord(DenseSet<VarID> &VarIDSet) {
74 for (const auto &MBB : *MFunc) {
75 for (const auto &MI : MBB) {
76 if (MI.isDebugValueLike()) {
77 auto *DbgVar = MI.getDebugVariable();
78 if (!DbgVar)
79 continue;
80 auto DbgLoc = MI.getDebugLoc();
81 populateVarIDSet(DbgVar, DbgLoc, VarIDSet);
82 }
83 }
84 }
85}
MachineBasicBlock & MBB
===- DroppedVariableStatsMIR.h - Opt Diagnostics -*- C++ -*----------—===//
IRTranslator LLVM IR MI
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
void runBeforePass(StringRef PassID, MachineFunction *MF)
void runAfterPass(StringRef PassID, MachineFunction *MF)
LLVM_ABI void populateVarIDSet(const DILocalVariable *DbgVar, DebugLoc DbgLoc, DenseSet< VarID > &VarIDSet)
Add the VarID of the debug record of DbgVar at DbgLoc to VarIDSet.
LLVM_ABI void run(DebugVariables &DbgVariables, bool Before)
Run code to populate relevant data structures over an llvm::Function or llvm::MachineFunction.
LLVM_ABI void calculateDroppedStatsAndPrint(DebugVariables &DbgVariables, StringRef PassID, StringRef FuncOrModName, StringRef PassLevel, const Function *Func)
Calculate the number of dropped variables in an llvm::Function or llvm::MachineFunction and print the...
SmallVector< DenseMap< const Function *, DebugVariables > > DebugVariablesStack
A stack of a DenseMap, that maps DebugVariables for every pass to an llvm::Function.
LLVM_ABI bool updateDroppedCount(const DILocation *DbgLoc, VarID Var, unsigned &DroppedCount)
Check if a Var has been dropped or is a false positive.
const BasicBlock & back() const
Definition Function.h:847
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Function & getFunction()
Return the LLVM function that this machine code represents.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
This is an optimization pass for GlobalISel generic memory operations.
DebugVariableAggregate VarID
A unique key that represents one instance of a debug variable.