Skip to content

Commit 722a5fc

Browse files
authored
[WebAssembly] Add -wasm-enable-exnref option (#93597)
This adds `-wasm-enable-exnref`, which will enable the new EH instructions using `exnref` (adopted in Oct 2023 CG meeting): https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md This option should be used with `-wasm-enable-eh`.
1 parent 39e5036 commit 722a5fc

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ cl::opt<bool>
5454
// setjmp/longjmp handling using wasm EH instrutions
5555
cl::opt<bool> WebAssembly::WasmEnableSjLj(
5656
"wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling"));
57+
// Whether we use the new exnref Wasm EH proposal adopted on Oct 2023.
58+
// Should be used with -wasm-enable-eh.
59+
// Currently set to false by default, but will later change to true and then
60+
// later can be removed after the legacy WAsm EH instructions are removed.
61+
cl::opt<bool> WebAssembly::WasmEnableExnref(
62+
"wasm-enable-exnref", cl::desc("WebAssembly exception handling (exnref)"),
63+
cl::init(false));
5764

5865
static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
5966
const Triple &TT,

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern cl::opt<bool> WasmEnableEmEH; // asm.js-style EH
4444
extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
4545
extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions
4646
extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions
47+
extern cl::opt<bool> WasmEnableExnref; // EH using new Wasm EH (exnref)
4748

4849
enum OperandType {
4950
/// Basic block label in a branch construct.

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
385385
using WebAssembly::WasmEnableEH;
386386
using WebAssembly::WasmEnableEmEH;
387387
using WebAssembly::WasmEnableEmSjLj;
388+
using WebAssembly::WasmEnableExnref;
388389
using WebAssembly::WasmEnableSjLj;
389390

390391
static void basicCheckForEHAndSjLj(TargetMachine *TM) {
@@ -401,6 +402,9 @@ static void basicCheckForEHAndSjLj(TargetMachine *TM) {
401402
if (WasmEnableEmEH && WasmEnableSjLj)
402403
report_fatal_error(
403404
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
405+
if (WasmEnableExnref && !WasmEnableEH)
406+
report_fatal_error(
407+
"-wasm-enable-exnref should be used with -wasm-enable-eh");
404408

405409
// Here we make sure TargetOptions.ExceptionModel is the same as
406410
// MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang

llvm/test/CodeGen/WebAssembly/eh-option-errors.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ target triple = "wasm32-unknown-unknown"
99
; RUN: not --crash llc < %s -enable-emscripten-cxx-exceptions -wasm-enable-sjlj 2>&1 | FileCheck %s --check-prefix=EM_EH_W_WASM_SJLJ
1010
; EM_EH_W_WASM_SJLJ: LLVM ERROR: -enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj
1111

12+
; RUN: not --crash llc < %s -wasm-enable-exnref 2>&1 | FileCheck %s --check-prefix=WASM_EXNREF_ONLY
13+
; WASM_EXNREF_ONLY: LLVM ERROR: -wasm-enable-exnref should be used with -wasm-enable-eh
14+
1215
; RUN: not --crash llc < %s -wasm-enable-eh -exception-model=dwarf 2>&1 | FileCheck %s --check-prefix=EH_MODEL_DWARF
1316
; EH_MODEL_DWARF: LLVM ERROR: -exception-model should be either 'none' or 'wasm'
1417

0 commit comments

Comments
 (0)