diff options
author | Alexander Musman <alexander.musman@gmail.com> | 2014-10-01 06:03:56 +0000 |
---|---|---|
committer | Alexander Musman <alexander.musman@gmail.com> | 2014-10-01 06:03:56 +0000 |
commit | a5f070aec0386d941a9a1bc2d47adc95553975ea (patch) | |
tree | 0eeff1d1f478a3664951b01e6ae0799c933206a9 /clang/lib/CodeGen/CodeGenFunction.h | |
parent | 6a107bad152aadeb93fda669f74ab77b728a12f5 (diff) | |
download | bcm5719-llvm-a5f070aec0386d941a9a1bc2d47adc95553975ea.tar.gz bcm5719-llvm-a5f070aec0386d941a9a1bc2d47adc95553975ea.zip |
[OPENMP] Loop collapsing and codegen for 'omp simd' directive.
This patch implements collapsing of the loops (in particular, in
presense of clause 'collapse'). It calculates number of iterations N
and expressions nesessary to calculate the nested loops counters
values based on new iteration variable (that goes from 0 to N-1)
in Sema. It also adds Codegen for 'omp simd', which uses
(and tests) this feature.
Differential Revision: http://reviews.llvm.org/D5184
llvm-svn: 218743
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 63e0f635599..2709a36d9a2 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -866,6 +866,48 @@ private: }; SmallVector<BreakContinue, 8> BreakContinueStack; + /// \brief The scope used to remap some variables as private in the OpenMP + /// loop body (or other captured region emitted without outlining), and to + /// restore old vars back on exit. + class OMPPrivateScope : public RunCleanupsScope { + DeclMapTy SavedLocals; + + private: + OMPPrivateScope(const OMPPrivateScope &) LLVM_DELETED_FUNCTION; + void operator=(const OMPPrivateScope &) LLVM_DELETED_FUNCTION; + + public: + /// \brief Enter a new OpenMP private scope. + explicit OMPPrivateScope(CodeGenFunction &CGF) : RunCleanupsScope(CGF) {} + + /// \brief Add and remap private variables (without initialization). + /// \param Vars - a range of DeclRefExprs for the private variables. + template <class IT> void addPrivates(IT Vars) { + assert(PerformCleanup && "adding private to dead scope"); + for (auto E : Vars) { + auto D = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl()); + assert(!SavedLocals.lookup(D) && "remapping a var twice"); + SavedLocals[D] = CGF.LocalDeclMap.lookup(D); + CGF.LocalDeclMap.erase(D); + // Emit var without initialization. + auto VarEmission = CGF.EmitAutoVarAlloca(*D); + CGF.EmitAutoVarCleanups(VarEmission); + } + } + + void ForceCleanup() { + RunCleanupsScope::ForceCleanup(); + // Remap vars back to the original values. + for (auto I : SavedLocals) { + CGF.LocalDeclMap[I.first] = I.second; + } + SavedLocals.clear(); + } + + /// \brief Exit scope - all the mapped variables are restored. + ~OMPPrivateScope() { ForceCleanup(); } + }; + CodeGenPGO PGO; public: @@ -1946,6 +1988,12 @@ public: void EmitOMPAtomicDirective(const OMPAtomicDirective &S); void EmitOMPTargetDirective(const OMPTargetDirective &S); + /// Helpers for 'omp simd' directive. + void EmitOMPSimdBody(const OMPLoopDirective &Directive, bool SeparateIter); + void EmitOMPSimdLoop(const OMPLoopDirective &S, OMPPrivateScope &LoopScope, + bool SeparateIter); + void EmitOMPSimdFinal(const OMPLoopDirective &S); + //===--------------------------------------------------------------------===// // LValue Expression Emission //===--------------------------------------------------------------------===// |