66//
77// ===----------------------------------------------------------------------===//
88
9+ #include " llvm/CodeGen/RemoveRedundantDebugValues.h"
910#include " llvm/ADT/DenseMap.h"
1011#include " llvm/ADT/DenseSet.h"
1112#include " llvm/ADT/SmallVector.h"
@@ -33,14 +34,15 @@ STATISTIC(NumRemovedForward, "Number of DBG_VALUEs removed (forward scan)");
3334
3435namespace {
3536
36- class RemoveRedundantDebugValues : public MachineFunctionPass {
37+ struct RemoveRedundantDebugValuesImpl {
38+ bool reduceDbgValues (MachineFunction &MF);
39+ };
40+
41+ class RemoveRedundantDebugValuesLegacy : public MachineFunctionPass {
3742public:
3843 static char ID;
3944
40- RemoveRedundantDebugValues ();
41-
42- bool reduceDbgValues (MachineFunction &MF);
43-
45+ RemoveRedundantDebugValuesLegacy ();
4446 // / Remove redundant debug value MIs for the given machine function.
4547 bool runOnMachineFunction (MachineFunction &MF) override ;
4648
@@ -56,17 +58,18 @@ class RemoveRedundantDebugValues : public MachineFunctionPass {
5658// Implementation
5759// ===----------------------------------------------------------------------===//
5860
59- char RemoveRedundantDebugValues ::ID = 0 ;
61+ char RemoveRedundantDebugValuesLegacy ::ID = 0 ;
6062
61- char &llvm::RemoveRedundantDebugValuesID = RemoveRedundantDebugValues ::ID;
63+ char &llvm::RemoveRedundantDebugValuesID = RemoveRedundantDebugValuesLegacy ::ID;
6264
63- INITIALIZE_PASS (RemoveRedundantDebugValues , DEBUG_TYPE,
65+ INITIALIZE_PASS (RemoveRedundantDebugValuesLegacy , DEBUG_TYPE,
6466 " Remove Redundant DEBUG_VALUE analysis" , false , false )
6567
6668// / Default construct and initialize the pass.
67- RemoveRedundantDebugValues::RemoveRedundantDebugValues ()
69+ RemoveRedundantDebugValuesLegacy::RemoveRedundantDebugValuesLegacy ()
6870 : MachineFunctionPass(ID) {
69- initializeRemoveRedundantDebugValuesPass (*PassRegistry::getPassRegistry ());
71+ initializeRemoveRedundantDebugValuesLegacyPass (
72+ *PassRegistry::getPassRegistry ());
7073}
7174
7275// This analysis aims to remove redundant DBG_VALUEs by going forward
@@ -199,7 +202,7 @@ static bool reduceDbgValsBackwardScan(MachineBasicBlock &MBB) {
199202 return !DbgValsToBeRemoved.empty ();
200203}
201204
202- bool RemoveRedundantDebugValues ::reduceDbgValues (MachineFunction &MF) {
205+ bool RemoveRedundantDebugValuesImpl ::reduceDbgValues (MachineFunction &MF) {
203206 LLVM_DEBUG (dbgs () << " \n Debug Value Reduction\n " );
204207
205208 bool Changed = false ;
@@ -212,16 +215,32 @@ bool RemoveRedundantDebugValues::reduceDbgValues(MachineFunction &MF) {
212215 return Changed;
213216}
214217
215- bool RemoveRedundantDebugValues::runOnMachineFunction (MachineFunction &MF) {
216- // Skip functions without debugging information.
217- if (!MF.getFunction ().getSubprogram ())
218+ bool RemoveRedundantDebugValuesLegacy::runOnMachineFunction (
219+ MachineFunction &MF) {
220+ // Skip functions without debugging information or functions from NoDebug
221+ // compilation units.
222+ if (!MF.getFunction ().getSubprogram () ||
223+ (MF.getFunction ().getSubprogram ()->getUnit ()->getEmissionKind () ==
224+ DICompileUnit::NoDebug))
218225 return false ;
219226
220- // Skip functions from NoDebug compilation units.
221- if (MF.getFunction ().getSubprogram ()->getUnit ()->getEmissionKind () ==
222- DICompileUnit::NoDebug)
223- return false ;
227+ return RemoveRedundantDebugValuesImpl ().reduceDbgValues (MF);
228+ }
224229
225- bool Changed = reduceDbgValues (MF);
226- return Changed;
230+ PreservedAnalyses
231+ RemoveRedundantDebugValuesPass::run (MachineFunction &MF,
232+ MachineFunctionAnalysisManager &MFAM) {
233+ // Skip functions without debugging information or functions from NoDebug
234+ // compilation units.
235+ if (!MF.getFunction ().getSubprogram () ||
236+ (MF.getFunction ().getSubprogram ()->getUnit ()->getEmissionKind () ==
237+ DICompileUnit::NoDebug))
238+ return PreservedAnalyses::all ();
239+
240+ if (!RemoveRedundantDebugValuesImpl ().reduceDbgValues (MF))
241+ return PreservedAnalyses::all ();
242+
243+ auto PA = getMachineFunctionPassPreservedAnalyses ();
244+ PA.preserveSet <CFGAnalyses>();
245+ return PA;
227246}
0 commit comments