diff options
author | Akshat Oke <Akshat.Oke@amd.com> | 2025-02-24 14:31:37 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-24 14:31:37 +0530 |
commit | 229dcf9d3456e95dff2aa0a8eef0a707bd2106c1 (patch) | |
tree | 51b177cb551802117306a81a7cc9e2ee5ed59c8c | |
parent | 47656dc765aabed8079c650261a79a7e85c4370c (diff) | |
download | llvm-229dcf9d3456e95dff2aa0a8eef0a707bd2106c1.zip llvm-229dcf9d3456e95dff2aa0a8eef0a707bd2106c1.tar.gz llvm-229dcf9d3456e95dff2aa0a8eef0a707bd2106c1.tar.bz2 |
[CodeGen][NPM] Port MachineLateInstrsCleanup to NPM (#128160)
There are no standalone tests for this pass for backends implementing
the NPM yet.
-rw-r--r-- | llvm/include/llvm/CodeGen/MachineLateInstrsCleanup.h | 29 | ||||
-rw-r--r-- | llvm/include/llvm/InitializePasses.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/Passes/CodeGenPassBuilder.h | 1 | ||||
-rw-r--r-- | llvm/include/llvm/Passes/MachinePassRegistry.def | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/CodeGen.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp | 36 | ||||
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 1 |
7 files changed, 63 insertions, 10 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineLateInstrsCleanup.h b/llvm/include/llvm/CodeGen/MachineLateInstrsCleanup.h new file mode 100644 index 0000000..8a539eb --- /dev/null +++ b/llvm/include/llvm/CodeGen/MachineLateInstrsCleanup.h @@ -0,0 +1,29 @@ +//===- llvm/CodeGen/MachineLateInstrsCleanup.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_MACHINELATEINSTRSCLEANUP_H +#define LLVM_CODEGEN_MACHINELATEINSTRSCLEANUP_H + +#include "llvm/CodeGen/MachinePassManager.h" + +namespace llvm { + +class MachineLateInstrsCleanupPass + : public PassInfoMixin<MachineLateInstrsCleanupPass> { +public: + PreservedAnalyses run(MachineFunction &MachineFunction, + MachineFunctionAnalysisManager &MachineFunctionAM); + + MachineFunctionProperties getRequiredProperties() const { + return MachineFunctionProperties().set( + MachineFunctionProperties::Property::NoVRegs); + } +}; + +} // namespace llvm + +#endif // LLVM_CODEGEN_MACHINELATEINSTRSCLEANUP_H diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 5b30eb5..0dfb46a 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -197,7 +197,7 @@ void initializeMachineDominanceFrontierPass(PassRegistry &); void initializeMachineDominatorTreeWrapperPassPass(PassRegistry &); void initializeMachineFunctionPrinterPassPass(PassRegistry &); void initializeMachineFunctionSplitterPass(PassRegistry &); -void initializeMachineLateInstrsCleanupPass(PassRegistry &); +void initializeMachineLateInstrsCleanupLegacyPass(PassRegistry &); void initializeMachineLICMPass(PassRegistry &); void initializeMachineLoopInfoWrapperPassPass(PassRegistry &); void initializeMachineModuleInfoWrapperPassPass(PassRegistry &); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 12781e2..30f0742 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -48,6 +48,7 @@ #include "llvm/CodeGen/MachineCopyPropagation.h" #include "llvm/CodeGen/MachineFunctionAnalysis.h" #include "llvm/CodeGen/MachineLICM.h" +#include "llvm/CodeGen/MachineLateInstrsCleanup.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachinePassManager.h" #include "llvm/CodeGen/MachineScheduler.h" diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def index 8de02e9..67eab42 100644 --- a/llvm/include/llvm/Passes/MachinePassRegistry.def +++ b/llvm/include/llvm/Passes/MachinePassRegistry.def @@ -144,6 +144,7 @@ MACHINE_FUNCTION_PASS("finalize-isel", FinalizeISelPass()) MACHINE_FUNCTION_PASS("localstackalloc", LocalStackSlotAllocationPass()) MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass()) MACHINE_FUNCTION_PASS("machine-cse", MachineCSEPass()) +MACHINE_FUNCTION_PASS("machine-latecleanup", MachineLateInstrsCleanupPass()) MACHINE_FUNCTION_PASS("machine-scheduler", MachineSchedulerPass(TM)) MACHINE_FUNCTION_PASS("machinelicm", MachineLICMPass()) MACHINE_FUNCTION_PASS("no-op-machine-function", NoOpMachineFunctionPass()) @@ -245,7 +246,6 @@ DUMMY_MACHINE_FUNCTION_PASS("lrshrink", LiveRangeShrinkPass) DUMMY_MACHINE_FUNCTION_PASS("machine-combiner", MachineCombinerPass) DUMMY_MACHINE_FUNCTION_PASS("static-data-splitter", StaticDataSplitter) DUMMY_MACHINE_FUNCTION_PASS("machine-function-splitter", MachineFunctionSplitterPass) -DUMMY_MACHINE_FUNCTION_PASS("machine-latecleanup", MachineLateInstrsCleanupPass) DUMMY_MACHINE_FUNCTION_PASS("machine-sanmd", MachineSanitizerBinaryMetadata) DUMMY_MACHINE_FUNCTION_PASS("machine-sink", MachineSinkingPass) DUMMY_MACHINE_FUNCTION_PASS("machine-uniformity", MachineUniformityInfoWrapperPass) diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index 35df2a47..046a3ee 100644 --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -83,7 +83,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) { initializeMachineDominatorTreeWrapperPassPass(Registry); initializeMachineFunctionPrinterPassPass(Registry); initializeMachineFunctionSplitterPass(Registry); - initializeMachineLateInstrsCleanupPass(Registry); + initializeMachineLateInstrsCleanupLegacyPass(Registry); initializeMachineLICMPass(Registry); initializeMachineLoopInfoWrapperPassPass(Registry); initializeMachineModuleInfoWrapperPassPass(Registry); diff --git a/llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp b/llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp index 8827a83..503e577 100644 --- a/llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp +++ b/llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp @@ -13,6 +13,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/MachineLateInstrsCleanup.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/Statistic.h" @@ -36,7 +37,7 @@ STATISTIC(NumRemoved, "Number of redundant instructions removed."); namespace { -class MachineLateInstrsCleanup : public MachineFunctionPass { +class MachineLateInstrsCleanup { const TargetRegisterInfo *TRI = nullptr; const TargetInstrInfo *TII = nullptr; @@ -60,10 +61,16 @@ class MachineLateInstrsCleanup : public MachineFunctionPass { BitVector &VisitedPreds); public: + bool run(MachineFunction &MF); +}; + +class MachineLateInstrsCleanupLegacy : public MachineFunctionPass { +public: static char ID; // Pass identification, replacement for typeid - MachineLateInstrsCleanup() : MachineFunctionPass(ID) { - initializeMachineLateInstrsCleanupPass(*PassRegistry::getPassRegistry()); + MachineLateInstrsCleanupLegacy() : MachineFunctionPass(ID) { + initializeMachineLateInstrsCleanupLegacyPass( + *PassRegistry::getPassRegistry()); } void getAnalysisUsage(AnalysisUsage &AU) const override { @@ -81,17 +88,32 @@ public: } // end anonymous namespace -char MachineLateInstrsCleanup::ID = 0; +char MachineLateInstrsCleanupLegacy::ID = 0; -char &llvm::MachineLateInstrsCleanupID = MachineLateInstrsCleanup::ID; +char &llvm::MachineLateInstrsCleanupID = MachineLateInstrsCleanupLegacy::ID; -INITIALIZE_PASS(MachineLateInstrsCleanup, DEBUG_TYPE, +INITIALIZE_PASS(MachineLateInstrsCleanupLegacy, DEBUG_TYPE, "Machine Late Instructions Cleanup Pass", false, false) -bool MachineLateInstrsCleanup::runOnMachineFunction(MachineFunction &MF) { +bool MachineLateInstrsCleanupLegacy::runOnMachineFunction(MachineFunction &MF) { if (skipFunction(MF.getFunction())) return false; + return MachineLateInstrsCleanup().run(MF); +} + +PreservedAnalyses +MachineLateInstrsCleanupPass::run(MachineFunction &MF, + MachineFunctionAnalysisManager &MFAM) { + MFPropsModifier _(*this, MF); + if (!MachineLateInstrsCleanup().run(MF)) + return PreservedAnalyses::all(); + auto PA = getMachineFunctionPassPreservedAnalyses(); + PA.preserveSet<CFGAnalyses>(); + return PA; +} + +bool MachineLateInstrsCleanup::run(MachineFunction &MF) { TRI = MF.getSubtarget().getRegisterInfo(); TII = MF.getSubtarget().getInstrInfo(); diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 3a07898..c9825df 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -114,6 +114,7 @@ #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFunctionAnalysis.h" #include "llvm/CodeGen/MachineLICM.h" +#include "llvm/CodeGen/MachineLateInstrsCleanup.h" #include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" #include "llvm/CodeGen/MachinePassManager.h" |