[flang-commits] [PATCH] D148128: [flang] Fold IS_CONTIGUOUS for TYPE(*) when possible

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Apr 13 23:43:04 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f5df4199e64: [flang] Fold IS_CONTIGUOUS for TYPE(*) when possible (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148128/new/

https://reviews.llvm.org/D148128

Files:
  flang/include/flang/Evaluate/check-expression.h
  flang/lib/Evaluate/check-expression.cpp
  flang/lib/Evaluate/fold-logical.cpp
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Evaluate/rewrite03.f90


Index: flang/test/Evaluate/rewrite03.f90
===================================================================
--- /dev/null
+++ flang/test/Evaluate/rewrite03.f90
@@ -0,0 +1,19 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+! Tests rewrite of IS_CONTIGUOUS with TYPE(*) arguments.
+
+subroutine test_is_contiguous(assumed_size, assumed_shape, &
+      & assumed_shape_contiguous, assumed_rank, assumed_rank_contiguous)
+  type(*) :: assumed_size(*), assumed_shape(:), assumed_shape_contiguous(:)
+  type(*) :: assumed_rank(..), assumed_rank_contiguous(..)
+  contiguous :: assumed_shape_contiguous, assumed_rank_contiguous
+! CHECK: PRINT *, .true._4
+  print *, is_contiguous(assumed_size)
+! CHECK: PRINT *, .true._4
+  print *, is_contiguous(assumed_shape_contiguous)
+! CHECK: PRINT *, .true._4
+  print *, is_contiguous(assumed_rank_contiguous)
+! CHECK: PRINT *, is_contiguous(assumed_shape)
+  print *, is_contiguous(assumed_shape)
+! CHECK: PRINT *, is_contiguous(assumed_rank)
+  print *, is_contiguous(assumed_rank)
+end subroutine
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -586,9 +586,8 @@
             symbol.name());
       }
       if (details.IsArray() && details.shape().IsExplicitShape()) {
-        messages_.Say(
-            "Assumed-type array argument 'arg8' must be assumed shape,"
-            " assumed size, or assumed rank"_err_en_US,
+        messages_.Say("Assumed-type array argument '%s' must be assumed shape,"
+                      " assumed size, or assumed rank"_err_en_US,
             symbol.name());
       }
     }
Index: flang/lib/Evaluate/fold-logical.cpp
===================================================================
--- flang/lib/Evaluate/fold-logical.cpp
+++ flang/lib/Evaluate/fold-logical.cpp
@@ -187,6 +187,10 @@
         if (auto contiguous{IsContiguous(*expr, context)}) {
           return Expr<T>{*contiguous};
         }
+      } else if (auto *assumedType{args[0]->GetAssumedTypeDummy()}) {
+        if (auto contiguous{IsContiguous(*assumedType, context)}) {
+          return Expr<T>{*contiguous};
+        }
       }
     }
   } else if (name == "lge" || name == "lgt" || name == "lle" || name == "llt") {
Index: flang/lib/Evaluate/check-expression.cpp
===================================================================
--- flang/lib/Evaluate/check-expression.cpp
+++ flang/lib/Evaluate/check-expression.cpp
@@ -768,11 +768,10 @@
     } else if (ultimate.has<semantics::AssocEntityDetails>()) {
       return Base::operator()(ultimate); // use expr
     } else if (semantics::IsPointer(ultimate) ||
-        semantics::IsAssumedShape(ultimate)) {
+        semantics::IsAssumedShape(ultimate) || IsAssumedRank(ultimate)) {
       return std::nullopt;
-    } else if (const auto *details{
-                   ultimate.detailsIf<semantics::ObjectEntityDetails>()}) {
-      return !details->IsAssumedRank();
+    } else if (ultimate.has<semantics::ObjectEntityDetails>()) {
+      return true;
     } else {
       return Base::operator()(ultimate);
     }
@@ -936,6 +935,7 @@
 template std::optional<bool> IsContiguous(
     const ComplexPart &, FoldingContext &);
 template std::optional<bool> IsContiguous(const CoarrayRef &, FoldingContext &);
+template std::optional<bool> IsContiguous(const Symbol &, FoldingContext &);
 
 // IsErrorExpr()
 struct IsErrorExprHelper : public AnyTraverse<IsErrorExprHelper, bool> {
Index: flang/include/flang/Evaluate/check-expression.h
===================================================================
--- flang/include/flang/Evaluate/check-expression.h
+++ flang/include/flang/Evaluate/check-expression.h
@@ -110,6 +110,8 @@
     const ComplexPart &, FoldingContext &);
 extern template std::optional<bool> IsContiguous(
     const CoarrayRef &, FoldingContext &);
+extern template std::optional<bool> IsContiguous(
+    const Symbol &, FoldingContext &);
 template <typename A>
 bool IsSimplyContiguous(const A &x, FoldingContext &context) {
   return IsContiguous(x, context).value_or(false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148128.513446.patch
Type: text/x-patch
Size: 4184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230414/2f001053/attachment-0001.bin>


More information about the flang-commits mailing list