[clang] [clang] Allow overriding any global variable address space (PR #195612)
Nicolai Hähnle via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 1 08:08:01 PDT 2026
nhaehnle wrote:
Digging into this a bit further in the context of the overall PR stack, I'm not convinced that this is the right approach. I agree with @arsenm that mapping LangAS to LangAS is a fundamentally dodgy operation.
The LLVM IR we want to achieve has a certain address space on the `llvm::GlobalVariable`, but taking its address in HIP results in an addrspace(0) pointer via an implicit addrspacecast.
This kind of behavior already exists for `__shared__` variables: they become addrspace(3) GlobalVariables, but taking their address results in an implicit addrspacecast to addrspace(0).
>From what I can tell, the way this works is that the language-level type of the address of the variable is just a pointer to the variable's type, i.e. it lives in the default address space, but `GetGlobalVarAddressSpace` returns `cuda_shared`. And I believe the `performAddrSpaceCast` at the end of `GetOrCreateLLVMGlobal` reconciles this difference by inserting an implicit addrspacecast.
So why not implement barriers the same way?
* Define a `LangAS::hip_barrier` language-level address space
* Make `GetGlobalVarAddressSpace` return that address space for barrier globals
* There may be some additional places where Clang needs to be taught to treat `hip_barrier` analogously to `cuda_shared`
... and then everything else hopefully just falls out?
https://github.com/llvm/llvm-project/pull/195612
More information about the cfe-commits
mailing list