[llvm] [AMDGPU] Rewrite GFX12 SGPR hazard handling to dedicated pass (PR #118750)
Carl Ritson via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 05:22:04 PST 2025
================
@@ -3103,274 +3097,6 @@ bool GCNHazardRecognizer::fixVALUMaskWriteHazard(MachineInstr *MI) {
return true;
}
-// Return the numeric ID 0-63 of an 64b SGPR pair for a given SGPR.
-// i.e. SGPR0 = SGPR0_SGPR1 = 0, SGPR3 = SGPR2_SGPR3 = 1, etc
-static std::optional<unsigned> sgprPairNumber(Register Reg,
- const SIRegisterInfo &TRI) {
- switch (Reg) {
- case AMDGPU::M0:
- case AMDGPU::EXEC:
- case AMDGPU::EXEC_LO:
- case AMDGPU::EXEC_HI:
- case AMDGPU::SGPR_NULL:
- case AMDGPU::SGPR_NULL64:
- return {};
- default:
- break;
- }
- unsigned RegN = TRI.getEncodingValue(Reg);
- if (RegN > 127)
- return {};
- return (RegN >> 1) & 0x3f;
-}
-
-// For VALUReadSGPRHazard: pre-compute a bit vector of all SGPRs used by VALUs.
-void GCNHazardRecognizer::computeVALUHazardSGPRs(MachineFunction *MMF) {
- assert(MMF == &MF);
-
- // Assume non-empty vector means it has already been computed.
- if (!VALUReadHazardSGPRs.empty())
- return;
-
- auto CallingConv = MF.getFunction().getCallingConv();
- bool IsCallFree =
- AMDGPU::isEntryFunctionCC(CallingConv) && !MF.getFrameInfo().hasCalls();
-
- // Exhaustive search is only viable in non-caller/callee functions where
- // VALUs will be exposed to the hazard recognizer.
- UseVALUReadHazardExhaustiveSearch =
- IsCallFree && MF.getTarget().getOptLevel() > CodeGenOptLevel::None &&
- MF.getInstructionCount() <= MaxExhaustiveHazardSearch;
-
- // Consider all SGPRs hazards if the shader uses function calls or is callee.
- bool UseVALUUseCache =
- IsCallFree && MF.getTarget().getOptLevel() > CodeGenOptLevel::None;
- VALUReadHazardSGPRs.resize(64, !UseVALUUseCache);
- if (!UseVALUUseCache)
- return;
-
- // Perform a post ordered reverse scan to find VALUs which read an SGPR
- // before a SALU write to the same SGPR. This provides a reduction in
- // hazard insertion when all VALU access to an SGPR occurs after its last
- // SALU write, when compared to a linear scan.
- const MachineRegisterInfo &MRI = MF.getRegInfo();
- BitVector SALUWriteSGPRs(64), ReadSGPRs(64);
- MachineCycleInfo CI;
- CI.compute(*MMF);
-
- for (auto *MBB : post_order(&MF)) {
----------------
perlfu wrote:
Done.
https://github.com/llvm/llvm-project/pull/118750
More information about the llvm-commits
mailing list