diff --git a/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td b/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td --- a/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td +++ b/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td @@ -170,7 +170,6 @@ ``` }]; - let arguments = (ins ); let results = (outs Async_GroupType:$result); let assemblyFormat = "attr-dict"; @@ -472,7 +471,6 @@ let arguments = (ins Async_AnyAsyncType:$operand, Confined:$count); - let results = (outs ); let assemblyFormat = [{ $operand attr-dict `:` type($operand) @@ -488,7 +486,6 @@ let arguments = (ins Async_AnyAsyncType:$operand, Confined:$count); - let results = (outs ); let assemblyFormat = [{ $operand attr-dict `:` type($operand) diff --git a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp --- a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp +++ b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp @@ -195,17 +195,11 @@ } //===----------------------------------------------------------------------===// -// LLVM coroutines intrinsics declarations. +// Add malloc/free declarations to the module. //===----------------------------------------------------------------------===// -static constexpr const char *kCoroId = "llvm.coro.id"; -static constexpr const char *kCoroSizeI64 = "llvm.coro.size.i64"; -static constexpr const char *kCoroBegin = "llvm.coro.begin"; -static constexpr const char *kCoroSave = "llvm.coro.save"; -static constexpr const char *kCoroSuspend = "llvm.coro.suspend"; -static constexpr const char *kCoroEnd = "llvm.coro.end"; -static constexpr const char *kCoroFree = "llvm.coro.free"; -static constexpr const char *kCoroResume = "llvm.coro.resume"; +static constexpr const char *kMalloc = "malloc"; +static constexpr const char *kFree = "free"; static void addLLVMFuncDecl(ModuleOp module, ImplicitLocOpBuilder &builder, StringRef name, Type ret, ArrayRef params) { @@ -215,40 +209,6 @@ builder.create(name, type); } -/// Adds coroutine intrinsics declarations to the module. -static void addCoroutineIntrinsicsDeclarations(ModuleOp module) { - using namespace mlir::LLVM; - - MLIRContext *ctx = module.getContext(); - ImplicitLocOpBuilder builder(module.getLoc(), - module.getBody()->getTerminator()); - - auto token = LLVMTokenType::get(ctx); - auto voidTy = LLVMVoidType::get(ctx); - - auto i8 = IntegerType::get(ctx, 8); - auto i1 = IntegerType::get(ctx, 1); - auto i32 = IntegerType::get(ctx, 32); - auto i64 = IntegerType::get(ctx, 64); - auto i8Ptr = LLVMPointerType::get(i8); - - addLLVMFuncDecl(module, builder, kCoroId, token, {i32, i8Ptr, i8Ptr, i8Ptr}); - addLLVMFuncDecl(module, builder, kCoroSizeI64, i64, {}); - addLLVMFuncDecl(module, builder, kCoroBegin, i8Ptr, {token, i8Ptr}); - addLLVMFuncDecl(module, builder, kCoroSave, token, {i8Ptr}); - addLLVMFuncDecl(module, builder, kCoroSuspend, i8, {token, i1}); - addLLVMFuncDecl(module, builder, kCoroEnd, i1, {i8Ptr, i1}); - addLLVMFuncDecl(module, builder, kCoroFree, i8Ptr, {token, i8Ptr}); - addLLVMFuncDecl(module, builder, kCoroResume, voidTy, {i8Ptr}); -} - -//===----------------------------------------------------------------------===// -// Add malloc/free declarations to the module. -//===----------------------------------------------------------------------===// - -static constexpr const char *kMalloc = "malloc"; -static constexpr const char *kFree = "free"; - /// Adds malloc/free declarations to the module. static void addCRuntimeDeclarations(ModuleOp module) { using namespace mlir::LLVM; @@ -293,10 +253,7 @@ auto *block = resumeOp.addEntryBlock(); auto blockBuilder = ImplicitLocOpBuilder::atBlockEnd(loc, block); - blockBuilder.create(TypeRange(), - blockBuilder.getSymbolRefAttr(kCoroResume), - resumeOp.getArgument(0)); - + blockBuilder.create(resumeOp.getArgument(0)); blockBuilder.create(ValueRange()); } @@ -1382,7 +1339,6 @@ // Add declarations for all functions required by the coroutines lowering. addResumeFunction(module); addAsyncRuntimeApiDeclarations(module); - addCoroutineIntrinsicsDeclarations(module); addCRuntimeDeclarations(module); // ------------------------------------------------------------------------ // diff --git a/mlir/test/Conversion/AsyncToLLVM/convert-to-llvm.mlir b/mlir/test/Conversion/AsyncToLLVM/convert-to-llvm.mlir --- a/mlir/test/Conversion/AsyncToLLVM/convert-to-llvm.mlir +++ b/mlir/test/Conversion/AsyncToLLVM/convert-to-llvm.mlir @@ -35,13 +35,13 @@ // Create token for return op, and mark a function as a coroutine. // CHECK: %[[RET:.*]] = call @mlirAsyncRuntimeCreateToken() -// CHECK: %[[HDL:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL:.*]] = llvm.intr.coro.begin // Pass a suspended coroutine to the async runtime. // CHECK: %[[STATE:.*]] = llvm.call @llvm.coro.save // CHECK: %[[RESUME:.*]] = llvm.mlir.addressof @__resume // CHECK: call @mlirAsyncRuntimeExecute(%[[HDL]], %[[RESUME]]) -// CHECK: %[[SUSPENDED:.*]] = llvm.call @llvm.coro.suspend(%[[STATE]] +// CHECK: %[[SUSPENDED:.*]] = llvm.intr.coro.suspend %[[STATE]] // Decide the next block based on the code returned from suspend. // CHECK: %[[SEXT:.*]] = llvm.sext %[[SUSPENDED]] : i8 to i32 @@ -56,12 +56,12 @@ // Delete coroutine. // CHECK: ^[[CLEANUP]]: -// CHECK: %[[MEM:.*]] = llvm.call @llvm.coro.free +// CHECK: %[[MEM:.*]] = llvm.intr.coro.free // CHECK: llvm.call @free(%[[MEM]]) // Suspend coroutine, and also a return statement for ramp function. // CHECK: ^[[SUSPEND]]: -// CHECK: llvm.call @llvm.coro.end +// CHECK: llvm.intr.coro.end // CHECK: return %[[RET]] // ----- @@ -92,9 +92,9 @@ // CHECK-LABEL: func private @async_execute_fn(%arg0: f32, %arg1: memref<1xf32>, %arg2: index) // CHECK-SAME: -> !llvm.ptr // CHECK: %[[RET_0:.*]] = call @mlirAsyncRuntimeCreateToken() -// CHECK: %[[HDL_0:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL_0:.*]] = llvm.intr.coro.begin // CHECK: call @mlirAsyncRuntimeExecute -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // CHECK: store %arg0, %arg1[%arg2] : memref<1xf32> // CHECK: call @mlirAsyncRuntimeEmplaceToken(%[[RET_0]]) @@ -102,17 +102,17 @@ // CHECK-LABEL: func private @async_execute_fn_0(%arg0: f32, %arg1: memref<1xf32>, %arg2: f32) // CHECK-SAME: -> !llvm.ptr // CHECK: %[[RET_1:.*]] = call @mlirAsyncRuntimeCreateToken() -// CHECK: %[[HDL_1:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL_1:.*]] = llvm.intr.coro.begin // Suspend coroutine in the beginning. // CHECK: call @mlirAsyncRuntimeExecute -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Suspend coroutine second time waiting for the completion of inner execute op. // CHECK: %[[TOKEN_1:.*]] = call @async_execute_fn -// CHECK: llvm.call @llvm.coro.save +// CHECK: llvm.intr.coro.save // CHECK: call @mlirAsyncRuntimeAwaitTokenAndExecute(%[[TOKEN_1]], %[[HDL_1]] -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Emplace result token after second resumption. // CHECK: store %arg2, %arg1[%c0] : memref<1xf32> @@ -141,9 +141,9 @@ // CHECK-LABEL: func private @async_execute_fn(%arg0: f32, %arg1: memref<1xf32>) // CHECK-SAME: -> !llvm.ptr // CHECK: %[[RET_0:.*]] = call @mlirAsyncRuntimeCreateToken() -// CHECK: %[[HDL_0:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL_0:.*]] = llvm.intr.coro.begin // CHECK: call @mlirAsyncRuntimeExecute -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // CHECK: store %arg0, %arg1[%c0] : memref<1xf32> // CHECK: call @mlirAsyncRuntimeEmplaceToken(%[[RET_0]]) @@ -151,16 +151,16 @@ // CHECK-LABEL: func private @async_execute_fn_0(%arg0: !llvm.ptr, %arg1: f32, %arg2: memref<1xf32>) // CHECK-SAME: -> !llvm.ptr // CHECK: %[[RET_1:.*]] = call @mlirAsyncRuntimeCreateToken() -// CHECK: %[[HDL_1:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL_1:.*]] = llvm.intr.coro.begin // Suspend coroutine in the beginning. // CHECK: call @mlirAsyncRuntimeExecute(%[[HDL_1]], -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Suspend coroutine second time waiting for the completion of token dependency. -// CHECK: llvm.call @llvm.coro.save +// CHECK: llvm.intr.coro.save // CHECK: call @mlirAsyncRuntimeAwaitTokenAndExecute(%arg0, %[[HDL_1]], -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Emplace result token after second resumption. // CHECK: store %arg1, %arg2[%c0] : memref<1xf32> @@ -193,16 +193,16 @@ // Function outlined from the async.execute operation. // CHECK: func private @async_execute_fn_0(%arg0: !llvm.ptr) // CHECK: %[[RET_1:.*]] = call @mlirAsyncRuntimeCreateToken() -// CHECK: %[[HDL_1:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL_1:.*]] = llvm.intr.coro.begin // Suspend coroutine in the beginning. // CHECK: call @mlirAsyncRuntimeExecute(%[[HDL_1]], -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Suspend coroutine second time waiting for the group. -// CHECK: llvm.call @llvm.coro.save +// CHECK: llvm.intr.coro.save // CHECK: call @mlirAsyncRuntimeAwaitAllInGroupAndExecute(%arg0, %[[HDL_1]], -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Emplace result token. // CHECK: call @mlirAsyncRuntimeEmplaceToken(%[[RET_1]]) @@ -229,11 +229,11 @@ // CHECK-LABEL: func private @async_execute_fn() // CHECK: %[[TOKEN:.*]] = call @mlirAsyncRuntimeCreateToken() // CHECK: %[[VALUE:.*]] = call @mlirAsyncRuntimeCreateValue -// CHECK: %[[HDL:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL:.*]] = llvm.intr.coro.begin // Suspend coroutine in the beginning. // CHECK: call @mlirAsyncRuntimeExecute(%[[HDL]], -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Emplace result value. // CHECK: %[[CST:.*]] = constant 1.230000e+02 : f32 @@ -274,16 +274,16 @@ // Function outlined from the second async.execute operation. // CHECK-LABEL: func private @async_execute_fn_0(%arg0: !llvm.ptr) // CHECK: %[[TOKEN:.*]] = call @mlirAsyncRuntimeCreateToken() -// CHECK: %[[HDL:.*]] = llvm.call @llvm.coro.begin +// CHECK: %[[HDL:.*]] = llvm.intr.coro.begin // Suspend coroutine in the beginning. // CHECK: call @mlirAsyncRuntimeExecute(%[[HDL]], -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Suspend coroutine second time waiting for the async operand. -// CHECK: llvm.call @llvm.coro.save +// CHECK: llvm.intr.coro.save // CHECK: call @mlirAsyncRuntimeAwaitValueAndExecute(%arg0, %[[HDL]], -// CHECK: llvm.call @llvm.coro.suspend +// CHECK: llvm.intr.coro.suspend // Get the operand value storage, cast to f32 and add the value. // CHECK: %[[STORAGE:.*]] = call @mlirAsyncRuntimeGetValueStorage(%arg0)