Skip to content

Commit 6794b4c

Browse files
committed
[AMDGPU][NewPM] Port AMDGPUMarkLastScratchLoad to NPM
1 parent d96ec48 commit 6794b4c

File tree

7 files changed

+68
-15
lines changed

7 files changed

+68
-15
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ extern char &AMDGPURegBankSelectID;
195195
void initializeAMDGPURegBankLegalizePass(PassRegistry &);
196196
extern char &AMDGPURegBankLegalizeID;
197197

198-
void initializeAMDGPUMarkLastScratchLoadPass(PassRegistry &);
199-
extern char &AMDGPUMarkLastScratchLoadID;
198+
void initializeAMDGPUMarkLastScratchLoadLegacyPass(PassRegistry &);
199+
extern char &AMDGPUMarkLastScratchLoadLegacyID;
200200

201201
void initializeSILowerSGPRSpillsLegacyPass(PassRegistry &);
202202
extern char &SILowerSGPRSpillsLegacyID;

llvm/lib/Target/AMDGPU/AMDGPUMarkLastScratchLoad.cpp

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16+
#include "AMDGPUMarkLastScratchLoad.h"
1617
#include "AMDGPU.h"
1718
#include "GCNSubtarget.h"
1819
#include "llvm/CodeGen/LiveIntervals.h"
@@ -25,18 +26,26 @@ using namespace llvm;
2526

