[WebAssembly] Rename wasm.catch.exn intrinsic back to wasm.catch
authorHeejin Ahn <aheejin@gmail.com>
Wed, 25 Aug 2021 02:43:28 +0000 (19:43 -0700)
committerHeejin Ahn <aheejin@gmail.com>
Wed, 25 Aug 2021 21:19:22 +0000 (14:19 -0700)
The plan was to use `wasm.catch.exn` intrinsic to catch exceptions and
add `wasm.catch.longjmp` intrinsic, that returns two values (setjmp
buffer and return value), later to catch longjmps. But because we
decided not to use multivalue support at the moment, we are going to use
one intrinsic that returns a single value for both exceptions and
longjmps. And even if it's not for that, I now think the naming of
`wasm.catch.exn` is a little weird, because the intrinsic can still take
a tag immediate, which means it can be used for anything, not only
exceptions, as long as that returns a single value.

This partially reverts D107405.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D108683

llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/CodeGen/WasmEHPrepare.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/test/CodeGen/WebAssembly/wasmehprepare.ll

index 320d9ba..158744a 100644 (file)
@@ -63,12 +63,12 @@ def int_wasm_get_exception : Intrinsic<[llvm_ptr_ty], [llvm_token_ty],
 def int_wasm_get_ehselector : Intrinsic<[llvm_i32_ty], [llvm_token_ty],
                                         [IntrHasSideEffects]>;
 
-// wasm.catch.exn returns the pointer to the exception object caught by wasm
-// 'catch' instruction. This returns a single pointer, which is the case for C++
+// wasm.catch returns the pointer to the exception object caught by wasm 'catch'
+// instruction. This returns a single pointer, which is the case for C++
 // exceptions. The immediate argument is an index to for a tag, which is 0 for
 // C++ exceptions.
-def int_wasm_catch_exn : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty],
-                                   [IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
+def int_wasm_catch : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty],
+                               [IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
 
 // WebAssembly EH must maintain the landingpads in the order assigned to them
 // by WasmEHPrepare pass to generate landingpad table in EHStreamer. This is
index 29aa65d..c4c84cd 100644 (file)
@@ -23,7 +23,7 @@
 //
 // - After:
 //   catchpad ...
-//   exn = wasm.catch.exn(WebAssembly::CPP_EXCEPTION);
+//   exn = wasm.catch(WebAssembly::CPP_EXCEPTION);
 //   // Only add below in case it's not a single catch (...)
 //   wasm.landingpad.index(index);
 //   __wasm_lpad_context.lpad_index = index;
@@ -103,7 +103,7 @@ class WasmEHPrepare : public FunctionPass {
   Function *LPadIndexF = nullptr;   // wasm.landingpad.index() intrinsic
   Function *LSDAF = nullptr;        // wasm.lsda() intrinsic
   Function *GetExnF = nullptr;      // wasm.get.exception() intrinsic
-  Function *CatchF = nullptr;       // wasm.catch.exn() intrinsic
+  Function *CatchF = nullptr;       // wasm.catch() intrinsic
   Function *GetSelectorF = nullptr; // wasm.get.ehselector() intrinsic
   FunctionCallee CallPersonalityF =
       nullptr; // _Unwind_CallPersonality() wrapper
@@ -232,9 +232,9 @@ bool WasmEHPrepare::prepareEHPads(Function &F) {
   GetExnF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_get_exception);
   GetSelectorF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_get_ehselector);
 
-  // wasm.catch.exn() will be lowered down to wasm 'catch' instruction in
+  // wasm.catch() will be lowered down to wasm 'catch' instruction in
   // instruction selection.
-  CatchF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_catch_exn);
+  CatchF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_catch);
 
   // _Unwind_CallPersonality() wrapper function, which calls the personality
   CallPersonalityF = M.getOrInsertFunction(
@@ -288,8 +288,8 @@ void WasmEHPrepare::prepareEHPad(BasicBlock *BB, bool NeedPersonality,
     return;
   }
 
-  // Replace wasm.get.exception intrinsic with wasm.catch.exn intrinsic, which
-  // will be lowered to wasm 'catch' instruction. We do this mainly because
+  // Replace wasm.get.exception intrinsic with wasm.catch intrinsic, which will
+  // be lowered to wasm 'catch' instruction. We do this mainly because
   // instruction selection cannot handle wasm.get.exception intrinsic's token
   // argument.
   Instruction *CatchCI =
index 818c9c8..4a7f28b 100644 (file)
@@ -186,7 +186,7 @@ void WebAssemblyDAGToDAGISel::Select(SDNode *Node) {
       return;
     }
 
-    case Intrinsic::wasm_catch_exn: {
+    case Intrinsic::wasm_catch: {
       int Tag = Node->getConstantOperandVal(2);
       SDValue SymNode = getTagSymNode(Tag, CurDAG);
       MachineSDNode *Catch =
index 1f5cbbd..63bdf2c 100644 (file)
@@ -9,7 +9,7 @@ target triple = "wasm32-unknown-unknown"
 %struct.Temp = type { i8 }
 
 ; A single 'catch (int)' clause.
-; A wasm.catch.exn() call, wasm.lsda() call, and personality call to generate a
+; A wasm.catch() call, wasm.lsda() call, and personality call to generate a
 ; selector should all be genereated after the catchpad.
 ;
 ; void foo();
@@ -37,7 +37,7 @@ catch.start:                                      ; preds = %catch.dispatch
   br i1 %matches, label %catch, label %rethrow
 ; CHECK: catch.start:
 ; CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad
-; CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.catch.exn(i32 0)
+; CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.catch(i32 0)
 ; CHECK-NEXT:   call void @llvm.wasm.landingpad.index(token %[[CATCHPAD]], i32 0)
 ; CHECK-NEXT:   store i32 0, i32* getelementptr inbounds ({ i32, i8*, i32 }, { i32, i8*, i32 }* @__wasm_lpad_context, i32 0, i32 0)
 ; CHECK-NEXT:   %[[LSDA:.*]] = call i8* @llvm.wasm.lsda()
@@ -62,10 +62,10 @@ try.cont:                                         ; preds = %entry, %catch
 }
 
 ; Two try-catches.
-; For the catchpad with a single 'catch (...)', only a wasm.catch.exn() call
-; should be generated after the catchpad; wasm.landingpad.index() and
-; personality call should NOT be generated. For the other catchpad, the argument
-; of wasm.landingpad.index() should be not 1 but 0.
+; For the catchpad with a single 'catch (...)', only a wasm.catch() call should
+; be generated after the catchpad; wasm.landingpad.index() and personality call
+; should NOT be generated. For the other catchpad, the argument of
+; wasm.landingpad.index() should be not 1 but 0.
 ;
 ; void foo();
 ; void test1() {