Skip to content

[flang][openacc] Accept scalar integer expression in the if clause #69381

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
Oct 17, 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
2 changes: 2 additions & 0 deletions flang/docs/OpenACC.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ local:
* `!$acc end loop` does not trigger a parsing error and is just ignored.
* The restriction on `!$acc data` required clauses is emitted as a portability
warning instead of an error as other compiler accepts it.
* The `if` clause accepts scalar integer expression in addition to scalar
logical expression.
15 changes: 14 additions & 1 deletion flang/lib/Semantics/check-acc-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ CHECK_SIMPLE_CLAUSE(DeviceNum, ACCC_device_num)
CHECK_SIMPLE_CLAUSE(Finalize, ACCC_finalize)
CHECK_SIMPLE_CLAUSE(Firstprivate, ACCC_firstprivate)
CHECK_SIMPLE_CLAUSE(Host, ACCC_host)
CHECK_SIMPLE_CLAUSE(If, ACCC_if)
CHECK_SIMPLE_CLAUSE(IfPresent, ACCC_if_present)
CHECK_SIMPLE_CLAUSE(Independent, ACCC_independent)
CHECK_SIMPLE_CLAUSE(NoCreate, ACCC_no_create)
Expand Down Expand Up @@ -660,6 +659,20 @@ void AccStructureChecker::Enter(const parser::AccClause::Link &x) {
CheckMultipleOccurrenceInDeclare(x.v, llvm::acc::Clause::ACCC_link);
}

void AccStructureChecker::Enter(const parser::AccClause::If &x) {
CheckAllowed(llvm::acc::Clause::ACCC_if);
if (const auto *expr{GetExpr(x.v)}) {
if (auto type{expr->GetType()}) {
if (type->category() == TypeCategory::Integer ||
type->category() == TypeCategory::Logical) {
return; // LOGICAL and INTEGER type supported for the if clause.
}
}
}
context_.Say(
GetContext().clauseSource, "Must have LOGICAL or INTEGER type"_err_en_US);
}

void AccStructureChecker::Enter(const parser::Module &) {
declareSymbols.clear();
}
Expand Down
6 changes: 6 additions & 0 deletions flang/test/Lower/OpenACC/acc-init.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

subroutine acc_init
logical :: ifCondition = .TRUE.
integer :: ifInt = 1

!$acc init
!CHECK: acc.init{{ *}}{{$}}
Expand All @@ -28,4 +29,9 @@ subroutine acc_init
!CHECK: [[DEVTYPE2:%.*]] = arith.constant 2 : i32
!CHECK: acc.init device_type([[DEVTYPE1]], [[DEVTYPE2]] : i32, i32) device_num([[DEVNUM]] : i32){{$}}

!$acc init if(ifInt)
!CHECK: %[[IFINT:.*]] = fir.load %{{.*}} : !fir.ref<i32>
!CHECK: %[[CONV:.*]] = fir.convert %[[IFINT]] : (i32) -> i1
!CHECK: acc.init if(%[[CONV]])

end subroutine acc_init
6 changes: 6 additions & 0 deletions flang/test/Semantics/OpenACC/acc-init-validity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ program openacc_init_validity
integer :: i, j
integer, parameter :: N = 256
logical :: ifCondition = .TRUE.
integer :: ifInt
real :: ifReal
real(8), dimension(N) :: a

!$acc init
!$acc init if(.TRUE.)
!$acc init if(ifCondition)
!$acc init if(ifInt)
!$acc init device_num(1)
!$acc init device_num(i)
!$acc init device_type(i)
Expand Down Expand Up @@ -93,4 +96,7 @@ program openacc_init_validity
!ERROR: At most one DEVICE_TYPE clause can appear on the INIT directive
!$acc init device_type(2) device_type(i, j)

!ERROR: Must have LOGICAL or INTEGER type
!$acc init if(ifReal)

end program openacc_init_validity
2 changes: 1 addition & 1 deletion llvm/include/llvm/Frontend/OpenACC/ACC.td
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def ACCC_Host : Clause<"host"> {

// 2.5.6
def ACCC_If : Clause <"if"> {
let flangClass = "ScalarLogicalExpr";
let flangClass = "ScalarExpr";
}

// 2.14.4
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ static void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
.Case("Name", "name")
.Case("ScalarIntConstantExpr", "scalarIntConstantExpr")
.Case("ScalarIntExpr", "scalarIntExpr")
.Case("ScalarExpr", "scalarExpr")
.Case("ScalarLogicalExpr", "scalarLogicalExpr")
.Default(("Parser<" + Clause.getFlangClass() + ">{}")
.toStringRef(Scratch));
Expand Down