[flang-commits] [flang] [flang][MLIR][OpenMP] Extend delayed privatization for allocatables (PR #84033)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Thu Mar 7 01:20:24 PST 2024


ergawy wrote:

Thanks @jeanPerier for your thoughts.

>From what you are describing:
1. For the purpose of OpenMP private cloning and copying, it always safe to use `#0` even for assume-shape. Is that correct?

2. Not exactly related to OpenMP privatization, but in order to understand the following part of you comment:

> `#1` is only here to help skipping the creation of temporary descriptors when propagating assumed-shape through calls and doing "FIR level" descriptor manipulation (the issue of assumed-shape is that there lower bounds are local, so a new descriptor `#0` is created to hold the accurate lower bounds in the descriptors. But we do not care about propagating these lower bounds through calls since the entity will get new lower bounds inside the call anyway.

I tested a small sample:
```fortran
subroutine foo()
  interface
    subroutine bar(x)
      character(*) :: x(3:)
    end subroutine
  end interface
  character(100) :: x(2:42)

  call bar(x)
end subroutine
```

And I thought that the `call` operation will use `#1` from the `hlfir.declare` operation that declares `x`. I though so since this is the original SSA value without the `shift` (i.e. without the lower bound). However, this is the generated IR:
```mlir
  func.func @_QPfoo() {
    %c100 = arith.constant 100 : index
    %c2 = arith.constant 2 : index
    %c41 = arith.constant 41 : index
    %0 = fir.alloca !fir.array<41x!fir.char<1,100>> {bindc_name = "x", uniq_name = "_QFfooEx"}
    %1 = fir.shape_shift %c2, %c41 : (index, index) -> !fir.shapeshift<1>
    %2:2 = hlfir.declare %0(%1) typeparams %c100 {uniq_name = "_QFfooEx"} : (!fir.ref<!fir.array<41x!fir.char<1,100>>>, !fir.shapeshift<1>, index) -> (!fir.box<!fir.array<41x!fir.char<1,100>>>, !fir.ref<!fir.array<41x!fir.char<1,100>>>)
    %3 = fir.convert %2#0 : (!fir.box<!fir.array<41x!fir.char<1,100>>>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
    fir.call @_QPbar(%3) fastmath<contract> : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> ()
    return
  }
```
So, `#0` is used for the `call` and that makes me think I might have misunderstood what you meant.



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


More information about the flang-commits mailing list