From b655d59ce25e17d89b8aafdd851e87923c370fd0 Mon Sep 17 00:00:00 2001 From: Kiran Chandramohan Date: Mon, 22 May 2023 09:50:28 +0000 Subject: [PATCH] [MLIR][OpenMP] Set AllocaIP correctly for constructs nested in task Fixes #60874 Reviewed By: psoni2628, NimishMishra Differential Revision: https://reviews.llvm.org/D151027 --- .../Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 5 +++++ mlir/test/Target/LLVMIR/openmp-llvm.mlir | 23 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index 95cb07f..c3ffd99 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -694,6 +694,11 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder, return taskOp.emitError("unhandled clauses for translation to LLVM IR"); } auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP) { + // Save the alloca insertion point on ModuleTranslation stack for use in + // nested regions. + LLVM::ModuleTranslation::SaveStack frame( + moduleTranslation, allocaIP); + builder.restoreIP(codegenIP); convertOmpOpRegions(taskOp.getRegion(), "omp.task.region", builder, moduleTranslation, bodyGenStatus); diff --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir b/mlir/test/Target/LLVMIR/openmp-llvm.mlir index 86166ea..89a4578 100644 --- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir +++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir @@ -2340,6 +2340,29 @@ module attributes {llvm.target_triple = "x86_64-unknown-linux-gnu"} { // ----- +llvm.func @par_task_(%arg0: !llvm.ptr {fir.bindc_name = "a"}) { + %0 = llvm.mlir.constant(1 : i32) : i32 + omp.task { + omp.parallel { + llvm.store %0, %arg0 : !llvm.ptr + omp.terminator + } + omp.terminator + } + llvm.return +} + +// CHECK-LABEL: @par_task_ +// CHECK: %[[TASK_ALLOC:.*]] = call ptr @__kmpc_omp_task_alloc({{.*}}ptr @par_task_..omp_par.wrapper) +// CHECK: call i32 @__kmpc_omp_task({{.*}}, ptr %[[TASK_ALLOC]]) +// CHECK-LABEL: define internal void @par_task_..omp_par +// CHECK: %[[ARG_ALLOC:.*]] = alloca { ptr }, align 8 +// CHECK: call void ({{.*}}) @__kmpc_fork_call({{.*}}, ptr @par_task_..omp_par..omp_par, ptr %[[ARG_ALLOC]]) +// CHECK: define internal void @par_task_..omp_par..omp_par +// CHECK: define i32 @par_task_..omp_par.wrapper +// CHECK: call void @par_task_..omp_par +// ----- + llvm.func @foo() -> () llvm.func @omp_taskgroup(%x: i32, %y: i32, %zaddr: !llvm.ptr) { -- 2.7.4