[clang] [clang-tools-extra] [Clang] Use TargetInfo when deciding is an address space is compatible (PR #115777)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 13 19:44:54 PST 2024
================
@@ -697,45 +699,21 @@ class Qualifiers {
/// every address space is a superset of itself.
/// CL2.0 adds:
/// __generic is a superset of any address space except for __constant.
- static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) {
- // Address spaces must match exactly.
- return A == B ||
- // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
- // for __constant can be used as __generic.
- (A == LangAS::opencl_generic && B != LangAS::opencl_constant) ||
- // We also define global_device and global_host address spaces,
- // to distinguish global pointers allocated on host from pointers
- // allocated on device, which are a subset of __global.
- (A == LangAS::opencl_global && (B == LangAS::opencl_global_device ||
- B == LangAS::opencl_global_host)) ||
- (A == LangAS::sycl_global && (B == LangAS::sycl_global_device ||
- B == LangAS::sycl_global_host)) ||
- // Consider pointer size address spaces to be equivalent to default.
- ((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
- (isPtrSizeAddressSpace(B) || B == LangAS::Default)) ||
- // Default is a superset of SYCL address spaces.
- (A == LangAS::Default &&
- (B == LangAS::sycl_private || B == LangAS::sycl_local ||
- B == LangAS::sycl_global || B == LangAS::sycl_global_device ||
- B == LangAS::sycl_global_host)) ||
- // In HIP device compilation, any cuda address space is allowed
- // to implicitly cast into the default address space.
- (A == LangAS::Default &&
- (B == LangAS::cuda_constant || B == LangAS::cuda_device ||
- B == LangAS::cuda_shared));
- }
+ static bool isAddressSpaceSupersetOf(LangAS A, LangAS B,
+ const ASTContext &Ctx);
----------------
rjmccall wrote:
Sorry for being picky here, but could you *only* leave the equality check inline? That will make this function very likely to be inlined, which is great because "both of the address spaces are DefaultAS" is like the 99.9999% case here, and then "the address space is something else but it's still the same on both sides" is probably another 0.00009%. Once we're in the vanishingly small case where we're not only using address spaces but actually have different ones, the overhead of a function call barely registers and we might as well write the code in a nice, well-organized way. (I won't ask you to do that, I'm just noting that it's currently a huge mess.)
https://github.com/llvm/llvm-project/pull/115777
More information about the cfe-commits
mailing list