[flang-commits] [flang] [OpenMP][Flang] Add "IsolatedFromAbove" trait to omp.target (PR #67164)

Akash Banerjee via flang-commits flang-commits at lists.llvm.org
Mon Oct 16 09:38:38 PDT 2023


TIFitis wrote:

I've updated the patch with the following changes:

- Generate `boundsOp` for `implicit` map operands.
- No longer adding bounds information from `box` types as map operands.
- Revert the type change for map entries, back to using `OpenMP_PointerLikeType`.
- Add a `block_args` variable to the TargetOp.
- This stores the mapping between `block arguments` and their corresponding `mlir values` for cases where we don't want to add them as map entries.
- If everyone is happy with this change, I can add a custom printer and parser for the block_args similar to the map_entries.

Here's what the MLIR looks like in LLVM dialect. From what I can see the default bounds information is not present.

Fortran:
```
subroutine omp_target_implicit_bounds(n)
   integer :: n
   integer :: a(n, 1024)
   !$omp target map(alloc : a(5:15, 20:30))
      a(11,22) = 33
   !$omp end target
end subroutine omp_target_implicit_bounds
```

MLIR-LLVM Dialect
```
llvm.func @_QPomp_target_implicit_bounds(%arg0: !llvm.ptr<i32> {fir.bindc_name = "n"}) {
  %0 = llvm.load %arg0 : !llvm.ptr<i32>
  %1 = llvm.sext %0 : i32 to i64
  %2 = llvm.mlir.constant(0 : index) : i64
  %3 = llvm.icmp "sgt" %1, %2 : i64
  %4 = llvm.select %3, %1, %2 : i1, i64
  %5 = llvm.mlir.constant(1024 : i64) : i64
  %6 = llvm.mlir.constant(0 : index) : i64
  %7 = llvm.icmp "sgt" %5, %6 : i64
  %8 = llvm.select %7, %5, %6 : i1, i64
  %9 = llvm.mlir.constant(1 : i64) : i64
  %10 = llvm.mlir.constant(1024 : i64) : i64
  %11 = llvm.mul %9, %10  : i64
  %12 = llvm.mul %11, %4  : i64
  %13 = llvm.alloca %12 x i32 {bindc_name = "a", in_type = !fir.array<?x1024xi32>, operandSegmentSizes = array<i32: 0, 1>, uniq_name = "_QFomp_target_implicit_boundsEa"} : (i64) -> !llvm.ptr<i32>
  %14 = llvm.mlir.constant(1 : index) : i64
  %15 = llvm.mlir.constant(4 : index) : i64
  %16 = llvm.mlir.constant(14 : index) : i64
  %17 = omp.bounds lower_bound(%15 : i64) upper_bound(%16 : i64) stride(%14 : i64) start_idx(%14 : i64)
  %18 = llvm.mlir.constant(19 : index) : i64
  %19 = llvm.mlir.constant(29 : index) : i64
  %20 = omp.bounds lower_bound(%18 : i64) upper_bound(%19 : i64) stride(%14 : i64) start_idx(%14 : i64)
  %21 = omp.map_info var_ptr(%13 : !llvm.ptr<i32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%17, %20) -> !llvm.ptr<i32> {name = "a(5:15,20:30)"}
  omp.target map_entries(%21 -> %arg1 : !llvm.ptr<i32>) block_args(%4, %8 : i64, i64) {
  ^bb0(%arg1: !llvm.ptr<i32>, %arg2: i64, %arg3: i64):
    %22 = llvm.mlir.constant(33 : i32) : i32
    %23 = llvm.mlir.constant(1 : index) : i64
    %24 = llvm.mlir.constant(0 : index) : i64
    %25 = llvm.mlir.constant(11 : i64) : i64
    %26 = llvm.sub %25, %23  : i64
    %27 = llvm.mlir.constant(22 : i64) : i64
    %28 = llvm.sub %27, %23  : i64
    %29 = llvm.mul %arg2, %28  : i64
    %30 = llvm.add %29, %26  : i64
    %31 = llvm.getelementptr %arg1[%30] : (!llvm.ptr<i32>, i64) -> !llvm.ptr<i32>
    llvm.store %22, %31 : !llvm.ptr<i32>
    omp.terminator
  }
  llvm.return
}
```

https://github.com/llvm/llvm-project/pull/67164


More information about the flang-commits mailing list