[llvm] [AMDGPU] Refine GCNHazardRecognizer hasHazard() (PR #138841)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 17 06:08:19 PDT 2025
================
@@ -441,42 +441,106 @@ using IsExpiredFn = function_ref<bool(const MachineInstr &, int WaitStates)>;
using GetNumWaitStatesFn = function_ref<unsigned int(const MachineInstr &)>;
// Search for a hazard in a block and its predecessors.
-template <typename StateT>
+template <typename StateT, typename StateTraitsT>
static bool
-hasHazard(StateT State,
+hasHazard(StateT InitialState,
function_ref<HazardFnResult(StateT &, const MachineInstr &)> IsHazard,
function_ref<void(StateT &, const MachineInstr &)> UpdateState,
- const MachineBasicBlock *MBB,
- MachineBasicBlock::const_reverse_instr_iterator I,
- DenseSet<const MachineBasicBlock *> &Visited) {
- for (auto E = MBB->instr_rend(); I != E; ++I) {
- // No need to look at parent BUNDLE instructions.
- if (I->isBundle())
- continue;
-
- switch (IsHazard(State, *I)) {
- case HazardFound:
- return true;
- case HazardExpired:
- return false;
- default:
- // Continue search
- break;
+ const MachineBasicBlock *InitialMBB,
+ MachineBasicBlock::const_reverse_instr_iterator InitialI) {
+ struct StateMapKey {
+ SmallVectorImpl<StateT> *States;
+ unsigned Idx;
+ static bool isEqual(const StateMapKey &LHS, const StateMapKey &RHS) {
+ return LHS.States == RHS.States && LHS.Idx == RHS.Idx;
+ }
+ };
+ struct StateMapKeyTraits : DenseMapInfo<StateMapKey> {
----------------
jayfoad wrote:
I think you would normally do this by specializing `DenseMapInfo`:
```suggestion
template <> struct DenseMapInfo<StateMapKey> {
```
Then there's no need to name it, or to mention it when you declare the StateMap below.
https://github.com/llvm/llvm-project/pull/138841
More information about the llvm-commits
mailing list