Skip to content

Commit c9197b2

Browse files
[AMDGPU] Use MapVector instead of DenseMap (NFC) (llvm#133356)
This patch combines: DenseMap<MachineBasicBlock *, bool> ReachableMap; SmallVector<MachineBasicBlock *, 4> ReachableOrdered; into: MapVector<MachineBasicBlock *, bool> ReachableMap; because we add elements to the two data structures in lockstep, and we care about preserving the insertion order. As a side benefit, we get to avoid hash lookups at: ReachableMap[MBB] = true;
1 parent d055e58 commit c9197b2

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ class PhiIncomingAnalysis {
109109

110110
// For each reachable basic block, whether it is a source in the induced
111111
// subgraph of the CFG.
112-
DenseMap<MachineBasicBlock *, bool> ReachableMap;
113-
SmallVector<MachineBasicBlock *, 4> ReachableOrdered;
112+
MapVector<MachineBasicBlock *, bool> ReachableMap;
114113
SmallVector<MachineBasicBlock *, 4> Stack;
115114
SmallVector<MachineBasicBlock *, 4> Predecessors;
116115

@@ -129,13 +128,11 @@ class PhiIncomingAnalysis {
129128
void analyze(MachineBasicBlock &DefBlock, ArrayRef<Incoming> Incomings) {
130129
assert(Stack.empty());
131130
ReachableMap.clear();
132-
ReachableOrdered.clear();
133131
Predecessors.clear();
134132

135133
// Insert the def block first, so that it acts as an end point for the
136134
// traversal.
137135
ReachableMap.try_emplace(&DefBlock, false);
138-
ReachableOrdered.push_back(&DefBlock);
139136

140137
for (auto Incoming : Incomings) {
141138
MachineBasicBlock *MBB = Incoming.Block;
@@ -145,7 +142,6 @@ class PhiIncomingAnalysis {
145142
}
146143

147144
ReachableMap.try_emplace(MBB, false);
148-
ReachableOrdered.push_back(MBB);
149145

150146
// If this block has a divergent terminator and the def block is its
151147
// post-dominator, the wave may first visit the other successors.
@@ -155,14 +151,11 @@ class PhiIncomingAnalysis {
155151

156152
while (!Stack.empty()) {
157153
MachineBasicBlock *MBB = Stack.pop_back_val();
158-
if (!ReachableMap.try_emplace(MBB, false).second)
159-
continue;
160-
ReachableOrdered.push_back(MBB);
161-
162-
append_range(Stack, MBB->successors());
154+
if (ReachableMap.try_emplace(MBB, false).second)
155+
append_range(Stack, MBB->successors());
163156
}
164157

165-
for (MachineBasicBlock *MBB : ReachableOrdered) {
158+
for (auto &[MBB, Reachable] : ReachableMap) {
166159
bool HaveReachablePred = false;
167160
for (MachineBasicBlock *Pred : MBB->predecessors()) {
168161
if (ReachableMap.count(Pred)) {
@@ -172,7 +165,7 @@ class PhiIncomingAnalysis {
172165
}
173166
}
174167
if (!HaveReachablePred)
175-
ReachableMap[MBB] = true;
168+
Reachable = true;
176169
if (HaveReachablePred) {
177170
for (MachineBasicBlock *UnreachablePred : Stack) {
178171
if (!llvm::is_contained(Predecessors, UnreachablePred))

0 commit comments

Comments
 (0)