diff options
author | Heejin Ahn <aheejin@gmail.com> | 2025-02-25 09:53:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-25 09:53:01 -0800 |
commit | d2d469eb7981885eac188bf7988c72d7e85b2d4e (patch) | |
tree | cf9e474b47adfe68ff3a629ef2b6360fa9af9014 /llvm/lib/IR/Verifier.cpp | |
parent | 041b7f508533417bcda4feaa03d6c16ff85275f5 (diff) | |
download | llvm-d2d469eb7981885eac188bf7988c72d7e85b2d4e.zip llvm-d2d469eb7981885eac188bf7988c72d7e85b2d4e.tar.gz llvm-d2d469eb7981885eac188bf7988c72d7e85b2d4e.tar.bz2 |
[WebAssembly] Make llvm.wasm.throw invokable (#128104)
`llvm.wasm.throw` intrinsic can throw but it was not invokable. Not sure
what the rationale was when it was first written that way, but I think
at least in Emscripten's C++ exception support with the Wasm port of
libunwind, `__builtin_wasm_throw`, which is lowered down to
`llvm.wasm.rethrow`, is used only within `_Unwind_RaiseException`, which
is an one-liner and thus does not need an `invoke`:
https://github.com/emscripten-core/emscripten/blob/720e97f76d6f19e0c6a2d6988988cfe23f0517fb/system/lib/libunwind/src/Unwind-wasm.c#L69
(`_Unwind_RaiseException` is called by `__cxa_throw`, which is generated
by the `throw` C++ keyword)
But this does not address other direct uses of the builtin in C++, whose
use I'm not sure about but is not prohibited. Also other language
frontends may need to use the builtin in different functions, which has
`try`-`catch`es or destructors.
This makes `llvm.wasm.throw` invokable in the backend. To do that, this
adds a custom lowering routine to `SelectionDAGBuilder::visitInvoke`,
like we did for `llvm.wasm.rethrow`.
This does not generate `invoke`s for `__builtin_wasm_throw` yet, which
will be done by a follow-up PR.
Addresses #124710.
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index b4f9273..3477e2b 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -5227,10 +5227,12 @@ void Verifier::visitInstruction(Instruction &I) { F->getIntrinsicID() == Intrinsic::experimental_patchpoint || F->getIntrinsicID() == Intrinsic::fake_use || F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || + F->getIntrinsicID() == Intrinsic::wasm_throw || F->getIntrinsicID() == Intrinsic::wasm_rethrow || IsAttachedCallOperand(F, CBI, i), "Cannot invoke an intrinsic other than donothing, patchpoint, " - "statepoint, coro_resume, coro_destroy or clang.arc.attachedcall", + "statepoint, coro_resume, coro_destroy, clang.arc.attachedcall or " + "wasm.(re)throw", &I); Check(F->getParent() == &M, "Referencing function in another module!", &I, &M, F, F->getParent()); |