summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2014-12-01 11:32:38 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2014-12-01 11:32:38 +0000
commit75ddfabed756bfeb75057b535dc4a128946ed816 (patch)
treeb284e5ea4f36d6e8ad7fd131c59e7c61da9fc484
parentb682ddf33ae05386c7069877abf2cd74ea89c13a (diff)
downloadbcm5719-llvm-75ddfabed756bfeb75057b535dc4a128946ed816.tar.gz
bcm5719-llvm-75ddfabed756bfeb75057b535dc4a128946ed816.zip
[OPENMP] Formating and code improvement for codegen of 'omp critical' directive.
No functional changes, only code improvements. llvm-svn: 223010
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntime.cpp25
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntime.h35
-rw-r--r--clang/lib/CodeGen/CGStmtOpenMP.cpp15
3 files changed, 28 insertions, 47 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ecc844f8646..04c2dfbb9ff 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<void()> &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 b9c1a35434f..09e3272e943 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<void()> &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 b160f17ccad..79af4bc00df 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();
- // <captured_body>
- // __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<CapturedStmt>(S.getAssociatedStmt())->getCapturedStmt());
EnsureInsertPoint();
- }
- CGM.getOpenMPRuntime().EmitOMPCriticalRegionEnd(*this, Lock, S.getLocEnd());
+ }, S.getLocStart());
}
void
OpenPOWER on IntegriCloud