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

Akash Banerjee via flang-commits flang-commits at lists.llvm.org
Fri Sep 29 05:32:25 PDT 2023


TIFitis wrote:




> Can you add new tests with the HLFIR flow?

I tried adding HLFIR tests, but I'm getting errors because of re-declaration of arrays inside the region.

Fortran:

```
subroutine omp_target_implicit
   integer :: a(1024)
   !$omp target
      a(1) = 10
   !$omp end target
end subroutine omp_target_implicit
```

HLFIR op dump:

```
"func.func"() <{function_type = () -> (), sym_name = "_QPomp_target_implicit"}> ({
  %0 = "arith.constant"() <{value = 1024 : index}> : () -> index
  %1 = "fir.alloca"() <{bindc_name = "a", in_type = !fir.array<1024xi32>, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_implicitEa"}> : () -> !fir.ref<!fir.array<1024xi32>>
  %2 = "fir.shape"(%0) : (index) -> !fir.shape<1>
  %3:2 = "hlfir.declare"(%1, %2) <{operandSegmentSizes = array<i32: 1, 1, 0>, uniq_name = "_QFomp_target_implicitEa"}> : (!fir.ref<!fir.array<1024xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>)
  %4 = "omp.map_info"(%3#1) <{map_capture_type = #omp<variable_capture_kind(ByCopy)>, map_type = 768 : ui64, name = "a", operandSegmentSizes = array<i32: 1, 0, 0>}> : (!fir.ref<!fir.array<1024xi32>>) -> !fir.ref<!fir.array<1024xi32>>
  "omp.target"(%4) <{operandSegmentSizes = array<i32: 0, 0, 0, 1>}> ({
  ^bb0(%arg0: !fir.ref<!fir.array<1024xi32>>):
    %5 = "fir.shape"(%0) : (index) -> !fir.shape<1>
    %6:2 = "hlfir.declare"(%arg0, %5) <{operandSegmentSizes = array<i32: 1, 1, 0>, uniq_name = "_QFomp_target_implicitEa"}> : (!fir.ref<!fir.array<1024xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>)
    "omp.terminator"() : () -> ()
  }) : (!fir.ref<!fir.array<1024xi32>>) -> ()
}) : () -> ()
```

The statement `%5 = "fir.shape"(%0) : (index) -> !fir.shape<1>` inside the target region is causing an error as `%0` has not been captured.

For scalar variables this error goes away as the `fir.shape` is not present.

I am not familiar with HLFIR, do you have any suggestions for fixing this?

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


More information about the flang-commits mailing list