1 // WebAssemblyInstrRef.td - WebAssembly reference type codegen --*- tablegen -*-
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// WebAssembly reference type operand codegen constructs.
12 //===----------------------------------------------------------------------===//
14 multiclass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
15 defm REF_NULL_#rc : I<(outs rc:$dst), (ins),
17 [(set rc:$dst, (!cast<Intrinsic>("int_wasm_ref_null_" # ht)))],
18 "ref.null_" # ht # "$dst",
20 !cond(!eq(ht, "func") : 0xd070,
21 !eq(ht, "extern") : 0xd06f)>,
22 Requires<[HasReferenceTypes]>;
23 defm SELECT_#rc: I<(outs rc:$dst), (ins rc:$lhs, rc:$rhs, I32:$cond),
26 (select I32:$cond, rc:$lhs, rc:$rhs))],
27 vt#".select\t$dst, $lhs, $rhs, $cond",
29 Requires<[HasReferenceTypes]>;
32 defm "" : REF_I<FUNCREF, funcref, "func">;
33 defm "" : REF_I<EXTERNREF, externref, "extern">;
35 foreach rc = [FUNCREF, EXTERNREF] in {
36 def : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
37 (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
38 def : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
39 (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;