[clang][OpenMP] Add codegen for scope directive (#109197)

Added codegen for scope directive, enabled allocate and firstprivate
clauses, and added scope directive LIT test.

Testing
  - LIT tests (including new scope test).
  - OpenMP scope example test from 5.2 OpenMP API examples document.
  - Three executable scope tests from OpenMP_VV/sollve_vv suite.
This commit is contained in:
David Pagan 2024-09-19 13:17:24 -07:00 committed by GitHub
parent 02d34d800b
commit d7c69c20a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 2297 additions and 9 deletions

View File

@ -420,7 +420,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
CGM.ErrorUnsupported(S, "OpenMP dispatch directive"); CGM.ErrorUnsupported(S, "OpenMP dispatch directive");
break; break;
case Stmt::OMPScopeDirectiveClass: case Stmt::OMPScopeDirectiveClass:
CGM.ErrorUnsupported(S, "scope with FE outlining"); EmitOMPScopeDirective(cast<OMPScopeDirective>(*S));
break; break;
case Stmt::OMPMaskedDirectiveClass: case Stmt::OMPMaskedDirectiveClass:
EmitOMPMaskedDirective(cast<OMPMaskedDirective>(*S)); EmitOMPMaskedDirective(cast<OMPMaskedDirective>(*S));

View File

@ -4223,6 +4223,32 @@ void CodeGenFunction::EmitSections(const OMPExecutableDirective &S) {
} }
} }
void CodeGenFunction::EmitOMPScopeDirective(const OMPScopeDirective &S) {
{
// Emit code for 'scope' region
auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
Action.Enter(CGF);
OMPPrivateScope PrivateScope(CGF);
(void)CGF.EmitOMPFirstprivateClause(S, PrivateScope);
CGF.EmitOMPPrivateClause(S, PrivateScope);
CGF.EmitOMPReductionClauseInit(S, PrivateScope);
(void)PrivateScope.Privatize();
CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt());
CGF.EmitOMPReductionClauseFinal(S, /*ReductionKind=*/OMPD_parallel);
};
auto LPCRegion =
CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
OMPLexicalScope Scope(*this, S, OMPD_unknown);
CGM.getOpenMPRuntime().emitInlinedDirective(*this, OMPD_scope, CodeGen);
}
// Emit an implicit barrier at the end.
if (!S.getSingleClause<OMPNowaitClause>()) {
CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getBeginLoc(), OMPD_scope);
}
// Check for outer lastprivate conditional update.
checkForLastprivateConditionalUpdate(*this, S);
}
void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) { void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
if (CGM.getLangOpts().OpenMPIRBuilder) { if (CGM.getLangOpts().OpenMPIRBuilder) {
llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder(); llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();

View File

@ -3823,6 +3823,7 @@ public:
void EmitOMPInterchangeDirective(const OMPInterchangeDirective &S); void EmitOMPInterchangeDirective(const OMPInterchangeDirective &S);
void EmitOMPForDirective(const OMPForDirective &S); void EmitOMPForDirective(const OMPForDirective &S);
void EmitOMPForSimdDirective(const OMPForSimdDirective &S); void EmitOMPForSimdDirective(const OMPForSimdDirective &S);
void EmitOMPScopeDirective(const OMPScopeDirective &S);
void EmitOMPSectionsDirective(const OMPSectionsDirective &S); void EmitOMPSectionsDirective(const OMPSectionsDirective &S);
void EmitOMPSectionDirective(const OMPSectionDirective &S); void EmitOMPSectionDirective(const OMPSectionDirective &S);
void EmitOMPSingleDirective(const OMPSingleDirective &S); void EmitOMPSingleDirective(const OMPSingleDirective &S);

View File

@ -1,8 +0,0 @@
// RUN: %clang_cc1 -emit-llvm-only -verify -fopenmp %s
int main () {
int r = 0;
#pragma omp scope reduction(+:r) // expected-error {{cannot compile this scope with FE outlining yet}}
r++;
return r;
}

File diff suppressed because it is too large Load Diff

View File

@ -887,6 +887,8 @@ def OMP_scope : Directive<"scope"> {
let allowedClauses = [ let allowedClauses = [
VersionedClause<OMPC_Private, 51>, VersionedClause<OMPC_Private, 51>,
VersionedClause<OMPC_Reduction, 51>, VersionedClause<OMPC_Reduction, 51>,
VersionedClause<OMPC_FirstPrivate, 52>,
VersionedClause<OMPC_Allocate, 52>,
]; ];
let allowedOnceClauses = [ let allowedOnceClauses = [
VersionedClause<OMPC_NoWait, 51>, VersionedClause<OMPC_NoWait, 51>,