WebAssemblyInstrRef.td 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. multiclass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
  14. defm REF_NULL_#rc : I<(outs rc:$dst), (ins),
  15. (outs), (ins),
  16. [(set rc:$dst, (!cast<Intrinsic>("int_wasm_ref_null_" # ht)))],
  17. "ref.null_" # ht # "$dst",
  18. "ref.null_" # ht,
  19. !cond(!eq(ht, "func") : 0xd070,
  20. !eq(ht, "extern") : 0xd06f)>,
  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. defm REF_IS_NULL_#rc
  30. : I<(outs I32:$dst), (ins rc:$ref), (outs), (ins),
  31. [(set I32:$dst, (!cast<Intrinsic>("int_wasm_ref_is_null_" # ht) rc:$ref))],
  32. "ref.is_null\t$ref",
  33. "ref.is_null", 0xd1>,
  34. Requires<[HasReferenceTypes]>;
  35. }
  36. defm "" : REF_I<FUNCREF, funcref, "func">;
  37. defm "" : REF_I<EXTERNREF, externref, "extern">;
  38. foreach rc = [FUNCREF, EXTERNREF] in {
  39. def : Pat<(select (i32 (setne I32:$cond, 0)), rc:$lhs, rc:$rhs),
  40. (!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
  41. def : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
  42. (!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
  43. }