Skip to content

Commit c74a931

Browse files
committed
Revert and Fix "Fix bug due to reusing cleanup blocks inside tasks. See more"
This reverts commit cea4335. There's a execution path in CodeGen that removes cleanup.dest.slot if there's only one use. We have to do the same. Add test for the optimized and non-optimized cases
1 parent 3657b5d commit c74a931

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

clang/lib/CodeGen/CGCleanup.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
840840
NormalCleanupDestSlot->user_back()->eraseFromParent();
841841
NormalCleanupDestSlot->eraseFromParent();
842842
NormalCleanupDest = Address::invalid();
843+
844+
// OmpSs-2: Clean up the possibly dead store to the cleanup dest slot.
845+
if (getContext().getLangOpts().OmpSs
846+
&& CGM.getOmpSsRuntime().inTaskBody())
847+
CGM.getOmpSsRuntime().setTaskNormalCleanupDestSlot(Address::invalid());
843848
}
844849

845850
llvm::BasicBlock *BranchAfter = Scope.getBranchAfterBlock(0);
@@ -1266,6 +1271,19 @@ void CodeGenFunction::DeactivateCleanupBlock(EHScopeStack::stable_iterator C,
12661271
}
12671272

12681273
Address CodeGenFunction::getNormalCleanupDestSlot() {
1274+
if (getContext().getLangOpts().OmpSs
1275+
&& CGM.getOmpSsRuntime().inTaskBody()) {
1276+
Address NCleanupDest = CGM.getOmpSsRuntime().getTaskNormalCleanupDestSlot();
1277+
if (NCleanupDest.isValid())
1278+
return NCleanupDest;
1279+
1280+
NCleanupDest =
1281+
CreateDefaultAlignTempAlloca(Builder.getInt32Ty(), "cleanup.dest.slot");
1282+
1283+
CGM.getOmpSsRuntime().setTaskNormalCleanupDestSlot(NCleanupDest);
1284+
return NCleanupDest;
1285+
1286+
}
12691287
if (!NormalCleanupDest.isValid())
12701288
NormalCleanupDest =
12711289
CreateDefaultAlignTempAlloca(Builder.getInt32Ty(), "cleanup.dest.slot");

clang/lib/CodeGen/CGOmpSsRuntime.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,10 @@ Address CGOmpSsRuntime::getTaskEHSelectorSlot() {
19411941
return TaskStack.back().EHSelectorSlot;
19421942
}
19431943

1944+
Address CGOmpSsRuntime::getTaskNormalCleanupDestSlot() {
1945+
return TaskStack.back().NormalCleanupDestSlot;
1946+
}
1947+
19441948
Address CGOmpSsRuntime::getTaskCaptureAddr(const VarDecl *VD) {
19451949
for (auto ItMap = CaptureMapStack.rbegin();
19461950
ItMap != CaptureMapStack.rend(); ++ItMap) {
@@ -1976,6 +1980,10 @@ void CGOmpSsRuntime::setTaskEHSelectorSlot(Address Addr) {
19761980
TaskStack.back().EHSelectorSlot = Addr;
19771981
}
19781982

1983+
void CGOmpSsRuntime::setTaskNormalCleanupDestSlot(Address Addr) {
1984+
TaskStack.back().NormalCleanupDestSlot = Addr;
1985+
}
1986+
19791987
// Borrowed brom CodeGenFunction.cpp
19801988
static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) {
19811989
if (!BB) return;

clang/lib/CodeGen/CGOmpSsRuntime.h

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class CGOmpSsRuntime {
142142
llvm::BasicBlock *UnreachableBlock = nullptr;
143143
Address ExceptionSlot = Address::invalid();
144144
Address EHSelectorSlot = Address::invalid();
145+
Address NormalCleanupDestSlot = Address::invalid();
145146
};
146147

147148
private:
@@ -230,6 +231,8 @@ class CGOmpSsRuntime {
230231
Address getTaskExceptionSlot();
231232
// returns the innermost nested task EHSelectorSlot address
232233
Address getTaskEHSelectorSlot();
234+
// returns the innermost nested task NormalCleanupDestSlot address
235+
Address getTaskNormalCleanupDestSlot();
233236
// returns the captured address of VD
234237
Address getTaskCaptureAddr(const VarDecl *VD);
235238

@@ -245,6 +248,8 @@ class CGOmpSsRuntime {
245248
void setTaskExceptionSlot(Address Addr);
246249
// sets the innermost nested task EHSelectorSlot address
247250
void setTaskEHSelectorSlot(Address Addr);
251+
// returns the innermost nested task NormalCleanupDestSlot address
252+
void setTaskNormalCleanupDestSlot(Address Addr);
248253

249254
RValue emitTaskFunction(CodeGenFunction &CGF,
250255
const FunctionDecl *FD,

clang/test/OmpSs-RT/Clang_OmpSs-2/success_task_cleanups.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
// RUN: %oss-compile
2828
// RUN: %oss-O2-compile
2929

30-
// This test was crashing because we were caching cleanup blocks, but
31-
// that is wrong
30+
// There's only one cleanup here, so codegen removes the cleanup.dest.slot.
31+
// We have to do the same in task context
3232

3333
int main(int argc, char **argv)
3434
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*--------------------------------------------------------------------
2+
(C) Copyright 2006-2013 Barcelona Supercomputing Center
3+
Centro Nacional de Supercomputacion
4+
5+
This file is part of Mercurium C/C++ source-to-source compiler.
6+
7+
See AUTHORS file in the top level directory for information
8+
regarding developers and contributors.
9+
10+
This library is free software; you can redistribute it and/or
11+
modify it under the terms of the GNU Lesser General Public
12+
License as published by the Free Software Foundation; either
13+
version 3 of the License, or (at your option) any later version.
14+
15+
Mercurium C/C++ source-to-source compiler is distributed in the hope
16+
that it will be useful, but WITHOUT ANY WARRANTY; without even the
17+
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18+
PURPOSE. See the GNU Lesser General Public License for more
19+
details.
20+
21+
You should have received a copy of the GNU Lesser General Public
22+
License along with Mercurium C/C++ source-to-source compiler; if
23+
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
24+
Cambridge, MA 02139, USA.
25+
--------------------------------------------------------------------*/
26+
27+
// RUN: %oss-compile
28+
// RUN: %oss-O2-compile
29+
30+
// There's more than one cleanup here
31+
32+
int main() {
33+
#pragma oss task
34+
{
35+
for (int i = 0; i < 10; ++i)
36+
for (int j = 0; j < 10; ++j)
37+
;
38+
}
39+
#pragma oss task
40+
{
41+
for (int i = 0; i < 10; ++i)
42+
for (int j = 0; j < 10; ++j)
43+
;
44+
}
45+
}

0 commit comments

Comments
 (0)