[llvm] [NVPTX][AA] Traverse use-def chain to find non-generic addrspace (PR #106477)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 16:27:49 PDT 2024


================
@@ -47,6 +53,27 @@ void NVPTXAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();
 }
 
+static unsigned getAddressSpace(const Value *V, unsigned MaxLookup) {
+  // Find the first non-generic address space traversing the UD chain.
+  // It is undefined behaviour if a pointer belongs to more than one
+  // non-overlapping address spaces along a valid execution path.
+  for (unsigned Count = 0;; ++Count) {
+    const auto *PTy = dyn_cast<PointerType>(V->getType());
+    if (!PTy)
+      return AddressSpace::ADDRESS_SPACE_GENERIC;
+
+    const unsigned AS = PTy->getAddressSpace();
+    if (AS != AddressSpace::ADDRESS_SPACE_GENERIC || Count >= MaxLookup)
+      return AS;
+
+    // Continue traversing if address space is generic
+    const Value *VNext = getUnderlyingObject(V, 1);
+    if (VNext == V)
+      return AddressSpace::ADDRESS_SPACE_GENERIC;
+    V = VNext;
+  }
+}
----------------
Artem-B wrote:

Thank you! 

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


More information about the llvm-commits mailing list