[llvm] [Attributor]: AApointerInfo - store the full chain of instructions that make up the access (PR #96526)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 08:26:51 PDT 2024
================
@@ -926,10 +933,101 @@ struct AA::PointerInfo::State : public AbstractState {
BooleanState BS;
};
+AAPointerInfo::Access::AccessPathSetTy *
+AA::PointerInfo::State::findAllAccessPaths(
+ AAPointerInfo::OffsetInfoMapTy &OffsetInfoMap, Instruction *LocalI) {
+
+ AAPointerInfo::Access::AccessPathSetTy *AccessPathsSet =
+ new AAPointerInfo::Access::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.
+ SmallVector<std::tuple<Value *, AAPointerInfo::Access::AccessPathTy *,
+ SmallPtrSet<Value *, 4>>,
+ 16>
+ Stack;
+
+ // Populate the stack with elements.
+ for (auto *It = LocalI->op_begin(); It != LocalI->op_end(); It++) {
+
+ Value *V = cast<Value>(It);
+
+ if (!OffsetInfoMap.contains(V))
+ continue;
+
+ SmallPtrSet<Value *, 4> LocalVisitedMap;
+ AAPointerInfo::Access::AccessPathTy *NewPath =
+ new AAPointerInfo::Access::AccessPathTy();
+ AccessPathsSet->insert(NewPath);
+ NewPath->push_back(LocalI);
+ Stack.push_back(std::make_tuple(V, NewPath, LocalVisitedMap));
+ }
+
+ while (!Stack.empty()) {
+
+ auto Entry = Stack.pop_back_val();
+ Value *Top = std::get<0>(Entry);
+ AAPointerInfo::Access::AccessPathTy *CurrentChain = std::get<1>(Entry);
+ auto &Visited = std::get<2>(Entry);
+
+ if (!OffsetInfoMap.contains(Top))
+ continue;
+
+ if (!Visited.insert(Top).second)
+ continue;
+
+ CurrentChain->push_back(Top);
+ auto OI = OffsetInfoMap.lookup(Top);
+ auto &Origins = OI.Origins;
+
+ SmallPtrSet<Value *, 16> Successors;
+ for (auto &Origin : Origins) {
+ for (auto *Val : Origin) {
+ // Since we store depth 1 predecessors in our Origins map
+ // We can be sure that we hit termination condition if the
+ // Successor is the current instruction.
+ if (Val != Top)
+ Successors.insert(Val);
+ }
+ }
+
+ if (Successors.size() == 0)
----------------
shiltian wrote:
`.empty()`
https://github.com/llvm/llvm-project/pull/96526
More information about the llvm-commits
mailing list