[all-commits] [llvm/llvm-project] 2cb31f: [flang] Centralize automatic deallocation code in ...

jeanPerier via All-commits all-commits at lists.llvm.org
Thu Sep 21 09:38:39 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2cb31fe8ea7bbe3c4fce0f03f8126341a353d01b
      https://github.com/llvm/llvm-project/commit/2cb31fe8ea7bbe3c4fce0f03f8126341a353d01b
  Author: jeanPerier <jperier at nvidia.com>
  Date:   2023-09-21 (Thu, 21 Sep 2023)

  Changed paths:
    M flang/include/flang/Lower/Allocatable.h
    M flang/include/flang/Optimizer/Builder/MutableBox.h
    M flang/lib/Lower/Allocatable.cpp
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Lower/ConvertCall.cpp
    M flang/lib/Lower/ConvertExpr.cpp
    M flang/lib/Lower/ConvertVariable.cpp
    M flang/lib/Optimizer/Builder/MutableBox.cpp
    M flang/test/Lower/Intrinsics/system_clock.f90
    M flang/test/Lower/OpenMP/FIR/parallel-private-clause.f90
    M flang/test/Lower/intentout-deallocate.f90

  Log Message:
  -----------
  [flang] Centralize automatic deallocation code in lowering (#67003)

There are currently several places that automatically deallocate
allocatble if they are allocated:
 - INTENT(OUT) allocatable are deallocated on entry in the callee
- INTENT(OUT) allocatable are also deallocated on the caller side of
BIND(C) function in case the implementation is in C.
- Results of function returning allocatable are deallocated after usage.
- OPENMP privatized allocatable are deallocated at the end of OPENMP
region.

Introduce genDeallocateIfAllocated that centralize all this code, except
for the function return that use genFreememIfAllocated since
finalization is done separately currently.

`fir::factory::genFinalization` and
`fir::factory::genInlinedDeallocation` are removed and replaced by
genFreemem since their name were misleading: finalization was not
called.

There is a fallout in the tests because previous generated code did not
check the allocated status when doing inline deallocation. This was OK
since free(null) is guaranteed to be a no-op, but this makes compiler
code more complex, is a bit surprising in the generated IR IMHO, and it
relied on knowing when genDeallocateBox inserts runtime calls or uses
inlined code.




More information about the All-commits mailing list