Skip to content

Commit dbca8aa

Browse files
authored
[WebAssembly] Use SetVector instead of SmallPtrSet in FixBrTableDefaults (#84418)
This pass inserts all the MBBs into a set and then iterates over them. But when the number of elements gets large enough, SmallPtrSet expands into a hash table which wouldn't have a deterministic iteration order since the elements are pointers. This results in nondeterministic jump table layouts. Use SetVector instead for a deterministic iteration order.
1 parent 0bbada9 commit dbca8aa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,21 @@ bool WebAssemblyFixBrTableDefaults::runOnMachineFunction(MachineFunction &MF) {
159159
<< MF.getName() << '\n');
160160

161161
bool Changed = false;
162-
SmallPtrSet<MachineBasicBlock *, 16> MBBSet;
162+
SetVector<MachineBasicBlock *, SmallVector<MachineBasicBlock *, 16>,
163+
DenseSet<MachineBasicBlock *>, 16>
164+
MBBSet;
163165
for (auto &MBB : MF)
164166
MBBSet.insert(&MBB);
165167

166168
while (!MBBSet.empty()) {
167169
MachineBasicBlock *MBB = *MBBSet.begin();
168-
MBBSet.erase(MBB);
170+
MBBSet.remove(MBB);
169171
for (auto &MI : *MBB) {
170172
if (WebAssembly::isBrTable(MI.getOpcode())) {
171173
fixBrTableIndex(MI, MBB, MF);
172174
auto *Fixed = fixBrTableDefault(MI, MBB, MF);
173175
if (Fixed != nullptr) {
174-
MBBSet.erase(Fixed);
176+
MBBSet.remove(Fixed);
175177
Changed = true;
176178
}
177179
break;

0 commit comments

Comments
 (0)