Skip to content

[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 2 commits into from
Mar 3, 2025

Conversation

vikramRH
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2025

@llvm/pr-subscribers-debuginfo

Author: Vikram Hegde (vikramRH)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/129005.diff

8 Files Affected:

  • (added) llvm/include/llvm/CodeGen/RemoveRedundantDebugValues.h (+25)
  • (modified) llvm/include/llvm/InitializePasses.h (+1-1)
  • (modified) llvm/include/llvm/Passes/CodeGenPassBuilder.h (+1)
  • (modified) llvm/include/llvm/Passes/MachinePassRegistry.def (+1-1)
  • (modified) llvm/lib/CodeGen/CodeGen.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp (+39-20)
  • (modified) llvm/lib/Passes/PassBuilder.cpp (+1)
  • (modified) llvm/test/DebugInfo/MIR/X86/remove-redundant-dbg-vals.mir (+1)
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

@vikramRH vikramRH force-pushed the remove_red_debug_val_npm branch from 438be67 to dc697fd Compare March 3, 2025 09:30
@arsenm arsenm merged commit 6abe148 into llvm:main Mar 3, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 3, 2025

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building llvm at step 6 "test-openmp".

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
Step 6 (test-openmp) failure: 1200 seconds without output running [b'ninja', b'-j 4', b'check-openmp'], attempting to kill
...
PASS: ompd-test :: openmp_examples/example_2.c (440 of 450)
PASS: ompd-test :: openmp_examples/example_4.c (441 of 450)
PASS: ompd-test :: openmp_examples/example_task.c (442 of 450)
PASS: ompd-test :: openmp_examples/example_5.c (443 of 450)
UNSUPPORTED: ompd-test :: openmp_examples/ompd_bt.c (444 of 450)
PASS: ompd-test :: openmp_examples/fibonacci.c (445 of 450)
UNSUPPORTED: ompd-test :: openmp_examples/ompd_parallel.c (446 of 450)
PASS: ompd-test :: openmp_examples/parallel.c (447 of 450)
PASS: ompd-test :: openmp_examples/nested.c (448 of 450)
PASS: ompd-test :: openmp_examples/ompd_icvs.c (449 of 450)
command timed out: 1200 seconds without output running [b'ninja', b'-j 4', b'check-openmp'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1322.512006

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants