|
14 | 14 | #define MLIR_CIR_DIALECT_CIR_TYPES |
15 | 15 |
|
16 | 16 | include "clang/CIR/Dialect/IR/CIRDialect.td" |
17 | | -include "clang/CIR/Interfaces/CIRFPTypeInterface.td" |
18 | 17 | include "mlir/Interfaces/DataLayoutInterfaces.td" |
19 | 18 | include "mlir/IR/AttrTypeBase.td" |
20 | 19 |
|
@@ -130,224 +129,4 @@ def PrimitiveInt |
130 | 129 | : AnyTypeOf<[UInt8, UInt16, UInt32, UInt64, SInt8, SInt16, SInt32, SInt64], |
131 | 130 | "primitive int", "::cir::IntType">; |
132 | 131 |
|
133 | | -//===----------------------------------------------------------------------===// |
134 | | -// FloatType |
135 | | -//===----------------------------------------------------------------------===// |
136 | | - |
137 | | -class CIR_FloatType<string name, string mnemonic> |
138 | | - : CIR_Type<name, mnemonic, |
139 | | - [ |
140 | | - DeclareTypeInterfaceMethods<DataLayoutTypeInterface>, |
141 | | - DeclareTypeInterfaceMethods<CIRFPTypeInterface>, |
142 | | - ]> {} |
143 | | - |
144 | | -def CIR_Single : CIR_FloatType<"Single", "float"> { |
145 | | - let summary = "CIR single-precision 32-bit float type"; |
146 | | - let description = [{ |
147 | | - A 32-bit floating-point type whose format is IEEE-754 `binary32`. It |
148 | | - represents the types `float`, `_Float32`, and `std::float32_t` in C and C++. |
149 | | - }]; |
150 | | -} |
151 | | - |
152 | | -def CIR_Double : CIR_FloatType<"Double", "double"> { |
153 | | - let summary = "CIR double-precision 64-bit float type"; |
154 | | - let description = [{ |
155 | | - A 64-bit floating-point type whose format is IEEE-754 `binary64`. It |
156 | | - represents the types `double', '_Float64`, `std::float64_t`, and `_Float32x` |
157 | | - in C and C++. This is the underlying type for `long double` on some |
158 | | - platforms, including Windows. |
159 | | - }]; |
160 | | -} |
161 | | - |
162 | | -def CIR_FP16 : CIR_FloatType<"FP16", "f16"> { |
163 | | - let summary = "CIR half-precision 16-bit float type"; |
164 | | - let description = [{ |
165 | | - A 16-bit floating-point type whose format is IEEE-754 `binary16`. It |
166 | | - represents the types '_Float16` and `std::float16_t` in C and C++. |
167 | | - }]; |
168 | | -} |
169 | | - |
170 | | -def CIR_BFloat16 : CIR_FloatType<"BF16", "bf16"> { |
171 | | - let summary = "CIR bfloat16 16-bit float type"; |
172 | | - let description = [{ |
173 | | - A 16-bit floating-point type in the bfloat16 format, which is the same as |
174 | | - IEEE `binary32` except that the lower 16 bits of the mantissa are missing. |
175 | | - It represents the type `std::bfloat16_t` in C++, also spelled `__bf16` in |
176 | | - some implementations. |
177 | | - }]; |
178 | | -} |
179 | | - |
180 | | -def CIR_FP80 : CIR_FloatType<"FP80", "f80"> { |
181 | | - let summary = "CIR x87 80-bit float type"; |
182 | | - let description = [{ |
183 | | - An 80-bit floating-point type in the x87 extended precision format. The |
184 | | - size and alignment of the type are both 128 bits, even though only 80 of |
185 | | - those bits are used. This is the underlying type for `long double` on Linux |
186 | | - x86 platforms, and it is available as an extension in some implementations. |
187 | | - }]; |
188 | | -} |
189 | | - |
190 | | -def CIR_FP128 : CIR_FloatType<"FP128", "f128"> { |
191 | | - let summary = "CIR quad-precision 128-bit float type"; |
192 | | - let description = [{ |
193 | | - A 128-bit floating-point type whose format is IEEE-754 `binary128`. It |
194 | | - represents the types `_Float128` and `std::float128_t` in C and C++, and the |
195 | | - extension `__float128` in some implementations. This is the underlying type |
196 | | - for `long double` on some platforms including Linux Arm. |
197 | | - }]; |
198 | | -} |
199 | | - |
200 | | -def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> { |
201 | | - let summary = "CIR float type for `long double`"; |
202 | | - let description = [{ |
203 | | - A floating-point type that represents the `long double` type in C and C++. |
204 | | - |
205 | | - The underlying floating-point format of a `long double` value depends on the |
206 | | - target platform and the implementation. The `underlying` parameter specifies |
207 | | - the CIR floating-point type that corresponds to this format. Underlying |
208 | | - types of IEEE 64-bit, IEEE 128-bit, x87 80-bit, and IBM's double-double |
209 | | - format are all in use. |
210 | | - }]; |
211 | | - |
212 | | - let parameters = (ins "mlir::Type":$underlying); |
213 | | - |
214 | | - let assemblyFormat = [{ |
215 | | - `<` $underlying `>` |
216 | | - }]; |
217 | | - |
218 | | - let genVerifyDecl = 1; |
219 | | -} |
220 | | - |
221 | | -// Constraints |
222 | | - |
223 | | -def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double, CIR_FP80, CIR_FP128, CIR_LongDouble, |
224 | | - CIR_FP16, CIR_BFloat16]>; |
225 | | -def CIR_AnyIntOrFloat: AnyTypeOf<[CIR_AnyFloat, CIR_IntType]>; |
226 | | - |
227 | | -//===----------------------------------------------------------------------===// |
228 | | -// PointerType |
229 | | -//===----------------------------------------------------------------------===// |
230 | | - |
231 | | -def CIR_PointerType : CIR_Type<"Pointer", "ptr", |
232 | | - [DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> { |
233 | | - |
234 | | - let summary = "CIR pointer type"; |
235 | | - let description = [{ |
236 | | - The `cir.ptr` type represents C and C++ pointer types and C++ reference |
237 | | - types, other than pointers-to-members. The `pointee` type is the type |
238 | | - pointed to. |
239 | | - |
240 | | - TODO(CIR): The address space attribute is not yet implemented. |
241 | | - }]; |
242 | | - |
243 | | - let parameters = (ins "mlir::Type":$pointee); |
244 | | - |
245 | | - let builders = [ |
246 | | - TypeBuilderWithInferredContext<(ins "mlir::Type":$pointee), [{ |
247 | | - return $_get(pointee.getContext(), pointee); |
248 | | - }]>, |
249 | | - TypeBuilder<(ins "mlir::Type":$pointee), [{ |
250 | | - return $_get($_ctxt, pointee); |
251 | | - }]> |
252 | | - ]; |
253 | | - |
254 | | - let assemblyFormat = [{ |
255 | | - `<` $pointee `>` |
256 | | - }]; |
257 | | - |
258 | | - let genVerifyDecl = 1; |
259 | | - |
260 | | - let skipDefaultBuilders = 1; |
261 | | - |
262 | | - let extraClassDeclaration = [{ |
263 | | - bool isVoidPtr() const { |
264 | | - return mlir::isa<cir::VoidType>(getPointee()); |
265 | | - } |
266 | | - }]; |
267 | | -} |
268 | | - |
269 | | -//===----------------------------------------------------------------------===// |
270 | | -// FuncType |
271 | | -//===----------------------------------------------------------------------===// |
272 | | - |
273 | | -def CIR_FuncType : CIR_Type<"Func", "func"> { |
274 | | - let summary = "CIR function type"; |
275 | | - let description = [{ |
276 | | - The `!cir.func` is a function type. It consists of a single return type, a |
277 | | - list of parameter types and can optionally be variadic. |
278 | | - |
279 | | - Example: |
280 | | - |
281 | | - ```mlir |
282 | | - !cir.func<!bool ()> |
283 | | - !cir.func<!s32i (!s8i, !s8i)> |
284 | | - !cir.func<!s32i (!s32i, ...)> |
285 | | - ``` |
286 | | - }]; |
287 | | - |
288 | | - let parameters = (ins ArrayRefParameter<"mlir::Type">:$inputs, |
289 | | - "mlir::Type":$returnType, "bool":$varArg); |
290 | | - let assemblyFormat = [{ |
291 | | - `<` $returnType ` ` `(` custom<FuncTypeArgs>($inputs, $varArg) `>` |
292 | | - }]; |
293 | | - |
294 | | - let builders = [ |
295 | | - TypeBuilderWithInferredContext<(ins |
296 | | - "llvm::ArrayRef<mlir::Type>":$inputs, "mlir::Type":$returnType, |
297 | | - CArg<"bool", "false">:$isVarArg), [{ |
298 | | - return $_get(returnType.getContext(), inputs, returnType, isVarArg); |
299 | | - }]> |
300 | | - ]; |
301 | | - |
302 | | - let extraClassDeclaration = [{ |
303 | | - /// Returns whether the function is variadic. |
304 | | - bool isVarArg() const { return getVarArg(); } |
305 | | - |
306 | | - /// Returns the `i`th input operand type. Asserts if out of bounds. |
307 | | - mlir::Type getInput(unsigned i) const { return getInputs()[i]; } |
308 | | - |
309 | | - /// Returns the number of arguments to the function. |
310 | | - unsigned getNumInputs() const { return getInputs().size(); } |
311 | | - |
312 | | - /// Returns the result type of the function as an ArrayRef, enabling better |
313 | | - /// integration with generic MLIR utilities. |
314 | | - llvm::ArrayRef<mlir::Type> getReturnTypes() const; |
315 | | - |
316 | | - /// Returns whether the function is returns void. |
317 | | - bool isVoid() const; |
318 | | - |
319 | | - /// Returns a clone of this function type with the given argument |
320 | | - /// and result types. |
321 | | - FuncType clone(mlir::TypeRange inputs, mlir::TypeRange results) const; |
322 | | - }]; |
323 | | -} |
324 | | - |
325 | | -//===----------------------------------------------------------------------===// |
326 | | -// Void type |
327 | | -//===----------------------------------------------------------------------===// |
328 | | - |
329 | | -def CIR_VoidType : CIR_Type<"Void", "void"> { |
330 | | - let summary = "CIR void type"; |
331 | | - let description = [{ |
332 | | - The `!cir.void` type represents the C and C++ `void` type. |
333 | | - }]; |
334 | | - let extraClassDeclaration = [{ |
335 | | - std::string getAlias() const { return "void"; }; |
336 | | - }]; |
337 | | -} |
338 | | - |
339 | | -// Constraints |
340 | | - |
341 | | -// Pointer to void |
342 | | -def VoidPtr : Type< |
343 | | - And<[ |
344 | | - CPred<"::mlir::isa<::cir::PointerType>($_self)">, |
345 | | - CPred<"::mlir::isa<::cir::VoidType>(" |
346 | | - "::mlir::cast<::cir::PointerType>($_self).getPointee())">, |
347 | | - ]>, "void*">, |
348 | | - BuildableType< |
349 | | - "cir::PointerType::get($_builder.getContext()," |
350 | | - "cir::VoidType::get($_builder.getContext()))"> { |
351 | | -} |
352 | | - |
353 | 132 | #endif // MLIR_CIR_DIALECT_CIR_TYPES |
0 commit comments