Skip to content

[WebAssembly] Use SetVector instead of SmallPtrSet in FixBrTableDefaults #84418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

dschuff
Copy link
Member

@dschuff dschuff commented Mar 8, 2024

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Mar 8, 2024

@llvm/pr-subscribers-backend-webassembly

Author: Derek Schuff (dschuff)

Changes

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 --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;

@dschuff dschuff merged commit dbca8aa into llvm:main Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants