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