Skip to content

[MLIR][OpenMP] Translaton of omp.target is broken when private variables are cleaned up #129202

Open
@bhandarkar-pranav

Description

@bhandarkar-pranav
$> cat reproducer.mlir
module attributes {omp.is_target_device = false, omp.requires = #omp<clause_requires none>, omp.target_triples = [], omp.version = #om\
p.version<version = 11>} {
  llvm.func @free(!llvm.ptr)
  llvm.func @malloc(i64) -> !llvm.ptr
  omp.private {type = private} @_QFtarget_allocatableEnon_alloc_var_private_box_10xi32 : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, \
array<1 x array<3 x i64>>)> init {
  ^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
    omp.yield(%arg1 : !llvm.ptr)
  } dealloc {
  ^bb0(%arg0: !llvm.ptr):
    llvm.br ^bb1
  ^bb1:  // 2 preds: ^bb0, ^bb1
    omp.yield
  }
  llvm.func @target_allocatable_(%arg0: !llvm.ptr {fir.bindc_name = "lb", llvm.nocapture}, %arg1: !llvm.ptr {fir.bindc_name = "ub", ll\
vm.nocapture}) attributes {fir.internal_name = "_QPtarget_allocatable"} {
    %2 = llvm.mlir.constant(1 : i64) : i64
    %5 = llvm.alloca %2 x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> : (i64) -> !llvm.ptr
    omp.target private(@_QFtarget_allocatableEnon_alloc_var_private_box_10xi32 %5 -> %arg2 : !llvm.ptr) {
      omp.terminator
    }
    llvm.return
  }
}

Command to reproduce the problem

mlir-translate -mlir-to-llvmir -allow-unregistered-dialect ./reproducer.mlir
Basic Block in function '__omp_offloading_10304_b734e3e_target_allocatable__l16' does not have terminator!
label %omp.region.cont1

This happens because after translating the dealloc regions of omp.private in the translation of omp.target we do not return the corret InsertPoint

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions