[llvm] [WebAssembly, llvm] Add llvm.wasm.ref.test.func intrinsic (PR #147486)

Hood Chatham via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 22 02:17:24 PDT 2025


================
@@ -189,6 +236,42 @@ void WebAssemblyDAGToDAGISel::Select(SDNode *Node) {
       ReplaceNode(Node, TLSAlign);
       return;
     }
+    case Intrinsic::wasm_ref_test_func: {
+      // First emit the TABLE_GET instruction to convert function pointer ==>
+      // funcref
+      MachineFunction &MF = CurDAG->getMachineFunction();
+      auto PtrVT = MVT::getIntegerVT(MF.getDataLayout().getPointerSizeInBits());
+      MCSymbol *Table = WebAssembly::getOrCreateFunctionTableSymbol(
+          MF.getContext(), Subtarget);
+      SDValue TableSym = CurDAG->getMCSymbol(Table, PtrVT);
+      SDValue FuncRef = SDValue(
+          CurDAG->getMachineNode(WebAssembly::TABLE_GET_FUNCREF, DL,
+                                 MVT::funcref, TableSym, Node->getOperand(1)),
+          0);
+
+      // Encode the signature information into the type index placeholder.
+      // This gets decoded and converted into the actual type signature in
+      // WebAssemblyMCInstLower.cpp.
+      SmallVector<MVT, 4> Params;
+      SmallVector<MVT, 1> Results;
+
+      MVT VT = Node->getOperand(2).getValueType().getSimpleVT();
+      if (VT != MVT::Untyped) {
+        Params.push_back(VT);
+      }
+      for (unsigned I = 3; I < Node->getNumOperands(); ++I) {
----------------
hoodmane wrote:

Added a comment.

https://github.com/llvm/llvm-project/pull/147486


More information about the llvm-commits mailing list