Open Quuxplusone opened 3 years ago
Bugzilla Link | PR48047 |
Status | NEW |
Importance | P enhancement |
Reported by | Anastasia Stulova (anastasia.stulova@arm.com) |
Reported on | 2020-11-02 05:21:29 -0800 |
Last modified on | 2020-12-30 03:38:48 -0800 |
Version | trunk |
Hardware | PC All |
CC | anastasia.stulova@arm.com, llvm-bugs@lists.llvm.org |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
For completenes I provide pseudo code explaining possible implementation of CXX
ABI that should be executed on the device side when the program is terminated.
struct __cxx_atexit_entry{
void* dtor;
};
// TODO: where is this created and how is it set on GPU side? (can be set via
ctor parameters? advantage is that is can be implemented by the applications)
// This list should be global to the entire program in case it is composed of
multiple translation units
extern __cxx_atexit_entry *__dtor_list;
// TODO: can be taken from modules metadata that counts number of cxa_atexit
calls or can be set by an API
extern size_t *__dtor_max_count;
void __cxx_atexit(void *f, void *arg, void *dsohandler)
{
size_t dtor_count = 0;
__dtor_list[dtor_count].dtor = f;
dtor_count++;
//TODO: assert(dtor_count < *__dtor_max_count);
}
extern void __cxx_invoke_dtor(void *f, void *arg); //TODO: CodeGen'ed, Clang
builtin or lib function compiled with func ptr extension.
void __cxx_finalize()
{
for (size_t i = 0 ; i < *__dtor_max_count; i++)
{
__cxx_invoke_dtor(__dtor_list[i].dtor);
}
}
// This kernel can be enqueued when the progam context is destroyed.
__kernel __exit(){
__cxx_finalize();
}
The design from standard C++ requires an extension for function pointers to be available or at least some limited form of it. As this is not portable across all implementations, there seems to be no way to provide global dtors all targets unless we significantly change C++ flow. This seems too expensive to justify at present. Therefore it is suggested to add a feature macro indicating whether global dtor's support is present or not - for example __opencl_cxx_global_dtors. The macro should not be defined by default but only for targets that support global dtors.