Skip to content

[AMDGPU][NewPM] Port AMDGPUReserveWWMRegs to NPM #123722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ struct AMDGPULowerBufferFatPointersPass
const TargetMachine &TM;
};

void initializeAMDGPUReserveWWMRegsPass(PassRegistry &);
extern char &AMDGPUReserveWWMRegsID;
void initializeAMDGPUReserveWWMRegsLegacyPass(PassRegistry &);
extern char &AMDGPUReserveWWMRegsLegacyID;

void initializeAMDGPURewriteOutArgumentsPass(PassRegistry &);
extern char &AMDGPURewriteOutArgumentsID;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ FUNCTION_PASS_WITH_PARAMS(
MACHINE_FUNCTION_PASS("amdgpu-insert-delay-alu", AMDGPUInsertDelayAluPass())
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
MACHINE_FUNCTION_PASS("amdgpu-pre-ra-long-branch-reg", GCNPreRALongBranchRegPass())
MACHINE_FUNCTION_PASS("amdgpu-reserve-wwm-regs", AMDGPUReserveWWMRegsPass())
MACHINE_FUNCTION_PASS("amdgpu-rewrite-partial-reg-uses", GCNRewritePartialRegUsesPass())
MACHINE_FUNCTION_PASS("amdgpu-pre-ra-optimizations", GCNPreRAOptimizationsPass())
MACHINE_FUNCTION_PASS("amdgpu-nsa-reassign", GCNNSAReassignPass())
Expand Down
33 changes: 26 additions & 7 deletions llvm/lib/Target/AMDGPU/AMDGPUReserveWWMRegs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
//===----------------------------------------------------------------------===//

#include "AMDGPUReserveWWMRegs.h"
#include "AMDGPU.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "SIMachineFunctionInfo.h"
Expand All @@ -27,12 +28,12 @@ using namespace llvm;

namespace {

class AMDGPUReserveWWMRegs : public MachineFunctionPass {
class AMDGPUReserveWWMRegsLegacy : public MachineFunctionPass {
public:
static char ID;

AMDGPUReserveWWMRegs() : MachineFunctionPass(ID) {
initializeAMDGPUReserveWWMRegsPass(*PassRegistry::getPassRegistry());
AMDGPUReserveWWMRegsLegacy() : MachineFunctionPass(ID) {
initializeAMDGPUReserveWWMRegsLegacyPass(*PassRegistry::getPassRegistry());
}

bool runOnMachineFunction(MachineFunction &MF) override;
Expand All @@ -47,16 +48,34 @@ class AMDGPUReserveWWMRegs : public MachineFunctionPass {
}
};

class AMDGPUReserveWWMRegs {
public:
bool run(MachineFunction &MF);
};

} // End anonymous namespace.

INITIALIZE_PASS(AMDGPUReserveWWMRegs, DEBUG_TYPE,
INITIALIZE_PASS(AMDGPUReserveWWMRegsLegacy, DEBUG_TYPE,
"AMDGPU Reserve WWM Registers", false, false)

char AMDGPUReserveWWMRegs::ID = 0;
char AMDGPUReserveWWMRegsLegacy::ID = 0;

char &llvm::AMDGPUReserveWWMRegsLegacyID = AMDGPUReserveWWMRegsLegacy::ID;

char &llvm::AMDGPUReserveWWMRegsID = AMDGPUReserveWWMRegs::ID;
bool AMDGPUReserveWWMRegsLegacy::runOnMachineFunction(MachineFunction &MF) {
return AMDGPUReserveWWMRegs().run(MF);
}

PreservedAnalyses
AMDGPUReserveWWMRegsPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &) {
AMDGPUReserveWWMRegs().run(MF);
// TODO: This should abandon RegisterClassInfo once it is turned into an
// analysis.
return PreservedAnalyses::all();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an open PR to treat RegisterClassInfo as an analysis this will not preserve

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a fixme to do something about RegisterClassInfo

}

bool AMDGPUReserveWWMRegs::runOnMachineFunction(MachineFunction &MF) {
bool AMDGPUReserveWWMRegs::run(MachineFunction &MF) {
SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();

bool Changed = false;
Expand Down
24 changes: 24 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUReserveWWMRegs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- AMDGPUReserveWWMRegs.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_AMDGPURESERVEWWMREGS_H
#define LLVM_LIB_TARGET_AMDGPU_AMDGPURESERVEWWMREGS_H

#include "llvm/CodeGen/MachinePassManager.h"

namespace llvm {
class AMDGPUReserveWWMRegsPass
: public PassInfoMixin<AMDGPUReserveWWMRegsPass> {
public:
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
static bool isRequired() { return true; }
};
} // namespace llvm

#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURESERVEWWMREGS_H
7 changes: 4 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "AMDGPUOpenCLEnqueuedBlockLowering.h"
#include "AMDGPUPerfHintAnalysis.h"
#include "AMDGPURemoveIncompatibleFunctions.h"
#include "AMDGPUReserveWWMRegs.h"
#include "AMDGPUSplitModule.h"
#include "AMDGPUTargetObjectFile.h"
#include "AMDGPUTargetTransformInfo.h"
Expand Down Expand Up @@ -528,7 +529,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeAMDGPURemoveIncompatibleFunctionsLegacyPass(*PR);
initializeAMDGPULowerModuleLDSLegacyPass(*PR);
initializeAMDGPULowerBufferFatPointersPass(*PR);
initializeAMDGPUReserveWWMRegsPass(*PR);
initializeAMDGPUReserveWWMRegsLegacyPass(*PR);
initializeAMDGPURewriteOutArgumentsPass(*PR);
initializeAMDGPURewriteUndefForPHILegacyPass(*PR);
initializeAMDGPUUnifyMetadataPass(*PR);
Expand Down Expand Up @@ -1599,7 +1600,7 @@ bool GCNPassConfig::addRegAssignAndRewriteFast() {
addPass(createWWMRegAllocPass(false));

addPass(&SILowerWWMCopiesLegacyID);
addPass(&AMDGPUReserveWWMRegsID);
addPass(&AMDGPUReserveWWMRegsLegacyID);

// For allocating per-thread VGPRs.
addPass(createVGPRAllocPass(false));
Expand Down Expand Up @@ -1636,7 +1637,7 @@ bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
addPass(createWWMRegAllocPass(true));
addPass(&SILowerWWMCopiesLegacyID);
addPass(createVirtRegRewriter(false));
addPass(&AMDGPUReserveWWMRegsID);
addPass(&AMDGPUReserveWWMRegsLegacyID);

// For allocating per-thread VGPRs.
addPass(createVGPRAllocPass(true));
Expand Down