[llvm] [SPIR-V] Add InferAddrSpaces pass to the backend (PR #137766)

Victor Lomuller via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 03:31:45 PDT 2025


================
@@ -190,6 +191,14 @@ void SPIRVPassConfig::addIRPasses() {
   TargetPassConfig::addIRPasses();
 
   if (TM.getSubtargetImpl()->isVulkanEnv()) {
+    // The frontend has a tendency to quickly addrspacecast pointers to the
+    // default address space, and relies on addrspacecast instructions at the
+    // boundaries. Vulkan does not allow such things, and we must keep the
+    // pointer address space stable.
+    // This pass will determine real address space of a pointer, and patch
+    // instructions removing Addrspacecasts.
+    addPass(createInferAddressSpacesPass(/* AddressSpace= */ 0));
----------------
Naghasan wrote:

The pass can call `TargetTransformInfo::getFlatAddressSpace()` to get the address space used as flat, so it would make sense to implement `SPIRVTTIImpl::getFlatAddressSpace()` for this and make it compatible with compute (which would use 4 in this case). There is other passes in LLVM that could use this information as well.

I'm saying this while not knowing much about hlsl.

https://github.com/llvm/llvm-project/pull/137766


More information about the llvm-commits mailing list