MLIR  19.0.0git
Classes | Namespaces | Macros | Typedefs | Functions | Variables
AsyncToAsyncRuntime.cpp File Reference
#include <utility>
#include "mlir/Dialect/Async/Passes.h"
#include "PassDetail.h"
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Async/IR/Async.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Support/Debug.h"
#include <optional>
#include "mlir/Dialect/Async/"

Go to the source code of this file.


class  YieldOpLowering
class  AssertOpLowering


 Include the generated interface declarations.


#define DEBUG_TYPE   "async-to-async-runtime"


using FuncCoroMapPtr = std::shared_ptr< llvm::DenseMap< func::FuncOp, CoroMachinery > >


static CoroMachinery setupCoroMachinery (func::FuncOp func)
 Utility to partially update the regular function CFG to the coroutine CFG compatible with LLVM coroutines switched-resume lowering using async.runtime. More...
static BlocksetupSetErrorBlock (CoroMachinery &coro)
static std::pair< func::FuncOp, CoroMachinery > outlineExecuteOp (SymbolTable &symbolTable, ExecuteOp execute)
 Outline the body region attached to the async.execute op into a standalone function. More...


static constexpr const char kAsyncFnPrefix [] = "async_execute_fn"

Macro Definition Documentation


#define DEBUG_TYPE   "async-to-async-runtime"

Definition at line 43 of file AsyncToAsyncRuntime.cpp.



Definition at line 36 of file AsyncToAsyncRuntime.cpp.



Definition at line 35 of file AsyncToAsyncRuntime.cpp.

Typedef Documentation

◆ FuncCoroMapPtr

using FuncCoroMapPtr = std::shared_ptr<llvm::DenseMap<func::FuncOp, CoroMachinery> >

Definition at line 124 of file AsyncToAsyncRuntime.cpp.

Function Documentation

◆ outlineExecuteOp()

static std::pair<func::FuncOp, CoroMachinery> outlineExecuteOp ( SymbolTable symbolTable,
ExecuteOp  execute 

◆ setupCoroMachinery()

static CoroMachinery setupCoroMachinery ( func::FuncOp  func)

Utility to partially update the regular function CFG to the coroutine CFG compatible with LLVM coroutines switched-resume lowering using async.runtime.

* and async.coro.* operations. Adds a new entry block that branches into preexisting entry block. Also inserts trailing blocks.

The result types of the passed func start with an optional async.token and be continued with some number of async.values.

See LLVM coroutines documentation:

  • entry block sets up the coroutine.
  • set_error block sets completion token and async values state to error.
  • cleanup block cleans up the coroutine state.
  • `suspend block after the @llvm.coro.end() defines what value will be returned to the initial caller of a coroutine. Everything before the @llvm.coro.end() will be executed at every suspension point.

Coroutine structure (only the important bits):

func @some_fn(<function-arguments>) -> (!async.token, !async.value<T>) { ^entry(<function-arguments>): token = <async token> : !async.token // create async runtime token value = <async value> : !async.value<T> // create async value id = async.coro.getId // create a coroutine id hdl = async.coro.begin id // create a coroutine handle ^preexisting_entry_block

/* preexisting blocks modified to branch to the cleanup block *‍/

^set_error: // this block created lazily only if needed (see code below) async.runtime.set_error token : !async.token async.runtime.set_error value : !async.value<T> ^cleanup

^cleanup: hdl // delete the coroutine state ^suspend

^suspend: async.coro.end hdl // marks the end of a coroutine return token, value : !async.token, !async.value<T> }

Definition at line 171 of file AsyncToAsyncRuntime.cpp.

References mlir::ImplicitLocOpBuilder::atBlockBegin(), mlir::Block::front(), mlir::get(), mlir::Block::getOperations(), and mlir::Block::splitBlock().

◆ setupSetErrorBlock()

static Block* setupSetErrorBlock ( CoroMachinery &  coro)

Variable Documentation

◆ kAsyncFnPrefix

constexpr const char kAsyncFnPrefix[] = "async_execute_fn"

Definition at line 45 of file AsyncToAsyncRuntime.cpp.

Referenced by outlineExecuteOp().