xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1// WebAssemblyInstrRef.td - WebAssembly reference type codegen --*- tablegen -*-
2//
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
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// WebAssembly reference type operand codegen constructs.
11///
12//===----------------------------------------------------------------------===//
13
14multiclass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
15  defm REF_NULL_#rc : I<(outs rc:$dst), (ins),
16                        (outs), (ins),
17                        [(set rc:$dst, (!cast<Intrinsic>("int_wasm_ref_null_" # ht)))],
18                        "ref.null_" # ht # "$dst",
19                        "ref.null_" # ht,
20                        !cond(!eq(ht, "func")   : 0xd070,
21                              !eq(ht, "extern") : 0xd06f,
22                              !eq(ht, "exn")    : 0xd069)>,
23                      Requires<[HasReferenceTypes]>;
24  defm SELECT_#rc: I<(outs rc:$dst), (ins rc:$lhs, rc:$rhs, I32:$cond),
25                     (outs), (ins),
26                     [(set rc:$dst,
27                       (select I32:$cond, rc:$lhs, rc:$rhs))],
28                     vt#".select\t$dst, $lhs, $rhs, $cond",
29                     vt#".select", 0x1b>,
30                   Requires<[HasReferenceTypes]>;
31  defm REF_IS_NULL_#rc
32      : I<(outs I32:$dst), (ins rc:$ref), (outs), (ins),
33          [(set I32:$dst, (!cast<Intrinsic>("int_wasm_ref_is_null_" # ht) rc:$ref))],
34          "ref.is_null\t$ref",
35          "ref.is_null", 0xd1>,
36        Requires<[HasReferenceTypes]>;
37}
38
39defm "" : REF_I<FUNCREF, funcref, "func">;
40defm "" : REF_I<EXTERNREF, externref, "extern">;
41defm "" : REF_I<EXNREF, exnref, "exn">;
42
43foreach rc = [FUNCREF, EXTERNREF, EXNREF] in {
44def : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
45          (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
46def : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
47          (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
48}
49