1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | |
20 | /*! |
21 | * \file tvm/tir/op_attr_types.h |
22 | * \brief Attribute types in the Op registry for TIR ops. |
23 | * |
24 | * These attributes can be set via OpRegEntry::set_attr |
25 | * |
26 | * \sa tvm/ir/op.h |
27 | */ |
28 | #ifndef TVM_TIR_OP_ATTR_TYPES_H_ |
29 | #define TVM_TIR_OP_ATTR_TYPES_H_ |
30 | |
31 | #include <tvm/ir/expr.h> |
32 | #include <tvm/runtime/container/string.h> |
33 | #include <tvm/runtime/packed_func.h> |
34 | |
35 | #include <ostream> |
36 | |
37 | namespace tvm { |
38 | namespace tir { |
39 | /*! |
40 | * \brief Global symbol of the op after lowering. |
41 | */ |
42 | using TGlobalSymbol = String; |
43 | |
44 | /*! |
45 | * \brief Whether the op is overloaded for vector form. |
46 | */ |
47 | using TVectorizable = bool; |
48 | |
49 | /*! |
50 | * \brief The intrinsic lowering function for given op. |
51 | */ |
52 | using FLowerIntrinsic = runtime::TypedPackedFunc<PrimExpr(PrimExpr)>; |
53 | |
54 | /*! |
55 | * \brief The legalization function for given tir op. |
56 | */ |
57 | using FLegalize = runtime::TypedPackedFunc<PrimExpr(PrimExpr)>; |
58 | |
59 | /*! |
60 | * \brief The operator's name in TVMScript printer |
61 | */ |
62 | using TScriptPrinterName = String; |
63 | |
64 | /*! |
65 | * \brief The effect type of the call. |
66 | */ |
67 | enum class CallEffectKind : int { |
68 | /*! \brief Function corresponds to an annotation(e.g. likely) and can translate to identity. */ |
69 | kExprAnnotation = 0, |
70 | /*! |
71 | * \brief Pure function that do not interacts |
72 | * with any external state. |
73 | */ |
74 | kPure = 1, |
75 | /*! |
76 | * \brief Function's that may read from states(e.g. RAM) |
77 | */ |
78 | kReadState = 2, |
79 | /*! |
80 | * \brief Function that may read/write from states(e.g. RAM). |
81 | */ |
82 | kUpdateState = 3, |
83 | /*! |
84 | * \brief Opaque function, cannot make any assumption |
85 | */ |
86 | kOpaque = kUpdateState, |
87 | /*! |
88 | * \brief Special intrinsic to annotate call arguments info |
89 | * only valid as a direct argument to a call. |
90 | */ |
91 | kSpecialCallArg = 4, |
92 | /*! |
93 | * \brief Embed opaque information in the Expr, cannot be codegen. |
94 | */ |
95 | kEmbedInfo = 5, |
96 | /*! |
97 | * \brief Function that changes control flow |
98 | */ |
99 | kControlJump = 6, |
100 | }; |
101 | |
102 | inline std::ostream& operator<<(std::ostream& os, CallEffectKind side_effect) { |
103 | switch (side_effect) { |
104 | case CallEffectKind::kExprAnnotation: |
105 | return os << "kExprAnnotation" ; |
106 | |
107 | case CallEffectKind::kPure: |
108 | return os << "kPure" ; |
109 | |
110 | case CallEffectKind::kReadState: |
111 | return os << "kReadState" ; |
112 | |
113 | case CallEffectKind::kUpdateState: |
114 | return os << "kUpdateState" ; |
115 | |
116 | case CallEffectKind::kSpecialCallArg: |
117 | return os << "kSpecialCallArg" ; |
118 | |
119 | case CallEffectKind::kEmbedInfo: |
120 | return os << "kEmbedInfo" ; |
121 | |
122 | case CallEffectKind::kControlJump: |
123 | return os << "kControlJump" ; |
124 | |
125 | default: |
126 | LOG(FATAL) << "Unknown CallEffectKind: " << static_cast<int>(side_effect); |
127 | } |
128 | } |
129 | |
130 | /*! \brief Use integer to record the kind. */ |
131 | using TCallEffectKind = Integer; |
132 | |
133 | } // namespace tir |
134 | } // namespace tvm |
135 | #endif // TVM_TIR_OP_ATTR_TYPES_H_ |
136 | |