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
15
16using namespace llvm;
17
19 MachineFunction *MF) {
20 if (PassID == "Debug Variable Analysis")
21 return;
22 setup();
23 return runOnMachineFunction(MF, true);
24}
25
27 MachineFunction *MF) {
28 if (PassID == "Debug Variable Analysis")
29 return;
30 runOnMachineFunction(MF, false);
31 calculateDroppedVarStatsOnMachineFunction(MF, PassID, MF->getName().str());
32 cleanup();
33}
34
35void DroppedVariableStatsMIR::runOnMachineFunction(const MachineFunction *MF,
36 bool Before) {
37 auto &DebugVariables = DebugVariablesStack.back()[&MF->getFunction()];
38 MFunc = MF;
39 run(DebugVariables, Before);
40}
41
42void DroppedVariableStatsMIR::calculateDroppedVarStatsOnMachineFunction(
43 const MachineFunction *MF, StringRef PassID, StringRef FuncOrModName) {
44 MFunc = MF;
45 const Function *Func = &MF->getFunction();
46 DebugVariables &DbgVariables = DebugVariablesStack.back()[Func];
47 calculateDroppedStatsAndPrint(DbgVariables, PassID, FuncOrModName,
48 "MachineFunction", Func);
49}
50
51void DroppedVariableStatsMIR::visitEveryInstruction(unsigned &DroppedCount,
52 VarID Var) {
53 unsigned PrevDroppedCount = DroppedCount;
54 for (const auto &MBB : *MFunc) {
55 for (const auto &MI : MBB) {
56 if (!MI.isDebugInstr()) {
57 auto *DbgLoc = MI.getDebugLoc().get();
58 if (!DbgLoc)
59 continue;
60
61 if (updateDroppedCount(DbgLoc, Var, DroppedCount))
62 break;
63 }
64 }
65 if (PrevDroppedCount != DroppedCount) {
66 PrevDroppedCount = DroppedCount;
67 break;
68 }
69 }
70}
71
72void DroppedVariableStatsMIR::visitEveryDebugRecord(DenseSet<VarID> &VarIDSet) {
73 for (const auto &MBB : *MFunc) {
74 for (const auto &MI : MBB) {
75 if (MI.isDebugValueLike()) {
76 auto *DbgVar = MI.getDebugVariable();
77 if (!DbgVar)
78 continue;
79 auto DbgLoc = MI.getDebugLoc();
80 populateVarIDSet(DbgVar, DbgLoc, VarIDSet);
81 }
82 }
83 }
84}
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:856
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.