29#define DEBUG_TYPE "removeredundantdebugvalues"
33STATISTIC(NumRemovedBackward,
"Number of DBG_VALUEs removed (backward scan)");
34STATISTIC(NumRemovedForward,
"Number of DBG_VALUEs removed (forward scan)");
38struct RemoveRedundantDebugValuesImpl {
46 RemoveRedundantDebugValuesLegacy();
48 bool runOnMachineFunction(MachineFunction &MF)
override;
50 void getAnalysisUsage(AnalysisUsage &AU)
const override {
62char RemoveRedundantDebugValuesLegacy::ID = 0;
67 "Remove Redundant DEBUG_VALUE analysis",
false,
false)
70RemoveRedundantDebugValuesLegacy::RemoveRedundantDebugValuesLegacy()
89 const auto *
TRI =
MBB.getParent()->getSubtarget().getRegisterInfo();
91 for (
auto &
MI :
MBB) {
92 if (
MI.isDebugValue()) {
94 MI.getDebugLoc()->getInlinedAt());
95 auto VMI = VariableMap.
find(Var);
102 if (
MI.isDebugValueList() && VMI != VariableMap.
end()) {
103 VariableMap.
erase(VMI);
110 if (VMI != VariableMap.
end())
111 VariableMap.
erase(VMI);
116 if (VMI == VariableMap.
end() ||
117 VMI->second.first->getReg() !=
Loc.getReg() ||
118 VMI->second.second !=
MI.getDebugExpression()) {
119 VariableMap[Var] = {&
Loc,
MI.getDebugExpression()};
128 if (
MI.isMetaInstruction())
132 VariableMap.
remove_if([&](
const auto &Var) {
133 return MI.modifiesRegister(Var.second.first->getReg(),
TRI);
137 for (
auto &Instr : DbgValsToBeRemoved) {
139 Instr->eraseFromParent();
143 return !DbgValsToBeRemoved.
empty();
161 if (
MI.isDebugValue()) {
163 MI.getDebugLoc()->getInlinedAt());
164 auto R = VariableSet.
insert(Var);
169 if (
MI.isNonListDebugValue()) {
175 VariableSet.
erase(Var);
192 for (
auto &Instr : DbgValsToBeRemoved) {
194 Instr->eraseFromParent();
195 ++NumRemovedBackward;
198 return !DbgValsToBeRemoved.
empty();
201bool RemoveRedundantDebugValuesImpl::reduceDbgValues(
MachineFunction &MF) {
206 for (
auto &
MBB : MF) {
214bool RemoveRedundantDebugValuesLegacy::runOnMachineFunction(
215 MachineFunction &MF) {
223 return RemoveRedundantDebugValuesImpl().reduceDbgValues(MF);
236 if (!RemoveRedundantDebugValuesImpl().reduceDbgValues(MF))
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool reduceDbgValsForwardScan(MachineBasicBlock &MBB)
static bool reduceDbgValsBackwardScan(MachineBasicBlock &MBB)
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
Identifies a unique instance of a variable.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
bool remove_if(Predicate Pred)
Remove entries that match the given predicate.
DISubprogram * getSubprogram() const
Get the attached subprogram.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Implements a dense probed hash-table based set with some number of buckets stored inline.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
std::pair< iterator, bool > insert(const ValueT &V)
bool erase(const ValueT &V)
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI char & RemoveRedundantDebugValuesID
RemoveRedundantDebugValues pass.