[Clang][CodeGen]`vtable`, `typeinfo` et al. are globals
commit8acdcf4016876d122733991561be706b64026e73
authorAlex Voicu <alexandru.voicu@amd.com>
Wed, 19 Jul 2023 17:04:31 +0000 (19 18:04 +0100)
committerAlex Voicu <alexandru.voicu@amd.com>
Wed, 19 Jul 2023 17:04:31 +0000 (19 18:04 +0100)
tree2cab27785342c4100dea53f53eae31a4913814a1
parent3055c5815ac08aa0d8597bff63569b9ed8ec0822
[Clang][CodeGen]`vtable`, `typeinfo` et al. are globals

All data structures and values associated with handling virtual functions / inheritance, as well as RTTI, are globals and thus can only reside in the global address space. This was not taken fully taken into account because for most targets, global & generic appear to coincide. However, on targets where global & generic ASes differ (e.g. AMDGPU), this was problematic, since it led to the generation of invalid bitcasts (which would trigger asserts in Debug) and less than optimal code. This patch does two things:

ensures that vtables, vptrs, vtts, typeinfo are generated in the right AS, and populated accordingly;
removes a bunch of bitcasts which look like left-overs from the typed ptr era.

Reviewed By: yxsamliu

Differential Revision: https://reviews.llvm.org/D153092
15 files changed:
clang/lib/CodeGen/CGVTT.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/vtable-align-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtable-consteval-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtable-constexpr-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtable-key-function-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtable-layout-extreme-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtable-linkage-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtable-pointer-initialization-address-space.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/vtt-address-space.cpp
clang/test/CodeGenCXX/vtt-layout-address-space.cpp [new file with mode: 0644]
clang/test/Headers/hip-header.hip