Skip to content

Commit 6abe148

Browse files
authored
[CodeGen][NewPM] Port "RemoveRedundantDebugValues" to NPM (#129005)
1 parent f6212c1 commit 6abe148

File tree

8 files changed

+70
-23
lines changed

8 files changed

+70
-23
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===- llvm/CodeGen/RemoveRedundantDebugValues.h ----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CODEGEN_REMOVEREDUNDANTDEBUGVALUES_H
10+
#define LLVM_CODEGEN_REMOVEREDUNDANTDEBUGVALUES_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class RemoveRedundantDebugValuesPass
17+
: public PassInfoMixin<RemoveRedundantDebugValuesPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
};
22+
23+
} // namespace llvm
24+
25+
#endif // LLVM_CODEGEN_REMOVEREDUNDANTDEBUGVALUES_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void initializeRegionPrinterPass(PassRegistry &);
266266
void initializeRegionViewerPass(PassRegistry &);
267267
void initializeRegisterCoalescerLegacyPass(PassRegistry &);
268268
void initializeRemoveLoadsIntoFakeUsesPass(PassRegistry &);
269-
void initializeRemoveRedundantDebugValuesPass(PassRegistry &);
269+
void initializeRemoveRedundantDebugValuesLegacyPass(PassRegistry &);
270270
void initializeRenameIndependentSubregsLegacyPass(PassRegistry &);
271271
void initializeReplaceWithVeclibLegacyPass(PassRegistry &);
272272
void initializeResetMachineFunctionPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
6767
#include "llvm/CodeGen/RegisterCoalescerPass.h"
6868
#include "llvm/CodeGen/RegisterUsageInfo.h"
69+
#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
6970
#include "llvm/CodeGen/RenameIndependentSubregs.h"
7071
#include "llvm/CodeGen/ReplaceWithVeclib.h"
7172
#include "llvm/CodeGen/SafeStack.h"

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
175175
MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass())
176176
MACHINE_FUNCTION_PASS("register-coalescer", RegisterCoalescerPass())
177177
MACHINE_FUNCTION_PASS("rename-independent-subregs", RenameIndependentSubregsPass())
178+
MACHINE_FUNCTION_PASS("remove-redundant-debug-values", RemoveRedundantDebugValuesPass())
178179
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
179180
RequireAllMachineFunctionPropertiesPass())
180181
MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass())
@@ -281,7 +282,6 @@ DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
281282
DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
282283
DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass)
283284
DUMMY_MACHINE_FUNCTION_PASS("remove-loads-into-fake-uses", RemoveLoadsIntoFakeUsesPass)
284-
DUMMY_MACHINE_FUNCTION_PASS("removeredundantdebugvalues", RemoveRedundantDebugValuesPass)
285285
DUMMY_MACHINE_FUNCTION_PASS("reset-machine-function", ResetMachineFunctionPass)
286286
DUMMY_MACHINE_FUNCTION_PASS("shrink-wrap", ShrinkWrapPass)
287287
DUMMY_MACHINE_FUNCTION_PASS("stack-frame-layout", StackFrameLayoutAnalysisPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
118118
initializeRegUsageInfoPropagationLegacyPass(Registry);
119119
initializeRegisterCoalescerLegacyPass(Registry);
120120
initializeRemoveLoadsIntoFakeUsesPass(Registry);
121-
initializeRemoveRedundantDebugValuesPass(Registry);
121+
initializeRemoveRedundantDebugValuesLegacyPass(Registry);
122122
initializeRenameIndependentSubregsLegacyPass(Registry);
123123
initializeSafeStackLegacyPassPass(Registry);
124124
initializeSelectOptimizePass(Registry);

llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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

3435
namespace {
3536

36-
class RemoveRedundantDebugValues : public MachineFunctionPass {
37+
struct RemoveRedundantDebugValuesImpl {
38+
bool reduceDbgValues(MachineFunction &MF);
39+
};
40+
41+
class RemoveRedundantDebugValuesLegacy : public MachineFunctionPass {
3742
public:
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() << "\nDebug 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
}

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
139139
#include "llvm/CodeGen/RegisterCoalescerPass.h"
140140
#include "llvm/CodeGen/RegisterUsageInfo.h"
141+
#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
141142
#include "llvm/CodeGen/RenameIndependentSubregs.h"
142143
#include "llvm/CodeGen/SafeStack.h"
143144
#include "llvm/CodeGen/SelectOptimize.h"

llvm/test/DebugInfo/MIR/X86/remove-redundant-dbg-vals.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc %s -o - -run-pass=removeredundantdebugvalues | FileCheck --implicit-check-not=DBG_VALUE %s
2+
# RUN: llc %s -o - -passes=remove-redundant-debug-values | FileCheck --implicit-check-not=DBG_VALUE %s
23

34
## This checks that the RemoveRedundantDebugValues removes redundant
45
## DBG_VALUEs. The MIR was hand-written, and foo{[2-6]}() are just

0 commit comments

Comments
 (0)