diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2015-03-10 04:22:11 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2015-03-10 04:22:11 +0000 |
commit | 7ab2cc178fd68568146d21e320733885bde3687c (patch) | |
tree | ef5f0588ad173b79579d479241e3a4889e928e9d /clang/lib/CodeGen | |
parent | 760bf9520ad1ec7a487ea1244c5c97ea235e4532 (diff) | |
download | bcm5719-llvm-7ab2cc178fd68568146d21e320733885bde3687c.tar.gz bcm5719-llvm-7ab2cc178fd68568146d21e320733885bde3687c.zip |
[OPENMP] Improved code for generating debug info + generation of all OpenMP regions in termination scope
Patch adds proper generation of debug info for all OpenMP regions. Also, all OpenMP regions are generated in a termination scope, because standard does not allow to throw exceptions out of structured blocks, associated with the OpenMP regions
Differential Revision: http://reviews.llvm.org/D7935
llvm-svn: 231752
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 7 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 43 |
3 files changed, 29 insertions, 23 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 51865a6141f..59a0b27f168 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1047,9 +1047,16 @@ InlinedOpenMPRegionRAII::InlinedOpenMPRegionRAII( CodeGenFunction &CGF, const OMPExecutableDirective &D) : CGF(CGF) { CGF.CapturedStmtInfo = new CGOpenMPInlinedRegionInfo(D, CGF.CapturedStmtInfo); + // 1.2.2 OpenMP Language Terminology + // Structured block - An executable statement with a single entry at the + // top and a single exit at the bottom. + // The point of exit cannot be a branch out of the structured block. + // longjmp() and throw() must not violate the entry/exit criteria. + CGF.EHStack.pushTerminate(); } InlinedOpenMPRegionRAII::~InlinedOpenMPRegionRAII() { + CGF.EHStack.popTerminate(); auto *OldCSI = cast<CGOpenMPInlinedRegionInfo>(CGF.CapturedStmtInfo)->getOldCSI(); delete CGF.CapturedStmtInfo; diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 0d160d3eee5..e4339849ca3 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -2186,6 +2186,8 @@ CodeGenFunction::GenerateCapturedStmtFunction(const CapturedStmt &S) { llvm::Function::Create(FuncLLVMTy, llvm::GlobalValue::InternalLinkage, CapturedStmtInfo->getHelperName(), &CGM.getModule()); CGM.SetInternalFunctionAttributes(CD, F, FuncInfo); + if (CD->isNothrow()) + F->addFnAttr(llvm::Attribute::NoUnwind); // Generate the function. StartFunction(CD, Ctx.VoidTy, F, FuncInfo, Args, diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index c83dfa17064..245fed01e52 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -23,6 +23,20 @@ using namespace CodeGen; //===----------------------------------------------------------------------===// // OpenMP Directive Emission //===----------------------------------------------------------------------===// +namespace { +/// \brief RAII for inlined OpenMP regions (like 'omp for', 'omp simd', 'omp +/// critical' etc.). Helps to generate proper debug info and provides correct +/// code generation for such constructs. +class InlinedOpenMPRegionScopeRAII { + InlinedOpenMPRegionRAII Region; + CodeGenFunction::LexicalScope DirectiveScope; + +public: + InlinedOpenMPRegionScopeRAII(CodeGenFunction &CGF, + const OMPExecutableDirective &D) + : Region(CGF, D), DirectiveScope(CGF, D.getSourceRange()) {} +}; +} // namespace /// \brief Emits code for OpenMP 'if' clause using specified \a CodeGen /// function. Here is the logic: @@ -417,12 +431,7 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) { } } - InlinedOpenMPRegionRAII Region(*this, S); - RunCleanupsScope DirectiveScope(*this); - - CGDebugInfo *DI = getDebugInfo(); - if (DI) - DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin()); + InlinedOpenMPRegionScopeRAII Region(*this, S); // Emit the loop iteration variable. const Expr *IVExpr = S.getIterationVariable(); @@ -466,9 +475,6 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) { } EmitOMPSimdFinal(S); } - - if (DI) - DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd()); } void CodeGenFunction::EmitOMPForOuterLoop(OpenMPScheduleClauseKind ScheduleKind, @@ -650,20 +656,13 @@ void CodeGenFunction::EmitOMPWorksharingLoop(const OMPLoopDirective &S) { } void CodeGenFunction::EmitOMPForDirective(const OMPForDirective &S) { - InlinedOpenMPRegionRAII Region(*this, S); - RunCleanupsScope DirectiveScope(*this); - - CGDebugInfo *DI = getDebugInfo(); - if (DI) - DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin()); + InlinedOpenMPRegionScopeRAII Region(*this, S); EmitOMPWorksharingLoop(S); // Emit an implicit barrier at the end. CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(), /*IsExplicit*/ false); - if (DI) - DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd()); } void CodeGenFunction::EmitOMPForSimdDirective(const OMPForSimdDirective &) { @@ -680,8 +679,7 @@ void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &) { void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &S) { CGM.getOpenMPRuntime().emitSingleRegion(*this, [&]() -> void { - InlinedOpenMPRegionRAII Region(*this, S); - RunCleanupsScope Scope(*this); + InlinedOpenMPRegionScopeRAII Region(*this, S); EmitStmt(cast<CapturedStmt>(S.getAssociatedStmt())->getCapturedStmt()); EnsureInsertPoint(); }, S.getLocStart()); @@ -689,8 +687,7 @@ void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &S) { void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) { CGM.getOpenMPRuntime().emitMasterRegion(*this, [&]() -> void { - InlinedOpenMPRegionRAII Region(*this, S); - RunCleanupsScope Scope(*this); + InlinedOpenMPRegionScopeRAII Region(*this, S); EmitStmt(cast<CapturedStmt>(S.getAssociatedStmt())->getCapturedStmt()); EnsureInsertPoint(); }, S.getLocStart()); @@ -699,8 +696,7 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) { void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) { CGM.getOpenMPRuntime().emitCriticalRegion( *this, S.getDirectiveName().getAsString(), [&]() -> void { - InlinedOpenMPRegionRAII Region(*this, S); - RunCleanupsScope Scope(*this); + InlinedOpenMPRegionScopeRAII Region(*this, S); EmitStmt(cast<CapturedStmt>(S.getAssociatedStmt())->getCapturedStmt()); EnsureInsertPoint(); }, S.getLocStart()); @@ -898,6 +894,7 @@ void CodeGenFunction::EmitOMPAtomicDirective(const OMPAtomicDirective &S) { break; } } + InlinedOpenMPRegionScopeRAII Region(*this, S); EmitOMPAtomicExpr(*this, Kind, IsSeqCst, S.getX(), S.getV(), S.getExpr(), S.getLocStart()); } |