xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric// WebAssemblyInstrRef.td - WebAssembly reference type codegen --*- tablegen -*-
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric///
90b57cec5SDimitry Andric/// \file
105ffd83dbSDimitry Andric/// WebAssembly reference type operand codegen constructs.
110b57cec5SDimitry Andric///
120b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric
140eae32dcSDimitry Andricmulticlass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
150eae32dcSDimitry Andric  defm REF_NULL_#rc : I<(outs rc:$dst), (ins),
160eae32dcSDimitry Andric                        (outs), (ins),
170eae32dcSDimitry Andric                        [(set rc:$dst, (!cast<Intrinsic>("int_wasm_ref_null_" # ht)))],
180eae32dcSDimitry Andric                        "ref.null_" # ht # "$dst",
190eae32dcSDimitry Andric                        "ref.null_" # ht,
200eae32dcSDimitry Andric                        !cond(!eq(ht, "func")   : 0xd070,
210eae32dcSDimitry Andric                              !eq(ht, "extern") : 0xd06f)>,
22e8d8bef9SDimitry Andric                      Requires<[HasReferenceTypes]>;
23fe6060f1SDimitry Andric  defm SELECT_#rc: I<(outs rc:$dst), (ins rc:$lhs, rc:$rhs, I32:$cond),
240b57cec5SDimitry Andric                     (outs), (ins),
25fe6060f1SDimitry Andric                     [(set rc:$dst,
26fe6060f1SDimitry Andric                       (select I32:$cond, rc:$lhs, rc:$rhs))],
27e8d8bef9SDimitry Andric                     vt#".select\t$dst, $lhs, $rhs, $cond",
28e8d8bef9SDimitry Andric                     vt#".select", 0x1b>,
29e8d8bef9SDimitry Andric                   Requires<[HasReferenceTypes]>;
30*81ad6265SDimitry Andric  defm REF_IS_NULL_#rc
31*81ad6265SDimitry Andric      : I<(outs I32:$dst), (ins rc:$ref), (outs), (ins),
32*81ad6265SDimitry Andric          [(set I32:$dst, (!cast<Intrinsic>("int_wasm_ref_is_null_" # ht) rc:$ref))],
33*81ad6265SDimitry Andric          "ref.is_null\t$ref",
34*81ad6265SDimitry Andric          "ref.is_null", 0xd1>,
35*81ad6265SDimitry Andric        Requires<[HasReferenceTypes]>;
36e8d8bef9SDimitry Andric}
370b57cec5SDimitry Andric
380eae32dcSDimitry Andricdefm "" : REF_I<FUNCREF, funcref, "func">;
390eae32dcSDimitry Andricdefm "" : REF_I<EXTERNREF, externref, "extern">;
40e8d8bef9SDimitry Andric
41fe6060f1SDimitry Andricforeach rc = [FUNCREF, EXTERNREF] in {
42fe6060f1SDimitry Andricdef : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
43fe6060f1SDimitry Andric          (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
44fe6060f1SDimitry Andricdef : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
45fe6060f1SDimitry Andric          (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
46e8d8bef9SDimitry Andric}
47