[llvm] [WebAssembly] Use SetVector instead of SmallPtrSet in FixBrTableDefaults (PR #84418)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 7 18:11:00 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-webassembly
Author: Derek Schuff (dschuff)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/84418.diff
1 Files Affected:
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp (+5-3)
``````````diff
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
index 495f19a7ccde55..4252fc1f55fc9f 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
@@ -159,19 +159,21 @@ bool WebAssemblyFixBrTableDefaults::runOnMachineFunction(MachineFunction &MF) {
<< MF.getName() << '\n');
bool Changed = false;
- SmallPtrSet<MachineBasicBlock *, 16> MBBSet;
+ SetVector<MachineBasicBlock *, SmallVector<MachineBasicBlock *, 16>,
+ DenseSet<MachineBasicBlock *>, 16>
+ MBBSet;
for (auto &MBB : MF)
MBBSet.insert(&MBB);
while (!MBBSet.empty()) {
MachineBasicBlock *MBB = *MBBSet.begin();
- MBBSet.erase(MBB);
+ MBBSet.remove(MBB);
for (auto &MI : *MBB) {
if (WebAssembly::isBrTable(MI.getOpcode())) {
fixBrTableIndex(MI, MBB, MF);
auto *Fixed = fixBrTableDefault(MI, MBB, MF);
if (Fixed != nullptr) {
- MBBSet.erase(Fixed);
+ MBBSet.remove(Fixed);
Changed = true;
}
break;
``````````
</details>
https://github.com/llvm/llvm-project/pull/84418
More information about the llvm-commits
mailing list