MLIR 24.0.0git
AsyncToLLVM.cpp
Go to the documentation of this file.
1//===- AsyncToLLVM.cpp - Convert Async to LLVM dialect --------------------===//
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
10
29#include "mlir/Pass/Pass.h"
31#include "llvm/ADT/TypeSwitch.h"
32
33namespace mlir {
34#define GEN_PASS_DEF_CONVERTASYNCTOLLVMPASS
35#include "mlir/Conversion/Passes.h.inc"
36} // namespace mlir
37
38#define DEBUG_TYPE "convert-async-to-llvm"
39
40using namespace mlir;
41using namespace mlir::async;
42
43//===----------------------------------------------------------------------===//
44// Async Runtime C API declaration.
45//===----------------------------------------------------------------------===//
46
47static constexpr const char *kAddRef = "mlirAsyncRuntimeAddRef";
48static constexpr const char *kDropRef = "mlirAsyncRuntimeDropRef";
49static constexpr const char *kCreateToken = "mlirAsyncRuntimeCreateToken";
50static constexpr const char *kCreateValue = "mlirAsyncRuntimeCreateValue";
51static constexpr const char *kCreateGroup = "mlirAsyncRuntimeCreateGroup";
52static constexpr const char *kEmplaceToken = "mlirAsyncRuntimeEmplaceToken";
53static constexpr const char *kEmplaceValue = "mlirAsyncRuntimeEmplaceValue";
54static constexpr const char *kSetTokenError = "mlirAsyncRuntimeSetTokenError";
55static constexpr const char *kSetValueError = "mlirAsyncRuntimeSetValueError";
56static constexpr const char *kIsTokenError = "mlirAsyncRuntimeIsTokenError";
57static constexpr const char *kIsValueError = "mlirAsyncRuntimeIsValueError";
58static constexpr const char *kIsGroupError = "mlirAsyncRuntimeIsGroupError";
59static constexpr const char *kAwaitToken = "mlirAsyncRuntimeAwaitToken";
60static constexpr const char *kAwaitValue = "mlirAsyncRuntimeAwaitValue";
61static constexpr const char *kAwaitGroup = "mlirAsyncRuntimeAwaitAllInGroup";
62static constexpr const char *kExecute = "mlirAsyncRuntimeExecute";
63static constexpr const char *kGetValueStorage =
64 "mlirAsyncRuntimeGetValueStorage";
65static constexpr const char *kAddTokenToGroup =
66 "mlirAsyncRuntimeAddTokenToGroup";
67static constexpr const char *kAwaitTokenAndExecute =
68 "mlirAsyncRuntimeAwaitTokenAndExecute";
69static constexpr const char *kAwaitValueAndExecute =
70 "mlirAsyncRuntimeAwaitValueAndExecute";
71static constexpr const char *kAwaitAllAndExecute =
72 "mlirAsyncRuntimeAwaitAllInGroupAndExecute";
73static constexpr const char *kGetNumWorkerThreads =
74 "mlirAsyncRuntimGetNumWorkerThreads";
75
76namespace {
77/// Async Runtime API function types.
78///
79/// Because we can't create API function signature for type parametrized
80/// async.getValue type, we use opaque pointers (!llvm.ptr) instead. After
81/// lowering all async data types become opaque pointers at runtime.
82struct AsyncAPI {
83 // All async types are lowered to opaque LLVM pointers at runtime.
84 static LLVM::LLVMPointerType opaquePointerType(MLIRContext *ctx) {
85 return LLVM::LLVMPointerType::get(ctx);
86 }
87
88 static mlir::TokenType tokenType(MLIRContext *ctx) {
89 return mlir::TokenType::get(ctx);
90 }
91
92 static FunctionType addOrDropRefFunctionType(MLIRContext *ctx) {
93 auto ref = opaquePointerType(ctx);
94 auto count = IntegerType::get(ctx, 64);
95 return FunctionType::get(ctx, {ref, count}, {});
96 }
97
98 static FunctionType createTokenFunctionType(MLIRContext *ctx) {
99 return FunctionType::get(ctx, {}, {async::TokenType::get(ctx)});
100 }
101
102 static FunctionType createValueFunctionType(MLIRContext *ctx) {
103 auto i64 = IntegerType::get(ctx, 64);
104 auto value = opaquePointerType(ctx);
105 return FunctionType::get(ctx, {i64}, {value});
106 }
107
108 static FunctionType createGroupFunctionType(MLIRContext *ctx) {
109 auto i64 = IntegerType::get(ctx, 64);
110 return FunctionType::get(ctx, {i64}, {GroupType::get(ctx)});
111 }
112
113 static FunctionType getValueStorageFunctionType(MLIRContext *ctx) {
114 auto ptrType = opaquePointerType(ctx);
115 return FunctionType::get(ctx, {ptrType}, {ptrType});
116 }
117
118 static FunctionType emplaceTokenFunctionType(MLIRContext *ctx) {
119 return FunctionType::get(ctx, {async::TokenType::get(ctx)}, {});
120 }
121
122 static FunctionType emplaceValueFunctionType(MLIRContext *ctx) {
123 auto value = opaquePointerType(ctx);
124 return FunctionType::get(ctx, {value}, {});
125 }
126
127 static FunctionType setTokenErrorFunctionType(MLIRContext *ctx) {
128 return FunctionType::get(ctx, {async::TokenType::get(ctx)}, {});
129 }
130
131 static FunctionType setValueErrorFunctionType(MLIRContext *ctx) {
132 auto value = opaquePointerType(ctx);
133 return FunctionType::get(ctx, {value}, {});
134 }
135
136 static FunctionType isTokenErrorFunctionType(MLIRContext *ctx) {
137 auto i1 = IntegerType::get(ctx, 1);
138 return FunctionType::get(ctx, {async::TokenType::get(ctx)}, {i1});
139 }
140
141 static FunctionType isValueErrorFunctionType(MLIRContext *ctx) {
142 auto value = opaquePointerType(ctx);
143 auto i1 = IntegerType::get(ctx, 1);
144 return FunctionType::get(ctx, {value}, {i1});
145 }
146
147 static FunctionType isGroupErrorFunctionType(MLIRContext *ctx) {
148 auto i1 = IntegerType::get(ctx, 1);
149 return FunctionType::get(ctx, {GroupType::get(ctx)}, {i1});
150 }
151
152 static FunctionType awaitTokenFunctionType(MLIRContext *ctx) {
153 return FunctionType::get(ctx, {async::TokenType::get(ctx)}, {});
154 }
155
156 static FunctionType awaitValueFunctionType(MLIRContext *ctx) {
157 auto value = opaquePointerType(ctx);
158 return FunctionType::get(ctx, {value}, {});
159 }
160
161 static FunctionType awaitGroupFunctionType(MLIRContext *ctx) {
162 return FunctionType::get(ctx, {GroupType::get(ctx)}, {});
163 }
164
165 static FunctionType executeFunctionType(MLIRContext *ctx) {
166 auto ptrType = opaquePointerType(ctx);
167 return FunctionType::get(ctx, {ptrType, ptrType}, {});
168 }
169
170 static FunctionType addTokenToGroupFunctionType(MLIRContext *ctx) {
171 auto i64 = IntegerType::get(ctx, 64);
172 return FunctionType::get(
173 ctx, {async::TokenType::get(ctx), GroupType::get(ctx)}, {i64});
174 }
175
176 static FunctionType awaitTokenAndExecuteFunctionType(MLIRContext *ctx) {
177 auto ptrType = opaquePointerType(ctx);
178 return FunctionType::get(
179 ctx, {async::TokenType::get(ctx), ptrType, ptrType}, {});
180 }
181
182 static FunctionType awaitValueAndExecuteFunctionType(MLIRContext *ctx) {
183 auto ptrType = opaquePointerType(ctx);
184 return FunctionType::get(ctx, {ptrType, ptrType, ptrType}, {});
185 }
186
187 static FunctionType awaitAllAndExecuteFunctionType(MLIRContext *ctx) {
188 auto ptrType = opaquePointerType(ctx);
189 return FunctionType::get(ctx, {GroupType::get(ctx), ptrType, ptrType}, {});
190 }
191
192 static FunctionType getNumWorkerThreads(MLIRContext *ctx) {
193 return FunctionType::get(ctx, {}, {IndexType::get(ctx)});
194 }
195
196 // Auxiliary coroutine resume intrinsic wrapper.
197 static Type resumeFunctionType(MLIRContext *ctx) {
198 auto voidTy = LLVM::LLVMVoidType::get(ctx);
199 auto ptrType = opaquePointerType(ctx);
200 return LLVM::LLVMFunctionType::get(voidTy, {ptrType}, false);
201 }
202};
203} // namespace
204
205/// Adds Async Runtime C API declarations to the module.
206static void addAsyncRuntimeApiDeclarations(ModuleOp module) {
207 auto builder =
208 ImplicitLocOpBuilder::atBlockEnd(module.getLoc(), module.getBody());
209
210 auto addFuncDecl = [&](StringRef name, FunctionType type) {
211 if (module.lookupSymbol(name))
212 return;
213 func::FuncOp::create(builder, name, type).setPrivate();
214 };
215
216 MLIRContext *ctx = module.getContext();
217 addFuncDecl(kAddRef, AsyncAPI::addOrDropRefFunctionType(ctx));
218 addFuncDecl(kDropRef, AsyncAPI::addOrDropRefFunctionType(ctx));
219 addFuncDecl(kCreateToken, AsyncAPI::createTokenFunctionType(ctx));
220 addFuncDecl(kCreateValue, AsyncAPI::createValueFunctionType(ctx));
221 addFuncDecl(kCreateGroup, AsyncAPI::createGroupFunctionType(ctx));
222 addFuncDecl(kEmplaceToken, AsyncAPI::emplaceTokenFunctionType(ctx));
223 addFuncDecl(kEmplaceValue, AsyncAPI::emplaceValueFunctionType(ctx));
224 addFuncDecl(kSetTokenError, AsyncAPI::setTokenErrorFunctionType(ctx));
225 addFuncDecl(kSetValueError, AsyncAPI::setValueErrorFunctionType(ctx));
226 addFuncDecl(kIsTokenError, AsyncAPI::isTokenErrorFunctionType(ctx));
227 addFuncDecl(kIsValueError, AsyncAPI::isValueErrorFunctionType(ctx));
228 addFuncDecl(kIsGroupError, AsyncAPI::isGroupErrorFunctionType(ctx));
229 addFuncDecl(kAwaitToken, AsyncAPI::awaitTokenFunctionType(ctx));
230 addFuncDecl(kAwaitValue, AsyncAPI::awaitValueFunctionType(ctx));
231 addFuncDecl(kAwaitGroup, AsyncAPI::awaitGroupFunctionType(ctx));
232 addFuncDecl(kExecute, AsyncAPI::executeFunctionType(ctx));
233 addFuncDecl(kGetValueStorage, AsyncAPI::getValueStorageFunctionType(ctx));
234 addFuncDecl(kAddTokenToGroup, AsyncAPI::addTokenToGroupFunctionType(ctx));
235 addFuncDecl(kAwaitTokenAndExecute,
236 AsyncAPI::awaitTokenAndExecuteFunctionType(ctx));
237 addFuncDecl(kAwaitValueAndExecute,
238 AsyncAPI::awaitValueAndExecuteFunctionType(ctx));
239 addFuncDecl(kAwaitAllAndExecute,
240 AsyncAPI::awaitAllAndExecuteFunctionType(ctx));
241 addFuncDecl(kGetNumWorkerThreads, AsyncAPI::getNumWorkerThreads(ctx));
242}
243
244//===----------------------------------------------------------------------===//
245// Coroutine resume function wrapper.
246//===----------------------------------------------------------------------===//
247
248static constexpr const char *kResume = "__resume";
249
250/// A function that takes a coroutine handle and calls a `llvm.coro.resume`
251/// intrinsics. We need this function to be able to pass it to the async
252/// runtime execute API.
253static void addResumeFunction(ModuleOp module) {
254 if (module.lookupSymbol(kResume))
255 return;
256
257 MLIRContext *ctx = module.getContext();
258 auto loc = module.getLoc();
259 auto moduleBuilder = ImplicitLocOpBuilder::atBlockEnd(loc, module.getBody());
260
261 auto voidTy = LLVM::LLVMVoidType::get(ctx);
262 Type ptrType = AsyncAPI::opaquePointerType(ctx);
263
264 auto resumeOp = LLVM::LLVMFuncOp::create(
265 moduleBuilder, kResume, LLVM::LLVMFunctionType::get(voidTy, {ptrType}));
266 resumeOp.setPrivate();
267
268 auto *block = resumeOp.addEntryBlock(moduleBuilder);
269 auto blockBuilder = ImplicitLocOpBuilder::atBlockEnd(loc, block);
270
271 LLVM::CoroResumeOp::create(blockBuilder, resumeOp.getArgument(0));
272 LLVM::ReturnOp::create(blockBuilder, ValueRange());
273}
274
275//===----------------------------------------------------------------------===//
276// Convert Async dialect types to LLVM types.
277//===----------------------------------------------------------------------===//
278
279namespace {
280/// AsyncRuntimeTypeConverter only converts types from the Async dialect to
281/// their runtime type (opaque pointers) and does not convert any other types.
282class AsyncRuntimeTypeConverter : public TypeConverter {
283public:
284 AsyncRuntimeTypeConverter(const LowerToLLVMOptions &options) {
285 addConversion([](Type type) { return type; });
286 addConversion([](Type type) { return convertAsyncTypes(type); });
287
288 // Use UnrealizedConversionCast as the bridge so that we don't need to pull
289 // in patterns for other dialects.
290 auto addUnrealizedCast = [](OpBuilder &builder, Type type,
291 ValueRange inputs, Location loc) -> Value {
292 auto cast =
293 UnrealizedConversionCastOp::create(builder, loc, type, inputs);
294 return cast.getResult(0);
295 };
296
297 addSourceMaterialization(addUnrealizedCast);
298 addTargetMaterialization(addUnrealizedCast);
299 }
300
301 static std::optional<Type> convertAsyncTypes(Type type) {
302 if (isa<async::TokenType, GroupType, ValueType>(type))
303 return AsyncAPI::opaquePointerType(type.getContext());
304
305 if (isa<CoroIdType, CoroStateType>(type))
306 return AsyncAPI::tokenType(type.getContext());
307 if (isa<CoroHandleType>(type))
308 return AsyncAPI::opaquePointerType(type.getContext());
309
310 return std::nullopt;
311 }
312};
313
314/// Base class for conversion patterns requiring AsyncRuntimeTypeConverter
315/// as type converter. Allows access to it via the 'getTypeConverter'
316/// convenience method.
317template <typename SourceOp>
318class AsyncOpConversionPattern : public OpConversionPattern<SourceOp> {
319
320 using Base = OpConversionPattern<SourceOp>;
321
322public:
323 AsyncOpConversionPattern(const AsyncRuntimeTypeConverter &typeConverter,
324 MLIRContext *context)
325 : Base(typeConverter, context) {}
326
327 /// Returns the 'AsyncRuntimeTypeConverter' of the pattern.
328 const AsyncRuntimeTypeConverter *getTypeConverter() const {
329 return static_cast<const AsyncRuntimeTypeConverter *>(
330 Base::getTypeConverter());
331 }
332};
333
334} // namespace
335
336//===----------------------------------------------------------------------===//
337// Convert async.coro.id to @llvm.coro.id intrinsic.
338//===----------------------------------------------------------------------===//
339
340namespace {
341class CoroIdOpConversion : public AsyncOpConversionPattern<CoroIdOp> {
342public:
343 using AsyncOpConversionPattern::AsyncOpConversionPattern;
344
345 LogicalResult
346 matchAndRewrite(CoroIdOp op, OpAdaptor adaptor,
347 ConversionPatternRewriter &rewriter) const override {
348 auto token = AsyncAPI::tokenType(op->getContext());
349 auto ptrType = AsyncAPI::opaquePointerType(op->getContext());
350 auto loc = op->getLoc();
351
352 // Constants for initializing coroutine frame.
353 auto constZero =
354 LLVM::ConstantOp::create(rewriter, loc, rewriter.getI32Type(), 0);
355 auto nullPtr = LLVM::ZeroOp::create(rewriter, loc, ptrType);
356
357 // Get coroutine id: @llvm.coro.id.
358 rewriter.replaceOpWithNewOp<LLVM::CoroIdOp>(
359 op, token, ValueRange({constZero, nullPtr, nullPtr, nullPtr}));
360
361 return success();
362 }
363};
364} // namespace
365
366//===----------------------------------------------------------------------===//
367// Convert async.coro.begin to @llvm.coro.begin intrinsic.
368//===----------------------------------------------------------------------===//
369
370namespace {
371class CoroBeginOpConversion : public AsyncOpConversionPattern<CoroBeginOp> {
372public:
373 using AsyncOpConversionPattern::AsyncOpConversionPattern;
374
375 LogicalResult
376 matchAndRewrite(CoroBeginOp op, OpAdaptor adaptor,
377 ConversionPatternRewriter &rewriter) const override {
378 auto ptrType = AsyncAPI::opaquePointerType(op->getContext());
379 auto loc = op->getLoc();
380
381 // Get coroutine frame size: @llvm.coro.size.i64.
382 Value coroSize =
383 LLVM::CoroSizeOp::create(rewriter, loc, rewriter.getI64Type());
384 // Get coroutine frame alignment: @llvm.coro.align.i64.
385 Value coroAlign =
386 LLVM::CoroAlignOp::create(rewriter, loc, rewriter.getI64Type());
387
388 // Round up the size to be multiple of the alignment. Since aligned_alloc
389 // requires the size parameter be an integral multiple of the alignment
390 // parameter.
391 auto makeConstant = [&](uint64_t c) {
392 return LLVM::ConstantOp::create(rewriter, op->getLoc(),
393 rewriter.getI64Type(), c);
394 };
395 coroSize = LLVM::AddOp::create(rewriter, op->getLoc(), coroSize, coroAlign);
396 coroSize =
397 LLVM::SubOp::create(rewriter, op->getLoc(), coroSize, makeConstant(1));
398 Value negCoroAlign =
399 LLVM::SubOp::create(rewriter, op->getLoc(), makeConstant(0), coroAlign);
400 coroSize =
401 LLVM::AndOp::create(rewriter, op->getLoc(), coroSize, negCoroAlign);
402
403 // Allocate memory for the coroutine frame.
404 auto allocFuncOp = LLVM::lookupOrCreateAlignedAllocFn(
405 rewriter, op->getParentOfType<ModuleOp>(), rewriter.getI64Type());
406 if (failed(allocFuncOp))
407 return failure();
408 auto coroAlloc = LLVM::CallOp::create(rewriter, loc, allocFuncOp.value(),
409 ValueRange{coroAlign, coroSize});
410
411 // Begin a coroutine: @llvm.coro.begin.
412 auto coroId = CoroBeginOpAdaptor(adaptor.getOperands()).getId();
413 rewriter.replaceOpWithNewOp<LLVM::CoroBeginOp>(
414 op, ptrType, ValueRange({coroId, coroAlloc.getResult()}));
415
416 return success();
417 }
418};
419} // namespace
420
421//===----------------------------------------------------------------------===//
422// Convert async.coro.free to @llvm.coro.free intrinsic.
423//===----------------------------------------------------------------------===//
424
425namespace {
426class CoroFreeOpConversion : public AsyncOpConversionPattern<CoroFreeOp> {
427public:
428 using AsyncOpConversionPattern::AsyncOpConversionPattern;
429
430 LogicalResult
431 matchAndRewrite(CoroFreeOp op, OpAdaptor adaptor,
432 ConversionPatternRewriter &rewriter) const override {
433 auto ptrType = AsyncAPI::opaquePointerType(op->getContext());
434 auto loc = op->getLoc();
435
436 // Get a pointer to the coroutine frame memory: @llvm.coro.free.
437 auto coroMem =
438 LLVM::CoroFreeOp::create(rewriter, loc, ptrType, adaptor.getOperands());
439
440 // Free the memory.
441 auto freeFuncOp =
442 LLVM::lookupOrCreateFreeFn(rewriter, op->getParentOfType<ModuleOp>());
443 if (failed(freeFuncOp))
444 return failure();
445 rewriter.replaceOpWithNewOp<LLVM::CallOp>(op, freeFuncOp.value(),
446 ValueRange(coroMem.getResult()));
447
448 return success();
449 }
450};
451} // namespace
452
453//===----------------------------------------------------------------------===//
454// Convert async.coro.end to @llvm.coro.end intrinsic.
455//===----------------------------------------------------------------------===//
456
457namespace {
458class CoroEndOpConversion : public OpConversionPattern<CoroEndOp> {
459public:
460 using Base::Base;
461
462 LogicalResult
463 matchAndRewrite(CoroEndOp op, OpAdaptor adaptor,
464 ConversionPatternRewriter &rewriter) const override {
465 // We are not in the block that is part of the unwind sequence.
466 auto constFalse =
467 LLVM::ConstantOp::create(rewriter, op->getLoc(), rewriter.getI1Type(),
468 rewriter.getBoolAttr(false));
469 auto noneToken = LLVM::NoneTokenOp::create(rewriter, op->getLoc());
470
471 // Mark the end of a coroutine: @llvm.coro.end.
472 auto coroHdl = adaptor.getHandle();
473 LLVM::CoroEndOp::create(rewriter, op->getLoc(), rewriter.getI1Type(),
474 ValueRange({coroHdl, constFalse, noneToken}));
475 rewriter.eraseOp(op);
476
477 return success();
478 }
479};
480} // namespace
481
482//===----------------------------------------------------------------------===//
483// Convert async.coro.save to @llvm.coro.save intrinsic.
484//===----------------------------------------------------------------------===//
485
486namespace {
487class CoroSaveOpConversion : public OpConversionPattern<CoroSaveOp> {
488public:
489 using Base::Base;
490
491 LogicalResult
492 matchAndRewrite(CoroSaveOp op, OpAdaptor adaptor,
493 ConversionPatternRewriter &rewriter) const override {
494 // Save the coroutine state: @llvm.coro.save
495 rewriter.replaceOpWithNewOp<LLVM::CoroSaveOp>(
496 op, AsyncAPI::tokenType(op->getContext()), adaptor.getOperands());
497
498 return success();
499 }
500};
501} // namespace
502
503//===----------------------------------------------------------------------===//
504// Convert async.coro.suspend to @llvm.coro.suspend intrinsic.
505//===----------------------------------------------------------------------===//
506
507namespace {
508
509/// Convert async.coro.suspend to the @llvm.coro.suspend intrinsic call, and
510/// branch to the appropriate block based on the return code.
511///
512/// Before:
513///
514/// ^suspended:
515/// "opBefore"(...)
516/// async.coro.suspend %state, ^suspend, ^resume, ^cleanup
517/// ^resume:
518/// "op"(...)
519/// ^cleanup: ...
520/// ^suspend: ...
521///
522/// After:
523///
524/// ^suspended:
525/// "opBefore"(...)
526/// %suspend = llmv.intr.coro.suspend ...
527/// switch %suspend [-1: ^suspend, 0: ^resume, 1: ^cleanup]
528/// ^resume:
529/// "op"(...)
530/// ^cleanup: ...
531/// ^suspend: ...
532///
533class CoroSuspendOpConversion : public OpConversionPattern<CoroSuspendOp> {
534public:
535 using Base::Base;
536
537 LogicalResult
538 matchAndRewrite(CoroSuspendOp op, OpAdaptor adaptor,
539 ConversionPatternRewriter &rewriter) const override {
540 auto i8 = rewriter.getIntegerType(8);
541 auto i32 = rewriter.getI32Type();
542 auto loc = op->getLoc();
543
544 // This is not a final suspension point.
545 auto constFalse = LLVM::ConstantOp::create(
546 rewriter, loc, rewriter.getI1Type(), rewriter.getBoolAttr(false));
547
548 // Suspend a coroutine: @llvm.coro.suspend
549 auto coroState = adaptor.getState();
550 auto coroSuspend = LLVM::CoroSuspendOp::create(
551 rewriter, loc, i8, ValueRange({coroState, constFalse}));
552
553 // Cast return code to i32.
554
555 // After a suspension point decide if we should branch into resume, cleanup
556 // or suspend block of the coroutine (see @llvm.coro.suspend return code
557 // documentation).
558 llvm::SmallVector<int32_t, 2> caseValues = {0, 1};
559 llvm::SmallVector<Block *, 2> caseDest = {op.getResumeDest(),
560 op.getCleanupDest()};
561 rewriter.replaceOpWithNewOp<LLVM::SwitchOp>(
562 op, LLVM::SExtOp::create(rewriter, loc, i32, coroSuspend.getResult()),
563 /*defaultDestination=*/op.getSuspendDest(),
564 /*defaultOperands=*/ValueRange(),
565 /*caseValues=*/caseValues,
566 /*caseDestinations=*/caseDest,
567 /*caseOperands=*/ArrayRef<ValueRange>({ValueRange(), ValueRange()}),
568 /*branchWeights=*/ArrayRef<int32_t>());
569
570 return success();
571 }
572};
573} // namespace
574
575//===----------------------------------------------------------------------===//
576// Convert async.runtime.create to the corresponding runtime API call.
577//
578// To allocate storage for the async values we use getelementptr trick:
579// http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt
580//===----------------------------------------------------------------------===//
581
582namespace {
583class RuntimeCreateOpLowering : public ConvertOpToLLVMPattern<RuntimeCreateOp> {
584public:
586
587 LogicalResult
588 matchAndRewrite(RuntimeCreateOp op, OpAdaptor adaptor,
589 ConversionPatternRewriter &rewriter) const override {
590 const TypeConverter *converter = getTypeConverter();
591 Type resultType = op->getResultTypes()[0];
592
593 // Tokens creation maps to a simple function call.
594 if (isa<async::TokenType>(resultType)) {
595 rewriter.replaceOpWithNewOp<func::CallOp>(
596 op, kCreateToken, converter->convertType(resultType));
597 return success();
598 }
599
600 // To create a value we need to compute the storage requirement.
601 if (auto value = dyn_cast<ValueType>(resultType)) {
602 // Returns the size requirements for the async value storage.
603 auto sizeOf = [&](ValueType valueType) -> Value {
604 auto loc = op->getLoc();
605 auto i64 = rewriter.getI64Type();
606
607 auto storedType = converter->convertType(valueType.getValueType());
608 auto storagePtrType =
609 AsyncAPI::opaquePointerType(rewriter.getContext());
610
611 // %Size = getelementptr %T* null, int 1
612 // %SizeI = ptrtoint %T* %Size to i64
613 auto nullPtr = LLVM::ZeroOp::create(rewriter, loc, storagePtrType);
614 auto gep =
615 LLVM::GEPOp::create(rewriter, loc, storagePtrType, storedType,
616 nullPtr, ArrayRef<LLVM::GEPArg>{1});
617 return LLVM::PtrToIntOp::create(rewriter, loc, i64, gep);
618 };
619
620 rewriter.replaceOpWithNewOp<func::CallOp>(op, kCreateValue, resultType,
621 sizeOf(value));
622
623 return success();
624 }
625
626 return rewriter.notifyMatchFailure(op, "unsupported async type");
627 }
628};
629} // namespace
630
631//===----------------------------------------------------------------------===//
632// Convert async.runtime.create_group to the corresponding runtime API call.
633//===----------------------------------------------------------------------===//
634
635namespace {
636class RuntimeCreateGroupOpLowering
637 : public ConvertOpToLLVMPattern<RuntimeCreateGroupOp> {
638public:
640
641 LogicalResult
642 matchAndRewrite(RuntimeCreateGroupOp op, OpAdaptor adaptor,
643 ConversionPatternRewriter &rewriter) const override {
644 const TypeConverter *converter = getTypeConverter();
645 Type resultType = op.getResult().getType();
646
647 rewriter.replaceOpWithNewOp<func::CallOp>(
648 op, kCreateGroup, converter->convertType(resultType),
649 adaptor.getOperands());
650 return success();
651 }
652};
653} // namespace
654
655//===----------------------------------------------------------------------===//
656// Convert async.runtime.set_available to the corresponding runtime API call.
657//===----------------------------------------------------------------------===//
658
659namespace {
660class RuntimeSetAvailableOpLowering
661 : public OpConversionPattern<RuntimeSetAvailableOp> {
662public:
663 using Base::Base;
664
665 LogicalResult
666 matchAndRewrite(RuntimeSetAvailableOp op, OpAdaptor adaptor,
667 ConversionPatternRewriter &rewriter) const override {
668 StringRef apiFuncName =
669 TypeSwitch<Type, StringRef>(op.getOperand().getType())
670 .Case<async::TokenType>([](Type) { return kEmplaceToken; })
671 .Case<ValueType>([](Type) { return kEmplaceValue; });
672
673 rewriter.replaceOpWithNewOp<func::CallOp>(op, apiFuncName, TypeRange(),
674 adaptor.getOperands());
675
676 return success();
677 }
678};
679} // namespace
680
681//===----------------------------------------------------------------------===//
682// Convert async.runtime.set_error to the corresponding runtime API call.
683//===----------------------------------------------------------------------===//
684
685namespace {
686class RuntimeSetErrorOpLowering
687 : public OpConversionPattern<RuntimeSetErrorOp> {
688public:
689 using Base::Base;
690
691 LogicalResult
692 matchAndRewrite(RuntimeSetErrorOp op, OpAdaptor adaptor,
693 ConversionPatternRewriter &rewriter) const override {
694 StringRef apiFuncName =
695 TypeSwitch<Type, StringRef>(op.getOperand().getType())
696 .Case<async::TokenType>([](Type) { return kSetTokenError; })
697 .Case<ValueType>([](Type) { return kSetValueError; });
698
699 rewriter.replaceOpWithNewOp<func::CallOp>(op, apiFuncName, TypeRange(),
700 adaptor.getOperands());
701
702 return success();
703 }
704};
705} // namespace
706
707//===----------------------------------------------------------------------===//
708// Convert async.runtime.is_error to the corresponding runtime API call.
709//===----------------------------------------------------------------------===//
710
711namespace {
712class RuntimeIsErrorOpLowering : public OpConversionPattern<RuntimeIsErrorOp> {
713public:
714 using Base::Base;
715
716 LogicalResult
717 matchAndRewrite(RuntimeIsErrorOp op, OpAdaptor adaptor,
718 ConversionPatternRewriter &rewriter) const override {
719 StringRef apiFuncName =
720 TypeSwitch<Type, StringRef>(op.getOperand().getType())
721 .Case<async::TokenType>([](Type) { return kIsTokenError; })
722 .Case<GroupType>([](Type) { return kIsGroupError; })
723 .Case<ValueType>([](Type) { return kIsValueError; });
724
725 rewriter.replaceOpWithNewOp<func::CallOp>(
726 op, apiFuncName, rewriter.getI1Type(), adaptor.getOperands());
727 return success();
728 }
729};
730} // namespace
731
732//===----------------------------------------------------------------------===//
733// Convert async.runtime.await to the corresponding runtime API call.
734//===----------------------------------------------------------------------===//
735
736namespace {
737class RuntimeAwaitOpLowering : public OpConversionPattern<RuntimeAwaitOp> {
738public:
739 using Base::Base;
740
741 LogicalResult
742 matchAndRewrite(RuntimeAwaitOp op, OpAdaptor adaptor,
743 ConversionPatternRewriter &rewriter) const override {
744 StringRef apiFuncName =
745 TypeSwitch<Type, StringRef>(op.getOperand().getType())
746 .Case<async::TokenType>([](Type) { return kAwaitToken; })
747 .Case<ValueType>([](Type) { return kAwaitValue; })
748 .Case<GroupType>([](Type) { return kAwaitGroup; });
749
750 func::CallOp::create(rewriter, op->getLoc(), apiFuncName, TypeRange(),
751 adaptor.getOperands());
752 rewriter.eraseOp(op);
753
754 return success();
755 }
756};
757} // namespace
758
759//===----------------------------------------------------------------------===//
760// Convert async.runtime.await_and_resume to the corresponding runtime API call.
761//===----------------------------------------------------------------------===//
762
763namespace {
764class RuntimeAwaitAndResumeOpLowering
765 : public AsyncOpConversionPattern<RuntimeAwaitAndResumeOp> {
766public:
767 using AsyncOpConversionPattern::AsyncOpConversionPattern;
768
769 LogicalResult
770 matchAndRewrite(RuntimeAwaitAndResumeOp op, OpAdaptor adaptor,
771 ConversionPatternRewriter &rewriter) const override {
772 StringRef apiFuncName =
773 TypeSwitch<Type, StringRef>(op.getOperand().getType())
774 .Case<async::TokenType>([](Type) { return kAwaitTokenAndExecute; })
775 .Case<ValueType>([](Type) { return kAwaitValueAndExecute; })
776 .Case<GroupType>([](Type) { return kAwaitAllAndExecute; });
777
778 Value operand = adaptor.getOperand();
779 Value handle = adaptor.getHandle();
780
781 // A pointer to coroutine resume intrinsic wrapper.
782 addResumeFunction(op->getParentOfType<ModuleOp>());
783 auto resumePtr = LLVM::AddressOfOp::create(
784 rewriter, op->getLoc(),
785 AsyncAPI::opaquePointerType(rewriter.getContext()), kResume);
786
787 func::CallOp::create(rewriter, op->getLoc(), apiFuncName, TypeRange(),
788 ValueRange({operand, handle, resumePtr.getRes()}));
789 rewriter.eraseOp(op);
790
791 return success();
792 }
793};
794} // namespace
795
796//===----------------------------------------------------------------------===//
797// Convert async.runtime.resume to the corresponding runtime API call.
798//===----------------------------------------------------------------------===//
799
800namespace {
801class RuntimeResumeOpLowering
802 : public AsyncOpConversionPattern<RuntimeResumeOp> {
803public:
804 using AsyncOpConversionPattern::AsyncOpConversionPattern;
805
806 LogicalResult
807 matchAndRewrite(RuntimeResumeOp op, OpAdaptor adaptor,
808 ConversionPatternRewriter &rewriter) const override {
809 // A pointer to coroutine resume intrinsic wrapper.
810 addResumeFunction(op->getParentOfType<ModuleOp>());
811 auto resumePtr = LLVM::AddressOfOp::create(
812 rewriter, op->getLoc(),
813 AsyncAPI::opaquePointerType(rewriter.getContext()), kResume);
814
815 // Call async runtime API to execute a coroutine in the managed thread.
816 auto coroHdl = adaptor.getHandle();
817 rewriter.replaceOpWithNewOp<func::CallOp>(
818 op, TypeRange(), kExecute, ValueRange({coroHdl, resumePtr.getRes()}));
819
820 return success();
821 }
822};
823} // namespace
824
825//===----------------------------------------------------------------------===//
826// Convert async.runtime.store to the corresponding runtime API call.
827//===----------------------------------------------------------------------===//
828
829namespace {
830class RuntimeStoreOpLowering : public ConvertOpToLLVMPattern<RuntimeStoreOp> {
831public:
833
834 LogicalResult
835 matchAndRewrite(RuntimeStoreOp op, OpAdaptor adaptor,
836 ConversionPatternRewriter &rewriter) const override {
837 Location loc = op->getLoc();
838
839 // Get a pointer to the async value storage from the runtime.
840 auto ptrType = AsyncAPI::opaquePointerType(rewriter.getContext());
841 auto storage = adaptor.getStorage();
842 auto storagePtr = func::CallOp::create(rewriter, loc, kGetValueStorage,
843 TypeRange(ptrType), storage);
844
845 // Cast from i8* to the LLVM pointer type.
846 auto valueType = op.getValue().getType();
847 auto llvmValueType = getTypeConverter()->convertType(valueType);
848 if (!llvmValueType)
849 return rewriter.notifyMatchFailure(
850 op, "failed to convert stored value type to LLVM type");
851
852 Value castedStoragePtr = storagePtr.getResult(0);
853 // Store the yielded value into the async value storage.
854 auto value = adaptor.getValue();
855 LLVM::StoreOp::create(rewriter, loc, value, castedStoragePtr);
856
857 // Erase the original runtime store operation.
858 rewriter.eraseOp(op);
859
860 return success();
861 }
862};
863} // namespace
864
865//===----------------------------------------------------------------------===//
866// Convert async.runtime.load to the corresponding runtime API call.
867//===----------------------------------------------------------------------===//
868
869namespace {
870class RuntimeLoadOpLowering : public ConvertOpToLLVMPattern<RuntimeLoadOp> {
871public:
873
874 LogicalResult
875 matchAndRewrite(RuntimeLoadOp op, OpAdaptor adaptor,
876 ConversionPatternRewriter &rewriter) const override {
877 Location loc = op->getLoc();
878
879 // Get a pointer to the async value storage from the runtime.
880 auto ptrType = AsyncAPI::opaquePointerType(rewriter.getContext());
881 auto storage = adaptor.getStorage();
882 auto storagePtr = func::CallOp::create(rewriter, loc, kGetValueStorage,
883 TypeRange(ptrType), storage);
884
885 // Cast from i8* to the LLVM pointer type.
886 auto valueType = op.getResult().getType();
887 auto llvmValueType = getTypeConverter()->convertType(valueType);
888 if (!llvmValueType)
889 return rewriter.notifyMatchFailure(
890 op, "failed to convert loaded value type to LLVM type");
891
892 Value castedStoragePtr = storagePtr.getResult(0);
893
894 // Load from the casted pointer.
895 rewriter.replaceOpWithNewOp<LLVM::LoadOp>(op, llvmValueType,
896 castedStoragePtr);
897
898 return success();
899 }
900};
901} // namespace
902
903//===----------------------------------------------------------------------===//
904// Convert async.runtime.add_to_group to the corresponding runtime API call.
905//===----------------------------------------------------------------------===//
906
907namespace {
908class RuntimeAddToGroupOpLowering
909 : public OpConversionPattern<RuntimeAddToGroupOp> {
910public:
911 using Base::Base;
912
913 LogicalResult
914 matchAndRewrite(RuntimeAddToGroupOp op, OpAdaptor adaptor,
915 ConversionPatternRewriter &rewriter) const override {
916 // Currently we can only add tokens to the group.
917 if (!isa<async::TokenType>(op.getOperand().getType()))
918 return rewriter.notifyMatchFailure(op, "only token type is supported");
919
920 // Replace with a runtime API function call.
921 rewriter.replaceOpWithNewOp<func::CallOp>(
922 op, kAddTokenToGroup, rewriter.getI64Type(), adaptor.getOperands());
923
924 return success();
925 }
926};
927} // namespace
928
929//===----------------------------------------------------------------------===//
930// Convert async.runtime.num_worker_threads to the corresponding runtime API
931// call.
932//===----------------------------------------------------------------------===//
933
934namespace {
935class RuntimeNumWorkerThreadsOpLowering
936 : public OpConversionPattern<RuntimeNumWorkerThreadsOp> {
937public:
938 using Base::Base;
939
940 LogicalResult
941 matchAndRewrite(RuntimeNumWorkerThreadsOp op, OpAdaptor adaptor,
942 ConversionPatternRewriter &rewriter) const override {
943
944 // Replace with a runtime API function call.
945 rewriter.replaceOpWithNewOp<func::CallOp>(op, kGetNumWorkerThreads,
946 rewriter.getIndexType());
947
948 return success();
949 }
950};
951} // namespace
952
953//===----------------------------------------------------------------------===//
954// Async reference counting ops lowering (`async.runtime.add_ref` and
955// `async.runtime.drop_ref` to the corresponding API calls).
956//===----------------------------------------------------------------------===//
957
958namespace {
959template <typename RefCountingOp>
960class RefCountingOpLowering : public OpConversionPattern<RefCountingOp> {
961public:
962 explicit RefCountingOpLowering(const TypeConverter &converter,
963 MLIRContext *ctx, StringRef apiFunctionName)
964 : OpConversionPattern<RefCountingOp>(converter, ctx),
965 apiFunctionName(apiFunctionName) {}
966
967 LogicalResult
968 matchAndRewrite(RefCountingOp op, typename RefCountingOp::Adaptor adaptor,
969 ConversionPatternRewriter &rewriter) const override {
970 auto count =
971 arith::ConstantOp::create(rewriter, op->getLoc(), rewriter.getI64Type(),
972 rewriter.getI64IntegerAttr(op.getCount()));
973
974 auto operand = adaptor.getOperand();
975 rewriter.replaceOpWithNewOp<func::CallOp>(op, TypeRange(), apiFunctionName,
976 ValueRange({operand, count}));
977
978 return success();
979 }
980
981private:
982 StringRef apiFunctionName;
983};
984
985class RuntimeAddRefOpLowering : public RefCountingOpLowering<RuntimeAddRefOp> {
986public:
987 explicit RuntimeAddRefOpLowering(const TypeConverter &converter,
988 MLIRContext *ctx)
989 : RefCountingOpLowering(converter, ctx, kAddRef) {}
990};
991
992class RuntimeDropRefOpLowering
993 : public RefCountingOpLowering<RuntimeDropRefOp> {
994public:
995 explicit RuntimeDropRefOpLowering(const TypeConverter &converter,
996 MLIRContext *ctx)
997 : RefCountingOpLowering(converter, ctx, kDropRef) {}
998};
999} // namespace
1000
1001//===----------------------------------------------------------------------===//
1002// Convert return operations that return async values from async regions.
1003//===----------------------------------------------------------------------===//
1004
1005namespace {
1006class ReturnOpOpConversion : public OpConversionPattern<func::ReturnOp> {
1007public:
1008 using Base::Base;
1009
1010 LogicalResult
1011 matchAndRewrite(func::ReturnOp op, OpAdaptor adaptor,
1012 ConversionPatternRewriter &rewriter) const override {
1013 rewriter.replaceOpWithNewOp<func::ReturnOp>(op, adaptor.getOperands());
1014 return success();
1015 }
1016};
1017} // namespace
1018
1019//===----------------------------------------------------------------------===//
1020
1021namespace {
1022struct ConvertAsyncToLLVMPass
1023 : public impl::ConvertAsyncToLLVMPassBase<ConvertAsyncToLLVMPass> {
1024 using Base::Base;
1025
1026 void runOnOperation() override;
1027};
1028} // namespace
1029
1030void ConvertAsyncToLLVMPass::runOnOperation() {
1031 ModuleOp module = getOperation();
1032 MLIRContext *ctx = module->getContext();
1033
1034 LowerToLLVMOptions options(ctx);
1035
1036 // Add declarations for most functions required by the coroutines lowering.
1037 // We delay adding the resume function until it's needed because it currently
1038 // fails to compile unless '-O0' is specified.
1040
1041 // Lower async.runtime and async.coro operations to Async Runtime API and
1042 // LLVM coroutine intrinsics.
1043
1044 // Convert async dialect types and operations to LLVM dialect.
1045 AsyncRuntimeTypeConverter converter(options);
1046 RewritePatternSet patterns(ctx);
1047
1048 // We use conversion to LLVM type to lower async.runtime load and store
1049 // operations.
1050 LLVMTypeConverter llvmConverter(ctx, options);
1051 llvmConverter.addConversion([&](Type type) {
1052 return AsyncRuntimeTypeConverter::convertAsyncTypes(type);
1053 });
1054
1055 // Convert async types in function signatures and function calls.
1056 populateFunctionOpInterfaceTypeConversionPattern<func::FuncOp>(patterns,
1057 converter);
1058 populateCallOpTypeConversionPattern(patterns, converter);
1059
1060 // Convert return operations inside async.execute regions.
1061 patterns.add<ReturnOpOpConversion>(converter, ctx);
1062
1063 // Lower async.runtime operations to the async runtime API calls.
1064 patterns.add<RuntimeSetAvailableOpLowering, RuntimeSetErrorOpLowering,
1065 RuntimeIsErrorOpLowering, RuntimeAwaitOpLowering,
1066 RuntimeAwaitAndResumeOpLowering, RuntimeResumeOpLowering,
1067 RuntimeAddToGroupOpLowering, RuntimeNumWorkerThreadsOpLowering,
1068 RuntimeAddRefOpLowering, RuntimeDropRefOpLowering>(converter,
1069 ctx);
1070
1071 // Lower async.runtime operations that rely on LLVM type converter to convert
1072 // from async value payload type to the LLVM type.
1073 patterns.add<RuntimeCreateOpLowering, RuntimeCreateGroupOpLowering,
1074 RuntimeStoreOpLowering, RuntimeLoadOpLowering>(llvmConverter);
1075
1076 // Lower async coroutine operations to LLVM coroutine intrinsics.
1077 patterns
1078 .add<CoroIdOpConversion, CoroBeginOpConversion, CoroFreeOpConversion,
1079 CoroEndOpConversion, CoroSaveOpConversion, CoroSuspendOpConversion>(
1080 converter, ctx);
1081
1082 ConversionTarget target(*ctx);
1083 target.addLegalOp<arith::ConstantOp, func::ConstantOp,
1084 UnrealizedConversionCastOp>();
1085 target.addLegalDialect<LLVM::LLVMDialect>();
1086
1087 // All operations from Async dialect must be lowered to the runtime API and
1088 // LLVM intrinsics calls.
1089 target.addIllegalDialect<AsyncDialect>();
1090
1091 // Add dynamic legality constraints to apply conversions defined above.
1092 target.addDynamicallyLegalOp<func::FuncOp>([&](func::FuncOp op) {
1093 return converter.isSignatureLegal(op.getFunctionType());
1094 });
1095 target.addDynamicallyLegalOp<func::ReturnOp>([&](func::ReturnOp op) {
1096 return converter.isLegal(op.getOperandTypes());
1097 });
1098 target.addDynamicallyLegalOp<func::CallOp>([&](func::CallOp op) {
1099 return converter.isSignatureLegal(op.getCalleeType());
1100 });
1101
1102 if (failed(applyPartialConversion(module, target, std::move(patterns))))
1103 signalPassFailure();
1104}
1105
1106//===----------------------------------------------------------------------===//
1107// Patterns for structural type conversions for the Async dialect operations.
1108//===----------------------------------------------------------------------===//
1109
1110namespace {
1111class ConvertExecuteOpTypes : public OpConversionPattern<ExecuteOp> {
1112public:
1113 using Base::Base;
1114 LogicalResult
1115 matchAndRewrite(ExecuteOp op, OpAdaptor adaptor,
1116 ConversionPatternRewriter &rewriter) const override {
1117 ExecuteOp newOp =
1118 cast<ExecuteOp>(rewriter.cloneWithoutRegions(*op.getOperation()));
1119 rewriter.inlineRegionBefore(op.getRegion(), newOp.getRegion(),
1120 newOp.getRegion().end());
1121
1122 // Set operands and update block argument and result types.
1123 newOp->setOperands(adaptor.getOperands());
1124 if (failed(rewriter.convertRegionTypes(&newOp.getRegion(), *typeConverter)))
1125 return failure();
1126 for (auto result : newOp.getResults())
1127 result.setType(typeConverter->convertType(result.getType()));
1128
1129 rewriter.replaceOp(op, newOp.getResults());
1130 return success();
1131 }
1132};
1133
1134// Dummy pattern to trigger the appropriate type conversion / materialization.
1135class ConvertAwaitOpTypes : public OpConversionPattern<AwaitOp> {
1136public:
1137 using Base::Base;
1138 LogicalResult
1139 matchAndRewrite(AwaitOp op, OpAdaptor adaptor,
1140 ConversionPatternRewriter &rewriter) const override {
1141 rewriter.replaceOpWithNewOp<AwaitOp>(op, adaptor.getOperands().front());
1142 return success();
1143 }
1144};
1145
1146// Dummy pattern to trigger the appropriate type conversion / materialization.
1147class ConvertYieldOpTypes : public OpConversionPattern<async::YieldOp> {
1148public:
1149 using Base::Base;
1150 LogicalResult
1151 matchAndRewrite(async::YieldOp op, OpAdaptor adaptor,
1152 ConversionPatternRewriter &rewriter) const override {
1153 rewriter.replaceOpWithNewOp<async::YieldOp>(op, adaptor.getOperands());
1154 return success();
1155 }
1156};
1157} // namespace
1158
1160 TypeConverter &typeConverter, RewritePatternSet &patterns,
1162 typeConverter.addConversion([&](async::TokenType type) { return type; });
1163 typeConverter.addConversion([&](ValueType type) {
1164 Type converted = typeConverter.convertType(type.getValueType());
1165 return converted ? ValueType::get(converted) : converted;
1166 });
1167
1168 patterns.add<ConvertExecuteOpTypes, ConvertAwaitOpTypes, ConvertYieldOpTypes>(
1169 typeConverter, patterns.getContext());
1170
1171 target.addDynamicallyLegalOp<AwaitOp, ExecuteOp, async::YieldOp>(
1172 [&](Operation *op) { return typeConverter.isLegal(op); });
1173}
return success()
static constexpr const char * kAwaitValueAndExecute
static constexpr const char * kCreateValue
static constexpr const char * kCreateGroup
static constexpr const char * kCreateToken
static constexpr const char * kEmplaceValue
static void addResumeFunction(ModuleOp module)
A function that takes a coroutine handle and calls a llvm.coro.resume intrinsics.
static constexpr const char * kEmplaceToken
static void addAsyncRuntimeApiDeclarations(ModuleOp module)
Adds Async Runtime C API declarations to the module.
static constexpr const char * kResume
static constexpr const char * kAddRef
static constexpr const char * kAwaitTokenAndExecute
static constexpr const char * kAwaitValue
static constexpr const char * kSetTokenError
static constexpr const char * kExecute
static constexpr const char * kAddTokenToGroup
static constexpr const char * kIsGroupError
static constexpr const char * kSetValueError
static constexpr const char * kIsTokenError
static constexpr const char * kAwaitGroup
static constexpr const char * kAwaitAllAndExecute
static constexpr const char * kGetNumWorkerThreads
static constexpr const char * kDropRef
static constexpr const char * kIsValueError
static constexpr const char * kAwaitToken
static constexpr const char * kGetValueStorage
static llvm::ManagedStatic< PassManagerOptions > options
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
Definition Pattern.h:233
ConvertOpToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
Definition Pattern.h:239
static ImplicitLocOpBuilder atBlockEnd(Location loc, Block *block, Listener *listener=nullptr)
Create a builder and set the insertion point to after the last operation in the block but still insid...
Definition Builders.h:649
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:71
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition Types.cpp:35
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateFreeFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateAlignedAllocFn(OpBuilder &b, Operation *moduleOp, Type indexType, SymbolTableCollection *symbolTables=nullptr)
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:886
Include the generated interface declarations.
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, PatternBenefit benefit=1)
Add a pattern to the given pattern list to convert the operand and result types of a CallOp with the ...
void populateAsyncStructuralTypeConversionsAndLegality(TypeConverter &typeConverter, RewritePatternSet &patterns, ConversionTarget &target)
Populates patterns for async structural type conversions.
llvm::TypeSwitch< T, ResultT > TypeSwitch
Definition LLVM.h:147