This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Add hlfir.forall_index operation
ClosedPublic

Authored by jeanPerier on May 4 2023, 3:03 AM.

Details

Summary

This is the last piece required to lower Forall (except pointer
assignments, where an operation may be needed to deal with bounds
remapping).

Lowering requires symbols to be mapped to memory SSA values produced
by a fir_FortranVariableOpInterface operation. This applies to
forall index-values, that are symbols.

fir.alloca/fir.store/hlfir.declare are not allowed inside the body of
an hlfir.forall that only accept operations with the
hlfir_OrderedAssignmentTreeOpInterface so that the forall structure is
well defined and easy to transform.
Allowing such operations in the forall body would open the doors to
generating ill-formed programs where such operation would be used for
non index-values.

Instead, add an hlfir.forall_index with both required interface to
produce a memory address for a forall index.

As a bonus, since forall index-value are by nature read-only, the
loads of hlfir.forall_index can be canonicalized, which will help
simplifying the hlfir.forall nested code (it is unclear we will be
able to tell MLIR enough about hlfir.forall and hlfir.where structure
so that it could safely do a generic mem-to-reg inside it, and getting
rid of read-effect operations will benefit the forall rewrite pass).

Diff Detail

Event Timeline

jeanPerier created this revision.May 4 2023, 3:03 AM
jeanPerier requested review of this revision.May 4 2023, 3:03 AM
clementval accepted this revision.May 4 2023, 10:02 AM

LGTM

flang/include/flang/Optimizer/HLFIR/HLFIROps.td
1240

Maybe?

This revision is now accepted and ready to land.May 4 2023, 10:02 AM
vzakhari accepted this revision.May 4 2023, 6:33 PM
This revision was automatically updated to reflect the committed changes.