[llvm] 353729b - [AMDGPU] Avoid quadratic erase in SIInstrWorklist (#211801)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 13:32:01 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-07-25T22:31:57+02:00
New Revision: 353729bbe4c53086c9acf3a9d1a4a88a61eec997
URL: https://github.com/llvm/llvm-project/commit/353729bbe4c53086c9acf3a9d1a4a88a61eec997
DIFF: https://github.com/llvm/llvm-project/commit/353729bbe4c53086c9acf3a9d1a4a88a61eec997.diff
LOG: [AMDGPU] Avoid quadratic erase in SIInstrWorklist (#211801)
Added:
Modified:
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 28914d598a72d..633a815447d9a 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -7852,7 +7852,8 @@ SIInstrInfo::legalizeOperands(MachineInstr &MI,
}
void SIInstrWorklist::insert(MachineInstr *MI) {
- InstrList.insert(MI);
+ if (InSet.insert(MI).second)
+ InstrList.push_back(MI);
// Add MBUF instructiosn to deferred list.
int RsrcIdx =
AMDGPU::getNamedOperandIdx(MI->getOpcode(), AMDGPU::OpName::srsrc);
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 8e15b7b45b609..1954e9c2f0d21 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -19,6 +19,7 @@
#include "SIRegisterInfo.h"
#include "Utils/AMDGPUBaseInfo.h"
#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetSchedule.h"
@@ -70,20 +71,19 @@ struct SIInstrWorklist {
void insert(MachineInstr *MI);
- MachineInstr *top() const {
- const auto *iter = InstrList.begin();
- return *iter;
- }
+ MachineInstr *top() const { return InstrList[Front]; }
void erase_top() {
- const auto *iter = InstrList.begin();
- InstrList.erase(iter);
+ InSet.erase(InstrList[Front]);
+ ++Front;
}
- bool empty() const { return InstrList.empty(); }
+ bool empty() const { return Front == InstrList.size(); }
void clear() {
InstrList.clear();
+ Front = 0;
+ InSet.clear();
DeferredList.clear();
}
@@ -93,7 +93,9 @@ struct SIInstrWorklist {
private:
/// InstrList contains the MachineInstrs.
- SetVector<MachineInstr *> InstrList;
+ SmallVector<MachineInstr *> InstrList;
+ SmallPtrSet<MachineInstr *, 8> InSet;
+ unsigned Front = 0;
/// Deferred instructions are specific MachineInstr
/// that will be added by insert method.
SetVector<MachineInstr *> DeferredList;
More information about the llvm-commits
mailing list