[flang][openacc] Relax required clauses on acc data as portability warning

Some compilers accept `!$acc data` without any clauses. For portability
reason, this patch relaxes the strict error to a simple portability warning.

Reviewed By: razvanlupusoru, vzakhari

Differential Revision: https://reviews.llvm.org/D159019
This commit is contained in:
Valentin Clement 2023-08-29 13:33:38 -07:00
parent 031b4e5e79
commit e8824e05e3
No known key found for this signature in database
GPG Key ID: 086D54783C928776
6 changed files with 25 additions and 9 deletions

View File

@ -18,3 +18,5 @@
* An `!$acc routine` with no parallelism clause is treated as if the `seq`
clause was present.
* `!$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.

View File

@ -1937,6 +1937,9 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
addOperands(operands, operandSegments, waitOperands);
addOperands(operands, operandSegments, dataClauseOperands);
if (dataClauseOperands.empty() && !hasDefaultNone && !hasDefaultPresent)
return;
auto dataOp = createRegionOp<mlir::acc::DataOp, mlir::acc::TerminatorOp>(
builder, currentLocation, operands, operandSegments);

View File

@ -147,8 +147,9 @@ void AccStructureChecker::Leave(const parser::OpenACCBlockConstruct &x) {
CheckNoBranching(block, GetContext().directive, blockDir.source);
break;
case llvm::acc::Directive::ACCD_data:
// Restriction - line 1249-1250
CheckRequireAtLeastOneOf();
// Restriction - 2.6.5 pt 1
// Only a warning is emitted here for portability reason.
CheckRequireAtLeastOneOf(/*warnInsteadOfError=*/true);
// Restriction is not formally in the specification but all compilers emit
// an error and it is likely to be omitted from the spec.
CheckNoBranching(block, GetContext().directive, blockDir.source);

View File

@ -331,7 +331,7 @@ protected:
// Check that only clauses in set are after the specific clauses.
void CheckOnlyAllowedAfter(C clause, common::EnumSet<C, ClauseEnumSize> set);
void CheckRequireAtLeastOneOf();
void CheckRequireAtLeastOneOf(bool warnInsteadOfError = false);
void CheckAllowed(C clause);
@ -422,7 +422,7 @@ DirectiveStructureChecker<D, C, PC, ClauseEnumSize>::ClauseSetToString(
// directive.
template <typename D, typename C, typename PC, std::size_t ClauseEnumSize>
void DirectiveStructureChecker<D, C, PC,
ClauseEnumSize>::CheckRequireAtLeastOneOf() {
ClauseEnumSize>::CheckRequireAtLeastOneOf(bool warnInsteadOfError) {
if (GetContext().requiredClauses.empty())
return;
for (auto cl : GetContext().actualClauses) {
@ -430,10 +430,16 @@ void DirectiveStructureChecker<D, C, PC,
return;
}
// No clause matched in the actual clauses list
context_.Say(GetContext().directiveSource,
"At least one of %s clause must appear on the %s directive"_err_en_US,
ClauseSetToString(GetContext().requiredClauses),
ContextDirectiveAsFortran());
if (warnInsteadOfError)
context_.Say(GetContext().directiveSource,
"At least one of %s clause should appear on the %s directive"_port_en_US,
ClauseSetToString(GetContext().requiredClauses),
ContextDirectiveAsFortran());
else
context_.Say(GetContext().directiveSource,
"At least one of %s clause must appear on the %s directive"_err_en_US,
ClauseSetToString(GetContext().requiredClauses),
ContextDirectiveAsFortran());
}
template <typename D, typename C, typename PC, std::size_t ClauseEnumSize>

View File

@ -188,5 +188,9 @@ subroutine acc_data
! CHECK: acc.terminator
! CHECK: } attributes {defaultAttr = #acc<defaultvalue present>}
!$acc data
!$acc end data
! CHECK-NOT: acc.data
end subroutine acc_data

View File

@ -132,7 +132,7 @@ program openacc_data_validity
!ERROR: At least one of COPYOUT, DELETE, DETACH clause must appear on the EXIT DATA directive
!$acc exit data
!ERROR: At least one of ATTACH, COPY, COPYIN, COPYOUT, CREATE, DEFAULT, DEVICEPTR, NO_CREATE, PRESENT clause must appear on the DATA directive
!PORTABILITY: At least one of ATTACH, COPY, COPYIN, COPYOUT, CREATE, DEFAULT, DEVICEPTR, NO_CREATE, PRESENT clause should appear on the DATA directive
!$acc data
!$acc end data