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*d7086af2SPaulo Matosmulticlass REF_I<WebAssemblyRegClass rc, ValueType vt> {
15*d7086af2SPaulo Matos  defm REF_NULL_#rc : I<(outs rc:$res), (ins HeapType:$heaptype),
16107c3a12SAndy Wingo                        (outs), (ins HeapType:$heaptype),
17107c3a12SAndy Wingo                        [],
18107c3a12SAndy Wingo                        "ref.null\t$res, $heaptype",
19107c3a12SAndy Wingo                        "ref.null\t$heaptype",
2060653e24SHeejin Ahn                        0xd0>,
2160653e24SHeejin Ahn                      Requires<[HasReferenceTypes]>;
22*d7086af2SPaulo Matos  defm SELECT_#rc: I<(outs rc:$dst), (ins rc:$lhs, rc:$rhs, I32:$cond),
2360653e24SHeejin Ahn                     (outs), (ins),
24*d7086af2SPaulo Matos                     [(set rc:$dst,
25*d7086af2SPaulo Matos                       (select I32:$cond, rc:$lhs, rc:$rhs))],
2660653e24SHeejin Ahn                     vt#".select\t$dst, $lhs, $rhs, $cond",
2760653e24SHeejin Ahn                     vt#".select", 0x1b>,
2860653e24SHeejin Ahn                   Requires<[HasReferenceTypes]>;
29107c3a12SAndy Wingo}
30107c3a12SAndy Wingo
3160653e24SHeejin Ahndefm "" : REF_I<FUNCREF, funcref>;
3260653e24SHeejin Ahndefm "" : REF_I<EXTERNREF, externref>;
3360653e24SHeejin Ahn
34*d7086af2SPaulo Matosforeach rc = [FUNCREF, EXTERNREF] in {
35*d7086af2SPaulo Matosdef : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
36*d7086af2SPaulo Matos          (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
37*d7086af2SPaulo Matosdef : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
38*d7086af2SPaulo Matos          (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
3960653e24SHeejin Ahn}
40