Skip to content

Commit 5901d89

Browse files
authored
[AMDGPU] Register amdgpu-lower-vgpr-encoding pass in npm (#156971)
1 parent 6030416 commit 5901d89

File tree

6 files changed

+69
-22
lines changed

6 files changed

+69
-22
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ extern char &SIModeRegisterID;
501501
void initializeAMDGPUInsertDelayAluLegacyPass(PassRegistry &);
502502
extern char &AMDGPUInsertDelayAluID;
503503

504-
void initializeAMDGPULowerVGPREncodingPass(PassRegistry &);
505-
extern char &AMDGPULowerVGPREncodingID;
504+
void initializeAMDGPULowerVGPREncodingLegacyPass(PassRegistry &);
505+
extern char &AMDGPULowerVGPREncodingLegacyID;
506506

507507
void initializeSIInsertHardClausesLegacyPass(PassRegistry &);
508508
extern char &SIInsertHardClausesID;

llvm/lib/Target/AMDGPU/AMDGPULowerVGPREncoding.cpp

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//
4141
//===----------------------------------------------------------------------===//
4242

43+
#include "AMDGPULowerVGPREncoding.h"
4344
#include "AMDGPU.h"
4445
#include "GCNSubtarget.h"
4546
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -52,7 +53,7 @@ using namespace llvm;
5253

5354
namespace {
5455

55-
class AMDGPULowerVGPREncoding : public MachineFunctionPass {
56+
class AMDGPULowerVGPREncoding {
5657
static constexpr unsigned OpNum = 4;
5758
static constexpr unsigned BitsPerField = 2;
5859
static constexpr unsigned NumFields = 4;
@@ -75,16 +76,7 @@ class AMDGPULowerVGPREncoding : public MachineFunctionPass {
7576
};
7677

7778
public:
78-
static char ID;
79-
80-
AMDGPULowerVGPREncoding() : MachineFunctionPass(ID) {}
81-
82-
void getAnalysisUsage(AnalysisUsage &AU) const override {
83-
AU.setPreservesCFG();
84-
MachineFunctionPass::getAnalysisUsage(AU);
85-
}
86-
87-
bool runOnMachineFunction(MachineFunction &MF) override;
79+
bool run(MachineFunction &MF);
8880

8981
private:
9082
const SIInstrInfo *TII;
@@ -280,7 +272,7 @@ MachineInstr *AMDGPULowerVGPREncoding::handleClause(MachineInstr *I) {
280272
return I;
281273
}
282274

283-
bool AMDGPULowerVGPREncoding::runOnMachineFunction(MachineFunction &MF) {
275+
bool AMDGPULowerVGPREncoding::run(MachineFunction &MF) {
284276
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
285277
if (!ST.has1024AddressableVGPRs())
286278
return false;
@@ -344,11 +336,38 @@ bool AMDGPULowerVGPREncoding::runOnMachineFunction(MachineFunction &MF) {
344336
return Changed;
345337
}
346338

339+
class AMDGPULowerVGPREncodingLegacy : public MachineFunctionPass {
340+
public:
341+
static char ID;
342+
343+
AMDGPULowerVGPREncodingLegacy() : MachineFunctionPass(ID) {}
344+
345+
bool runOnMachineFunction(MachineFunction &MF) override {
346+
return AMDGPULowerVGPREncoding().run(MF);
347+
}
348+
349+
void getAnalysisUsage(AnalysisUsage &AU) const override {
350+
AU.setPreservesCFG();
351+
MachineFunctionPass::getAnalysisUsage(AU);
352+
}
353+
};
354+
347355
} // namespace
348356

349-
char AMDGPULowerVGPREncoding::ID = 0;
357+
char AMDGPULowerVGPREncodingLegacy::ID = 0;
350358

351-
char &llvm::AMDGPULowerVGPREncodingID = AMDGPULowerVGPREncoding::ID;
359+
char &llvm::AMDGPULowerVGPREncodingLegacyID = AMDGPULowerVGPREncodingLegacy::ID;
352360

353-
INITIALIZE_PASS(AMDGPULowerVGPREncoding, DEBUG_TYPE,
361+
INITIALIZE_PASS(AMDGPULowerVGPREncodingLegacy, DEBUG_TYPE,
354362
"AMDGPU Lower VGPR Encoding", false, false)
363+
364+
PreservedAnalyses
365+
AMDGPULowerVGPREncodingPass::run(MachineFunction &MF,
366+
MachineFunctionAnalysisManager &MFAM) {
367+
if (!AMDGPULowerVGPREncoding().run(MF))
368+
return PreservedAnalyses::all();
369+
370+
PreservedAnalyses PA;
371+
PA.preserveSet<CFGAnalyses>();
372+
return PA;
373+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===--- AMDGPULowerVGPREncoding.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_AMDGPULOWERVGPRENCODING_H
10+
#define LLVM_LIB_TARGET_AMDGPU_AMDGPULOWERVGPRENCODING_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class AMDGPULowerVGPREncodingPass
17+
: public PassInfoMixin<AMDGPULowerVGPREncodingPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
};
22+
23+
} // namespace llvm
24+
25+
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPULOWERVGPRENCODING_H

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ MACHINE_FUNCTION_ANALYSIS("amdgpu-resource-usage", AMDGPUResourceUsageAnalysis(*
106106
#endif
107107
MACHINE_FUNCTION_PASS("amdgpu-insert-delay-alu", AMDGPUInsertDelayAluPass())
108108
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
109+
MACHINE_FUNCTION_PASS("amdgpu-lower-vgpr-encoding", AMDGPULowerVGPREncodingPass())
109110
MACHINE_FUNCTION_PASS("amdgpu-mark-last-scratch-load", AMDGPUMarkLastScratchLoadPass())
110111
MACHINE_FUNCTION_PASS("amdgpu-pre-ra-long-branch-reg", GCNPreRALongBranchRegPass())
111112
MACHINE_FUNCTION_PASS("amdgpu-reserve-wwm-regs", AMDGPUReserveWWMRegsPass())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "AMDGPUExportKernelRuntimeHandles.h"
2323
#include "AMDGPUIGroupLP.h"
2424
#include "AMDGPUISelDAGToDAG.h"
25+
#include "AMDGPULowerVGPREncoding.h"
2526
#include "AMDGPUMacroFusion.h"
2627
#include "AMDGPUPerfHintAnalysis.h"
2728
#include "AMDGPUPreloadKernArgProlog.h"
@@ -584,7 +585,7 @@ extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
584585
initializeAMDGPURewriteUndefForPHILegacyPass(*PR);
585586
initializeSIAnnotateControlFlowLegacyPass(*PR);
586587
initializeAMDGPUInsertDelayAluLegacyPass(*PR);
587-
initializeAMDGPULowerVGPREncodingPass(*PR);
588+
initializeAMDGPULowerVGPREncodingLegacyPass(*PR);
588589
initializeSIInsertHardClausesLegacyPass(*PR);
589590
initializeSIInsertWaitcntsLegacyPass(*PR);
590591
initializeSIModeRegisterLegacyPass(*PR);
@@ -1800,7 +1801,7 @@ void GCNPassConfig::addPreEmitPass() {
18001801

18011802
addPass(&AMDGPUWaitSGPRHazardsLegacyID);
18021803

1803-
addPass(&AMDGPULowerVGPREncodingID);
1804+
addPass(&AMDGPULowerVGPREncodingLegacyID);
18041805

18051806
if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
18061807
addPass(&AMDGPUInsertDelayAluID);
@@ -2389,6 +2390,7 @@ void AMDGPUCodeGenPassBuilder::addPreEmitPass(AddMachinePass &addPass) const {
23892390
// cases.
23902391
addPass(PostRAHazardRecognizerPass());
23912392
addPass(AMDGPUWaitSGPRHazardsPass());
2393+
addPass(AMDGPULowerVGPREncodingPass());
23922394

23932395
if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
23942396
addPass(AMDGPUInsertDelayAluPass());

0 commit comments

Comments
 (0)