Skip to content

Commit 9b6e8df

Browse files
authored
[AMDGPU][NewPM] Port SIFixVGPRCopies to NPM (#123592)
Extends NPM pipeline support till PostRegAlloc passes (greedy is in the works)
1 parent b6b18f1 commit 9b6e8df

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extern char &SIShrinkInstructionsLegacyID;
177177
void initializeSIFixSGPRCopiesLegacyPass(PassRegistry &);
178178
extern char &SIFixSGPRCopiesLegacyID;
179179

180-
void initializeSIFixVGPRCopiesPass(PassRegistry &);
180+
void initializeSIFixVGPRCopiesLegacyPass(PassRegistry &);
181181
extern char &SIFixVGPRCopiesID;
182182

183183
void initializeSILowerWWMCopiesPass(PassRegistry &);

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ FUNCTION_PASS_WITH_PARAMS(
9999
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
100100
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
101101
MACHINE_FUNCTION_PASS("si-i1-copies", SILowerI1CopiesPass())
102+
MACHINE_FUNCTION_PASS("si-fix-vgpr-copies", SIFixVGPRCopiesPass())
102103
MACHINE_FUNCTION_PASS("si-fold-operands", SIFoldOperandsPass());
103104
MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
104105
MACHINE_FUNCTION_PASS("si-load-store-opt", SILoadStoreOptimizerPass())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "R600.h"
3737
#include "R600TargetMachine.h"
3838
#include "SIFixSGPRCopies.h"
39+
#include "SIFixVGPRCopies.h"
3940
#include "SIFoldOperands.h"
4041
#include "SILoadStoreOptimizer.h"
4142
#include "SILowerControlFlow.h"
@@ -486,7 +487,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
486487
initializeAMDGPUMarkLastScratchLoadPass(*PR);
487488
initializeSILowerSGPRSpillsLegacyPass(*PR);
488489
initializeSIFixSGPRCopiesLegacyPass(*PR);
489-
initializeSIFixVGPRCopiesPass(*PR);
490+
initializeSIFixVGPRCopiesLegacyPass(*PR);
490491
initializeSIFoldOperandsLegacyPass(*PR);
491492
initializeSIPeepholeSDWALegacyPass(*PR);
492493
initializeSIShrinkInstructionsLegacyPass(*PR);
@@ -2107,7 +2108,7 @@ void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
21072108
}
21082109

21092110
void AMDGPUCodeGenPassBuilder::addPostRegAlloc(AddMachinePass &addPass) const {
2110-
// addPass(SIFixVGPRCopiesID);
2111+
addPass(SIFixVGPRCopiesPass());
21112112
if (TM.getOptLevel() > CodeGenOptLevel::None)
21122113
addPass(SIOptimizeExecMaskingPass());
21132114
Base::addPostRegAlloc(addPass);

llvm/lib/Target/AMDGPU/SIFixVGPRCopies.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
///
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "SIFixVGPRCopies.h"
1415
#include "AMDGPU.h"
1516
#include "GCNSubtarget.h"
1617
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -22,13 +23,12 @@ using namespace llvm;
2223

2324
namespace {
2425

25-
class SIFixVGPRCopies : public MachineFunctionPass {
26+
class SIFixVGPRCopiesLegacy : public MachineFunctionPass {
2627
public:
2728
static char ID;
2829

29-
public:
30-
SIFixVGPRCopies() : MachineFunctionPass(ID) {
31-
initializeSIFixVGPRCopiesPass(*PassRegistry::getPassRegistry());
30+
SIFixVGPRCopiesLegacy() : MachineFunctionPass(ID) {
31+
initializeSIFixVGPRCopiesLegacyPass(*PassRegistry::getPassRegistry());
3232
}
3333

3434
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -41,15 +41,31 @@ class SIFixVGPRCopies : public MachineFunctionPass {
4141
StringRef getPassName() const override { return "SI Fix VGPR copies"; }
4242
};
4343

44+
class SIFixVGPRCopies {
45+
public:
46+
bool run(MachineFunction &MF);
47+
};
48+
4449
} // End anonymous namespace.
4550

46-
INITIALIZE_PASS(SIFixVGPRCopies, DEBUG_TYPE, "SI Fix VGPR copies", false, false)
51+
INITIALIZE_PASS(SIFixVGPRCopiesLegacy, DEBUG_TYPE, "SI Fix VGPR copies", false,
52+
false)
4753

48-
char SIFixVGPRCopies::ID = 0;
54+
char SIFixVGPRCopiesLegacy::ID = 0;
4955

50-
char &llvm::SIFixVGPRCopiesID = SIFixVGPRCopies::ID;
56+
char &llvm::SIFixVGPRCopiesID = SIFixVGPRCopiesLegacy::ID;
57+
58+
PreservedAnalyses SIFixVGPRCopiesPass::run(MachineFunction &MF,
59+
MachineFunctionAnalysisManager &) {
60+
SIFixVGPRCopies().run(MF);
61+
return PreservedAnalyses::all();
62+
}
63+
64+
bool SIFixVGPRCopiesLegacy::runOnMachineFunction(MachineFunction &MF) {
65+
return SIFixVGPRCopies().run(MF);
66+
}
5167

52-
bool SIFixVGPRCopies::runOnMachineFunction(MachineFunction &MF) {
68+
bool SIFixVGPRCopies::run(MachineFunction &MF) {
5369
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
5470
const SIRegisterInfo *TRI = ST.getRegisterInfo();
5571
const SIInstrInfo *TII = ST.getInstrInfo();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- SIFixVGPRCopies.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_SIFIXVGPRCOPIES_H
10+
#define LLVM_LIB_TARGET_AMDGPU_SIFIXVGPRCOPIES_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
class SIFixVGPRCopiesPass : public PassInfoMixin<SIFixVGPRCopiesPass> {
16+
public:
17+
PreservedAnalyses run(MachineFunction &MF,
18+
MachineFunctionAnalysisManager &MFAM);
19+
};
20+
} // namespace llvm
21+
22+
#endif // LLVM_LIB_TARGET_AMDGPU_SIFIXVGPRCOPIES_H

llvm/test/CodeGen/AMDGPU/fix-vgpr-copies.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# RUN: llc -mtriple=amdgcn -start-after=greedy -disable-copyprop -stop-after=si-optimize-exec-masking -o - %s | FileCheck %s
2+
# RUN: llc -mtriple=amdgcn -passes=si-fix-vgpr-copies,si-optimize-exec-masking -o - %s | FileCheck %s
3+
24
# Check that we first do all vector instructions and only then change exec
35
# CHECK-DAG: COPY $vgpr10_vgpr11
46
# CHECK-DAG: COPY $vgpr12_vgpr13

0 commit comments

Comments
 (0)