summaryrefslogtreecommitdiff
path: root/flang/include
diff options
context:
space:
mode:
authorJean Perier <jperier@nvidia.com>2023-05-05 09:13:50 +0200
committerJean Perier <jperier@nvidia.com>2023-05-05 09:17:50 +0200
commit0aa80b42ac975a10087c4356b475a188ef1f5afa (patch)
tree8c95c3820ea2bd38d81989577e0379c34bddd687 /flang/include
parent309bfecf7dddb9d6530fa95656bbcdd82423fd44 (diff)
downloadllvm-0aa80b42ac975a10087c4356b475a188ef1f5afa.tar.gz
[flang][hlfir] Add hlfir.forall_index operation
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). Differential Revision: https://reviews.llvm.org/D149836
Diffstat (limited to 'flang/include')
-rw-r--r--flang/include/flang/Optimizer/HLFIR/HLFIROps.td45
1 files changed, 45 insertions, 0 deletions
diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td
index 12f9a8b98fce..87136197851a 100644
--- a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td
+++ b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td
@@ -1258,4 +1258,49 @@ def hlfir_ElseWhereOp : hlfir_Op<"elsewhere", [Terminator,
let hasVerifier = 1;
}
+def hlfir_ForallIndexOp : hlfir_Op<"forall_index", [fir_FortranVariableOpInterface,
+ hlfir_OrderedAssignmentTreeOpInterface, Pure]> {
+ let summary = "represent a Fortran forall index declaration";
+ let description = [{
+ This operation allows placing an hlfir.forall index in memory with
+ the related Fortran index-value name and type.
+
+ So far, lowering needs to manipulate symbols as memory entities.
+ This operation allows fulfilling this requirements without allowing
+ bare alloca/declare/store inside the body of hlfir.forall, which would
+ make their analysis more complex.
+
+ Given Forall index-value cannot be modified it also allows defining
+ a canonicalization of all its loads into a fir.convert of the
+ hlfir.forall index, which helps simplifying the data dependency analysis
+ of hlfir.forall.
+ }];
+
+ let arguments = (ins AnyIntegerType:$index,
+ Builtin_StringAttr:$name);
+
+ let results = (outs AnyFortranVariable);
+
+ let assemblyFormat = [{
+ $name $index attr-dict `:` functional-type(operands, results)
+ }];
+
+ let extraClassDeclaration = [{
+ /// Implement FortranVariableInterface interface.
+ std::optional<fir::FortranVariableFlagsEnum> getFortranAttrs() const {
+ return std::nullopt;
+ }
+ mlir::Value getShape() const {return mlir::Value{};}
+ mlir::OperandRange getExplicitTypeParams() const {
+ // Return an empty range.
+ return {(*this)->getOperands().begin(), (*this)->getOperands().begin()};
+ }
+ /// Implement OrderedAssignmentTreeOpInterface interface.
+ void getLeafRegions(llvm::SmallVectorImpl<mlir::Region*>& regions) {}
+ mlir::Region* getSubTreeRegion() { return nullptr; }
+ }];
+
+ let hasCanonicalizeMethod = 1;
+}
+
#endif // FORTRAN_DIALECT_HLFIR_OPS