xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1// WebAssemblyInstrRef.td - WebAssembly reference type codegen --*- tablegen -*-
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// WebAssembly reference type operand codegen constructs.
11///
12//===----------------------------------------------------------------------===//
13
14multiclass REF_I<WebAssemblyRegClass rc, ValueType vt> {
15  defm REF_NULL_#rc : I<(outs rc:$res), (ins HeapType:$heaptype),
16                        (outs), (ins HeapType:$heaptype),
17                        [],
18                        "ref.null\t$res, $heaptype",
19                        "ref.null\t$heaptype",
20                        0xd0>,
21                      Requires<[HasReferenceTypes]>;
22  defm SELECT_#rc: I<(outs rc:$dst), (ins rc:$lhs, rc:$rhs, I32:$cond),
23                     (outs), (ins),
24                     [(set rc:$dst,
25                       (select I32:$cond, rc:$lhs, rc:$rhs))],
26                     vt#".select\t$dst, $lhs, $rhs, $cond",
27                     vt#".select", 0x1b>,
28                   Requires<[HasReferenceTypes]>;
29}
30
31defm "" : REF_I<FUNCREF, funcref>;
32defm "" : REF_I<EXTERNREF, externref>;
33
34foreach rc = [FUNCREF, EXTERNREF] in {
35def : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
36          (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
37def : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
38          (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
39}
40