Skip to content

Commit 273fca9

Browse files
[MLIR][OpenMP] - Fix translation of omp.target when private variables need cleaning up (#129205)
This is a simple fix that ensures that the InsertPoint is properly fixed up after we have translated the dealloc region of all privatized variables during translation of omp.target from MLIR to LLVMIR. Fix for #129202
1 parent 743571b commit 273fca9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4832,6 +4832,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
48324832
"failed to inline `dealloc` region of `omp.private` "
48334833
"op in the target region");
48344834
}
4835+
return builder.saveIP();
48354836
}
48364837

48374838
return InsertPointTy(exitBlock.get(), exitBlock.get()->end());

mlir/test/Target/LLVMIR/openmp-target-private-allocatable.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ omp.private {type = private} @box.heap_privatizer : !llvm.struct<(ptr, i64, i32,
88
llvm.call @alloc_foo_1(%arg0) : (!llvm.ptr) -> ()
99
omp.yield(%arg1 : !llvm.ptr)
1010
} dealloc {
11+
// There is no reason for the dealloc region here to have two blocks.
12+
// But a multi-block test is useful in checking that the OMPIRBuilder
13+
// has updated the InsertPoint properly after translating the dealloc
14+
// region to LLVMIR.
15+
// See https://github.com/llvm/llvm-project/issues/129202 for more
16+
// context
1117
^bb0(%arg0: !llvm.ptr):
18+
llvm.br ^bb1
19+
^bb1:
1220
llvm.call @dealloc_foo_1(%arg0) : (!llvm.ptr) -> ()
1321
omp.yield
1422
}
@@ -60,3 +68,6 @@ llvm.func @_FortranAAssign(!llvm.ptr, !llvm.ptr, !llvm.ptr, i32) -> !llvm.struct
6068

6169
// Now, check the deallocation of the private var.
6270
// CHECK: call void @dealloc_foo_1(ptr %[[DESC_TO_DEALLOC]])
71+
// CHECK-NEXT: br label %[[CONT_BLOCK:.*]]
72+
// CHECK: [[CONT_BLOCK]]:
73+
// CHECK-NEXT: ret void

0 commit comments

Comments
 (0)