[llvm] [CodeGen] Port mir-strip-debug to new pass manager (PR #190738)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 7 13:01:08 PDT 2026
================
@@ -23,60 +28,67 @@
using namespace llvm;
namespace {
-cl::opt<bool>
- OnlyDebugifiedDefault("mir-strip-debugify-only",
- cl::desc("Should mir-strip-debug only strip debug "
- "info from debugified modules by default"),
- cl::init(true));
-struct StripDebugMachineModule : public ModulePass {
- bool runOnModule(Module &M) override {
- if (OnlyDebugified) {
- NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify");
- if (!DebugifyMD) {
- LLVM_DEBUG(dbgs() << "Not stripping debug info"
- " (debugify metadata not found)?\n");
- return false;
- }
+bool stripDebugMachineModuleImpl(
+ Module &M, llvm::function_ref<MachineFunction *(Function &)> GetMF,
+ bool OnlyDebugified) {
+ if (OnlyDebugified) {
+ NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify");
+ if (!DebugifyMD) {
+ LLVM_DEBUG(dbgs() << "Not stripping debug info"
+ " (debugify metadata not found)?\n");
+ return false;
}
+ }
- MachineModuleInfo &MMI =
- getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
-
- bool Changed = false;
- for (Function &F : M.functions()) {
- MachineFunction *MaybeMF = MMI.getMachineFunction(F);
- if (!MaybeMF)
- continue;
- MachineFunction &MF = *MaybeMF;
- for (MachineBasicBlock &MBB : MF) {
- for (MachineInstr &MI : llvm::make_early_inc_range(MBB.instrs())) {
- if (MI.isDebugInstr()) {
- // FIXME: We should remove all of them. However, AArch64 emits an
- // invalid `DBG_VALUE $lr` with only one operand instead of
- // the usual three and has a test that depends on it's
- // preservation. Preserve it for now.
- if (MI.getNumOperands() > 1) {
- LLVM_DEBUG(dbgs() << "Removing debug instruction " << MI);
- MBB.erase_instr(&MI);
- Changed |= true;
- continue;
- }
- }
- if (MI.getDebugLoc()) {
- LLVM_DEBUG(dbgs() << "Removing location " << MI);
- MI.setDebugLoc(DebugLoc());
+ bool Changed = false;
+ for (Function &F : M.functions()) {
+ MachineFunction *MaybeMF = GetMF(F);
+ if (!MaybeMF)
+ continue;
+ MachineFunction &MF = *MaybeMF;
+ for (MachineBasicBlock &MBB : MF) {
+ for (MachineInstr &MI : llvm::make_early_inc_range(MBB.instrs())) {
+ if (MI.isDebugInstr()) {
+ // FIXME: We should remove all of them. However, AArch64 emits an
+ // invalid `DBG_VALUE $lr` with only one operand instead of
+ // the usual three and has a test that depends on it's
+ // preservation. Preserve it for now.
+ if (MI.getNumOperands() > 1) {
+ LLVM_DEBUG(dbgs() << "Removing debug instruction " << MI);
+ MBB.erase_instr(&MI);
Changed |= true;
continue;
}
- LLVM_DEBUG(dbgs() << "Keeping " << MI);
}
+ if (MI.getDebugLoc()) {
+ LLVM_DEBUG(dbgs() << "Removing location " << MI);
+ MI.setDebugLoc(DebugLoc());
+ Changed |= true;
+ continue;
+ }
+ LLVM_DEBUG(dbgs() << "Keeping " << MI);
}
}
+ }
- Changed |= stripDebugifyMetadata(M);
+ Changed |= stripDebugifyMetadata(M);
- return Changed;
+ return Changed;
+}
+
+cl::opt<bool>
+ OnlyDebugifiedDefault("mir-strip-debugify-only",
+ cl::desc("Should mir-strip-debug only strip debug "
+ "info from debugified modules by default"),
+ cl::init(true));
+
+struct StripDebugMachineModule : public ModulePass {
+ bool runOnModule(Module &M) override {
+ MachineModuleInfo &MMI =
+ getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
+ auto GetMF = [&MMI](Function &F) { return MMI.getMachineFunction(F); };
----------------
boomanaiden154 wrote:
We can probably inline the lambda given the name doesn't signify much.
https://github.com/llvm/llvm-project/pull/190738
More information about the llvm-commits
mailing list