19f96a58cSHeejin Ahn// WebAssemblyInstrRef.td - WebAssembly reference type codegen --*- tablegen -*-
29f96a58cSHeejin Ahn//
39f96a58cSHeejin Ahn// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
49f96a58cSHeejin Ahn// See https://llvm.org/LICENSE.txt for license information.
59f96a58cSHeejin Ahn// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
69f96a58cSHeejin Ahn//
79f96a58cSHeejin Ahn//===----------------------------------------------------------------------===//
89f96a58cSHeejin Ahn///
99f96a58cSHeejin Ahn/// \file
100312b9f5SKazuaki Ishizaki/// WebAssembly reference type operand codegen constructs.
119f96a58cSHeejin Ahn///
129f96a58cSHeejin Ahn//===----------------------------------------------------------------------===//
139f96a58cSHeejin Ahn
14*a96d8285SPaulo Matosmulticlass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
15*a96d8285SPaulo Matos  defm REF_NULL_#rc : I<(outs rc:$dst), (ins),
16*a96d8285SPaulo Matos                        (outs), (ins),
17*a96d8285SPaulo Matos                        [(set rc:$dst, (!cast<Intrinsic>("int_wasm_ref_null_" # ht)))],
18*a96d8285SPaulo Matos                        "ref.null_" # ht # "$dst",
19*a96d8285SPaulo Matos                        "ref.null_" # ht,
20*a96d8285SPaulo Matos                        !cond(!eq(ht, "func")   : 0xd070,
21*a96d8285SPaulo Matos                              !eq(ht, "extern") : 0xd06f)>,
2260653e24SHeejin Ahn                      Requires<[HasReferenceTypes]>;
23d7086af2SPaulo Matos  defm SELECT_#rc: I<(outs rc:$dst), (ins rc:$lhs, rc:$rhs, I32:$cond),
2460653e24SHeejin Ahn                     (outs), (ins),
25d7086af2SPaulo Matos                     [(set rc:$dst,
26d7086af2SPaulo Matos                       (select I32:$cond, rc:$lhs, rc:$rhs))],
2760653e24SHeejin Ahn                     vt#".select\t$dst, $lhs, $rhs, $cond",
2860653e24SHeejin Ahn                     vt#".select", 0x1b>,
2960653e24SHeejin Ahn                   Requires<[HasReferenceTypes]>;
30107c3a12SAndy Wingo}
31107c3a12SAndy Wingo
32*a96d8285SPaulo Matosdefm "" : REF_I<FUNCREF, funcref, "func">;
33*a96d8285SPaulo Matosdefm "" : REF_I<EXTERNREF, externref, "extern">;
3460653e24SHeejin Ahn
35d7086af2SPaulo Matosforeach rc = [FUNCREF, EXTERNREF] in {
36d7086af2SPaulo Matosdef : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
37d7086af2SPaulo Matos          (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
38d7086af2SPaulo Matosdef : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
39d7086af2SPaulo Matos          (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
4060653e24SHeejin Ahn}
41