[llvm] c2c9a3f - [WebAssembly] Rename wasm.catch.exn intrinsic back to wasm.catch

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 25 14:19:41 PDT 2021


Author: Heejin Ahn
Date: 2021-08-25T14:19:22-07:00
New Revision: c2c9a3fd9c2c2d293e31d2e406a255fb18e4bb81

URL: https://github.com/llvm/llvm-project/commit/c2c9a3fd9c2c2d293e31d2e406a255fb18e4bb81
DIFF: https://github.com/llvm/llvm-project/commit/c2c9a3fd9c2c2d293e31d2e406a255fb18e4bb81.diff

LOG: [WebAssembly] Rename wasm.catch.exn intrinsic back to wasm.catch

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index 320d9bae47c2..158744a609a1 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -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

diff  --git a/llvm/lib/CodeGen/WasmEHPrepare.cpp b/llvm/lib/CodeGen/WasmEHPrepare.cpp
index 29aa65d7b4d9..c4c84cd921fa 100644
--- a/llvm/lib/CodeGen/WasmEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WasmEHPrepare.cpp
@@ -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 =

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
index 818c9c8633bc..4a7f28b04e56 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
@@ -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 =

diff  --git a/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll b/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
index 1f5cbbd9a06e..63bdf2c6bea0 100644
--- a/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
+++ b/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
@@ -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() {


        


More information about the llvm-commits mailing list