Skip to content

Commit bd16a87

Browse files
authored
[AMDGPU][NewPM] Port SIPostRABundler to NPM (#123717)
1 parent 6bd88bb commit bd16a87

File tree

6 files changed

+54
-12
lines changed

6 files changed

+54
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ extern char &SIInsertWaitcntsID;
428428
void initializeSIFormMemoryClausesLegacyPass(PassRegistry &);
429429
extern char &SIFormMemoryClausesID;
430430

431-
void initializeSIPostRABundlerPass(PassRegistry&);
432-
extern char &SIPostRABundlerID;
431+
void initializeSIPostRABundlerLegacyPass(PassRegistry &);
432+
extern char &SIPostRABundlerLegacyID;
433433

434434
void initializeGCNCreateVOPDPass(PassRegistry &);
435435
extern char &GCNCreateVOPDID;

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ MACHINE_FUNCTION_PASS("si-opt-vgpr-liverange", SIOptimizeVGPRLiveRangePass())
115115
MACHINE_FUNCTION_PASS("si-optimize-exec-masking", SIOptimizeExecMaskingPass())
116116
MACHINE_FUNCTION_PASS("si-optimize-exec-masking-pre-ra", SIOptimizeExecMaskingPreRAPass())
117117
MACHINE_FUNCTION_PASS("si-peephole-sdwa", SIPeepholeSDWAPass())
118+
MACHINE_FUNCTION_PASS("si-post-ra-bundler", SIPostRABundlerPass())
118119
MACHINE_FUNCTION_PASS("si-pre-allocate-wwm-regs", SIPreAllocateWWMRegsPass())
119120
MACHINE_FUNCTION_PASS("si-shrink-instructions", SIShrinkInstructionsPass())
120121
MACHINE_FUNCTION_PASS("si-wqm", SIWholeQuadModePass())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "SIOptimizeExecMaskingPreRA.h"
5555
#include "SIOptimizeVGPRLiveRange.h"
5656
#include "SIPeepholeSDWA.h"
57+
#include "SIPostRABundler.h"
5758
#include "SIPreAllocateWWMRegs.h"
5859
#include "SIShrinkInstructions.h"
5960
#include "SIWholeQuadMode.h"
@@ -544,7 +545,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
544545
initializeSIOptimizeExecMaskingLegacyPass(*PR);
545546
initializeSIPreAllocateWWMRegsLegacyPass(*PR);
546547
initializeSIFormMemoryClausesLegacyPass(*PR);
547-
initializeSIPostRABundlerPass(*PR);
548+
initializeSIPostRABundlerLegacyPass(*PR);
548549
initializeGCNCreateVOPDPass(*PR);
549550
initializeAMDGPUUnifyDivergentExitNodesPass(*PR);
550551
initializeAMDGPUAAWrapperPassPass(*PR);
@@ -1658,7 +1659,7 @@ void GCNPassConfig::addPostRegAlloc() {
16581659
void GCNPassConfig::addPreSched2() {
16591660
if (TM->getOptLevel() > CodeGenOptLevel::None)
16601661
addPass(createSIShrinkInstructionsLegacyPass());
1661-
addPass(&SIPostRABundlerID);
1662+
addPass(&SIPostRABundlerLegacyID);
16621663
}
16631664

16641665
void GCNPassConfig::addPreEmitPass() {

llvm/lib/Target/AMDGPU/SIPostRABundler.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
///
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "SIPostRABundler.h"
1516
#include "AMDGPU.h"
1617
#include "GCNSubtarget.h"
1718
#include "llvm/ADT/SmallSet.h"
@@ -23,13 +24,13 @@ using namespace llvm;
2324

2425
namespace {
2526

26-
class SIPostRABundler : public MachineFunctionPass {
27+
class SIPostRABundlerLegacy : public MachineFunctionPass {
2728
public:
2829
static char ID;
2930

3031
public:
31-
SIPostRABundler() : MachineFunctionPass(ID) {
32-
initializeSIPostRABundlerPass(*PassRegistry::getPassRegistry());
32+
SIPostRABundlerLegacy() : MachineFunctionPass(ID) {
33+
initializeSIPostRABundlerLegacyPass(*PassRegistry::getPassRegistry());
3334
}
3435

3536
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -42,6 +43,11 @@ class SIPostRABundler : public MachineFunctionPass {
4243
AU.setPreservesAll();
4344
MachineFunctionPass::getAnalysisUsage(AU);
4445
}
46+
};
47+
48+
class SIPostRABundler {
49+
public:
50+
bool run(MachineFunction &MF);
4551

4652
private:
4753
const SIRegisterInfo *TRI;
@@ -62,14 +68,15 @@ constexpr uint64_t MemFlags = SIInstrFlags::MTBUF | SIInstrFlags::MUBUF |
6268

6369
} // End anonymous namespace.
6470

65-
INITIALIZE_PASS(SIPostRABundler, DEBUG_TYPE, "SI post-RA bundler", false, false)
71+
INITIALIZE_PASS(SIPostRABundlerLegacy, DEBUG_TYPE, "SI post-RA bundler", false,
72+
false)
6673

67-
char SIPostRABundler::ID = 0;
74+
char SIPostRABundlerLegacy::ID = 0;
6875

69-
char &llvm::SIPostRABundlerID = SIPostRABundler::ID;
76+
char &llvm::SIPostRABundlerLegacyID = SIPostRABundlerLegacy::ID;
7077

7178
FunctionPass *llvm::createSIPostRABundlerPass() {
72-
return new SIPostRABundler();
79+
return new SIPostRABundlerLegacy();
7380
}
7481

7582
bool SIPostRABundler::isDependentLoad(const MachineInstr &MI) const {
@@ -121,9 +128,19 @@ bool SIPostRABundler::canBundle(const MachineInstr &MI,
121128
!isDependentLoad(NextMI));
122129
}
123130

124-
bool SIPostRABundler::runOnMachineFunction(MachineFunction &MF) {
131+
bool SIPostRABundlerLegacy::runOnMachineFunction(MachineFunction &MF) {
125132
if (skipFunction(MF.getFunction()))
126133
return false;
134+
return SIPostRABundler().run(MF);
135+
}
136+
137+
PreservedAnalyses SIPostRABundlerPass::run(MachineFunction &MF,
138+
MachineFunctionAnalysisManager &) {
139+
SIPostRABundler().run(MF);
140+
return PreservedAnalyses::all();
141+
}
142+
143+
bool SIPostRABundler::run(MachineFunction &MF) {
127144

128145
TRI = MF.getSubtarget<GCNSubtarget>().getRegisterInfo();
129146
BitVector BundleUsedRegUnits(TRI->getNumRegUnits());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- SIPostRABundler.h ----------------------------------------*- C++- *-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIB_TARGET_AMDGPU_SIPOSTRABUNDLER_H
10+
#define LLVM_LIB_TARGET_AMDGPU_SIPOSTRABUNDLER_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
class SIPostRABundlerPass : public PassInfoMixin<SIPostRABundlerPass> {
16+
public:
17+
PreservedAnalyses run(MachineFunction &MF,
18+
MachineFunctionAnalysisManager &MFAM);
19+
};
20+
} // namespace llvm
21+
22+
#endif // LLVM_LIB_TARGET_AMDGPU_SIPOSTRABUNDLER_H

llvm/test/CodeGen/AMDGPU/postra-bundle-memops.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -verify-machineinstrs -run-pass=si-post-ra-bundler %s -o - | FileCheck -check-prefix=GCN %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -passes=si-post-ra-bundler %s -o - | FileCheck -check-prefix=GCN %s
34

45
---
56
name: bundle_memops

0 commit comments

Comments
 (0)