1#pragma once
2
3#include <string>
4
5#include "taichi/common/core.h"
6
7namespace taichi::lang {
8
9enum 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
15std::string unary_op_type_name(UnaryOpType type);
16
17inline bool constexpr unary_op_is_cast(UnaryOpType op) {
18 return op == UnaryOpType::cast_value || op == UnaryOpType::cast_bits;
19}
20
21inline 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
31enum 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
37inline 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
43inline bool binary_is_logical(BinaryOpType t) {
44 return t == BinaryOpType ::logical_and || t == BinaryOpType ::logical_or;
45}
46
47std::string binary_op_type_name(BinaryOpType type);
48
49inline bool is_shift_op(BinaryOpType type) {
50 return type == BinaryOpType::bit_sar || type == BinaryOpType::bit_shl ||
51 type == BinaryOpType::bit_shr;
52}
53
54inline bool is_comparison(BinaryOpType type) {
55 return starts_with(binary_op_type_name(type), "cmp");
56}
57
58inline bool is_bit_op(BinaryOpType type) {
59 return starts_with(binary_op_type_name(type), "bit");
60}
61
62std::string binary_op_type_symbol(BinaryOpType type);
63
64enum class TernaryOpType : int { select, ifte, undefined };
65
66std::string ternary_type_name(TernaryOpType type);
67
68enum class AtomicOpType : int { add, sub, max, min, bit_and, bit_or, bit_xor };
69
70std::string atomic_op_type_name(AtomicOpType type);
71BinaryOpType atomic_to_binary_op_type(AtomicOpType type);
72
73enum 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
85std::string snode_op_type_name(SNodeOpType type);
86
87enum class TextureOpType : int {
88 kUndefined,
89 kSampleLod,
90 kFetchTexel,
91 kLoad,
92 kStore
93};
94
95std::string texture_op_type_name(TextureOpType type);
96
97} // namespace taichi::lang
98