[Mlir-commits] [mlir] 5b38816 - [mlir] Delay adding the __resume function

Christian Sigg llvmlistbot at llvm.org
Tue Feb 2 11:03:04 PST 2021


Author: Christian Sigg
Date: 2021-02-02T20:02:54+01:00
New Revision: 5b3881691f3375344c1b4c3d594b5958948851d7

URL: https://github.com/llvm/llvm-project/commit/5b3881691f3375344c1b4c3d594b5958948851d7
DIFF: https://github.com/llvm/llvm-project/commit/5b3881691f3375344c1b4c3d594b5958948851d7.diff

LOG: [mlir] Delay adding the __resume function

The __resume function trips up LLVM's 'X86 DAG->DAG Instruction Selection' unless optimizations are disabled.

Only adding the __resume function when it's needed allows lowering through AsyncToLLVM and LLVM without '-O0' as long as the coroutine functionality is not used.

Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D95868

Added: 
    

Modified: 
    mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
index 215b87cd3437..3fe1c7fef2ec 100644
--- a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
+++ b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
@@ -228,14 +228,14 @@ static constexpr const char *kResume = "__resume";
 /// intrinsics. We need this function to be able to pass it to the async
 /// runtime execute API.
 static void addResumeFunction(ModuleOp module) {
+  if (module.lookupSymbol(kResume))
+    return;
+
   MLIRContext *ctx = module.getContext();
 
   OpBuilder moduleBuilder(module.getBody()->getTerminator());
   Location loc = module.getLoc();
 
-  if (module.lookupSymbol(kResume))
-    return;
-
   auto voidTy = LLVM::LLVMVoidType::get(ctx);
   auto i8Ptr = LLVM::LLVMPointerType::get(IntegerType::get(ctx, 8));
 
@@ -637,6 +637,7 @@ class RuntimeAwaitAndResumeOpLowering
     Value handle = RuntimeAwaitAndResumeOpAdaptor(operands).handle();
 
     // A pointer to coroutine resume intrinsic wrapper.
+    addResumeFunction(op->getParentOfType<ModuleOp>());
     auto resumeFnTy = AsyncAPI::resumeFunctionType(op->getContext());
     auto resumePtr = rewriter.create<LLVM::AddressOfOp>(
         op->getLoc(), LLVM::LLVMPointerType::get(resumeFnTy), kResume);
@@ -663,6 +664,7 @@ class RuntimeResumeOpLowering : public OpConversionPattern<RuntimeResumeOp> {
   matchAndRewrite(RuntimeResumeOp op, ArrayRef<Value> operands,
                   ConversionPatternRewriter &rewriter) const override {
     // A pointer to coroutine resume intrinsic wrapper.
+    addResumeFunction(op->getParentOfType<ModuleOp>());
     auto resumeFnTy = AsyncAPI::resumeFunctionType(op->getContext());
     auto resumePtr = rewriter.create<LLVM::AddressOfOp>(
         op->getLoc(), LLVM::LLVMPointerType::get(resumeFnTy), kResume);
@@ -862,8 +864,9 @@ void ConvertAsyncToLLVMPass::runOnOperation() {
   ModuleOp module = getOperation();
   MLIRContext *ctx = module->getContext();
 
-  // Add declarations for all functions required by the coroutines lowering.
-  addResumeFunction(module);
+  // Add declarations for most functions required by the coroutines lowering.
+  // We delay adding the resume function until it's needed because it currently
+  // fails to compile unless '-O0' is specified.
   addAsyncRuntimeApiDeclarations(module);
   addCRuntimeDeclarations(module);
 


        


More information about the Mlir-commits mailing list