forked from OSchip/llvm-project
[OPENMP] Formating and code improvement for codegen of 'omp critical' directive.
No functional changes, only code improvements. llvm-svn: 223010
This commit is contained in:
parent
b682ddf33a
commit
75ddfabed7
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue