Skip to content

Commit

Permalink
[CodeGen][NewPM] Port GCNPreRALongBranchReg to NPM. (#125844)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdevadas authored Feb 5, 2025
1 parent b83c960 commit 814db6c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ extern char &AMDGPUOpenCLEnqueuedBlockLoweringLegacyID;
void initializeGCNNSAReassignPass(PassRegistry &);
extern char &GCNNSAReassignID;

void initializeGCNPreRALongBranchRegPass(PassRegistry &);
void initializeGCNPreRALongBranchRegLegacyPass(PassRegistry &);
extern char &GCNPreRALongBranchRegID;

void initializeGCNPreRAOptimizationsPass(PassRegistry &);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ FUNCTION_PASS_WITH_PARAMS(
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
#endif
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
MACHINE_FUNCTION_PASS("amdgpu-pre-ra-long-branch-reg", GCNPreRALongBranchRegPass())
MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
MACHINE_FUNCTION_PASS("si-fix-vgpr-copies", SIFixVGPRCopiesPass())
Expand All @@ -117,7 +118,6 @@ MACHINE_FUNCTION_PASS("si-wqm", SIWholeQuadModePass())
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-insert-delay-alu", AMDGPUInsertDelayAluPass())
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-nsa-reassign", GCNNSAReassignPass())
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-pre-ra-long-branch-reg", GCNPreRALongBranchRegPass())
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-pre-ra-optimizations", GCNPreRAOptimizationsPass())
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-rewrite-partial-reg-uses", GCNRewritePartialRegUsesPass())
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-set-wave-priority", AMDGPUSetWavePriorityPass())
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "AMDGPUWaitSGPRHazards.h"
#include "GCNDPPCombine.h"
#include "GCNIterativeScheduler.h"
#include "GCNPreRALongBranchReg.h"
#include "GCNSchedStrategy.h"
#include "GCNVOPDUtils.h"
#include "R600.h"
Expand Down Expand Up @@ -548,7 +549,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeAMDGPUResourceUsageAnalysisPass(*PR);
initializeGCNNSAReassignPass(*PR);
initializeGCNPreRAOptimizationsPass(*PR);
initializeGCNPreRALongBranchRegPass(*PR);
initializeGCNPreRALongBranchRegLegacyPass(*PR);
initializeGCNRewritePartialRegUsesPass(*PR);
initializeGCNRegPressurePrinterPass(*PR);
initializeAMDGPUPreloadKernArgPrologLegacyPass(*PR);
Expand Down
37 changes: 29 additions & 8 deletions llvm/lib/Target/AMDGPU/GCNPreRALongBranchReg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// distrance threshold tuning of what is considered "long" is handled through
// amdgpu-long-branch-factor cl argument which sets LongBranchFactor.
//===----------------------------------------------------------------------===//
#include "GCNPreRALongBranchReg.h"
#include "AMDGPU.h"
#include "GCNSubtarget.h"
#include "SIMachineFunctionInfo.h"
Expand All @@ -36,7 +37,7 @@ static cl::opt<double> LongBranchFactor(
"reserved. We lean towards always reserving a register for "
"long jumps"));

class GCNPreRALongBranchReg : public MachineFunctionPass {
class GCNPreRALongBranchReg {

struct BasicBlockInfo {
// Offset - Distance from the beginning of the function to the beginning
Expand All @@ -48,27 +49,39 @@ class GCNPreRALongBranchReg : public MachineFunctionPass {
void generateBlockInfo(MachineFunction &MF,
SmallVectorImpl<BasicBlockInfo> &BlockInfo);

public:
GCNPreRALongBranchReg() = default;
bool run(MachineFunction &MF);
};

class GCNPreRALongBranchRegLegacy : public MachineFunctionPass {
public:
static char ID;
GCNPreRALongBranchReg() : MachineFunctionPass(ID) {
initializeGCNPreRALongBranchRegPass(*PassRegistry::getPassRegistry());
GCNPreRALongBranchRegLegacy() : MachineFunctionPass(ID) {
initializeGCNPreRALongBranchRegLegacyPass(*PassRegistry::getPassRegistry());
}
bool runOnMachineFunction(MachineFunction &MF) override;

bool runOnMachineFunction(MachineFunction &MF) override {
return GCNPreRALongBranchReg().run(MF);
}

StringRef getPassName() const override {
return "AMDGPU Pre-RA Long Branch Reg";
}

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
MachineFunctionPass::getAnalysisUsage(AU);
}
};
} // End anonymous namespace.
char GCNPreRALongBranchReg::ID = 0;

INITIALIZE_PASS(GCNPreRALongBranchReg, DEBUG_TYPE,
char GCNPreRALongBranchRegLegacy::ID = 0;

INITIALIZE_PASS(GCNPreRALongBranchRegLegacy, DEBUG_TYPE,
"AMDGPU Pre-RA Long Branch Reg", false, false)

char &llvm::GCNPreRALongBranchRegID = GCNPreRALongBranchReg::ID;
char &llvm::GCNPreRALongBranchRegID = GCNPreRALongBranchRegLegacy::ID;
void GCNPreRALongBranchReg::generateBlockInfo(
MachineFunction &MF, SmallVectorImpl<BasicBlockInfo> &BlockInfo) {

Expand Down Expand Up @@ -99,7 +112,8 @@ void GCNPreRALongBranchReg::generateBlockInfo(
PrevNum = Num;
}
}
bool GCNPreRALongBranchReg::runOnMachineFunction(MachineFunction &MF) {

bool GCNPreRALongBranchReg::run(MachineFunction &MF) {
const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
const SIInstrInfo *TII = STM.getInstrInfo();
const SIRegisterInfo *TRI = STM.getRegisterInfo();
Expand Down Expand Up @@ -136,3 +150,10 @@ bool GCNPreRALongBranchReg::runOnMachineFunction(MachineFunction &MF) {
}
return false;
}

PreservedAnalyses
GCNPreRALongBranchRegPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
GCNPreRALongBranchReg().run(MF);
return PreservedAnalyses::all();
}
23 changes: 23 additions & 0 deletions llvm/lib/Target/AMDGPU/GCNPreRALongBranchReg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===- GCNPreRALongBranchReg.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_GCNPRERALONGBRANCHREG_H
#define LLVM_LIB_TARGET_AMDGPU_GCNPRERALONGBRANCHREG_H

#include "llvm/CodeGen/MachinePassManager.h"

namespace llvm {
class GCNPreRALongBranchRegPass
: public PassInfoMixin<GCNPreRALongBranchRegPass> {
public:
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
};
} // namespace llvm

#endif // LLVM_LIB_TARGET_AMDGPU_GCNPRERALONGBRANCHREG_H

0 comments on commit 814db6c

Please sign in to comment.