[flang] rework non-block DO loop canonicalization
authorpeter klausler <pklausler@nvidia.com>
Tue, 2 Oct 2018 21:19:51 +0000 (14:19 -0700)
committerpeter klausler <pklausler@nvidia.com>
Thu, 4 Oct 2018 20:52:42 +0000 (13:52 -0700)
Original-commit: flang-compiler/f18@50574936f23685730c0f709fb2a60c3c86ff8aac
Reviewed-on: https://github.com/flang-compiler/f18/pull/200
Tree-same-pre-rewrite: false

flang/lib/parser/parse-tree-visitor.h
flang/lib/semantics/canonicalize-do.cc
flang/test/semantics/canondo01.f90
flang/test/semantics/canondo02.f90
flang/test/semantics/canondo03.f90
flang/test/semantics/canondo04.f90

index 574cac2..f268389 100644 (file)
@@ -85,6 +85,23 @@ template<typename T, typename M> void Walk(std::list<T> &x, M &mutator) {
     Walk(elem, mutator);
   }
 }
+// When a list constitutes a Block, invoke the visitor or mutator.
+template<typename V> void Walk(const Block &x, V &visitor) {
+  if (visitor.Pre(x)) {
+    for (const auto &elem : x) {
+      Walk(elem, visitor);
+    }
+    visitor.Post(x);
+  }
+}
+template<typename M> void Walk(Block &x, M &mutator) {
+  if (mutator.Pre(x)) {
+    for (auto &elem : x) {
+      Walk(elem, mutator);
+    }
+  }
+  mutator.Post(x);
+}
 template<std::size_t I = 0, typename Func, typename T>
 void ForEachInTuple(const T &tuple, Func func) {
   if constexpr (I < std::tuple_size_v<T>) {
index 80cd6f0..e0521f1 100644 (file)
@@ -14,6 +14,8 @@
 
 #include "canonicalize-do.h"
 #include "../parser/parse-tree-visitor.h"
+#include <variant>
+#include <vector>
 
 namespace Fortran::parser {
 
@@ -116,5 +118,4 @@ void CanonicalizeDo(Program &program) {
   CanonicalizationOfDoLoops canonicalizationOfDoLoops{labelInfos};
   Walk(program, canonicalizationOfDoLoops);
 }
-
 }  // namespace Fortran::parser
index d63ab5a..5cbb0ce 100644 (file)
@@ -12,6 +12,8 @@
 ! See the License for the specific language governing permissions and
 ! limitations under the License.
 
+! negative test -- invalid labels, out of range
+
 ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s
 ! CHECK: end do
 
index 40992a0..a54e451 100644 (file)
@@ -12,6 +12,8 @@
 ! See the License for the specific language governing permissions and
 ! limitations under the License.
 
+! negative test -- invalid labels, out of range
+
 ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s
 ! CHECK: end do
 
index 4e822c7..e6ec377 100644 (file)
@@ -12,6 +12,8 @@
 ! See the License for the specific language governing permissions and
 ! limitations under the License.
 
+! negative test -- invalid labels, out of range
+
 ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s
 ! CHECK: 10 continue
 ! CHECK: end do
index e53a6ea..4260f20 100644 (file)
@@ -23,14 +23,18 @@ program main
           print *, j1, j2, j3
           do 2 j4=1,2
             print *, j3, j4
-2         continue
+2         end do
       else
         do 3 j3=3,4
           print *, j1, j2, j3
           do 3 j4=3,4
             print *, j3, j4
-3         continue
+3         end do
       end if
     print *, j1, j2
 1   continue
+  do 4 j1=3,4 ! adjacent non-block DO loops
+4   print *, j1
+  do 5 j1=5,6 ! non-block DO loop at end of execution part
+5   print *, j1
 end