[all-commits] [llvm/llvm-project] 3eeb9b: [flang] add AllocationPolicy attribute to module a...

jeanPerier via All-commits all-commits at lists.llvm.org
Thu Sep 10 05:06:10 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3eeb9b2bdb2a9ac4020a8ab8729e96ecb283691c
      https://github.com/llvm/llvm-project/commit/3eeb9b2bdb2a9ac4020a8ab8729e96ecb283691c
  Author: jeanPerier <jperier at nvidia.com>
  Date:   2026-09-10 (Thu, 10 Sep 2026)

  Changed paths:
    M flang/include/flang/Optimizer/Dialect/FIRAttr.td
    M flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
    M flang/include/flang/Optimizer/HLFIR/Passes.h
    M flang/include/flang/Optimizer/HLFIR/Passes.td
    M flang/include/flang/Optimizer/Passes/CommandLineOpts.h
    M flang/include/flang/Optimizer/Passes/Pipelines.h
    A flang/include/flang/Optimizer/Support/AllocationPolicy.h
    R flang/include/flang/Optimizer/Transforms/AllocationPlacementPolicy.h
    M flang/include/flang/Optimizer/Transforms/Passes.h
    M flang/include/flang/Optimizer/Transforms/Passes.td
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopy.cpp
    M flang/lib/Optimizer/Passes/CommandLineOpts.cpp
    M flang/lib/Optimizer/Passes/Pipelines.cpp
    A flang/lib/Optimizer/Support/AllocationPolicy.cpp
    M flang/lib/Optimizer/Support/CMakeLists.txt
    M flang/lib/Optimizer/Transforms/AllocationPlacement.cpp
    A flang/test/Driver/allocation-policy.f90
    A flang/test/Fir/allocation-policy-attr.fir
    A flang/test/Fir/allocation-policy-pipeline.fir
    A flang/test/HLFIR/inline-hlfir-copy-stack.fir
    M flang/test/HLFIR/inline-hlfir-copy.fir
    M flang/test/Transforms/allocation-placement.fir
    A flang/test/Transforms/allocation-policy-precedence.fir

  Log Message:
  -----------
  [flang] add AllocationPolicy attribute to module and use it in InlineHLFIRCopy (#222013)

The StackArrays/AllocationPlacement pass cannot move fir.allocmem
created during InlineHLFIRCopy for the copy-in/cop-out buffers because
of there placement in branches.

Moving these allocmem outside of the branches is suboptimal as these
allocations may never occur at runtime (when the data is actually
already contiguous).
Extending the StackArrays pass is doable but very tedious (the data flow
analysis passes used in the pass cannot recognized "same
predicates"/understand that the two fir.if block that
allocate/deallocates will be both reached or never reached (even when
modifying InlineHLFIRCopy to use the same SSA value for both fir.if). So
this requires custom logic, and was adding 200 lines of non trivial code
to audit and I did not like it.

I decided to expose the allocation policy so that other passes can rely
on it. To make it the most flexible and future proof this is done via a
new module attribute instead of threading options in the driver to this
and that pass. This way, it will also be possible to have custom per
function policy if ever needed.

The InlineHLFIRCopy is updated to apply the small array threshold policy
(that decide when constant size arrays should always be placed on the
stack, regardless of the -fstack-array/-fno-stack-array). I also
increased this threshold from 64 to 1024 so that it cover my application
use case. This increase is in line with the industry practice (NV, IFX,
and gfortran will all allocate few Kb temporary copy-in/out buffers on
the stack, regardless of the optimization level). For now, I decided to
not apply the `-fstack-array` aspect as it is on by default with flang
and I want to measure the effect first before doing so (gfortran/ifx
also control dynamic copy-in/out buffer allocations with the stack-array
related flag, so there is a good chance we end-up doing it at some
point).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list