2627
namespace {
2728

28-
class AMDGPUMarkLastScratchLoad : public MachineFunctionPass {
29+
class AMDGPUMarkLastScratchLoad {
2930
private:
3031
LiveStacks *LS = nullptr;
3132
LiveIntervals *LIS = nullptr;
3233
SlotIndexes *SI = nullptr;
3334
const SIInstrInfo *SII = nullptr;
3435

36+
public:
37+
AMDGPUMarkLastScratchLoad(LiveStacks *LS, LiveIntervals *LIS, SlotIndexes *SI)
38+
: LS(LS), LIS(LIS), SI(SI) {}
39+
bool run(MachineFunction &MF);
40+
};
41+
42+
class AMDGPUMarkLastScratchLoadLegacy : public MachineFunctionPass {
3543
public:
3644
static char ID;
3745

38-
AMDGPUMarkLastScratchLoad() : MachineFunctionPass(ID) {
39-
initializeAMDGPUMarkLastScratchLoadPass(*PassRegistry::getPassRegistry());
46+
AMDGPUMarkLastScratchLoadLegacy() : MachineFunctionPass(ID) {
47+
initializeAMDGPUMarkLastScratchLoadLegacyPass(
48+
*PassRegistry::getPassRegistry());
4049
}
4150

4251
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -56,17 +65,33 @@ class AMDGPUMarkLastScratchLoad : public MachineFunctionPass {
5665

5766
} // end anonymous namespace
5867

59-
bool AMDGPUMarkLastScratchLoad::runOnMachineFunction(MachineFunction &MF) {
68+
bool AMDGPUMarkLastScratchLoadLegacy::runOnMachineFunction(
69+
MachineFunction &MF) {
6070
if (skipFunction(MF.getFunction()))
6171
return false;
72+
auto *LS = &getAnalysis<LiveStacksWrapperLegacy>().getLS();
73+
auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
74+
auto *SI = &getAnalysis<SlotIndexesWrapperPass>().getSI();
75+
76+
return AMDGPUMarkLastScratchLoad(LS, LIS, SI).run(MF);
77+
}
78+
79+
PreservedAnalyses
80+
AMDGPUMarkLastScratchLoadPass::run(MachineFunction &MF,
81+
MachineFunctionAnalysisManager &MFAM) {
82+
auto *LS = &MFAM.getResult<LiveStacksAnalysis>(MF);
83+
auto *LIS = &MFAM.getResult<LiveIntervalsAnalysis>(MF);
84+
auto *SI = &MFAM.getResult<SlotIndexesAnalysis>(MF);
85+
86+
AMDGPUMarkLastScratchLoad(LS, LIS, SI).run(MF);
87+
return PreservedAnalyses::all();
88+
}
6289

90+
bool AMDGPUMarkLastScratchLoad::run(MachineFunction &MF) {
6391
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
6492
if (ST.getGeneration() < AMDGPUSubtarget::GFX12)
6593
return false;
6694

67-
LS = &getAnalysis<LiveStacksWrapperLegacy>().getLS();
68-
LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
69-
SI = &getAnalysis<SlotIndexesWrapperPass>().getSI();
7095
SII = ST.getInstrInfo();
7196
SlotIndexes &Slots = *LIS->getSlotIndexes();
7297

@@ -130,13 +155,14 @@ bool AMDGPUMarkLastScratchLoad::runOnMachineFunction(MachineFunction &MF) {
130155
return Changed;
131156
}
132157

133-
char AMDGPUMarkLastScratchLoad::ID = 0;
158+
char AMDGPUMarkLastScratchLoadLegacy::ID = 0;
134159

135-
char &llvm::AMDGPUMarkLastScratchLoadID = AMDGPUMarkLastScratchLoad::ID;
160+
char &llvm::AMDGPUMarkLastScratchLoadLegacyID =
161+
AMDGPUMarkLastScratchLoadLegacy::ID;
136162

137-
INITIALIZE_PASS_BEGIN(AMDGPUMarkLastScratchLoad, DEBUG_TYPE,
163+
INITIALIZE_PASS_BEGIN(AMDGPUMarkLastScratchLoadLegacy, DEBUG_TYPE,
138164
"AMDGPU Mark last scratch load", false, false)
139165
INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass)
140166
INITIALIZE_PASS_DEPENDENCY(LiveStacksWrapperLegacy)
141-
INITIALIZE_PASS_END(AMDGPUMarkLastScratchLoad, DEBUG_TYPE,
167+
INITIALIZE_PASS_END(AMDGPUMarkLastScratchLoadLegacy, DEBUG_TYPE,
142168
"AMDGPU Mark last scratch load", false, false)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===- AMDGPUMarkLastScratchLoad.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_AMDGPUMARKLASTSCRATCHLOAD_H
10+
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMARKLASTSCRATCHLOAD_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
class AMDGPUMarkLastScratchLoadPass
16+
: public PassInfoMixin<AMDGPUMarkLastScratchLoadPass> {
17+
public:
18+
PreservedAnalyses run(MachineFunction &MF,
19+
MachineFunctionAnalysisManager &MFAM);
20+
};
21+
} // namespace llvm
22+
23+
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMARKLASTSCRATCHLOAD_H

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ FUNCTION_PASS_WITH_PARAMS(
9797
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
9898
#endif
9999
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
100+
MACHINE_FUNCTION_PASS("amdgpu-mark-last-scratch-load", AMDGPUMarkLastScratchLoadPass())
100101
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
101102
MACHINE_FUNCTION_PASS("si-i1-copies", SILowerI1CopiesPass())
102103
MACHINE_FUNCTION_PASS("si-fix-vgpr-copies", SIFixVGPRCopiesPass())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "AMDGPUIGroupLP.h"
2323
#include "AMDGPUISelDAGToDAG.h"
2424
#include "AMDGPUMacroFusion.h"
25+
#include "AMDGPUMarkLastScratchLoad.h"
2526
#include "AMDGPUOpenCLEnqueuedBlockLowering.h"
2627
#include "AMDGPUPerfHintAnalysis.h"
2728
#include "AMDGPURemoveIncompatibleFunctions.h"
@@ -484,7 +485,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
484485
initializeAMDGPURegBankSelectPass(*PR);
485486
initializeAMDGPURegBankLegalizePass(*PR);
486487
initializeSILowerWWMCopiesPass(*PR);
487-
initializeAMDGPUMarkLastScratchLoadPass(*PR);
488+
initializeAMDGPUMarkLastScratchLoadLegacyPass(*PR);
488489
initializeSILowerSGPRSpillsLegacyPass(*PR);
489490
initializeSIFixSGPRCopiesLegacyPass(*PR);
490491
initializeSIFixVGPRCopiesLegacyPass(*PR);
@@ -1628,7 +1629,7 @@ bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
16281629
addPreRewrite();
16291630
addPass(&VirtRegRewriterID);
16301631

1631-
addPass(&AMDGPUMarkLastScratchLoadID);
1632+
addPass(&AMDGPUMarkLastScratchLoadLegacyID);
16321633

16331634
return true;
16341635
}

llvm/test/CodeGen/AMDGPU/live-interval-bug-in-rename-independent-subregs.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
22
# RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1010 -start-before=rename-independent-subregs -mattr=+wavefrontsize64 -stop-before=amdgpu-mark-last-scratch-load %s -o - | FileCheck -check-prefix=REG_ALLOC %s
33
# RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1010 -start-before=rename-independent-subregs -mattr=+wavefrontsize64 -stop-after=machine-cp %s -o - | FileCheck -check-prefix=DEAD_INST_DEL %s
4+
# TODO: add test for NPM once RA is ported
45

56
---
67
name: _amdgpu_cs_main

llvm/test/CodeGen/AMDGPU/vgpr-mark-last-scratch-load.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 UTC_ARGS: --version 3
22
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 -o - %s -run-pass=greedy -run-pass=amdgpu-mark-last-scratch-load -verify-machineinstrs | FileCheck -check-prefix=CHECK %s
3+
# TODO: Add test for NPM once Greedy is ported.
34

45
--- |
56
define amdgpu_cs void @test_spill_12x32() "amdgpu-num-vgpr"="12" {

0 commit comments

Comments
 (0)