[PATCH] D153092: [Clang][CodeGen]`vtable`, `typeinfo` et al. are globals

Alex Voicu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 15 18:07:39 PDT 2023


AlexVlx created this revision.
AlexVlx added reviewers: rjmccall, efriedma, yaxunl.
Herald added subscribers: arichardson, tpr.
Herald added a project: All.
AlexVlx requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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` `AS`es differ (e.g. AMDGPU), this was problematic, since it led to the generation of invalid `bitcast`s (which would trigger `assert`s in Debug) and less than optimal code. This patch does two things:

- ensures that `vtable`s, `vptr`s, `vtt`s, `typeinfo` are generated in the right AS, and populated accordingly;
- removes a bunch of `bitcast`s which look like left-overs from the typed ptr era.

This is a bit more noisy than I'd have liked, but functionality is somewhat spread out. There's one bit of less than ideal code, stemming from the fact that functions are in the `generic` AS, and thus it's necessary to insert a `constexpr` cast from `generic` to `global` when populating the `vtable`. Adjusting appears disruptive enough to prefer to do it separately (unless I missed something obvious).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153092

Files:
  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
  clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp
  clang/test/CodeGenCXX/vtable-consteval-address-space.cpp
  clang/test/CodeGenCXX/vtable-constexpr-address-space.cpp
  clang/test/CodeGenCXX/vtable-key-function-address-space.cpp
  clang/test/CodeGenCXX/vtable-layout-extreme-address-space.cpp
  clang/test/CodeGenCXX/vtable-linkage-address-space.cpp
  clang/test/CodeGenCXX/vtable-pointer-initialization-address-space.cpp
  clang/test/CodeGenCXX/vtt-address-space.cpp
  clang/test/CodeGenCXX/vtt-layout-address-space.cpp
  clang/test/Headers/hip-header.hip

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153092.531956.patch
Type: text/x-patch
Size: 64203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230616/a709f37c/attachment-0001.bin>


More information about the cfe-commits mailing list