summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp
AgeCommit message (Collapse)Author
2025-07-24[mlir][NFC] update `mlir/Dialect` create APIs (15/n) (#149921)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-23[mlir] Remove unused includes (NFC) (#150266)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-07-13[mlir] Remove unused includes (NFC) (#148535)Kazu Hirata
2025-07-01[mlir][async] Erase op later to preserve insertion point (#146516)Matthias Springer
Delay the erasure of an op, so that the insertion point of the rewriter remains valid. This commit is in preparation of the One-Shot Dialect Conversion refactoring. (The current implementation works with the current dialect conversion driver because op erasure is delayed.)
2025-05-16[mlir] Use DenseMap::contains (NFC) (#140351)Kazu Hirata
2025-04-28[MLIR][NFC] Retire let constructor for Async (#137461)lorenzo chelini
let constructor is legacy (do not use in tree!) since the tableGen backend emits most of the glue logic to build a pass. Note: The following constructor has been retired: ```cpp std::unique_ptr<Pass> createAsyncParallelForPass(bool asyncDispatch, int32_t numWorkerThreads, int32_t minTaskSize); ``` To update your codebase, replace it with the new options-based API: ```cpp AsyncParallelForPassOptions options{/*asyncDispatch=*/, /*numWorkerThreads=*/, /*minTaskSize=*/}; createAsyncParallelForPass(options); ```
2025-04-27[mlir] Use range constructors of *Set (NFC) (#137563)Kazu Hirata
2025-04-14[mlir] Use llvm::append_range (NFC) (#135722)Kazu Hirata
2025-03-20[mlir] Use *Set::insert_range (NFC) (#132326)Kazu Hirata
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2024-02-14[mlir][Transforms][NFC] Improve listener layering in dialect conversion (#81236)Matthias Springer
Context: Conversion patterns provide a `ConversionPatternRewriter` to modify the IR. `ConversionPatternRewriter` provides the public API. Most function calls are forwarded/handled by `ConversionPatternRewriterImpl`. The dialect conversion uses the listener infrastructure to get notified about op/block insertions. In the current design, `ConversionPatternRewriter` inherits from both `PatternRewriter` and `Listener`. The conversion rewriter registers itself as a listener. This is problematic because listener functions such as `notifyOperationInserted` are now part of the public API and can be called from conversion patterns; that would bring the dialect conversion into an inconsistent state. With this commit, `ConversionPatternRewriter` no longer inherits from `Listener`. Instead `ConversionPatternRewriterImpl` inherits from `Listener`. This removes the problematic public API and also simplifies the code a bit: block/op insertion notifications were previously forwarded to the `ConversionPatternRewriterImpl`. This is no longer needed.
2024-01-16[Coroutines] Fix incorrect attribute name coroutine.presplit (NFC) (#78296) yonillasky
Those are probably leftovers from an old name of the same attribute. Fixed for the sake of consistency. Co-authored-by: Yoni Lavi <yoni.lavi@nextsilicon.com>
2023-09-12Splits cleanup block lowered by AsyncToAsyncRuntime. (#66123)Yunlong Liu
Splits the cleanup block lowered from AsyncToAsyncRuntime. The incentive of this change is to clarify the CFG branched by `async.coro.suspend`. The `async.coro.suspend` op branches into 3 blocks, depending on the state of the coroutine: 1) suspend 2) resume 3) cleanup The behavior before this change is that after the coroutine is resumed and completed, it will jump to a shared cleanup block for destroying the states of coroutines. The CFG looks like the following, Entry block | \ resume | | | Cleanup | End This CFG can potentially be problematic, because the `Cleanup` block is a shared block and it is not dominated by `resume`. For instance, if some pass wants to add some specific cleanup mechanism to resume, it can be confused and add them to the shared `Cleanup`, which leads to the "operand not dominate its use" error because of the existence of the other "Entry->cleanup" path. After this change, the CFG will look like the following, The overall structure of the lowered CFG can be the following, Entry (calling async.coro.suspend) | \ Resume Destroy (duplicate of Cleanup) | | Cleanup | | / End (ends the corontine) In this case, the Cleanup block tied to the Resume block will be isolated from the other path and it is strictly dominated by "Resume".
2023-08-31[mlir] Move FunctionInterfaces to Interfaces directory and inherit from ↵Martin Erhart
CallableOpInterface Functions are always callable operations and thus every operation implementing the `FunctionOpInterface` also implements the `CallableOpInterface`. The only exception was the FuncOp in the toy example. To make implementation of the `FunctionOpInterface` easier, this commit lets `FunctionOpInterface` inherit from `CallableOpInterface` and merges some of their methods. More precisely, the `CallableOpInterface` has methods to get the argument and result attributes and a method to get the result types of the callable region. These methods are always implemented the same way as their analogues in `FunctionOpInterface` and thus this commit moves all the argument and result attribute handling methods to the callable interface as well as the methods to get the argument and result types. The `FuntionOpInterface` then does not have to declare them as well, but just inherits them from the `CallableOpInterface`. Adding the inheritance relation also required to move the `FunctionOpInterface` from the IR directory to the Interfaces directory since IR should not depend on Interfaces. Reviewed By: jpienaar, springerm Differential Revision: https://reviews.llvm.org/D157988
2023-08-27[mlir] Use {DenseSet,DenseMap,SemallDenseSet}::contains (NFC)Kazu Hirata
2023-05-12[mlir] Move casting calls from methods to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-02-22This change makes `RewriterBase` symmetric to `OpBuilder`.Matthias Springer
``` OpBuilder OpBuilder::Listener ^ ^ | | RewriterBase RewriterBase::Listener ``` * Clients can listen to IR modifications with `RewriterBase::Listener`. * `RewriterBase` no longer inherits from `OpBuilder::Listener`. * Only a single listener can be registered at the moment (same as `OpBuilder`). RFC: https://discourse.llvm.org/t/rfc-listeners-for-rewriterbase/68198 Differential Revision: https://reviews.llvm.org/D143339
2023-01-14[mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-13[mlir][async] Allow to call async.execute inside async.funcyijiagu
This change added support of calling async execute inside async.func. Ex. ``` async.func @async_func_call_func() -> !async.token { %token = async.execute { %c0 = arith.constant 0 : index memref.store %arg0, %arg1[%c0] : memref<1xf32> async.yield } async.await %token : !async.token return } ``` Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D141730
2023-01-12[mlir] Add operations to BlockAndValueMapping and rename it to IRMappingJeff Niu
The patch adds operations to `BlockAndValueMapping` and renames it to `IRMapping`. When operations are cloned, old operations are mapped to the cloned operations. This allows mapping from an operation to a cloned operation. Example: ``` Operation *opWithRegion = ... Operation *opInsideRegion = &opWithRegion->front().front(); IRMapping map Operation *newOpWithRegion = opWithRegion->clone(map); Operation *newOpInsideRegion = map.lookupOrNull(opInsideRegion); ``` Migration instructions: All includes to `mlir/IR/BlockAndValueMapping.h` should be replaced with `mlir/IR/IRMapping.h`. All uses of `BlockAndValueMapping` need to be renamed to `IRMapping`. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D139665
2022-12-13Apply clang-tidy fixes for readability-identifier-naming in ↵Mehdi Amini
AsyncToAsyncRuntime.cpp (NFC)
2022-12-13Apply clang-tidy fixes for performance-unnecessary-value-param in ↵Mehdi Amini
AsyncToAsyncRuntime.cpp (NFC)
2022-12-10[Transforms] Use std::optional in AsyncToAsyncRuntime.cpp (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[mlir] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-30Add async_funcs_only option to AsyncToAsyncRuntime passyijiagu
This change adds async_funcs_only option to AsyncToAsyncRuntimePass. The goal is to convert async functions to regular functions in early stages of compilation pipeline. Differential Revision: https://reviews.llvm.org/D138611
2022-11-07[mlir] Lower async.func with async.coro and async.runtime operationsyijiagu
Lower async.func with async.coro and async.runtime operations - This patch modifies AsyncToAsyncRuntime pass to add lowering async.func ops with coroutine cfg. Example: ``` async.func @foo() -> !async.value<f32> { %cst = arith.constant 42.0 : f32 return %cst: f32 } ``` After lowering: ``` func.func @foo() -> !async.value<f32> attributes {passthrough = ["presplitcoroutine"]} { %0 = async.runtime.create : !async.value<f32> %1 = async.coro.id %2 = async.coro.begin %1 cf.br ^bb1 ^bb1: // pred: ^bb0 %cst = arith.constant 4.200000e+01 : f32 async.runtime.store %cst, %0 : <f32> async.runtime.set_available %0 : !async.value<f32> cf.br ^bb2 ^bb2: // pred: ^bb1 async.coro.free %1, %2 cf.br ^bb3 ^bb3: // pred: ^bb2 async.coro.end %2 return %0 : !async.value<f32> } ``` Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D137462
2022-11-02[mlir] Remove eliminateBlockingAwaitOps option in AsyncToAsyncRuntime passyijiagu
Remove the eliminateBlockingAwaitOps option in AsyncToAsyncRuntime pass Today the AsyncToAsyncRuntime pass does two things: one is converting normal funcs with async ops to coroutine cfg; the other is lowering high level async operations to async.coro and async.runtime operations. This patch removes the converting step from AsyncToAsyncRuntime pass. In the next step we will create a new asyncfication pass for converting normal funcs to the newly added async.func operation. Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D137282
2022-09-30[mlir:Async][NFC] Update Async API to use prefixed accessorsRiver Riddle
This doesn't flip the switch for prefix generation yet, that'll be done in a followup.
2022-09-29[mlir][arith] Change dialect name from Arithmetic to ArithJakub Kuderski
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22. Tested with: `ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples` and `bazel build --config=generic_clang @llvm-project//mlir:all`. Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini Differential Revision: https://reviews.llvm.org/D134762
2022-09-21[mlir] Flip Async/GPU/OpenACC/OpenMP to use Both accessorsRiver Riddle
This allows for incrementally updating the old API usages without needing to update everything at once. These will be left on Both for a little bit and then flipped to prefixed when all APIs have been updated. Differential Revision: https://reviews.llvm.org/D134386
2022-09-19BEGIN_PUBLICRahul Joshi
Use isa<> instead of dyn_cast END_PUBLIC Differential Revision: https://reviews.llvm.org/D134092
2022-08-31[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-08-30Revert "[MLIR] Update pass declarations to new autogenerated files"Michele Scuttari
This reverts commit 2be8af8f0e0780901213b6fd3013a5268ddc3359.
2022-08-30[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-06-20[mlir] move SCF headers to SCF/{IR,Transforms} respectivelyAlex Zinenko
This aligns the SCF dialect file layout with the majority of the dialects. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D128049
2022-06-14[Coroutines] Convert coroutine.presplit to enum attrChuanqi Xu
This is required by @nikic in https://reviews.llvm.org/D127383 to decrease the cost to check whether a function is a coroutine and this fixes a FIXME too. Reviewed By: rjmccall, ezhulenev Differential Revision: https://reviews.llvm.org/D127471
2022-04-18[mlir:NFC] Remove the forward declaration of FuncOp in the mlir namespaceRiver Riddle
FuncOp has been moved to the `func` namespace for a little over a month, the using directive can be dropped now.
2022-03-16[mlir:FunctionOpInterface] Rename the "type" attribute to "function_type"River Riddle
This removes any potential confusion with the `getType` accessors which correspond to SSA results of an operation, and makes it clear what the intent is (i.e. to represent the type of the function). Differential Revision: https://reviews.llvm.org/D121762
2022-03-08[mlir][NFC] Update the Builtin dialect to use "Both" accessorsRiver Riddle
Differential Revision: https://reviews.llvm.org/D121189
2022-03-01[mlir] Rename the Standard dialect to the Func dialectRiver Riddle
The last remaining operations in the standard dialect all revolve around FuncOp/function related constructs. This patch simply handles the initial renaming (which by itself is already huge), but there are a large number of cleanups unlocked/necessary afterwards: * Removing a bunch of unnecessary dependencies on Func * Cleaning up the From/ToStandard conversion passes * Preparing for the move of FuncOp to the Func dialect See the discussion at https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061 Differential Revision: https://reviews.llvm.org/D120624
2022-02-06[mlir] Split out a new ControlFlow dialect from StandardRiver Riddle
This dialect is intended to model lower level/branch based control-flow constructs. The initial set of operations are: AssertOp, BranchOp, CondBranchOp, SwitchOp; all split out from the current standard dialect. See https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061 Differential Revision: https://reviews.llvm.org/D118966
2022-01-05[Coroutines] Set presplit attribute in Clang and mlirChuanqi Xu
This fixes bug49264. Simply, coroutine shouldn't be inlined before CoroSplit. And the marker for pre-splited coroutine is created in CoroEarly pass, which ran after AlwaysInliner Pass in O0 pipeline. So that the AlwaysInliner couldn't detect it shouldn't inline a coroutine. So here is the error. This patch set the presplit attribute in clang and mlir. So the inliner would always detect the attribute before splitting. Reviewed By: rjmccall, ezhulenev Differential Revision: https://reviews.llvm.org/D115790
2021-10-24[mlir] Switch arith, llvm, std & shape dialects to accessors prefixed both form.Jacques Pienaar
Following https://llvm.discourse.group/t/psa-ods-generated-accessors-will-change-to-have-a-get-prefix-update-you-apis/4476, this follows flipping these dialects to _Both prefixed form. This changes the accessors to have a prefix. This was possibly mostly without breaking breaking changes if the existing convenience methods were used. (https://github.com/jpienaar/llvm-project/blob/main/clang-tools-extra/clang-tidy/misc/AddGetterCheck.cpp was used to migrate the callers post flipping, using the output from Operator.cpp) Differential Revision: https://reviews.llvm.org/D112383
2021-10-14[MLIR][arith] fix references to std.constant in commentsMogball
Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D111820
2021-10-13[MLIR] Replace std ops with arith dialect opsMogball
Precursor: https://reviews.llvm.org/D110200 Removed redundant ops from the standard dialect that were moved to the `arith` or `math` dialects. Renamed all instances of operations in the codebase and in tests. Reviewed By: rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D110797
2021-09-24[mlir:OpConversionPattern] Add overloads for taking an Adaptor instead of ↵River Riddle
ArrayRef This has been a TODO for a long time, and it brings about many advantages (namely nice accessors, and less fragile code). The existing overloads that accept ArrayRef are now treated as deprecated and will be removed in a followup (after a small grace period). Most of the upstream MLIR usages have been fixed by this commit, the rest will be handled in a followup. Differential Revision: https://reviews.llvm.org/D110293
2021-09-04[mlir] Async: check awaited operand error state after sync awaitEugene Zhulenev
Previously only await inside the async function (coroutine after lowering to async runtime) would check the error state Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D109229
2021-08-02[mlir] Async: clone constants into async.execute functions and parallel ↵Eugene Zhulenev
compute functions Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D107007
2021-07-29Refactor AsyncToAsyncRuntime pass to boost understandability.bakhtiyar
Depends On D106730 Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D106731
2021-07-29Add an escape-hatch for conversion of funcs with blocking awaits to coroutines.bakhtiyar
Currently TFRT does not support top-level coroutines, so this functionality will allow to have a single blocking await at the top level until TFRT implements the necessary functionality. Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D106730
2021-07-28Optionally eliminate blocking runtime.await calls by converting functions to ↵bakhtiyar
coroutines. Interop parallelism requires needs awaiting on results. Blocking awaits are bad for performance. TFRT supports lightweight resumption on threads, and coroutines are an abstraction than can be used to lower the kernels onto TFRT threads. Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D106508