From 75ddfabed756bfeb75057b535dc4a128946ed816 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Mon, 1 Dec 2014 11:32:38 +0000 Subject: [PATCH] [OPENMP] Formating and code improvement for codegen of 'omp critical' directive. No functional changes, only code improvements. llvm-svn: 223010 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 25 +++++++++++-------------- clang/lib/CodeGen/CGOpenMPRuntime.h | 35 ++++++++++++++--------------------- clang/lib/CodeGen/CGStmtOpenMP.cpp | 15 +++------------ 3 files changed, 28 insertions(+), 47 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index ecc844f..04c2dfbb 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -616,24 +616,21 @@ llvm::Value *CGOpenMPRuntime::GetCriticalRegionLock(StringRef CriticalName) { return GetOrCreateInternalVariable(KmpCriticalNameTy, Name.concat(".var")); } -void CGOpenMPRuntime::EmitOMPCriticalRegionStart(CodeGenFunction &CGF, - llvm::Value *RegionLock, - SourceLocation Loc) { - // Prepare other arguments and build a call to __kmpc_critical +void CGOpenMPRuntime::EmitOMPCriticalRegion( + CodeGenFunction &CGF, StringRef CriticalName, + const std::function &CriticalOpGen, SourceLocation Loc) { + auto RegionLock = GetCriticalRegionLock(CriticalName); + // __kmpc_critical(ident_t *, gtid, Lock); + // CriticalOpGen(); + // __kmpc_end_critical(ident_t *, gtid, Lock); + // Prepare arguments and build a call to __kmpc_critical llvm::Value *Args[] = {EmitOpenMPUpdateLocation(CGF, Loc), GetOpenMPThreadID(CGF, Loc), RegionLock}; auto RTLFn = CreateRuntimeFunction(CGOpenMPRuntime::OMPRTL__kmpc_critical); CGF.EmitRuntimeCall(RTLFn, Args); -} - -void CGOpenMPRuntime::EmitOMPCriticalRegionEnd(CodeGenFunction &CGF, - llvm::Value *RegionLock, - SourceLocation Loc) { - // Prepare other arguments and build a call to __kmpc_end_critical - llvm::Value *Args[] = {EmitOpenMPUpdateLocation(CGF, Loc), - GetOpenMPThreadID(CGF, Loc), RegionLock}; - auto RTLFn = - CreateRuntimeFunction(CGOpenMPRuntime::OMPRTL__kmpc_end_critical); + CriticalOpGen(); + // Build a call to __kmpc_end_critical + RTLFn = CreateRuntimeFunction(CGOpenMPRuntime::OMPRTL__kmpc_end_critical); CGF.EmitRuntimeCall(RTLFn, Args); } diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h index b9c1a35..09e3272 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.h +++ b/clang/lib/CodeGen/CGOpenMPRuntime.h @@ -230,6 +230,13 @@ private: llvm::Value *Ctor, llvm::Value *CopyCtor, llvm::Value *Dtor, SourceLocation Loc); + /// \brief Returns corresponding lock object for the specified critical region + /// name. If the lock object does not exist it is created, otherwise the + /// reference to the existing copy is returned. + /// \param CriticalName Name of the critical region. + /// + llvm::Value *GetCriticalRegionLock(StringRef CriticalName); + public: explicit CGOpenMPRuntime(CodeGenModule &CGM); virtual ~CGOpenMPRuntime() {} @@ -270,28 +277,14 @@ public: llvm::Value *OutlinedFn, llvm::Value *CapturedStruct); - /// \brief Returns corresponding lock object for the specified critical region - /// name. If the lock object does not exist it is created, otherwise the - /// reference to the existing copy is returned. + /// \brief Emits a critical region. /// \param CriticalName Name of the critical region. - /// - llvm::Value *GetCriticalRegionLock(StringRef CriticalName); - - /// \brief Emits start of the critical region by calling void - /// __kmpc_critical(ident_t *loc, kmp_int32 global_tid, kmp_critical_name - /// * \a RegionLock) - /// \param RegionLock The lock object for critical region. - virtual void EmitOMPCriticalRegionStart(CodeGenFunction &CGF, - llvm::Value *RegionLock, - SourceLocation Loc); - - /// \brief Emits end of the critical region by calling void - /// __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid, kmp_critical_name - /// * \a RegionLock) - /// \param RegionLock The lock object for critical region. - virtual void EmitOMPCriticalRegionEnd(CodeGenFunction &CGF, - llvm::Value *RegionLock, - SourceLocation Loc); + /// \param CriticalOpGen Generator for the statement associated with the given + /// critical region. + virtual void EmitOMPCriticalRegion(CodeGenFunction &CGF, + StringRef CriticalName, + const std::function &CriticalOpGen, + SourceLocation Loc); /// \brief Emits a barrier for OpenMP threads. /// \param Flags Flags for the barrier. diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index b160f17..79af4bc 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -495,21 +495,12 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &) { } void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) { - // __kmpc_critical(); - // - // __kmpc_end_critical(); - // - - auto Lock = CGM.getOpenMPRuntime().GetCriticalRegionLock( - S.getDirectiveName().getAsString()); - CGM.getOpenMPRuntime().EmitOMPCriticalRegionStart(*this, Lock, - S.getLocStart()); - { + CGM.getOpenMPRuntime().EmitOMPCriticalRegion( + *this, S.getDirectiveName().getAsString(), [&]() -> void { RunCleanupsScope Scope(*this); EmitStmt(cast(S.getAssociatedStmt())->getCapturedStmt()); EnsureInsertPoint(); - } - CGM.getOpenMPRuntime().EmitOMPCriticalRegionEnd(*this, Lock, S.getLocEnd()); + }, S.getLocStart()); } void -- 2.7.4