1//===- AsyncTypes.td - Async dialect types -----------------*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file declares the Async dialect types. 10// 11//===----------------------------------------------------------------------===// 12 13#ifndef MLIR_DIALECT_ASYNC_IR_ASYNCTYPES 14#define MLIR_DIALECT_ASYNC_IR_ASYNCTYPES 15 16include "mlir/Dialect/Async/IR/AsyncDialect.td" 17 18//===----------------------------------------------------------------------===// 19// Async Types 20//===----------------------------------------------------------------------===// 21 22class Async_Type<string name, string typeMnemonic> : TypeDef<AsyncDialect, 23 name> { 24 let mnemonic = typeMnemonic; 25} 26 27def Async_TokenType : Async_Type<"Token", "token"> { 28 let summary = "async token type"; 29 let description = [{ 30 `async.token` is a type returned by asynchronous operations, and it becomes 31 `available` when the asynchronous operations that created it is completed. 32 }]; 33} 34 35def Async_ValueType : Async_Type<"Value", "value"> { 36 let summary = "async value type"; 37 let description = [{ 38 `async.value` represents a value returned by asynchronous operations, 39 which may or may not be available currently, but will be available at some 40 point in the future. 41 }]; 42 43 let parameters = (ins "Type":$valueType); 44 let builders = [ 45 TypeBuilderWithInferredContext<(ins "Type":$valueType), [{ 46 return $_get(valueType.getContext(), valueType); 47 }]> 48 ]; 49 let skipDefaultBuilders = 1; 50} 51 52def Async_GroupType : Async_Type<"Group", "group"> { 53 let summary = "async group type"; 54 let description = [{ 55 `async.group` represent a set of async tokens or values and allows to 56 execute async operations on all of them together (e.g. wait for the 57 completion of all/any of them). 58 }]; 59} 60 61def Async_AnyValueOrTokenType : AnyTypeOf<[Async_ValueType, 62 Async_TokenType]>; 63 64def Async_AnyAsyncType : AnyTypeOf<[Async_ValueType, 65 Async_TokenType, 66 Async_GroupType]>; 67 68//===----------------------------------------------------------------------===// 69// Types for lowering to LLVM + Async Runtime via the LLVM Coroutines. 70//===----------------------------------------------------------------------===// 71 72// LLVM coroutines intrinsics use `token` and `i8*` types to represent coroutine 73// identifiers and handles. To define type-safe Async Runtime operations and 74// build a properly typed intermediate IR during the Async to LLVM lowering we 75// define a separate types for values that can be produced by LLVM intrinsics. 76 77def Async_CoroIdType : Async_Type<"CoroId", "coro.id"> { 78 let summary = "switched-resume coroutine identifier"; 79 let description = [{ 80 `async.coro.id` is a type identifying a switched-resume coroutine. 81 }]; 82} 83 84def Async_CoroHandleType : Async_Type<"CoroHandle", "coro.handle"> { 85 let summary = "coroutine handle"; 86 let description = [{ 87 `async.coro.handle` is a handle to the coroutine (pointer to the coroutine 88 frame) that can be passed around to resume or destroy the coroutine. 89 }]; 90} 91 92def Async_CoroStateType : Async_Type<"CoroState", "coro.state"> { 93 let summary = "saved coroutine state"; 94 let description = [{ 95 `async.coro.state` is a saved coroutine state that should be passed to the 96 coroutine suspension operation. 97 }]; 98} 99 100#endif // MLIR_DIALECT_ASYNC_IR_ASYNCTYPES 101