Skip to content
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

[flang][openacc] Correctly lower acc routine in interface block #71451

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3201,8 +3201,21 @@ void Fortran::lower::genOpenACCRoutineConstruct(
funcName = converter.mangleName(*name->symbol);
funcOp = builder.getNamedFunction(mod, funcName);
} else {
funcOp = builder.getFunction();
funcName = funcOp.getName();
Fortran::semantics::Scope &scope =
semanticsContext.FindScope(routineConstruct.source);
const Fortran::semantics::Scope &progUnit{GetProgramUnitContaining(scope)};
const auto *subpDetails{
progUnit.symbol()
? progUnit.symbol()
->detailsIf<Fortran::semantics::SubprogramDetails>()
: nullptr};
if (subpDetails && subpDetails->isInterface()) {
funcName = converter.mangleName(*progUnit.symbol());
funcOp = builder.getNamedFunction(mod, funcName);
} else {
funcOp = builder.getFunction();
funcName = funcOp.getName();
}
}
bool hasSeq = false, hasGang = false, hasWorker = false, hasVector = false,
hasNohost = false;
Expand Down
36 changes: 36 additions & 0 deletions flang/test/Lower/OpenACC/acc-routine03.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
! This test checks lowering of OpenACC routine directive in interfaces.

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s


subroutine sub1(a)
!$acc routine worker bind(sub2)
real :: a(:)
end subroutine

subroutine sub2(a)
!$acc routine worker nohost
real :: a(:)
end subroutine

subroutine test

interface
subroutine sub1(a)
!$acc routine worker bind(sub2)
real :: a(:)
end subroutine

subroutine sub2(a)
!$acc routine worker nohost
real :: a(:)
end subroutine
end interface

end subroutine

! CHECK: acc.routine @acc_routine_1 func(@_QPsub2) worker nohost
! CHECK: acc.routine @acc_routine_0 func(@_QPsub1) bind("_QPsub2") worker
! CHECK: func.func @_QPsub1(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a"}) attributes {acc.routine_info = #acc.routine_info<[@acc_routine_0]>}
! CHECK: func.func @_QPsub2(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a"}) attributes {acc.routine_info = #acc.routine_info<[@acc_routine_1]>}