• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//===-- WebAssemblyInstrConv.td-WebAssembly Conversion support -*- tablegen -*-=
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief WebAssembly datatype conversions, truncations, reinterpretations,
12/// promotions, and demotions operand code-gen constructs.
13///
14//===----------------------------------------------------------------------===//
15
16let Defs = [ARGUMENTS] in {
17
18def I32_WRAP_I64 : I<(outs I32:$dst), (ins I64:$src),
19                      [(set I32:$dst, (trunc I64:$src))],
20                      "i32.wrap/i64\t$dst, $src">;
21
22def I64_EXTEND_S_I32 : I<(outs I64:$dst), (ins I32:$src),
23                          [(set I64:$dst, (sext I32:$src))],
24                          "i64.extend_s/i32\t$dst, $src">;
25def I64_EXTEND_U_I32 : I<(outs I64:$dst), (ins I32:$src),
26                         [(set I64:$dst, (zext I32:$src))],
27                         "i64.extend_u/i32\t$dst, $src">;
28
29} // defs = [ARGUMENTS]
30
31// Expand a "don't care" extend into zero-extend (chosen over sign-extend
32// somewhat arbitrarily, although it favors popular hardware architectures
33// and is conceptually a simpler operation).
34def : Pat<(i64 (anyext I32:$src)), (I64_EXTEND_U_I32 I32:$src)>;
35
36let Defs = [ARGUMENTS] in {
37
38// Conversion from floating point to integer traps on overflow and invalid.
39let hasSideEffects = 1 in {
40def I32_TRUNC_S_F32 : I<(outs I32:$dst), (ins F32:$src),
41                        [(set I32:$dst, (fp_to_sint F32:$src))],
42                        "i32.trunc_s/f32\t$dst, $src">;
43def I32_TRUNC_U_F32 : I<(outs I32:$dst), (ins F32:$src),
44                        [(set I32:$dst, (fp_to_uint F32:$src))],
45                        "i32.trunc_u/f32\t$dst, $src">;
46def I64_TRUNC_S_F32 : I<(outs I64:$dst), (ins F32:$src),
47                        [(set I64:$dst, (fp_to_sint F32:$src))],
48                        "i64.trunc_s/f32\t$dst, $src">;
49def I64_TRUNC_U_F32 : I<(outs I64:$dst), (ins F32:$src),
50                        [(set I64:$dst, (fp_to_uint F32:$src))],
51                        "i64.trunc_u/f32\t$dst, $src">;
52def I32_TRUNC_S_F64 : I<(outs I32:$dst), (ins F64:$src),
53                        [(set I32:$dst, (fp_to_sint F64:$src))],
54                        "i32.trunc_s/f64\t$dst, $src">;
55def I32_TRUNC_U_F64 : I<(outs I32:$dst), (ins F64:$src),
56                        [(set I32:$dst, (fp_to_uint F64:$src))],
57                        "i32.trunc_u/f64\t$dst, $src">;
58def I64_TRUNC_S_F64 : I<(outs I64:$dst), (ins F64:$src),
59                        [(set I64:$dst, (fp_to_sint F64:$src))],
60                        "i64.trunc_s/f64\t$dst, $src">;
61def I64_TRUNC_U_F64 : I<(outs I64:$dst), (ins F64:$src),
62                        [(set I64:$dst, (fp_to_uint F64:$src))],
63                        "i64.trunc_u/f64\t$dst, $src">;
64} // hasSideEffects = 1
65
66def F32_CONVERT_S_I32 : I<(outs F32:$dst), (ins I32:$src),
67                          [(set F32:$dst, (sint_to_fp I32:$src))],
68                          "f32.convert_s/i32\t$dst, $src">;
69def F32_CONVERT_U_I32 : I<(outs F32:$dst), (ins I32:$src),
70                          [(set F32:$dst, (uint_to_fp I32:$src))],
71                          "f32.convert_u/i32\t$dst, $src">;
72def F64_CONVERT_S_I32 : I<(outs F64:$dst), (ins I32:$src),
73                          [(set F64:$dst, (sint_to_fp I32:$src))],
74                          "f64.convert_s/i32\t$dst, $src">;
75def F64_CONVERT_U_I32 : I<(outs F64:$dst), (ins I32:$src),
76                          [(set F64:$dst, (uint_to_fp I32:$src))],
77                          "f64.convert_u/i32\t$dst, $src">;
78def F32_CONVERT_S_I64 : I<(outs F32:$dst), (ins I64:$src),
79                          [(set F32:$dst, (sint_to_fp I64:$src))],
80                          "f32.convert_s/i64\t$dst, $src">;
81def F32_CONVERT_U_I64 : I<(outs F32:$dst), (ins I64:$src),
82                          [(set F32:$dst, (uint_to_fp I64:$src))],
83                          "f32.convert_u/i64\t$dst, $src">;
84def F64_CONVERT_S_I64 : I<(outs F64:$dst), (ins I64:$src),
85                          [(set F64:$dst, (sint_to_fp I64:$src))],
86                          "f64.convert_s/i64\t$dst, $src">;
87def F64_CONVERT_U_I64 : I<(outs F64:$dst), (ins I64:$src),
88                          [(set F64:$dst, (uint_to_fp I64:$src))],
89                          "f64.convert_u/i64\t$dst, $src">;
90
91def F64_PROMOTE_F32 : I<(outs F64:$dst), (ins F32:$src),
92                        [(set F64:$dst, (fextend F32:$src))],
93                        "f64.promote/f32\t$dst, $src">;
94def F32_DEMOTE_F64 : I<(outs F32:$dst), (ins F64:$src),
95                       [(set F32:$dst, (fround F64:$src))],
96                       "f32.demote/f64\t$dst, $src">;
97
98def I32_REINTERPRET_F32 : I<(outs I32:$dst), (ins F32:$src),
99                            [(set I32:$dst, (bitconvert F32:$src))],
100                            "i32.reinterpret/f32\t$dst, $src">;
101def F32_REINTERPRET_I32 : I<(outs F32:$dst), (ins I32:$src),
102                            [(set F32:$dst, (bitconvert I32:$src))],
103                            "f32.reinterpret/i32\t$dst, $src">;
104def I64_REINTERPRET_F64 : I<(outs I64:$dst), (ins F64:$src),
105                            [(set I64:$dst, (bitconvert F64:$src))],
106                            "i64.reinterpret/f64\t$dst, $src">;
107def F64_REINTERPRET_I64 : I<(outs F64:$dst), (ins I64:$src),
108                            [(set F64:$dst, (bitconvert I64:$src))],
109                            "f64.reinterpret/i64\t$dst, $src">;
110
111} // Defs = [ARGUMENTS]
112