[OpenMP][IR-Builder] Introduce the finalization stack
authorJohannes Doerfert <johannes@jdoerfert.de>
Wed, 25 Dec 2019 16:33:56 +0000 (10:33 -0600)
committerJohannes Doerfert <johannes@jdoerfert.de>
Wed, 25 Dec 2019 22:57:08 +0000 (16:57 -0600)
commitf9c3c5da19ab6d8cbbd4611fbb24e97fe7a85078
tree710fb71721975dbc15ef9d8d6306a6ca15cb85a3
parentc5b4a2386b51a18daad7e42040c685c2e9708c47
[OpenMP][IR-Builder] Introduce the finalization stack

As a permanent and generic solution to the problem of variable
finalization (destructors, lastprivate, ...), this patch introduces the
finalization stack. The objects on the stack describe (1) the
(structured) regions the OpenMP-IR-Builder is currently constructing,
(2) if these are cancellable, and (3) the callback that will perform the
finalization (=cleanup) when necessary.

As the finalization can be necessary multiple times, at different source
locations, the callback takes the position at which code is currently
generated. This position will also encode the destination of the "region
exit" block *iff* the finalization call was issues for a region
generated by the OpenMPIRBuilder. For regions generated through the old
Clang OpenMP code geneneration, the "region exit" is determined by Clang
inside the finalization call instead (see getOMPCancelDestination).

As a first user, the parallel + cancel barrier interaction is changed.
In contrast to the temporary solution before, the barrier generation in
Clang does not need to be aware of the "CancelDestination" block.
Instead, the finalization callback is and, as described above, later
even that one does not need to be.

D70109 will be updated to use this scheme.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D70258
clang/lib/CodeGen/CGOpenMPRuntime.cpp
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp