Skip to content

Commit a744ff5

Browse files
committedMay 5, 2015
[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 llvm-svn: 236491
1 parent ce348a4 commit a744ff5

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed
 

‎clang/lib/CodeGen/CGOpenMPRuntime.cpp

+24-17
Original file line numberDiff line numberDiff line change
@@ -1154,16 +1154,16 @@ llvm::Value *CGOpenMPRuntime::getCriticalRegionLock(StringRef CriticalName) {
11541154
}
11551155

11561156
namespace {
1157-
class CallEndCleanup : public EHScopeStack::Cleanup {
1158-
public:
1159-
typedef ArrayRef<llvm::Value *> CleanupValuesTy;
1160-
private:
1157+
template <size_t N> class CallEndCleanup : public EHScopeStack::Cleanup {
11611158
llvm::Value *Callee;
1162-
llvm::SmallVector<llvm::Value *, 8> Args;
1159+
llvm::Value *Args[N];
11631160

11641161
public:
1165-
CallEndCleanup(llvm::Value *Callee, CleanupValuesTy Args)
1166-
: Callee(Callee), Args(Args.begin(), Args.end()) {}
1162+
CallEndCleanup(llvm::Value *Callee, ArrayRef<llvm::Value *> CleanupArgs)
1163+
: Callee(Callee) {
1164+
assert(CleanupArgs.size() == N);
1165+
std::copy(CleanupArgs.begin(), CleanupArgs.end(), std::begin(Args));
1166+
}
11671167
void Emit(CodeGenFunction &CGF, Flags /*flags*/) override {
11681168
CGF.EmitRuntimeCall(Callee, Args);
11691169
}
@@ -1184,7 +1184,7 @@ void CGOpenMPRuntime::emitCriticalRegion(CodeGenFunction &CGF,
11841184
getCriticalRegionLock(CriticalName)};
11851185
CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_critical), Args);
11861186
// Build a call to __kmpc_end_critical
1187-
CGF.EHStack.pushCleanup<CallEndCleanup>(
1187+
CGF.EHStack.pushCleanup<CallEndCleanup<std::extent<decltype(Args)>::value>>(
11881188
NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_critical),
11891189
llvm::makeArrayRef(Args));
11901190
emitInlinedDirective(CGF, CriticalOpGen);
@@ -1220,9 +1220,11 @@ void CGOpenMPRuntime::emitMasterRegion(CodeGenFunction &CGF,
12201220
llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)};
12211221
auto *IsMaster =
12221222
CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_master), Args);
1223+
typedef CallEndCleanup<std::extent<decltype(Args)>::value>
1224+
MasterCallEndCleanup;
12231225
emitIfStmt(CGF, IsMaster, [&](CodeGenFunction &CGF) -> void {
12241226
CodeGenFunction::RunCleanupsScope Scope(CGF);
1225-
CGF.EHStack.pushCleanup<CallEndCleanup>(
1227+
CGF.EHStack.pushCleanup<MasterCallEndCleanup>(
12261228
NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_master),
12271229
llvm::makeArrayRef(Args));
12281230
MasterOpGen(CGF);
@@ -1326,9 +1328,11 @@ void CGOpenMPRuntime::emitSingleRegion(CodeGenFunction &CGF,
13261328
llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)};
13271329
auto *IsSingle =
13281330
CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_single), Args);
1331+
typedef CallEndCleanup<std::extent<decltype(Args)>::value>
1332+
SingleCallEndCleanup;
13291333
emitIfStmt(CGF, IsSingle, [&](CodeGenFunction &CGF) -> void {
13301334
CodeGenFunction::RunCleanupsScope Scope(CGF);
1331-
CGF.EHStack.pushCleanup<CallEndCleanup>(
1335+
CGF.EHStack.pushCleanup<SingleCallEndCleanup>(
13321336
NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_single),
13331337
llvm::makeArrayRef(Args));
13341338
SingleOpGen(CGF);
@@ -1391,7 +1395,7 @@ void CGOpenMPRuntime::emitOrderedRegion(CodeGenFunction &CGF,
13911395
llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)};
13921396
CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_ordered), Args);
13931397
// Build a call to __kmpc_end_ordered
1394-
CGF.EHStack.pushCleanup<CallEndCleanup>(
1398+
CGF.EHStack.pushCleanup<CallEndCleanup<std::extent<decltype(Args)>::value>>(
13951399
NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_ordered),
13961400
llvm::makeArrayRef(Args));
13971401
emitInlinedDirective(CGF, OrderedOpGen);
@@ -1991,6 +1995,8 @@ void CGOpenMPRuntime::emitTaskCall(
19911995
// TODO: add check for untied tasks.
19921996
CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_task), TaskArgs);
19931997
};
1998+
typedef CallEndCleanup<std::extent<decltype(TaskArgs)>::value>
1999+
IfCallEndCleanup;
19942000
auto &&ElseCodeGen =
19952001
[this, &TaskArgs, ThreadID, NewTaskNewTaskTTy, TaskEntry](
19962002
CodeGenFunction &CGF) {
@@ -1999,7 +2005,7 @@ void CGOpenMPRuntime::emitTaskCall(
19992005
createRuntimeFunction(OMPRTL__kmpc_omp_task_begin_if0), TaskArgs);
20002006
// Build void __kmpc_omp_task_complete_if0(ident_t *, kmp_int32 gtid,
20012007
// kmp_task_t *new_task);
2002-
CGF.EHStack.pushCleanup<CallEndCleanup>(
2008+
CGF.EHStack.pushCleanup<IfCallEndCleanup>(
20032009
NormalAndEHCleanup,
20042010
createRuntimeFunction(OMPRTL__kmpc_omp_task_complete_if0),
20052011
llvm::makeArrayRef(TaskArgs));
@@ -2191,11 +2197,12 @@ void CGOpenMPRuntime::emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
21912197
ThreadId, // i32 <gtid>
21922198
Lock // kmp_critical_name *&<lock>
21932199
};
2194-
CGF.EHStack.pushCleanup<CallEndCleanup>(
2195-
NormalAndEHCleanup,
2196-
createRuntimeFunction(WithNowait ? OMPRTL__kmpc_end_reduce_nowait
2197-
: OMPRTL__kmpc_end_reduce),
2198-
llvm::makeArrayRef(EndArgs));
2200+
CGF.EHStack
2201+
.pushCleanup<CallEndCleanup<std::extent<decltype(EndArgs)>::value>>(
2202+
NormalAndEHCleanup,
2203+
createRuntimeFunction(WithNowait ? OMPRTL__kmpc_end_reduce_nowait
2204+
: OMPRTL__kmpc_end_reduce),
2205+
llvm::makeArrayRef(EndArgs));
21992206
for (auto *E : ReductionOps) {
22002207
CGF.EmitIgnoredExpr(E);
22012208
}

0 commit comments

Comments
 (0)
Please sign in to comment.