Skip to content

[AMDGPU][NPM] Port SIModeRegister to NPM #129014

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 2 commits into from
Mar 4, 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
8 changes: 7 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ class AMDGPUAnnotateUniformValuesPass
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

class SIModeRegisterPass : public PassInfoMixin<SIModeRegisterPass> {
public:
SIModeRegisterPass() {}
PreservedAnalyses run(MachineFunction &F, MachineFunctionAnalysisManager &AM);
};

FunctionPass *createAMDGPUAnnotateUniformValuesLegacy();

ModulePass *createAMDGPUPrintfRuntimeBinding();
Expand Down Expand Up @@ -419,7 +425,7 @@ extern char &SIAnnotateControlFlowLegacyPassID;
void initializeSIMemoryLegalizerPass(PassRegistry&);
extern char &SIMemoryLegalizerID;

void initializeSIModeRegisterPass(PassRegistry&);
void initializeSIModeRegisterLegacyPass(PassRegistry &);
extern char &SIModeRegisterID;

void initializeAMDGPUInsertDelayAluLegacyPass(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 @@ -112,6 +112,7 @@ MACHINE_FUNCTION_PASS("si-load-store-opt", SILoadStoreOptimizerPass())
MACHINE_FUNCTION_PASS("si-lower-control-flow", SILowerControlFlowPass())
MACHINE_FUNCTION_PASS("si-lower-sgpr-spills", SILowerSGPRSpillsPass())
MACHINE_FUNCTION_PASS("si-lower-wwm-copies", SILowerWWMCopiesPass())
MACHINE_FUNCTION_PASS("si-mode-register", SIModeRegisterPass())
MACHINE_FUNCTION_PASS("si-opt-vgpr-liverange", SIOptimizeVGPRLiveRangePass())
MACHINE_FUNCTION_PASS("si-optimize-exec-masking", SIOptimizeExecMaskingPass())
MACHINE_FUNCTION_PASS("si-optimize-exec-masking-pre-ra", SIOptimizeExecMaskingPreRAPass())
Expand All @@ -131,7 +132,6 @@ DUMMY_MACHINE_FUNCTION_PASS("si-insert-hard-clauses", SIInsertHardClausesPass())
DUMMY_MACHINE_FUNCTION_PASS("si-insert-waitcnts", SIInsertWaitcntsPass())
DUMMY_MACHINE_FUNCTION_PASS("si-late-branch-lowering", SILateBranchLoweringPass())
DUMMY_MACHINE_FUNCTION_PASS("si-memory-legalizer", SIMemoryLegalizerPass())
DUMMY_MACHINE_FUNCTION_PASS("si-mode-register", SIModeRegisterPass())
DUMMY_MACHINE_FUNCTION_PASS("si-pre-emit-peephole", SIPreEmitPeepholePass())
// TODO: Move amdgpu-preload-kern-arg-prolog to MACHINE_FUNCTION_PASS since it
// already exists.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeAMDGPUInsertDelayAluLegacyPass(*PR);
initializeSIInsertHardClausesPass(*PR);
initializeSIInsertWaitcntsPass(*PR);
initializeSIModeRegisterPass(*PR);
initializeSIModeRegisterLegacyPass(*PR);
initializeSIWholeQuadModeLegacyPass(*PR);
initializeSILowerControlFlowLegacyPass(*PR);
initializeSIPreEmitPeepholePass(*PR);
Expand Down
53 changes: 36 additions & 17 deletions llvm/lib/Target/AMDGPU/SIModeRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ class BlockData {

namespace {

class SIModeRegister : public MachineFunctionPass {
class SIModeRegister {
public:
static char ID;

std::vector<std::unique_ptr<BlockData>> BlockInfo;
std::queue<MachineBasicBlock *> Phase2List;

Expand All @@ -125,15 +123,7 @@ class SIModeRegister : public MachineFunctionPass {

bool Changed = false;

public:
SIModeRegister() : MachineFunctionPass(ID) {}

bool runOnMachineFunction(MachineFunction &MF) override;

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesCFG();
MachineFunctionPass::getAnalysisUsage(AU);
}
bool run(MachineFunction &MF);

void processBlockPhase1(MachineBasicBlock &MBB, const SIInstrInfo *TII);

Expand All @@ -146,16 +136,32 @@ class SIModeRegister : public MachineFunctionPass {
void insertSetreg(MachineBasicBlock &MBB, MachineInstr *I,
const SIInstrInfo *TII, Status InstrMode);
};

class SIModeRegisterLegacy : public MachineFunctionPass {
public:
static char ID;

SIModeRegisterLegacy() : MachineFunctionPass(ID) {}

bool runOnMachineFunction(MachineFunction &MF) override;

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesCFG();
MachineFunctionPass::getAnalysisUsage(AU);
}
};
} // End anonymous namespace.

INITIALIZE_PASS(SIModeRegister, DEBUG_TYPE,
INITIALIZE_PASS(SIModeRegisterLegacy, DEBUG_TYPE,
"Insert required mode register values", false, false)

char SIModeRegister::ID = 0;
char SIModeRegisterLegacy::ID = 0;

char &llvm::SIModeRegisterID = SIModeRegister::ID;
char &llvm::SIModeRegisterID = SIModeRegisterLegacy::ID;

FunctionPass *llvm::createSIModeRegisterPass() { return new SIModeRegister(); }
FunctionPass *llvm::createSIModeRegisterPass() {
return new SIModeRegisterLegacy();
}

// Determine the Mode register setting required for this instruction.
// Instructions which don't use the Mode register return a null Status.
Expand Down Expand Up @@ -422,7 +428,20 @@ void SIModeRegister::processBlockPhase3(MachineBasicBlock &MBB,
}
}

bool SIModeRegister::runOnMachineFunction(MachineFunction &MF) {
bool SIModeRegisterLegacy::runOnMachineFunction(MachineFunction &MF) {
return SIModeRegister().run(MF);
}

PreservedAnalyses SIModeRegisterPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &AM) {
if (!SIModeRegister().run(MF))
return PreservedAnalyses::all();
auto PA = getMachineFunctionPassPreservedAnalyses();
PA.preserveSet<CFGAnalyses>();
return PA;
}

bool SIModeRegister::run(MachineFunction &MF) {
// Constrained FP intrinsics are used to support non-default rounding modes.
// strictfp attribute is required to mark functions with strict FP semantics
// having constrained FP intrinsics. This pass fixes up operations that uses
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-real-true16 -run-pass si-mode-register %s -o - | FileCheck %s --check-prefixes=GFX11
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-real-true16 -passes si-mode-register %s -o - | FileCheck %s --check-prefixes=GFX11

---
name: ftrunc_tonearest
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AMDGPU/mode-register.mir
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass si-mode-register %s -o - | FileCheck %s
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -passes=si-mode-register %s -o - | FileCheck %s

---
# check that the mode is changed to rtz from default rtn for interp f16
Expand Down