[llvm] [Attributor] Change allocation size and load/store offsets using AAPointerInfo for Alloca instructions and keep track of instructions causing an Access (PR #72029)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 7 21:50:43 PST 2025


================
@@ -935,10 +951,111 @@ struct AA::PointerInfo::State : public AbstractState {
   BooleanState BS;
 };
 
+/// This function stores all the paths that lead to the access in AAPointerInfo.
+/// Arguments:
+/// - A: Attributor
+/// - OffsetInfoMap: Contains Accessed Offsets and Origins for AAPointerInfo.
+/// - LocalI: The Access causing instruction.
+//  We backtrack the access causing instruction and keep forking new paths as we
+//  encounter new predecessors which backtracking. At the end of the
+//  backtracking we store all the unique access causing paths in
+//  AccessPathSetTy.
+/// - Return: A set containing all the access causing paths.
+AAPointerInfo::AccessPathSetTy *AA::PointerInfo::State::findAllAccessPaths(
+    Attributor &A, AAPointerInfo::OffsetInfoMapTy &OffsetInfoMap,
+    Instruction *LocalI) {
+  AAPointerInfo::AccessPathSetTy *AccessPathsSet =
+      new (A.Allocator) AAPointerInfo::AccessPathSetTy();
+
+  // Store the instruction and its storage (i.e, which path it belongs to)
+  // on the stack.
+  // We also store the visited map on the stack.
+  // Since we want to find new paths, we want to make sure an instruction is
+  // not visited twice on the same path. However, we can visit the same
+  // instruction more that once if it exists on different paths.
+  using VisitedTy = SmallPtrSet<Value *, 4>;
+  using StackElementTy =
+      std::tuple<Value *, AAPointerInfo::AccessPathTy *, VisitedTy>;
+  using OffsetInfoTy = AAPointerInfo::OffsetInfo::OriginsTy;
+  using OriginTy = AAPointerInfo::OffsetInfo::OriginTy;
+
+  SmallVector<StackElementTy, 16> Stack;
+  // Populate the stack with elements.
+  // LocalI is the final instruction causing the access.
+  // To begin with, we fork new paths for the arguments of LocalI.
+  for (Use *It = LocalI->op_begin(); It != LocalI->op_end(); It++) {
+    Value *V = cast<Value>(It);
----------------
shiltian wrote:

I don't actually understand a `Use *` can be casted to `Value *`, since they don't have the same base class.

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


More information about the llvm-commits mailing list