aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorAkshat Oke <Akshat.Oke@amd.com>2025-02-24 14:31:37 +0530
committerGitHub <noreply@github.com>2025-02-24 14:31:37 +0530
commit229dcf9d3456e95dff2aa0a8eef0a707bd2106c1 (patch)
tree51b177cb551802117306a81a7cc9e2ee5ed59c8c /llvm/lib
parent47656dc765aabed8079c650261a79a7e85c4370c (diff)
downloadllvm-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.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/CodeGen.cpp2
-rw-r--r--llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp36
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp1
3 files changed, 31 insertions, 8 deletions
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"