28#define DEBUG_TYPE "removeredundantdebugvalues"
32STATISTIC(NumRemovedBackward,
"Number of DBG_VALUEs removed (backward scan)");
33STATISTIC(NumRemovedForward,
"Number of DBG_VALUEs removed (forward scan)");
37struct RemoveRedundantDebugValuesImpl {
45 RemoveRedundantDebugValuesLegacy();
61char RemoveRedundantDebugValuesLegacy::ID = 0;
66 "Remove Redundant DEBUG_VALUE analysis",
false,
false)
69RemoveRedundantDebugValuesLegacy::RemoveRedundantDebugValuesLegacy()
93 for (
auto &
MI :
MBB) {
94 if (
MI.isDebugValue()) {
96 MI.getDebugLoc()->getInlinedAt());
97 auto VMI = VariableMap.
find(Var);
104 if (
MI.isDebugValueList() && VMI != VariableMap.
end()) {
105 VariableMap.
erase(VMI);
112 if (VMI != VariableMap.
end())
113 VariableMap.
erase(VMI);
118 if (VMI == VariableMap.
end() ||
119 VMI->second.first->getReg() != Loc.
getReg() ||
120 VMI->second.second !=
MI.getDebugExpression()) {
121 VariableMap[Var] = {&Loc,
MI.getDebugExpression()};
130 if (
MI.isMetaInstruction())
134 for (
auto &Var : VariableMap) {
135 auto &LocOp = Var.second.first;
136 if (
MI.modifiesRegister(LocOp->getReg(),
TRI))
137 VariableMap.erase(Var.first);
141 for (
auto &Instr : DbgValsToBeRemoved) {
143 Instr->eraseFromParent();
147 return !DbgValsToBeRemoved.
empty();
165 if (
MI.isDebugValue()) {
167 MI.getDebugLoc()->getInlinedAt());
168 auto R = VariableSet.
insert(Var);
173 if (
MI.isNonListDebugValue()) {
179 VariableSet.
erase(Var);
196 for (
auto &Instr : DbgValsToBeRemoved) {
198 Instr->eraseFromParent();
199 ++NumRemovedBackward;
202 return !DbgValsToBeRemoved.
empty();
205bool RemoveRedundantDebugValuesImpl::reduceDbgValues(
MachineFunction &MF) {
208 bool Changed =
false;
210 for (
auto &
MBB : MF) {
218bool RemoveRedundantDebugValuesLegacy::runOnMachineFunction(
227 return RemoveRedundantDebugValuesImpl().reduceDbgValues(MF);
240 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)
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a 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)
DISubprogram * getSubprogram() const
Get the attached subprogram.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
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.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
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.
LLVM_ABI void initializeRemoveRedundantDebugValuesLegacyPass(PassRegistry &)
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.