summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2015-03-30 04:30:22 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2015-03-30 04:30:22 +0000
commitf268568447067410bb7c5e0b8674cd197325c179 (patch)
tree6dc83bfcea38baf41912ea760b068d31b52db900 /clang/lib/CodeGen
parente3526025175a69ef919934fd4a84dac524948f78 (diff)
downloadbcm5719-llvm-f268568447067410bb7c5e0b8674cd197325c179.tar.gz
bcm5719-llvm-f268568447067410bb7c5e0b8674cd197325c179.zip
[OPENMP] Improved codegen for implicit/explicit 'barrier' constructs.
Replace boolean IsExplicit parameter of OpenMPRuntime::emitBarrierCall() method by OpenMPDirectiveKind Kind for better compatibility with the runtime library. Also add processing of 'nowait' clause on worksharing directives. Differential Revision: http://reviews.llvm.org/D8659 llvm-svn: 233511
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntime.cpp22
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntime.h7
-rw-r--r--clang/lib/CodeGen/CGStmtOpenMP.cpp21
3 files changed, 33 insertions, 17 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ef2d2147aca..2dbaae5624c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -179,7 +179,7 @@ void CGOpenMPRegionInfo::EmitBody(CodeGenFunction &CGF, const Stmt *S) {
if (PrivateScope.Privatize())
// Emit implicit barrier to synchronize threads and avoid data races.
CGF.CGM.getOpenMPRuntime().emitBarrierCall(CGF, Directive.getLocStart(),
- /*IsExplicit=*/false);
+ OMPD_unknown);
CGCapturedStmtInfo::EmitBody(CGF, S);
}
@@ -1138,11 +1138,23 @@ void CGOpenMPRuntime::emitSingleRegion(CodeGenFunction &CGF,
}
void CGOpenMPRuntime::emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
- bool IsExplicit) {
+ OpenMPDirectiveKind Kind) {
// Build call __kmpc_cancel_barrier(loc, thread_id);
- auto Flags = static_cast<OpenMPLocationFlags>(
- OMP_IDENT_KMPC |
- (IsExplicit ? OMP_IDENT_BARRIER_EXPL : OMP_IDENT_BARRIER_IMPL));
+ OpenMPLocationFlags Flags = OMP_IDENT_KMPC;
+ if (Kind == OMPD_for) {
+ Flags =
+ static_cast<OpenMPLocationFlags>(Flags | OMP_IDENT_BARRIER_IMPL_FOR);
+ } else if (Kind == OMPD_sections) {
+ Flags = static_cast<OpenMPLocationFlags>(Flags |
+ OMP_IDENT_BARRIER_IMPL_SECTIONS);
+ } else if (Kind == OMPD_single) {
+ Flags =
+ static_cast<OpenMPLocationFlags>(Flags | OMP_IDENT_BARRIER_IMPL_SINGLE);
+ } else if (Kind == OMPD_barrier) {
+ Flags = static_cast<OpenMPLocationFlags>(Flags | OMP_IDENT_BARRIER_EXPL);
+ } else {
+ Flags = static_cast<OpenMPLocationFlags>(Flags | OMP_IDENT_BARRIER_IMPL);
+ }
// Build call __kmpc_cancel_barrier(loc, thread_id);
// Replace __kmpc_barrier() function by __kmpc_cancel_barrier() because this
// one provides the same functionality and adds initial support for
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h
index f8849e627c8..d32e2ab1732 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -358,11 +358,12 @@ public:
ArrayRef<const Expr *> DstExprs,
ArrayRef<const Expr *> AssignmentOps);
- /// \brief Emits explicit barrier for OpenMP threads.
- /// \param IsExplicit true, if it is explicitly specified barrier.
+ /// \brief Emit an implicit/explicit barrier for OpenMP threads.
+ /// \param Kind Directive for which this implicit barrier call must be
+ /// generated. Must be OMPD_barrier for explicit barrier generation.
///
virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
- bool IsExplicit = true);
+ OpenMPDirectiveKind Kind);
/// \brief Check if the specified \a ScheduleKind is static non-chunked.
/// This kind of worksharing directive is emitted without outer loop.
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 9af74749f17..f74e47a4ca5 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -785,8 +785,9 @@ void CodeGenFunction::EmitOMPForDirective(const OMPForDirective &S) {
EmitOMPWorksharingLoop(S);
// Emit an implicit barrier at the end.
- CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(),
- /*IsExplicit*/ false);
+ if (!S.getSingleClause(OMPC_nowait)) {
+ CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(), OMPD_for);
+ }
}
void CodeGenFunction::EmitOMPForSimdDirective(const OMPForSimdDirective &) {
@@ -886,9 +887,11 @@ void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
}
// Emit an implicit barrier at the end.
- if (!S.getSingleClause(OMPC_nowait))
- CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(),
- /*IsExplicit=*/false);
+ if (!S.getSingleClause(OMPC_nowait)) {
+ CGM.getOpenMPRuntime().emitBarrierCall(
+ *this, S.getLocStart(),
+ (CS && CS->size() > 1) ? OMPD_sections : OMPD_single);
+ }
}
void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &S) {
@@ -927,9 +930,9 @@ void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &S) {
EnsureInsertPoint();
}, S.getLocStart(), CopyprivateVars, SrcExprs, DstExprs, AssignmentOps);
// Emit an implicit barrier at the end.
- if (!S.getSingleClause(OMPC_nowait))
- CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(),
- /*IsExplicit=*/false);
+ if (!S.getSingleClause(OMPC_nowait)) {
+ CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(), OMPD_single);
+ }
}
void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
@@ -1001,7 +1004,7 @@ void CodeGenFunction::EmitOMPTaskyieldDirective(
}
void CodeGenFunction::EmitOMPBarrierDirective(const OMPBarrierDirective &S) {
- CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart());
+ CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(), OMPD_barrier);
}
void CodeGenFunction::EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &) {
OpenPOWER on IntegriCloud