Skip to content

[flang][openacc] Keep CYCLE check for compute and data construct #73897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

clementval
Copy link
Contributor

Unlike mentioned in #73839, some OpenACC construct still need the cycle branching check to be performed. This patch adds a list of construct where the check is not needed (loop and combined construct) and add tests to check where it is still needed.

@llvmbot
Copy link
Member

llvmbot commented Nov 30, 2023

@llvm/pr-subscribers-openacc

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Unlike mentioned in #73839, some OpenACC construct still need the cycle branching check to be performed. This patch adds a list of construct where the check is not needed (loop and combined construct) and add tests to check where it is still needed.


Full diff: https://github.com/llvm/llvm-project/pull/73897.diff

5 Files Affected:

  • (modified) flang/lib/Semantics/check-directive-structure.h (+11-1)
  • (modified) flang/test/Semantics/OpenACC/acc-data.f90 (+13)
  • (modified) flang/test/Semantics/OpenACC/acc-kernels.f90 (+13)
  • (modified) flang/test/Semantics/OpenACC/acc-parallel.f90 (+13)
  • (modified) flang/test/Semantics/OpenACC/acc-serial.f90 (+13)
diff --git a/flang/lib/Semantics/check-directive-structure.h b/flang/lib/Semantics/check-directive-structure.h
index 7965fb595ff1bab..84240b87f47ec4b 100644
--- a/flang/lib/Semantics/check-directive-structure.h
+++ b/flang/lib/Semantics/check-directive-structure.h
@@ -79,7 +79,17 @@ template <typename D> class NoBranchingEnforce {
           break;
         }
       } else if constexpr (std::is_same_v<D, llvm::acc::Directive>) {
-        return; // OpenACC construct do not need check for unlabelled CYCLES
+        switch ((llvm::acc::Directive)currentDirective_) {
+        // exclude loop directives which do not need a check for unlabelled
+        // CYCLES
+        case llvm::acc::Directive::ACCD_loop:
+        case llvm::acc::Directive::ACCD_kernels_loop:
+        case llvm::acc::Directive::ACCD_parallel_loop:
+        case llvm::acc::Directive::ACCD_serial_loop:
+          return;
+        default:
+          break;
+        }
       }
       CheckConstructNameBranching("CYCLE");
     }
diff --git a/flang/test/Semantics/OpenACC/acc-data.f90 b/flang/test/Semantics/OpenACC/acc-data.f90
index 8d801ebb30f4eca..84eb72825b34cd3 100644
--- a/flang/test/Semantics/OpenACC/acc-data.f90
+++ b/flang/test/Semantics/OpenACC/acc-data.f90
@@ -187,6 +187,19 @@ program openacc_data_validity
   !$acc data copy(aa) device_type(default) wait
   !$acc end data
 
+  do i = 1, 100
+    !$acc data copy(aa)
+    !ERROR: CYCLE to construct outside of DATA construct is not allowed
+    if (i == 10) cycle
+    !$acc end data
+  end do
+
+  !$acc data copy(aa)
+  do i = 1, 100
+    if (i == 10) cycle
+  end do
+  !$acc end data
+
 end program openacc_data_validity
 
 module mod1
diff --git a/flang/test/Semantics/OpenACC/acc-kernels.f90 b/flang/test/Semantics/OpenACC/acc-kernels.f90
index de220f7c7ddf7cf..8a209040a779361 100644
--- a/flang/test/Semantics/OpenACC/acc-kernels.f90
+++ b/flang/test/Semantics/OpenACC/acc-kernels.f90
@@ -144,4 +144,17 @@ program openacc_kernels_validity
   end do
   !$acc end kernels
 
+  do i = 1, 100
+    !$acc kernels
+    !ERROR: CYCLE to construct outside of KERNELS construct is not allowed
+    if (i == 10) cycle
+    !$acc end kernels
+  end do
+
+  !$acc kernels
+  do i = 1, 100
+    if (i == 10) cycle
+  end do
+  !$acc end kernels
+
 end program openacc_kernels_validity
diff --git a/flang/test/Semantics/OpenACC/acc-parallel.f90 b/flang/test/Semantics/OpenACC/acc-parallel.f90
index 0e8d240d019983f..c87d321593ddf3d 100644
--- a/flang/test/Semantics/OpenACC/acc-parallel.f90
+++ b/flang/test/Semantics/OpenACC/acc-parallel.f90
@@ -142,4 +142,17 @@ program openacc_parallel_validity
   end do
   !$acc end parallel
 
+  do i = 1, 100
+    !$acc parallel
+    !ERROR: CYCLE to construct outside of PARALLEL construct is not allowed
+    if (i == 10) cycle
+    !$acc end parallel
+  end do
+
+  !$acc parallel
+  do i = 1, 100
+    if (i == 10) cycle
+  end do
+  !$acc end parallel
+
 end program openacc_parallel_validity
diff --git a/flang/test/Semantics/OpenACC/acc-serial.f90 b/flang/test/Semantics/OpenACC/acc-serial.f90
index db4cd7689435c7f..a23daecce8dd350 100644
--- a/flang/test/Semantics/OpenACC/acc-serial.f90
+++ b/flang/test/Semantics/OpenACC/acc-serial.f90
@@ -166,4 +166,17 @@ program openacc_serial_validity
   end do
   !$acc end serial
 
+  do i = 1, 100
+    !$acc serial
+    !ERROR: CYCLE to construct outside of SERIAL construct is not allowed
+    if (i == 10) cycle
+    !$acc end serial
+  end do
+
+  !$acc serial
+  do i = 1, 100
+    if (i == 10) cycle
+  end do
+  !$acc end serial
+
 end program openacc_serial_validity

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@clementval clementval merged commit a6c02ed into llvm:main Nov 30, 2023
@clementval clementval deleted the acc_cycle_branching_compute branch January 18, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category openacc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants