Skip to content

Conversation

clementval
Copy link
Contributor

Allow position of the acc routine in the implicit part.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir openacc flang:parser labels Nov 6, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-openacc

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

Changes

Allow position of the acc routine in the implicit part.


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

3 Files Affected:

  • (modified) flang/include/flang/Parser/parse-tree.h (+2-1)
  • (modified) flang/lib/Parser/Fortran-parsers.cpp (+2-1)
  • (added) flang/test/Lower/OpenACC/acc-routine04.f90 (+34)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 4806fc49f3441de..393e0e24ec5cbd9 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -413,7 +413,8 @@ struct ImplicitPartStmt {
       Statement<common::Indirection<OldParameterStmt>>,
       Statement<common::Indirection<FormatStmt>>,
       Statement<common::Indirection<EntryStmt>>,
-      common::Indirection<CompilerDirective>>
+      common::Indirection<CompilerDirective>,
+      common::Indirection<OpenACCDeclarativeConstruct>>
       u;
 };
 
diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index d7e01c924c6b32c..c070bc1de37352f 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -114,7 +114,8 @@ TYPE_PARSER(first(
     construct<ImplicitPartStmt>(statement(indirect(oldParameterStmt))),
     construct<ImplicitPartStmt>(statement(indirect(formatStmt))),
     construct<ImplicitPartStmt>(statement(indirect(entryStmt))),
-    construct<ImplicitPartStmt>(indirect(compilerDirective))))
+    construct<ImplicitPartStmt>(indirect(compilerDirective)),
+    construct<ImplicitPartStmt>(indirect(openaccDeclarativeConstruct))))
 
 // R512 internal-subprogram -> function-subprogram | subroutine-subprogram
 // Internal subprograms are not program units, so their END statements
diff --git a/flang/test/Lower/OpenACC/acc-routine04.f90 b/flang/test/Lower/OpenACC/acc-routine04.f90
new file mode 100644
index 000000000000000..f7b1d50af2bda30
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-routine04.f90
@@ -0,0 +1,34 @@
+! This test checks correct lowering when OpenACC routine directive is placed
+! before implicit none.
+
+! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+module dummy_mod
+contains
+
+  subroutine sub1(i)
+    !$acc routine seq
+    integer :: i
+  end subroutine
+end module
+
+program test_acc_routine
+  use dummy_mod
+  
+  !$acc routine(sub2) seq
+  
+  implicit none
+  
+  integer :: i
+
+contains
+  subroutine sub2()
+  end subroutine
+  
+end program
+
+! CHECK: acc.routine @acc_routine_1 func(@_QFPsub2) seq
+! CHECK: acc.routine @acc_routine_0 func(@_QMdummy_modPsub1) seq
+! CHECK: func.func @_QMdummy_modPsub1(%arg0: !fir.ref<i32> {fir.bindc_name = "i"}) attributes {acc.routine_info = #acc.routine_info<[@acc_routine_0]>}
+! CHECK: func.func @_QQmain() attributes {fir.bindc_name = "test_acc_routine"}

@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-flang-parser

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

Changes

Allow position of the acc routine in the implicit part.


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

3 Files Affected:

  • (modified) flang/include/flang/Parser/parse-tree.h (+2-1)
  • (modified) flang/lib/Parser/Fortran-parsers.cpp (+2-1)
  • (added) flang/test/Lower/OpenACC/acc-routine04.f90 (+34)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 4806fc49f3441de..393e0e24ec5cbd9 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -413,7 +413,8 @@ struct ImplicitPartStmt {
       Statement<common::Indirection<OldParameterStmt>>,
       Statement<common::Indirection<FormatStmt>>,
       Statement<common::Indirection<EntryStmt>>,
-      common::Indirection<CompilerDirective>>
+      common::Indirection<CompilerDirective>,
+      common::Indirection<OpenACCDeclarativeConstruct>>
       u;
 };
 
diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index d7e01c924c6b32c..c070bc1de37352f 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -114,7 +114,8 @@ TYPE_PARSER(first(
     construct<ImplicitPartStmt>(statement(indirect(oldParameterStmt))),
     construct<ImplicitPartStmt>(statement(indirect(formatStmt))),
     construct<ImplicitPartStmt>(statement(indirect(entryStmt))),
-    construct<ImplicitPartStmt>(indirect(compilerDirective))))
+    construct<ImplicitPartStmt>(indirect(compilerDirective)),
+    construct<ImplicitPartStmt>(indirect(openaccDeclarativeConstruct))))
 
 // R512 internal-subprogram -> function-subprogram | subroutine-subprogram
 // Internal subprograms are not program units, so their END statements
diff --git a/flang/test/Lower/OpenACC/acc-routine04.f90 b/flang/test/Lower/OpenACC/acc-routine04.f90
new file mode 100644
index 000000000000000..f7b1d50af2bda30
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-routine04.f90
@@ -0,0 +1,34 @@
+! This test checks correct lowering when OpenACC routine directive is placed
+! before implicit none.
+
+! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+module dummy_mod
+contains
+
+  subroutine sub1(i)
+    !$acc routine seq
+    integer :: i
+  end subroutine
+end module
+
+program test_acc_routine
+  use dummy_mod
+  
+  !$acc routine(sub2) seq
+  
+  implicit none
+  
+  integer :: i
+
+contains
+  subroutine sub2()
+  end subroutine
+  
+end program
+
+! CHECK: acc.routine @acc_routine_1 func(@_QFPsub2) seq
+! CHECK: acc.routine @acc_routine_0 func(@_QMdummy_modPsub1) seq
+! CHECK: func.func @_QMdummy_modPsub1(%arg0: !fir.ref<i32> {fir.bindc_name = "i"}) attributes {acc.routine_info = #acc.routine_info<[@acc_routine_0]>}
+! CHECK: func.func @_QQmain() attributes {fir.bindc_name = "test_acc_routine"}

! CHECK: acc.routine @acc_routine_1 func(@_QFPsub2) seq
! CHECK: acc.routine @acc_routine_0 func(@_QMdummy_modPsub1) seq
! CHECK: func.func @_QMdummy_modPsub1(%arg0: !fir.ref<i32> {fir.bindc_name = "i"}) attributes {acc.routine_info = #acc.routine_info<[@acc_routine_0]>}
! CHECK: func.func @_QQmain() attributes {fir.bindc_name = "test_acc_routine"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a check that sub2 has acc_routine_1 attached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I'll add it.

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.

Thanks!

@clementval clementval merged commit ba2f40a into llvm:main Nov 7, 2023
@clementval clementval deleted the acc_routine_placement branch November 7, 2023 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:parser 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