xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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,
21*0fca6ea1SDimitry Andric                              !eq(ht, "extern") : 0xd06f,
22*0fca6ea1SDimitry Andric                              !eq(ht, "exn")    : 0xd069)>,
23e8d8bef9SDimitry Andric                      Requires<[HasReferenceTypes]>;
24fe6060f1SDimitry Andric  defm SELECT_#rc: I<(outs rc:$dst), (ins rc:$lhs, rc:$rhs, I32:$cond),
250b57cec5SDimitry Andric                     (outs), (ins),
26fe6060f1SDimitry Andric                     [(set rc:$dst,
27fe6060f1SDimitry Andric                       (select I32:$cond, rc:$lhs, rc:$rhs))],
28e8d8bef9SDimitry Andric                     vt#".select\t$dst, $lhs, $rhs, $cond",
29e8d8bef9SDimitry Andric                     vt#".select", 0x1b>,
30e8d8bef9SDimitry Andric                   Requires<[HasReferenceTypes]>;
3181ad6265SDimitry Andric  defm REF_IS_NULL_#rc
3281ad6265SDimitry Andric      : I<(outs I32:$dst), (ins rc:$ref), (outs), (ins),
3381ad6265SDimitry Andric          [(set I32:$dst, (!cast<Intrinsic>("int_wasm_ref_is_null_" # ht) rc:$ref))],
3481ad6265SDimitry Andric          "ref.is_null\t$ref",
3581ad6265SDimitry Andric          "ref.is_null", 0xd1>,
3681ad6265SDimitry Andric        Requires<[HasReferenceTypes]>;
37e8d8bef9SDimitry Andric}
380b57cec5SDimitry Andric
390eae32dcSDimitry Andricdefm "" : REF_I<FUNCREF, funcref, "func">;
400eae32dcSDimitry Andricdefm "" : REF_I<EXTERNREF, externref, "extern">;
41*0fca6ea1SDimitry Andricdefm "" : REF_I<EXNREF, exnref, "exn">;
42e8d8bef9SDimitry Andric
43*0fca6ea1SDimitry Andricforeach rc = [FUNCREF, EXTERNREF, EXNREF] in {
44fe6060f1SDimitry Andricdef : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
45fe6060f1SDimitry Andric          (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
46fe6060f1SDimitry Andricdef : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
47fe6060f1SDimitry Andric          (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
48e8d8bef9SDimitry Andric}
49