summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorAlexander Musman <alexander.musman@gmail.com>2015-03-21 10:12:56 +0000
committerAlexander Musman <alexander.musman@gmail.com>2015-03-21 10:12:56 +0000
commit3276a27b5cde44d24b67be07227c2b9daba85196 (patch)
tree02fbc25e178fb90d65521638c57e9acfa9355d92 /clang/lib/CodeGen
parente165502ed7675f5c9ce9c0d064df6beed8961224 (diff)
downloadbcm5719-llvm-3276a27b5cde44d24b67be07227c2b9daba85196.tar.gz
bcm5719-llvm-3276a27b5cde44d24b67be07227c2b9daba85196.zip
[OPENMP] CodeGen of the 'linear' clause for the 'omp simd' directive.
The linear variable is privatized (similar to 'private') and its value on current iteration is calculated, similar to the loop counter variables. Differential revision: http://reviews.llvm.org/D8375 llvm-svn: 232890
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGStmtOpenMP.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index a7615ce10a2..42e6a841cdf 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -266,6 +266,13 @@ void CodeGenFunction::EmitOMPLoopBody(const OMPLoopDirective &S,
for (auto I : S.updates()) {
EmitIgnoredExpr(I);
}
+ // Update the linear variables.
+ for (auto C : OMPExecutableDirective::linear_filter(S.clauses())) {
+ for (auto U : C->updates()) {
+ EmitIgnoredExpr(U);
+ }
+ }
+
// On a continue in the body, jump to the end.
auto Continue = getJumpDestInCurrentScope("omp.body.continue");
BreakContinueStack.push_back(BreakContinue(JumpDest(), Continue));
@@ -336,6 +343,12 @@ void CodeGenFunction::EmitOMPSimdFinal(const OMPLoopDirective &S) {
}
++IC;
}
+ // Emit the final values of the linear variables.
+ for (auto C : OMPExecutableDirective::linear_filter(S.clauses())) {
+ for (auto F : C->finals()) {
+ EmitIgnoredExpr(F);
+ }
+ }
}
static void EmitOMPAlignedClause(CodeGenFunction &CGF, CodeGenModule &CGM,
@@ -381,6 +394,25 @@ static void EmitPrivateLoopCounters(CodeGenFunction &CGF,
}
}
+static void
+EmitPrivateLinearVars(CodeGenFunction &CGF, const OMPExecutableDirective &D,
+ CodeGenFunction::OMPPrivateScope &PrivateScope) {
+ for (auto Clause : OMPExecutableDirective::linear_filter(D.clauses())) {
+ for (auto *E : Clause->varlists()) {
+ auto VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
+ bool IsRegistered = PrivateScope.addPrivate(VD, [&]()->llvm::Value * {
+ // Emit var without initialization.
+ auto VarEmission = CGF.EmitAutoVarAlloca(*VD);
+ CGF.EmitAutoVarCleanups(VarEmission);
+ return VarEmission.getAllocatedAddress();
+ });
+ assert(IsRegistered && "linear var already registered as private");
+ // Silence the warning about unused variable.
+ (void)IsRegistered;
+ }
+ }
+}
+
void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) {
// Pragma 'simd' code depends on presence of 'lastprivate'.
// If present, we have to separate last iteration of the loop:
@@ -428,6 +460,14 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) {
InlinedOpenMPRegionScopeRAII Region(*this, S);
+ // Emit inits for the linear variables.
+ for (auto C : OMPExecutableDirective::linear_filter(S.clauses())) {
+ for (auto Init : C->inits()) {
+ auto *D = cast<VarDecl>(cast<DeclRefExpr>(Init)->getDecl());
+ EmitVarDecl(*D);
+ }
+ }
+
// Emit the loop iteration variable.
const Expr *IVExpr = S.getIterationVariable();
const VarDecl *IVDecl = cast<VarDecl>(cast<DeclRefExpr>(IVExpr)->getDecl());
@@ -443,6 +483,17 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) {
EmitIgnoredExpr(S.getCalcLastIteration());
}
+ // Emit the linear steps for the linear clauses.
+ // If a step is not constant, it is pre-calculated before the loop.
+ for (auto C : OMPExecutableDirective::linear_filter(S.clauses())) {
+ if (auto CS = cast_or_null<BinaryOperator>(C->getCalcStep()))
+ if (auto SaveRef = cast<DeclRefExpr>(CS->getLHS())) {
+ EmitVarDecl(*cast<VarDecl>(SaveRef->getDecl()));
+ // Emit calculation of the linear step.
+ EmitIgnoredExpr(CS);
+ }
+ }
+
if (SeparateIter) {
// Emit: if (LastIteration > 0) - begin.
RegionCounter Cnt = getPGORegionCounter(&S);
@@ -455,6 +506,7 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) {
{
OMPPrivateScope LoopScope(*this);
EmitPrivateLoopCounters(*this, LoopScope, S.counters());
+ EmitPrivateLinearVars(*this, S, LoopScope);
EmitOMPPrivateClause(S, LoopScope);
(void)LoopScope.Privatize();
EmitOMPInnerLoop(S, LoopScope.requiresCleanups(),
@@ -473,6 +525,7 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) {
{
OMPPrivateScope LoopScope(*this);
EmitPrivateLoopCounters(*this, LoopScope, S.counters());
+ EmitPrivateLinearVars(*this, S, LoopScope);
EmitOMPPrivateClause(S, LoopScope);
(void)LoopScope.Privatize();
EmitOMPInnerLoop(S, LoopScope.requiresCleanups(),
OpenPOWER on IntegriCloud