[clang][OpenMP] Add codegen for scope directive by ddpagan · Pull Request #109197 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-flang-openmp
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: David Pagan (ddpagan)

Changes

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

Testing


Patch is 160.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/109197.diff

6 Files Affected:

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index b138c87a853495..27cf3de531d8a4 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -420,7 +420,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) { CGM.ErrorUnsupported(S, "OpenMP dispatch directive"); break; case Stmt::OMPScopeDirectiveClass: - CGM.ErrorUnsupported(S, "scope with FE outlining"); + EmitOMPScopeDirective(cast(*S)); break; case Stmt::OMPMaskedDirectiveClass: EmitOMPMaskedDirective(cast(*S)); diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 8afe2abf2cc494..b11df8334766a8 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -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()) { + CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getBeginLoc(), OMPD_scope); + } + // Check for outer lastprivate conditional update. + checkForLastprivateConditionalUpdate(*this, S); +} + void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) { if (CGM.getLangOpts().OpenMPIRBuilder) { llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder(); diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 6802dc7f0c1598..2df17e83bae2ee 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3823,6 +3823,7 @@ class CodeGenFunction : public CodeGenTypeCache { void EmitOMPInterchangeDirective(const OMPInterchangeDirective &S); void EmitOMPForDirective(const OMPForDirective &S); void EmitOMPForSimdDirective(const OMPForSimdDirective &S); + void EmitOMPScopeDirective(const OMPScopeDirective &S); void EmitOMPSectionsDirective(const OMPSectionsDirective &S); void EmitOMPSectionDirective(const OMPSectionDirective &S); void EmitOMPSingleDirective(const OMPSingleDirective &S); diff --git a/clang/test/OpenMP/error_unsupport_feature.c b/clang/test/OpenMP/error_unsupport_feature.c deleted file mode 100644 index eb381b3bea1e1a..00000000000000 --- a/clang/test/OpenMP/error_unsupport_feature.c +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %clang_cc1 -emit-llvm-only -verify -fopenmp %s

-int main () {

+#ifndef HEADER +#define HEADER + +class TestClass { +public:

+#pragma omp parallel num_threads(b) +#pragma omp scope firstprivate(a, this->b, (this)->c) reduction(+:e)

+#pragma omp parallel firstprivate(a) +#pragma omp scope private((this)->a) allocate(omp_cgroup_mem_alloc:a)

+#pragma omp scope