[llvm] WebAssembly: Move target EH passes into backend (PR #225172)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 11:57:18 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-webassembly
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Currently the wasm-specific EH lowering passes are added in the
generic pass configs, driven by the TargetOptions ExceptionModel.
As preparation for driving this process off the IR flag, move these
pass runs into the target. There should be no change in the relative
pass ordering.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply@<!-- -->anthropic.com>
---
Full diff: https://github.com/llvm/llvm-project/pull/225172.diff
4 Files Affected:
- (modified) llvm/lib/CodeGen/TargetPassConfig.cpp (-1)
- (modified) llvm/lib/Passes/CodeGenPassBuilder.cpp (-2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp (+4)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp (+3)
``````````diff
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index bda74e0d6461b..9e73048264b0a 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -958,7 +958,6 @@ void TargetPassConfig::addPassesToHandleExceptions() {
// funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
// should remove PHIs there.
addPass(createWinEHPass(/*DemoteCatchSwitchPHIOnly=*/true));
- addPass(createWasmEHPass());
break;
case ExceptionHandling::Default:
case ExceptionHandling::None:
diff --git a/llvm/lib/Passes/CodeGenPassBuilder.cpp b/llvm/lib/Passes/CodeGenPassBuilder.cpp
index c68de7efa1842..a24323d816caa 100644
--- a/llvm/lib/Passes/CodeGenPassBuilder.cpp
+++ b/llvm/lib/Passes/CodeGenPassBuilder.cpp
@@ -94,7 +94,6 @@
#include "llvm/CodeGen/TwoAddressInstructionPass.h"
#include "llvm/CodeGen/UnreachableBlockElim.h"
#include "llvm/CodeGen/VirtRegMap.h"
-#include "llvm/CodeGen/WasmEHPrepare.h"
#include "llvm/CodeGen/WinEHPrepare.h"
#include "llvm/CodeGen/XRayInstrumentation.h"
#include "llvm/IR/PassManager.h"
@@ -471,7 +470,6 @@ void CodeGenPassBuilder::addPassesToHandleExceptions(PassManagerWrapper &PMW) {
// funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
// should remove PHIs there.
addFunctionPass(WinEHPreparePass(/*DemoteCatchSwitchPHIOnly=*/false), PMW);
- addFunctionPass(WasmEHPreparePass(), PMW);
break;
case ExceptionHandling::Default:
case ExceptionHandling::None:
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
index 960f01f1e73a0..d10770787433b 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
@@ -27,6 +27,7 @@
#include "llvm/CodeGen/RemoveLoadsIntoFakeUses.h"
#include "llvm/CodeGen/ShrinkWrap.h"
#include "llvm/CodeGen/UnreachableBlockElim.h"
+#include "llvm/CodeGen/WasmEHPrepare.h"
#include "llvm/IR/PassInstrumentation.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Passes/CodeGenPassBuilder.h"
@@ -151,6 +152,9 @@ void WebAssemblyCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
}
void WebAssemblyCodeGenPassBuilder::addISelPrepare(PassManagerWrapper &PMW) {
+ if (TM.Options.ExceptionModel == ExceptionHandling::Wasm)
+ addFunctionPass(WasmEHPreparePass(), PMW);
+
// We need to move reference type allocas to WASM_ADDRESS_SPACE_VAR so that
// loads and stores are promoted to local.gets/local.sets.
addFunctionPass(WebAssemblyRefTypeMem2LocalPass(), PMW);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 7d6d545fa169c..41f628f0c97e0 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -335,6 +335,9 @@ void WebAssemblyPassConfig::addIRPasses() {
}
void WebAssemblyPassConfig::addISelPrepare() {
+ if (TM->Options.ExceptionModel == ExceptionHandling::Wasm)
+ addPass(createWasmEHPass());
+
// We need to move reference type allocas to WASM_ADDRESS_SPACE_VAR so that
// loads and stores are promoted to local.gets/local.sets.
addPass(createWebAssemblyRefTypeMem2LocalLegacyPass());
``````````
</details>
https://github.com/llvm/llvm-project/pull/225172
More information about the llvm-commits
mailing list