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 {
63char RemoveRedundantDebugValuesLegacy::ID = 0;
68 "Remove Redundant DEBUG_VALUE analysis",
false,
false)
71RemoveRedundantDebugValuesLegacy::RemoveRedundantDebugValuesLegacy()
90 const auto *
TRI =
MBB.getParent()->getSubtarget().getRegisterInfo();
92 for (
auto &
MI :
MBB) {
93 if (
MI.isDebugValue()) {
95 MI.getDebugLoc()->getInlinedAt());
96 auto VMI = VariableMap.
find(Var);
103 if (
MI.isDebugValueList() && VMI != VariableMap.
end()) {
104 VariableMap.
erase(VMI);
111 if (VMI != VariableMap.
end())
112 VariableMap.
erase(VMI);
117 if (VMI == VariableMap.
end() ||
118 VMI->second.first->getReg() !=
Loc.getReg() ||
119 VMI->second.second !=
MI.getDebugExpression()) {
120 VariableMap[Var] = {&
Loc,
MI.getDebugExpression()};
129 if (
MI.isMetaInstruction())
133 VariableMap.
remove_if([&](
const auto &Var) {
134 return MI.modifiesRegister(Var.second.first->getReg(),
TRI);
138 for (
auto &Instr : DbgValsToBeRemoved) {
140 Instr->eraseFromParent();
144 return !DbgValsToBeRemoved.
empty();
162 if (
MI.isDebugValue()) {
164 MI.getDebugLoc()->getInlinedAt());
165 auto R = VariableSet.
insert(Var);
170 if (
MI.isNonListDebugValue()) {
176 VariableSet.
erase(Var);
193 for (
auto &Instr : DbgValsToBeRemoved) {
195 Instr->eraseFromParent();
196 ++NumRemovedBackward;
199 return !DbgValsToBeRemoved.
empty();
202bool RemoveRedundantDebugValuesImpl::reduceDbgValues(
MachineFunction &MF) {
207 for (
auto &
MBB : MF) {
215bool RemoveRedundantDebugValuesLegacy::runOnMachineFunction(
216 MachineFunction &MF) {
224 return RemoveRedundantDebugValuesImpl().reduceDbgValues(MF);
237 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)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
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)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.