[flang] rework non-block DO loop canonicalization

Original-commit: flang-compiler/f18@50574936f2
Reviewed-on: https://github.com/flang-compiler/f18/pull/200
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2018-10-02 14:19:51 -07:00
parent 2df6a9638b
commit 4d6885346e
6 changed files with 31 additions and 3 deletions

View File

@ -85,6 +85,23 @@ template<typename T, typename M> void Walk(std::list<T> &x, M &mutator) {
Walk(elem, 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> template<std::size_t I = 0, typename Func, typename T>
void ForEachInTuple(const T &tuple, Func func) { void ForEachInTuple(const T &tuple, Func func) {
if constexpr (I < std::tuple_size_v<T>) { if constexpr (I < std::tuple_size_v<T>) {

View File

@ -14,6 +14,8 @@
#include "canonicalize-do.h" #include "canonicalize-do.h"
#include "../parser/parse-tree-visitor.h" #include "../parser/parse-tree-visitor.h"
#include <variant>
#include <vector>
namespace Fortran::parser { namespace Fortran::parser {
@ -116,5 +118,4 @@ void CanonicalizeDo(Program &program) {
CanonicalizationOfDoLoops canonicalizationOfDoLoops{labelInfos}; CanonicalizationOfDoLoops canonicalizationOfDoLoops{labelInfos};
Walk(program, canonicalizationOfDoLoops); Walk(program, canonicalizationOfDoLoops);
} }
} // namespace Fortran::parser } // namespace Fortran::parser

View File

@ -12,6 +12,8 @@
! See the License for the specific language governing permissions and ! See the License for the specific language governing permissions and
! limitations under the License. ! limitations under the License.
! negative test -- invalid labels, out of range
! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s
! CHECK: end do ! CHECK: end do

View File

@ -12,6 +12,8 @@
! See the License for the specific language governing permissions and ! See the License for the specific language governing permissions and
! limitations under the License. ! limitations under the License.
! negative test -- invalid labels, out of range
! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s
! CHECK: end do ! CHECK: end do

View File

@ -12,6 +12,8 @@
! See the License for the specific language governing permissions and ! See the License for the specific language governing permissions and
! limitations under the License. ! limitations under the License.
! negative test -- invalid labels, out of range
! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s
! CHECK: 10 continue ! CHECK: 10 continue
! CHECK: end do ! CHECK: end do

View File

@ -23,14 +23,18 @@ program main
print *, j1, j2, j3 print *, j1, j2, j3
do 2 j4=1,2 do 2 j4=1,2
print *, j3, j4 print *, j3, j4
2 continue 2 end do
else else
do 3 j3=3,4 do 3 j3=3,4
print *, j1, j2, j3 print *, j1, j2, j3
do 3 j4=3,4 do 3 j4=3,4
print *, j3, j4 print *, j3, j4
3 continue 3 end do
end if end if
print *, j1, j2 print *, j1, j2
1 continue 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 end