-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CodeGen][NewPM] Port "RemoveRedundantDebugValues" to NPM #129005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-debuginfo Author: Vikram Hegde (vikramRH) ChangesFull diff: https://github.com/llvm/llvm-project/pull/129005.diff 8 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/RemoveRedundantDebugValues.h b/llvm/include/llvm/CodeGen/RemoveRedundantDebugValues.h
new file mode 100644
index 0000000000000..7d6dfa9bb830d
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/RemoveRedundantDebugValues.h
@@ -0,0 +1,25 @@
+//===- llvm/CodeGen/RemoveRedundantDebugValues.h ----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_REMOVEREDUNDANTDEBUGVALUES_H
+#define LLVM_CODEGEN_REMOVEREDUNDANTDEBUGVALUES_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+
+class RemoveRedundantDebugValuesPass
+ : public PassInfoMixin<RemoveRedundantDebugValuesPass> {
+public:
+ PreservedAnalyses run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_REMOVEREDUNDANTDEBUGVALUES_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 0dfb46a210c7e..39e454adba57c 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -266,7 +266,7 @@ void initializeRegionPrinterPass(PassRegistry &);
void initializeRegionViewerPass(PassRegistry &);
void initializeRegisterCoalescerLegacyPass(PassRegistry &);
void initializeRemoveLoadsIntoFakeUsesPass(PassRegistry &);
-void initializeRemoveRedundantDebugValuesPass(PassRegistry &);
+void initializeRemoveRedundantDebugValuesLegacyPass(PassRegistry &);
void initializeRenameIndependentSubregsLegacyPass(PassRegistry &);
void initializeReplaceWithVeclibLegacyPass(PassRegistry &);
void initializeResetMachineFunctionPass(PassRegistry &);
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 30f0742fd2c26..9d998b0e4e8c6 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -64,6 +64,7 @@
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
#include "llvm/CodeGen/RegisterCoalescerPass.h"
#include "llvm/CodeGen/RegisterUsageInfo.h"
+#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
#include "llvm/CodeGen/RenameIndependentSubregs.h"
#include "llvm/CodeGen/ReplaceWithVeclib.h"
#include "llvm/CodeGen/SafeStack.h"
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 67eab42b014c9..a94b5505b7ecc 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -173,6 +173,7 @@ MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass())
MACHINE_FUNCTION_PASS("register-coalescer", RegisterCoalescerPass())
MACHINE_FUNCTION_PASS("rename-independent-subregs", RenameIndependentSubregsPass())
+MACHINE_FUNCTION_PASS("removeredundantdebugvalues", RemoveRedundantDebugValuesPass())
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
RequireAllMachineFunctionPropertiesPass())
MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass())
@@ -266,7 +267,6 @@ DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass)
DUMMY_MACHINE_FUNCTION_PASS("remove-loads-into-fake-uses", RemoveLoadsIntoFakeUsesPass)
-DUMMY_MACHINE_FUNCTION_PASS("removeredundantdebugvalues", RemoveRedundantDebugValuesPass)
DUMMY_MACHINE_FUNCTION_PASS("reset-machine-function", ResetMachineFunctionPass)
DUMMY_MACHINE_FUNCTION_PASS("shrink-wrap", ShrinkWrapPass)
DUMMY_MACHINE_FUNCTION_PASS("stack-frame-layout", StackFrameLayoutAnalysisPass)
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 046a3ee42dd6b..c57953299590f 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -118,7 +118,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeRegUsageInfoPropagationLegacyPass(Registry);
initializeRegisterCoalescerLegacyPass(Registry);
initializeRemoveLoadsIntoFakeUsesPass(Registry);
- initializeRemoveRedundantDebugValuesPass(Registry);
+ initializeRemoveRedundantDebugValuesLegacyPass(Registry);
initializeRenameIndependentSubregsLegacyPass(Registry);
initializeSafeStackLegacyPassPass(Registry);
initializeSelectOptimizePass(Registry);
diff --git a/llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp b/llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp
index ba8dd49ba9291..e9ea50160b7df 100644
--- a/llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp
+++ b/llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallVector.h"
@@ -33,14 +34,15 @@ STATISTIC(NumRemovedForward, "Number of DBG_VALUEs removed (forward scan)");
namespace {
-class RemoveRedundantDebugValues : public MachineFunctionPass {
+struct RemoveRedundantDebugValuesImpl {
+ bool reduceDbgValues(MachineFunction &MF);
+};
+
+class RemoveRedundantDebugValuesLegacy : public MachineFunctionPass {
public:
static char ID;
- RemoveRedundantDebugValues();
-
- bool reduceDbgValues(MachineFunction &MF);
-
+ RemoveRedundantDebugValuesLegacy();
/// Remove redundant debug value MIs for the given machine function.
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -56,17 +58,18 @@ class RemoveRedundantDebugValues : public MachineFunctionPass {
// Implementation
//===----------------------------------------------------------------------===//
-char RemoveRedundantDebugValues::ID = 0;
+char RemoveRedundantDebugValuesLegacy::ID = 0;
-char &llvm::RemoveRedundantDebugValuesID = RemoveRedundantDebugValues::ID;
+char &llvm::RemoveRedundantDebugValuesID = RemoveRedundantDebugValuesLegacy::ID;
-INITIALIZE_PASS(RemoveRedundantDebugValues, DEBUG_TYPE,
+INITIALIZE_PASS(RemoveRedundantDebugValuesLegacy, DEBUG_TYPE,
"Remove Redundant DEBUG_VALUE analysis", false, false)
/// Default construct and initialize the pass.
-RemoveRedundantDebugValues::RemoveRedundantDebugValues()
+RemoveRedundantDebugValuesLegacy::RemoveRedundantDebugValuesLegacy()
: MachineFunctionPass(ID) {
- initializeRemoveRedundantDebugValuesPass(*PassRegistry::getPassRegistry());
+ initializeRemoveRedundantDebugValuesLegacyPass(
+ *PassRegistry::getPassRegistry());
}
// This analysis aims to remove redundant DBG_VALUEs by going forward
@@ -199,7 +202,7 @@ static bool reduceDbgValsBackwardScan(MachineBasicBlock &MBB) {
return !DbgValsToBeRemoved.empty();
}
-bool RemoveRedundantDebugValues::reduceDbgValues(MachineFunction &MF) {
+bool RemoveRedundantDebugValuesImpl::reduceDbgValues(MachineFunction &MF) {
LLVM_DEBUG(dbgs() << "\nDebug Value Reduction\n");
bool Changed = false;
@@ -212,16 +215,32 @@ bool RemoveRedundantDebugValues::reduceDbgValues(MachineFunction &MF) {
return Changed;
}
-bool RemoveRedundantDebugValues::runOnMachineFunction(MachineFunction &MF) {
- // Skip functions without debugging information.
- if (!MF.getFunction().getSubprogram())
+bool RemoveRedundantDebugValuesLegacy::runOnMachineFunction(
+ MachineFunction &MF) {
+ // Skip functions without debugging information or functions from NoDebug
+ // compilation units.
+ if (!MF.getFunction().getSubprogram() ||
+ (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
+ DICompileUnit::NoDebug))
return false;
- // Skip functions from NoDebug compilation units.
- if (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
- DICompileUnit::NoDebug)
- return false;
+ return RemoveRedundantDebugValuesImpl().reduceDbgValues(MF);
+}
- bool Changed = reduceDbgValues(MF);
- return Changed;
+PreservedAnalyses
+RemoveRedundantDebugValuesPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+ // Skip functions without debugging information or functions from NoDebug
+ // compilation units.
+ if (!MF.getFunction().getSubprogram() ||
+ (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
+ DICompileUnit::NoDebug))
+ return PreservedAnalyses::all();
+
+ if (!RemoveRedundantDebugValuesImpl().reduceDbgValues(MF))
+ return PreservedAnalyses::all();
+
+ auto PA = getMachineFunctionPassPreservedAnalyses();
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
}
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index c9825dfc89d3d..6134820370431 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -135,6 +135,7 @@
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
#include "llvm/CodeGen/RegisterCoalescerPass.h"
#include "llvm/CodeGen/RegisterUsageInfo.h"
+#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
#include "llvm/CodeGen/RenameIndependentSubregs.h"
#include "llvm/CodeGen/SafeStack.h"
#include "llvm/CodeGen/SelectOptimize.h"
diff --git a/llvm/test/DebugInfo/MIR/X86/remove-redundant-dbg-vals.mir b/llvm/test/DebugInfo/MIR/X86/remove-redundant-dbg-vals.mir
index 4817fe3115058..1e5fb5943407c 100644
--- a/llvm/test/DebugInfo/MIR/X86/remove-redundant-dbg-vals.mir
+++ b/llvm/test/DebugInfo/MIR/X86/remove-redundant-dbg-vals.mir
@@ -1,4 +1,5 @@
# RUN: llc %s -o - -run-pass=removeredundantdebugvalues | FileCheck --implicit-check-not=DBG_VALUE %s
+# RUN: llc %s -o - -passes=removeredundantdebugvalues | FileCheck --implicit-check-not=DBG_VALUE %s
## This checks that the RemoveRedundantDebugValues removes redundant
## DBG_VALUEs. The MIR was hand-written, and foo{[2-6]}() are just
|
cdevadas
approved these changes
Feb 27, 2025
arsenm
approved these changes
Feb 27, 2025
optimisan
reviewed
Feb 27, 2025
438be67
to
dc697fd
Compare
optimisan
approved these changes
Mar 3, 2025
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/8679 Here is the relevant piece of the build log for the reference
|
jph-13
pushed a commit
to jph-13/llvm-project
that referenced
this pull request
Mar 21, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.