[llvm] [AMDGPU][NewPM] Port SIPostRABundler to NPM (PR #123717)
Akshat Oke via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 01:39:57 PST 2025
https://github.com/optimisan updated https://github.com/llvm/llvm-project/pull/123717
>From f874c2ba06191883e2ee5c9a21264d054a665797 Mon Sep 17 00:00:00 2001
From: Akshat Oke <Akshat.Oke at amd.com>
Date: Tue, 21 Jan 2025 09:17:21 +0000
Subject: [PATCH 1/2] [AMDGPU][NewPM] Port SIPostRABundler to NPM
---
llvm/lib/Target/AMDGPU/AMDGPU.h | 4 +--
llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def | 1 +
.../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 5 ++--
llvm/lib/Target/AMDGPU/SIPostRABundler.cpp | 30 ++++++++++++++-----
llvm/lib/Target/AMDGPU/SIPostRABundler.h | 22 ++++++++++++++
.../CodeGen/AMDGPU/postra-bundle-memops.mir | 1 +
6 files changed, 51 insertions(+), 12 deletions(-)
create mode 100644 llvm/lib/Target/AMDGPU/SIPostRABundler.h
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 5d9a830f041a74..846b7c98399a4a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -428,8 +428,8 @@ extern char &SIInsertWaitcntsID;
void initializeSIFormMemoryClausesPass(PassRegistry&);
extern char &SIFormMemoryClausesID;
-void initializeSIPostRABundlerPass(PassRegistry&);
-extern char &SIPostRABundlerID;
+void initializeSIPostRABundlerLegacyPass(PassRegistry&);
+extern char &SIPostRABundlerLegacyID;
void initializeGCNCreateVOPDPass(PassRegistry &);
extern char &GCNCreateVOPDID;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def b/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
index 09a39d23d801b9..e0ff0dfc97fa9e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
@@ -108,5 +108,6 @@ MACHINE_FUNCTION_PASS("si-opt-vgpr-liverange", SIOptimizeVGPRLiveRangePass())
MACHINE_FUNCTION_PASS("si-optimize-exec-masking", SIOptimizeExecMaskingPass())
MACHINE_FUNCTION_PASS("si-peephole-sdwa", SIPeepholeSDWAPass())
MACHINE_FUNCTION_PASS("si-pre-allocate-wwm-regs", SIPreAllocateWWMRegsPass())
+MACHINE_FUNCTION_PASS("si-post-ra-bundler", SIPostRABundlerPass())
MACHINE_FUNCTION_PASS("si-shrink-instructions", SIShrinkInstructionsPass())
#undef MACHINE_FUNCTION_PASS
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 53ec80b8f72049..f3b8f5926a3aa4 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -45,6 +45,7 @@
#include "SIOptimizeExecMasking.h"
#include "SIOptimizeVGPRLiveRange.h"
#include "SIPeepholeSDWA.h"
+#include "SIPostRABundler.h"
#include "SIPreAllocateWWMRegs.h"
#include "SIShrinkInstructions.h"
#include "TargetInfo/AMDGPUTargetInfo.h"
@@ -532,7 +533,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeSIOptimizeExecMaskingLegacyPass(*PR);
initializeSIPreAllocateWWMRegsLegacyPass(*PR);
initializeSIFormMemoryClausesPass(*PR);
- initializeSIPostRABundlerPass(*PR);
+ initializeSIPostRABundlerLegacyPass(*PR);
initializeGCNCreateVOPDPass(*PR);
initializeAMDGPUUnifyDivergentExitNodesPass(*PR);
initializeAMDGPUAAWrapperPassPass(*PR);
@@ -1642,7 +1643,7 @@ void GCNPassConfig::addPostRegAlloc() {
void GCNPassConfig::addPreSched2() {
if (TM->getOptLevel() > CodeGenOptLevel::None)
addPass(createSIShrinkInstructionsLegacyPass());
- addPass(&SIPostRABundlerID);
+ addPass(&SIPostRABundlerLegacyID);
}
void GCNPassConfig::addPreEmitPass() {
diff --git a/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp b/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp
index 8464cb3d6fc43d..cbd8f3ad5c5e61 100644
--- a/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp
+++ b/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp
@@ -12,6 +12,7 @@
///
//===----------------------------------------------------------------------===//
+#include "SIPostRABundler.h"
#include "AMDGPU.h"
#include "GCNSubtarget.h"
#include "llvm/ADT/SmallSet.h"
@@ -23,13 +24,13 @@ using namespace llvm;
namespace {
-class SIPostRABundler : public MachineFunctionPass {
+class SIPostRABundlerLegacy : public MachineFunctionPass {
public:
static char ID;
public:
- SIPostRABundler() : MachineFunctionPass(ID) {
- initializeSIPostRABundlerPass(*PassRegistry::getPassRegistry());
+ SIPostRABundlerLegacy() : MachineFunctionPass(ID) {
+ initializeSIPostRABundlerLegacyPass(*PassRegistry::getPassRegistry());
}
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -42,7 +43,11 @@ class SIPostRABundler : public MachineFunctionPass {
AU.setPreservesAll();
MachineFunctionPass::getAnalysisUsage(AU);
}
+};
+class SIPostRABundler {
+public:
+ bool run(MachineFunction &MF);
private:
const SIRegisterInfo *TRI;
@@ -62,14 +67,14 @@ constexpr uint64_t MemFlags = SIInstrFlags::MTBUF | SIInstrFlags::MUBUF |
} // End anonymous namespace.
-INITIALIZE_PASS(SIPostRABundler, DEBUG_TYPE, "SI post-RA bundler", false, false)
+INITIALIZE_PASS(SIPostRABundlerLegacy, DEBUG_TYPE, "SI post-RA bundler", false, false)
-char SIPostRABundler::ID = 0;
+char SIPostRABundlerLegacy::ID = 0;
-char &llvm::SIPostRABundlerID = SIPostRABundler::ID;
+char &llvm::SIPostRABundlerLegacyID = SIPostRABundlerLegacy::ID;
FunctionPass *llvm::createSIPostRABundlerPass() {
- return new SIPostRABundler();
+ return new SIPostRABundlerLegacy();
}
bool SIPostRABundler::isDependentLoad(const MachineInstr &MI) const {
@@ -121,9 +126,18 @@ bool SIPostRABundler::canBundle(const MachineInstr &MI,
!isDependentLoad(NextMI));
}
-bool SIPostRABundler::runOnMachineFunction(MachineFunction &MF) {
+bool SIPostRABundlerLegacy::runOnMachineFunction(MachineFunction &MF) {
if (skipFunction(MF.getFunction()))
return false;
+ return SIPostRABundler().run(MF);
+}
+
+PreservedAnalyses SIPostRABundlerPass::run(MachineFunction &MF, MachineFunctionAnalysisManager &) {
+ SIPostRABundler().run(MF);
+ return PreservedAnalyses::all();
+}
+
+bool SIPostRABundler::run(MachineFunction &MF) {
TRI = MF.getSubtarget<GCNSubtarget>().getRegisterInfo();
BitVector BundleUsedRegUnits(TRI->getNumRegUnits());
diff --git a/llvm/lib/Target/AMDGPU/SIPostRABundler.h b/llvm/lib/Target/AMDGPU/SIPostRABundler.h
new file mode 100644
index 00000000000000..2038bbe1617f4f
--- /dev/null
+++ b/llvm/lib/Target/AMDGPU/SIPostRABundler.h
@@ -0,0 +1,22 @@
+//===- SIPostRABundler.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_LIB_TARGET_AMDGPU_SIPOSTRABUNDLER_H
+#define LLVM_LIB_TARGET_AMDGPU_SIPOSTRABUNDLER_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+class SIPostRABundlerPass : public PassInfoMixin<SIPostRABundlerPass> {
+public:
+ PreservedAnalyses run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM);
+};
+} // namespace llvm
+
+#endif // LLVM_LIB_TARGET_AMDGPU_SIPOSTRABUNDLER_H
diff --git a/llvm/test/CodeGen/AMDGPU/postra-bundle-memops.mir b/llvm/test/CodeGen/AMDGPU/postra-bundle-memops.mir
index b878ee51cdb433..458afca384911e 100644
--- a/llvm/test/CodeGen/AMDGPU/postra-bundle-memops.mir
+++ b/llvm/test/CodeGen/AMDGPU/postra-bundle-memops.mir
@@ -1,5 +1,6 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -verify-machineinstrs -run-pass=si-post-ra-bundler %s -o - | FileCheck -check-prefix=GCN %s
+# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -passes=si-post-ra-bundler %s -o - | FileCheck -check-prefix=GCN %s
---
name: bundle_memops
>From 5a4587009ac55b4693e23172b4d59c2bb07562a5 Mon Sep 17 00:00:00 2001
From: Akshat Oke <Akshat.Oke at amd.com>
Date: Tue, 21 Jan 2025 09:39:23 +0000
Subject: [PATCH 2/2] clang-format
---
llvm/lib/Target/AMDGPU/AMDGPU.h | 2 +-
llvm/lib/Target/AMDGPU/SIPostRABundler.cpp | 9 ++++++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 846b7c98399a4a..0c5178ec23170e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -428,7 +428,7 @@ extern char &SIInsertWaitcntsID;
void initializeSIFormMemoryClausesPass(PassRegistry&);
extern char &SIFormMemoryClausesID;
-void initializeSIPostRABundlerLegacyPass(PassRegistry&);
+void initializeSIPostRABundlerLegacyPass(PassRegistry &);
extern char &SIPostRABundlerLegacyID;
void initializeGCNCreateVOPDPass(PassRegistry &);
diff --git a/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp b/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp
index cbd8f3ad5c5e61..87ff4b4d369407 100644
--- a/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp
+++ b/llvm/lib/Target/AMDGPU/SIPostRABundler.cpp
@@ -47,7 +47,8 @@ class SIPostRABundlerLegacy : public MachineFunctionPass {
class SIPostRABundler {
public:
- bool run(MachineFunction &MF);
+ bool run(MachineFunction &MF);
+
private:
const SIRegisterInfo *TRI;
@@ -67,7 +68,8 @@ constexpr uint64_t MemFlags = SIInstrFlags::MTBUF | SIInstrFlags::MUBUF |
} // End anonymous namespace.
-INITIALIZE_PASS(SIPostRABundlerLegacy, DEBUG_TYPE, "SI post-RA bundler", false, false)
+INITIALIZE_PASS(SIPostRABundlerLegacy, DEBUG_TYPE, "SI post-RA bundler", false,
+ false)
char SIPostRABundlerLegacy::ID = 0;
@@ -132,7 +134,8 @@ bool SIPostRABundlerLegacy::runOnMachineFunction(MachineFunction &MF) {
return SIPostRABundler().run(MF);
}
-PreservedAnalyses SIPostRABundlerPass::run(MachineFunction &MF, MachineFunctionAnalysisManager &) {
+PreservedAnalyses SIPostRABundlerPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &) {
SIPostRABundler().run(MF);
return PreservedAnalyses::all();
}
More information about the llvm-commits
mailing list