1 | #pragma once |
2 | |
3 | #include <string> |
4 | |
5 | #include "taichi/common/core.h" |
6 | |
7 | namespace taichi::lang { |
8 | |
9 | enum class UnaryOpType : int { |
10 | #define PER_UNARY_OP(x) x, |
11 | #include "taichi/inc/unary_op.inc.h" |
12 | #undef PER_UNARY_OP |
13 | }; |
14 | |
15 | std::string unary_op_type_name(UnaryOpType type); |
16 | |
17 | inline bool constexpr unary_op_is_cast(UnaryOpType op) { |
18 | return op == UnaryOpType::cast_value || op == UnaryOpType::cast_bits; |
19 | } |
20 | |
21 | inline bool constexpr is_trigonometric(UnaryOpType op) { |
22 | return op == UnaryOpType::sin || op == UnaryOpType::asin || |
23 | op == UnaryOpType::cos || op == UnaryOpType::acos || |
24 | op == UnaryOpType::tan || op == UnaryOpType::tanh; |
25 | } |
26 | |
27 | // Regular binary ops: |
28 | // Operations that take two operands, and returns a single operand with the |
29 | // same type |
30 | |
31 | enum class BinaryOpType : int { |
32 | #define PER_BINARY_OP(x) x, |
33 | #include "taichi/inc/binary_op.inc.h" |
34 | #undef PER_BINARY_OP |
35 | }; |
36 | |
37 | inline bool binary_is_bitwise(BinaryOpType t) { |
38 | return t == BinaryOpType ::bit_and || t == BinaryOpType ::bit_or || |
39 | t == BinaryOpType ::bit_xor || t == BinaryOpType ::bit_shl || |
40 | t == BinaryOpType ::bit_shr || t == BinaryOpType ::bit_sar; |
41 | } |
42 | |
43 | inline bool binary_is_logical(BinaryOpType t) { |
44 | return t == BinaryOpType ::logical_and || t == BinaryOpType ::logical_or; |
45 | } |
46 | |
47 | std::string binary_op_type_name(BinaryOpType type); |
48 | |
49 | inline bool is_shift_op(BinaryOpType type) { |
50 | return type == BinaryOpType::bit_sar || type == BinaryOpType::bit_shl || |
51 | type == BinaryOpType::bit_shr; |
52 | } |
53 | |
54 | inline bool is_comparison(BinaryOpType type) { |
55 | return starts_with(binary_op_type_name(type), "cmp" ); |
56 | } |
57 | |
58 | inline bool is_bit_op(BinaryOpType type) { |
59 | return starts_with(binary_op_type_name(type), "bit" ); |
60 | } |
61 | |
62 | std::string binary_op_type_symbol(BinaryOpType type); |
63 | |
64 | enum class TernaryOpType : int { select, ifte, undefined }; |
65 | |
66 | std::string ternary_type_name(TernaryOpType type); |
67 | |
68 | enum class AtomicOpType : int { add, sub, max, min, bit_and, bit_or, bit_xor }; |
69 | |
70 | std::string atomic_op_type_name(AtomicOpType type); |
71 | BinaryOpType atomic_to_binary_op_type(AtomicOpType type); |
72 | |
73 | enum class SNodeOpType : int { |
74 | is_active, |
75 | length, |
76 | get_addr, |
77 | activate, |
78 | deactivate, |
79 | append, |
80 | allocate, |
81 | clear, |
82 | undefined |
83 | }; |
84 | |
85 | std::string snode_op_type_name(SNodeOpType type); |
86 | |
87 | enum class TextureOpType : int { |
88 | kUndefined, |
89 | kSampleLod, |
90 | kFetchTexel, |
91 | kLoad, |
92 | kStore |
93 | }; |
94 | |
95 | std::string texture_op_type_name(TextureOpType type); |
96 | |
97 | } // namespace taichi::lang |
98 | |