[Mlir-commits] [mlir] [flang][OpenMP] Translate OpenMP scopes when compiling for target device (PR #130078)
Sergio Afonso
llvmlistbot at llvm.org
Mon Mar 17 06:45:58 PDT 2025
================
@@ -5315,6 +5320,46 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
return WalkResult::interrupt();
return WalkResult::skip();
}
+
+ // Non-target ops might nest target-related ops, therefore, we
+ // translate them as non-OpenMP scopes. Translating them is needed by
+ // nested target-related ops since they might need LLVM values defined
+ // in their parent non-target ops.
+ if (isa<omp::OpenMPDialect>(oper->getDialect()) &&
+ oper->getParentOfType<LLVM::LLVMFuncOp>() &&
+ !oper->getRegions().empty()) {
----------------
skatrak wrote:
I was thinking of something like this (since `omp.threadprivate` seems to be the only non map-related OpenMP op that returns some value at the moment):
```f90
module test
implicit none
integer :: n
!$omp threadprivate(n)
contains
subroutine foo(x)
integer, intent(inout) :: x(10)
!$omp target map(tofrom: x(1:n))
call bar(x)
!$omp end target
end subroutine
end module
```
Lowering it to MLIR for the device results in the following sequence of operations:
```mlir
%3 = omp.threadprivate ...
%4 = fir.declare %3
%13 = omp.map.info var_ptr(%4 : !fir.ref<i32>, i32) ...
omp.target map_entries(%13 -> %arg2 ...) {
...
}
```
https://github.com/llvm/llvm-project/pull/130078
More information about the Mlir-commits
mailing list