[flang-commits] [flang] [flang][OpenMP][Lower] lower array subscripts for task depend (PR #132994)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Thu Mar 27 07:21:39 PDT 2025


================
@@ -808,7 +809,21 @@ bool ClauseProcessor::processCopyprivate(
   return hasCopyPrivate;
 }
 
-bool ClauseProcessor::processDepend(mlir::omp::DependClauseOps &result) const {
+template <typename T>
+static bool isVectorSubscript(const evaluate::Expr<T> &expr) {
+  if (std::optional<evaluate::DataRef> dataRef{evaluate::ExtractDataRef(expr)})
+    if (const auto *arrayRef = std::get_if<evaluate::ArrayRef>(&dataRef->u))
+      for (const evaluate::Subscript &subscript : arrayRef->subscript())
+        if (std::holds_alternative<evaluate::IndirectSubscriptIntegerExpr>(
----------------
tblah wrote:

Some examples might make this clearer

- `array(1:3)` here the triplet is `(1:3)` and `array` is the thing being subscripted. This doesn't need special handling as a vector subscript because we don't need to index a second array to know what indices are being selected in which order - we know the answer statically so a simple `hlfir.designate` is sufficient
- `array(indices)` (where indices is an array) requires special handling as a vector subscript because `indices` has to be read in order to know which elements of `array` have been selected. The access to the indices is indirect.
- `array(indices(1:4:2))`. Here the triplet `(1:4:2)` has to be first applied to `indices` to select `indices(1)` and `indices(3)`. Then those two elements have to be read to find the right elements to access in `array`. This is also a vector subscript because of the indirection through `indices`.

The same logic (mixed into other things) in the hlfir lowering code that handles this: see how `sawVectorSubscripts` is handled in `HlfirDesignatorBuilder::visit(const Fortran::evaluate::ArrayRef &, PartInfo &)` in `convertExprToHlfir.cpp`.

https://github.com/llvm/llvm-project/pull/132994


More information about the flang-commits mailing list