[flang-commits] [PATCH] D150455: [flang][hlfir] Implement the scheduling part of hlfir.forall codegen

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri May 12 09:22:45 PDT 2023


jeanPerier created this revision.
jeanPerier added reviewers: Renaud-K, vzakhari, tblah, clementval.
jeanPerier added a project: Flang.
Herald added subscribers: sunshaoce, bzcheeseman, mehdi_amini, rriddle, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
Herald added a project: All.
jeanPerier requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added a subscriber: stephenneuendorffer.

The lowering of hlfir.forall to loops (and later hlfir.where) requires
doing a data dependency analysis to avoid creating temporary storage for
every control/mask/rhs/lhs expressions.

The added code implements a data dependency analysis for the hlfir
ordered assignment trees (it is not specific to Forall since these nodes
includes Where, user defined assignments, and assignment to vector
subscripted entities, but the added code is only plugged and tested
with hlfir.forall in this patch).

This data dependency analysis returns a "schedule", which is a list of
runs containing actions. Each runs will result in a single loop nest
evaluating all its action "at the same time" inside the loop body.
Actions may either evaluating an assignment, or saving some expression
evaluation (the value yielded inside the ordered assignment hlfir operations)
in a temporary storage before doing the assignment that requires this
expression value but may "conflict" with it.

A "conflict" is a read in an expression E to a variable that is, or may
be (analysis is conservative), written by an assignment that depends on
E.

The analysis is based on MLIR SideEffectInterface and fir AliasAnalysis
which makes it generic.

For now, the codegen that will apply the schedule and rewrite the
hlfir.forall into a set of loops is not implemented, but the scheduling
is tested on its own (from Fortran, because it allows testing many cases
in very readable fashions).

The current scheduling has limitations, for instance
"forall(i=1, 10) x(i)=2*x(i)" does not require saving the RHS values for
all "i" before doing the assignments since the RHS does not depend
on values computed during previous iterations. Any user call will also
trigger a conservative assumption that there is a conflict. Finally,
a lot of operations are missing memory effect interfaces (especially
in HLFIR). This patch adds a few so that it can be tested, but more
will be added in later patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150455

Files:
  flang/include/flang/Optimizer/Dialect/FIROps.td
  flang/include/flang/Optimizer/HLFIR/HLFIROps.td
  flang/include/flang/Optimizer/HLFIR/Passes.td
  flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
  flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
  flang/lib/Optimizer/HLFIR/Transforms/ScheduleOrderAssignments.cpp
  flang/lib/Optimizer/HLFIR/Transforms/ScheduleOrderAssignments.h
  flang/test/HLFIR/order_assignments/forall-fusing-scheduling.f90
  flang/test/HLFIR/order_assignments/forall-scheduling.f90
  flang/tools/bbc/bbc.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150455.521685.patch
Type: text/x-patch
Size: 59604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230512/6a7af012/attachment-0001.bin>


More information about the flang-commits mailing list