From: Alexey Bataev Date: Tue, 5 May 2015 09:24:37 +0000 (+0000) Subject: [OPENMP] Fixed incorrect work with cleanups, NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c62dcdda6a8536f48829b8f487c261331a5102a;p=clang [OPENMP] Fixed incorrect work with cleanups, NFC. Destructors are never called for cleanups, so we can't use SmallVector as a member. Differential Revision: http://reviews.llvm.org/D9399 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236491 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index a0c02ce868..1455ae9528 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1154,16 +1154,16 @@ llvm::Value *CGOpenMPRuntime::getCriticalRegionLock(StringRef CriticalName) { } namespace { -class CallEndCleanup : public EHScopeStack::Cleanup { -public: - typedef ArrayRef CleanupValuesTy; -private: +template class CallEndCleanup : public EHScopeStack::Cleanup { llvm::Value *Callee; - llvm::SmallVector Args; + llvm::Value *Args[N]; public: - CallEndCleanup(llvm::Value *Callee, CleanupValuesTy Args) - : Callee(Callee), Args(Args.begin(), Args.end()) {} + CallEndCleanup(llvm::Value *Callee, ArrayRef CleanupArgs) + : Callee(Callee) { + assert(CleanupArgs.size() == N); + std::copy(CleanupArgs.begin(), CleanupArgs.end(), std::begin(Args)); + } void Emit(CodeGenFunction &CGF, Flags /*flags*/) override { CGF.EmitRuntimeCall(Callee, Args); } @@ -1184,7 +1184,7 @@ void CGOpenMPRuntime::emitCriticalRegion(CodeGenFunction &CGF, getCriticalRegionLock(CriticalName)}; CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_critical), Args); // Build a call to __kmpc_end_critical - CGF.EHStack.pushCleanup( + CGF.EHStack.pushCleanup::value>>( NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_critical), llvm::makeArrayRef(Args)); emitInlinedDirective(CGF, CriticalOpGen); @@ -1220,9 +1220,11 @@ void CGOpenMPRuntime::emitMasterRegion(CodeGenFunction &CGF, llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)}; auto *IsMaster = CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_master), Args); + typedef CallEndCleanup::value> + MasterCallEndCleanup; emitIfStmt(CGF, IsMaster, [&](CodeGenFunction &CGF) -> void { CodeGenFunction::RunCleanupsScope Scope(CGF); - CGF.EHStack.pushCleanup( + CGF.EHStack.pushCleanup( NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_master), llvm::makeArrayRef(Args)); MasterOpGen(CGF); @@ -1326,9 +1328,11 @@ void CGOpenMPRuntime::emitSingleRegion(CodeGenFunction &CGF, llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)}; auto *IsSingle = CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_single), Args); + typedef CallEndCleanup::value> + SingleCallEndCleanup; emitIfStmt(CGF, IsSingle, [&](CodeGenFunction &CGF) -> void { CodeGenFunction::RunCleanupsScope Scope(CGF); - CGF.EHStack.pushCleanup( + CGF.EHStack.pushCleanup( NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_single), llvm::makeArrayRef(Args)); SingleOpGen(CGF); @@ -1391,7 +1395,7 @@ void CGOpenMPRuntime::emitOrderedRegion(CodeGenFunction &CGF, llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)}; CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_ordered), Args); // Build a call to __kmpc_end_ordered - CGF.EHStack.pushCleanup( + CGF.EHStack.pushCleanup::value>>( NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_ordered), llvm::makeArrayRef(Args)); emitInlinedDirective(CGF, OrderedOpGen); @@ -1991,6 +1995,8 @@ void CGOpenMPRuntime::emitTaskCall( // TODO: add check for untied tasks. CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_task), TaskArgs); }; + typedef CallEndCleanup::value> + IfCallEndCleanup; auto &&ElseCodeGen = [this, &TaskArgs, ThreadID, NewTaskNewTaskTTy, TaskEntry]( CodeGenFunction &CGF) { @@ -1999,7 +2005,7 @@ void CGOpenMPRuntime::emitTaskCall( createRuntimeFunction(OMPRTL__kmpc_omp_task_begin_if0), TaskArgs); // Build void __kmpc_omp_task_complete_if0(ident_t *, kmp_int32 gtid, // kmp_task_t *new_task); - CGF.EHStack.pushCleanup( + CGF.EHStack.pushCleanup( NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_omp_task_complete_if0), llvm::makeArrayRef(TaskArgs)); @@ -2191,11 +2197,12 @@ void CGOpenMPRuntime::emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ThreadId, // i32 Lock // kmp_critical_name *& }; - CGF.EHStack.pushCleanup( - NormalAndEHCleanup, - createRuntimeFunction(WithNowait ? OMPRTL__kmpc_end_reduce_nowait - : OMPRTL__kmpc_end_reduce), - llvm::makeArrayRef(EndArgs)); + CGF.EHStack + .pushCleanup::value>>( + NormalAndEHCleanup, + createRuntimeFunction(WithNowait ? OMPRTL__kmpc_end_reduce_nowait + : OMPRTL__kmpc_end_reduce), + llvm::makeArrayRef(EndArgs)); for (auto *E : ReductionOps) { CGF.EmitIgnoredExpr(E); }