From 8298d64d4ab1a1b3853a6545d03c263900ca22f1 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Mon, 6 Nov 2023 15:27:56 -0800 Subject: [PATCH 1/2] [flang][openacc] Allow acc routine before implicit part --- flang/include/flang/Parser/parse-tree.h | 3 +- flang/lib/Parser/Fortran-parsers.cpp | 3 +- flang/test/Lower/OpenACC/acc-routine04.f90 | 34 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 flang/test/Lower/OpenACC/acc-routine04.f90 diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 4806fc49f3441..393e0e24ec5cb 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -413,7 +413,8 @@ struct ImplicitPartStmt { Statement>, Statement>, Statement>, - common::Indirection> + common::Indirection, + common::Indirection> u; }; diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp index d7e01c924c6b3..c070bc1de3735 100644 --- a/flang/lib/Parser/Fortran-parsers.cpp +++ b/flang/lib/Parser/Fortran-parsers.cpp @@ -114,7 +114,8 @@ TYPE_PARSER(first( construct(statement(indirect(oldParameterStmt))), construct(statement(indirect(formatStmt))), construct(statement(indirect(entryStmt))), - construct(indirect(compilerDirective)))) + construct(indirect(compilerDirective)), + construct(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 0000000000000..f7b1d50af2bda --- /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 {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"} From ce38b2c5d09ec5dc4ebc487750634a1c7ef78a17 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Mon, 6 Nov 2023 16:13:02 -0800 Subject: [PATCH 2/2] Add check line for sub2 --- flang/test/Lower/OpenACC/acc-routine04.f90 | 1 + 1 file changed, 1 insertion(+) diff --git a/flang/test/Lower/OpenACC/acc-routine04.f90 b/flang/test/Lower/OpenACC/acc-routine04.f90 index f7b1d50af2bda..a2987a3598e79 100644 --- a/flang/test/Lower/OpenACC/acc-routine04.f90 +++ b/flang/test/Lower/OpenACC/acc-routine04.f90 @@ -32,3 +32,4 @@ subroutine sub2() ! CHECK: acc.routine @acc_routine_0 func(@_QMdummy_modPsub1) seq ! CHECK: func.func @_QMdummy_modPsub1(%arg0: !fir.ref {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: func.func @_QFPsub2() attributes {acc.routine_info = #acc.routine_info<[@acc_routine_1]>}