diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2015-05-07 03:54:03 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2015-05-07 03:54:03 +0000 |
commit | 69a4779965a47ca7ce767a2c28fd8ffc041df77c (patch) | |
tree | d74ed279af56fec28db57f8d51ac2caa1fba0741 /clang/lib | |
parent | 28b8ea1d551dea33232359329a63fd8d8b3e410d (diff) | |
download | bcm5719-llvm-69a4779965a47ca7ce767a2c28fd8ffc041df77c.tar.gz bcm5719-llvm-69a4779965a47ca7ce767a2c28fd8ffc041df77c.zip |
[OPENMP] Fixed codegen for 'reduction' clause.
Fixed codegen for reduction operations min, max, && and ||. Codegen for them is quite similar and I was confused by this similarity.
Also added a call to kmpc_end_reduce() in atomic part of reduction codegen (call to kmpc_end_reduce_nowait() is not required).
Differential Revision: http://reviews.llvm.org/D9513
llvm-svn: 236689
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 34 | ||||
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 2 |
2 files changed, 26 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 1455ae9528f..d8c81532f63 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -2121,6 +2121,7 @@ void CGOpenMPRuntime::emitReduction(CodeGenFunction &CGF, SourceLocation Loc, // ... // Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); // ... + // [__kmpc_end_reduce(<loc>, <gtid>, &<lock>);] // break; // default:; // } @@ -2221,28 +2222,43 @@ void CGOpenMPRuntime::emitReduction(CodeGenFunction &CGF, SourceLocation Loc, { CodeGenFunction::RunCleanupsScope Scope(CGF); + if (!WithNowait) { + // Add emission of __kmpc_end_reduce(<loc>, <gtid>, &<lock>); + llvm::Value *EndArgs[] = { + IdentTLoc, // ident_t *<loc> + ThreadId, // i32 <gtid> + Lock // kmp_critical_name *&<lock> + }; + CGF.EHStack + .pushCleanup<CallEndCleanup<std::extent<decltype(EndArgs)>::value>>( + NormalAndEHCleanup, + createRuntimeFunction(OMPRTL__kmpc_end_reduce), + llvm::makeArrayRef(EndArgs)); + } auto I = LHSExprs.begin(); for (auto *E : ReductionOps) { const Expr *XExpr = nullptr; const Expr *EExpr = nullptr; const Expr *UpExpr = nullptr; BinaryOperatorKind BO = BO_Comma; - // Try to emit update expression as a simple atomic. - if (auto *ACO = dyn_cast<AbstractConditionalOperator>(E)) { - // If this is a conditional operator, analyze it's condition for - // min/max reduction operator. - E = ACO->getCond(); - } if (auto *BO = dyn_cast<BinaryOperator>(E)) { if (BO->getOpcode() == BO_Assign) { XExpr = BO->getLHS(); UpExpr = BO->getRHS(); } } - // Analyze RHS part of the whole expression. - if (UpExpr) { + // Try to emit update expression as a simple atomic. + auto *RHSExpr = UpExpr; + if (RHSExpr) { + // Analyze RHS part of the whole expression. + if (auto *ACO = dyn_cast<AbstractConditionalOperator>( + RHSExpr->IgnoreParenImpCasts())) { + // If this is a conditional operator, analyze its condition for + // min/max reduction operator. + RHSExpr = ACO->getCond(); + } if (auto *BORHS = - dyn_cast<BinaryOperator>(UpExpr->IgnoreParenImpCasts())) { + dyn_cast<BinaryOperator>(RHSExpr->IgnoreParenImpCasts())) { EExpr = BORHS->getRHS(); BO = BORHS->getOpcode(); } diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 67fa678db3e..d814b135a3c 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -5676,7 +5676,7 @@ OMPClause *Sema::ActOnOpenMPReductionClause( BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); if (ReductionOp.isUsable()) { - if (BOK != BO_LOr && BOK != BO_LAnd) { + if (BOK != BO_LT && BOK != BO_GT) { ReductionOp = BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BO_Assign, LHSDRE, ReductionOp.get()); |