diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2015-06-17 06:21:39 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2015-06-17 06:21:39 +0000 |
commit | 89e7e8eb0e18316647ccf1953154ffa29f97f545 (patch) | |
tree | bbeab00b38fc00db40c15d4d31426f89893c49aa /clang/lib/CodeGen | |
parent | 8321006d44c351e4cd4d1383de7e9d11764da56e (diff) | |
download | bcm5719-llvm-89e7e8eb0e18316647ccf1953154ffa29f97f545.tar.gz bcm5719-llvm-89e7e8eb0e18316647ccf1953154ffa29f97f545.zip |
[OPENMP] Supported reduction clause in omp simd construct.
The following code is generated for reduction clause within 'omp simd' loop construct:
#pragma omp simd reduction(op:var)
for (...)
<body>
alloca priv_var
priv_var = <initial reduction value>;
<loop_start>:
<body> // references to original 'var' are replaced by 'priv_var'
<loop_end>:
var op= priv_var;
llvm-svn: 239881
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 15 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.h | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 6 |
3 files changed, 20 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 1238accf42d..269799dffc1 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -2242,7 +2242,7 @@ void CGOpenMPRuntime::emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef<const Expr *> LHSExprs, ArrayRef<const Expr *> RHSExprs, ArrayRef<const Expr *> ReductionOps, - bool WithNowait) { + bool WithNowait, bool SimpleReduction) { // Next code should be emitted for reduction: // // static kmp_critical_name lock = { 0 }; @@ -2272,9 +2272,22 @@ void CGOpenMPRuntime::emitReduction(CodeGenFunction &CGF, SourceLocation Loc, // break; // default:; // } + // + // if SimpleReduction is true, only the next code is generated: + // ... + // <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); + // ... auto &C = CGM.getContext(); + if (SimpleReduction) { + CodeGenFunction::RunCleanupsScope Scope(CGF); + for (auto *E : ReductionOps) { + CGF.EmitIgnoredExpr(E); + } + return; + } + // 1. Build a list of reduction variables. // void *RedList[<n>] = {<ReductionVars>[0], ..., <ReductionVars>[<n>-1]}; llvm::APInt ArraySize(/*unsigned int numBits=*/32, RHSExprs.size()); diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h index f5aa4a51df9..4db3db4ae9d 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.h +++ b/clang/lib/CodeGen/CGOpenMPRuntime.h @@ -632,7 +632,7 @@ public: ArrayRef<const Expr *> LHSExprs, ArrayRef<const Expr *> RHSExprs, ArrayRef<const Expr *> ReductionOps, - bool WithNowait); + bool WithNowait, bool SimpleReduction); /// \brief Emit code for 'taskwait' directive. virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc); diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 907fe93efc4..ed960fa858d 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -443,7 +443,9 @@ void CodeGenFunction::EmitOMPReductionClauseFinal( CGM.getOpenMPRuntime().emitReduction( *this, D.getLocEnd(), LHSExprs, RHSExprs, ReductionOps, D.getSingleClause(OMPC_nowait) || - isOpenMPParallelDirective(D.getDirectiveKind())); + isOpenMPParallelDirective(D.getDirectiveKind()) || + D.getDirectiveKind() == OMPD_simd, + D.getDirectiveKind() == OMPD_simd); } } @@ -807,6 +809,7 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) { EmitPrivateLoopCounters(CGF, LoopScope, S.counters()); EmitPrivateLinearVars(CGF, S, LoopScope); CGF.EmitOMPPrivateClause(S, LoopScope); + CGF.EmitOMPReductionClauseInit(S, LoopScope); HasLastprivateClause = CGF.EmitOMPLastprivateClauseInit(S, LoopScope); (void)LoopScope.Privatize(); CGF.EmitOMPInnerLoop(S, LoopScope.requiresCleanups(), @@ -820,6 +823,7 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) { if (HasLastprivateClause) { CGF.EmitOMPLastprivateClauseFinal(S); } + CGF.EmitOMPReductionClauseFinal(S); } CGF.EmitOMPSimdFinal(S); // Emit: if (PreCond) - end. |