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*60653e24SHeejin Ahnmulticlass REF_I<WebAssemblyRegClass reg, ValueType vt> {
15*60653e24SHeejin Ahn  defm REF_NULL_#reg : I<(outs reg:$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",
20*60653e24SHeejin Ahn                         0xd0>,
21*60653e24SHeejin Ahn                       Requires<[HasReferenceTypes]>;
22*60653e24SHeejin Ahn  defm SELECT_#reg: I<(outs reg:$dst), (ins reg:$lhs, reg:$rhs, I32:$cond),
23*60653e24SHeejin Ahn                      (outs), (ins),
24*60653e24SHeejin Ahn                      [(set reg:$dst,
25*60653e24SHeejin Ahn                        (select I32:$cond, reg:$lhs, reg:$rhs))],
26*60653e24SHeejin Ahn                      vt#".select\t$dst, $lhs, $rhs, $cond",
27*60653e24SHeejin Ahn                      vt#".select", 0x1b>,
28*60653e24SHeejin Ahn                    Requires<[HasReferenceTypes]>;
29107c3a12SAndy Wingo}
30107c3a12SAndy Wingo
31*60653e24SHeejin Ahndefm "" : REF_I<FUNCREF, funcref>;
32*60653e24SHeejin Ahndefm "" : REF_I<EXTERNREF, externref>;
33*60653e24SHeejin Ahndefm "" : REF_I<EXNREF, exnref>;
34*60653e24SHeejin Ahn
35*60653e24SHeejin Ahnforeach reg = [FUNCREF, EXTERNREF, EXNREF] in {
36*60653e24SHeejin Ahndef : Pat<(select (i32 (setne I32:$cond, 0)), reg:$lhs, reg:$rhs),
37*60653e24SHeejin Ahn          (!cast<Instruction>("SELECT_"#reg) reg:$lhs, reg:$rhs, I32:$cond)>;
38*60653e24SHeejin Ahndef : Pat<(select (i32 (seteq I32:$cond, 0)), reg:$lhs, reg:$rhs),
39*60653e24SHeejin Ahn          (!cast<Instruction>("SELECT_"#reg) reg:$rhs, reg:$lhs, I32:$cond)>;
40*60653e24SHeejin Ahn}
41