diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index c7012631989..b88452944c7 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -1164,6 +1164,16 @@ static OpenMPDirectiveKind emitSections(CodeGenFunction &CGF, } CGF.EmitBlock(ExitBB, /*IsFinished=*/true); }; + + CodeGenFunction::OMPPrivateScope LoopScope(CGF); + if (CGF.EmitOMPFirstprivateClause(S, LoopScope)) { + // Emit implicit barrier to synchronize threads and avoid data races on + // initialization of firstprivate variables. + CGF.CGM.getOpenMPRuntime().emitBarrierCall(CGF, S.getLocStart(), + OMPD_unknown); + } + (void)LoopScope.Privatize(); + // Emit static non-chunked loop. CGF.CGM.getOpenMPRuntime().emitForInit( CGF, S.getLocStart(), OMPC_SCHEDULE_static, /*IVSize=*/32, @@ -1188,13 +1198,27 @@ static OpenMPDirectiveKind emitSections(CodeGenFunction &CGF, } // If only one section is found - no need to generate loop, emit as a single // region. - auto &&CodeGen = [Stmt](CodeGenFunction &CGF) { + bool HasFirstprivates; + auto &&CodeGen = [Stmt, &S, &HasFirstprivates](CodeGenFunction &CGF) { + CodeGenFunction::OMPPrivateScope SingleScope(CGF); + HasFirstprivates = CGF.EmitOMPFirstprivateClause(S, SingleScope); + (void)SingleScope.Privatize(); + CGF.EmitStmt(Stmt); CGF.EnsureInsertPoint(); }; CGF.CGM.getOpenMPRuntime().emitSingleRegion(CGF, CodeGen, S.getLocStart(), llvm::None, llvm::None, llvm::None, llvm::None); + // Emit barrier for firstprivates only if 'sections' directive has 'nowait' + // clause. Otherwise the barrier will be generated by the codegen for the + // directive. + if (HasFirstprivates && S.getSingleClause(OMPC_nowait)) { + // Emit implicit barrier to synchronize threads and avoid data races on + // initialization of firstprivate variables. + CGF.CGM.getOpenMPRuntime().emitBarrierCall(CGF, S.getLocStart(), + OMPD_unknown); + } return OMPD_single; } |