[llvm] [Attributor]: AApointerInfo - store the full chain of instructions that make up the access (PR #96526)

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 08:30:22 PDT 2024


================
@@ -6077,6 +6134,58 @@ struct AAPointerInfo : public AbstractAttribute {
       }
     }
 
+    // Generate the full chain of access cauing instruction to the
+    void storeCompleteInstructionChain(OffsetInfoMapTy &OffsetInfoMap) {
+
+      SmallVector<Instruction *> ReadyList;
+      DenseMap<Instruction *, bool> Visited;
+      ReadyList.push_back(LocalI);
+      CompleteAccessChain.push_back(LocalI);
+
+      while (!ReadyList.empty()) {
+
+        Instruction *Back = ReadyList.back();
+        ReadyList.pop_back();
+
+        if (!Visited.insert(std::make_pair(Back, true)).second)
+          continue;
+
+        // populate worklist with operands.
+        for (auto *It = Back->op_begin(); It != Back->op_end(); It++) {
+          if (Instruction *I = dyn_cast<Instruction>(It))
+            ReadyList.push_back(I);
+        }
+
+        if (!OffsetInfoMap.contains(Back))
+          continue;
+
+        const OffsetInfo &Info = OffsetInfoMap.lookup(Back);
+        const auto &OffsetVec = Info.Offsets;
+
+        // Check if the intermidiate instruction has at least one same Offset
+        // as the access causing local instruction.
+        // If so, we consider it part of the access causing chain of
+        // instructions.
+        bool HasAtLeastOneSameOffset = false;
+        for (auto *It = begin(); It != end(); It++) {
+          int64_t RangeOffset = It->Offset;
+          for (auto Offset : OffsetVec) {
+            if (RangeOffset == Offset) {
+              HasAtLeastOneSameOffset = true;
+              break;
+            }
+          }
+        }
+
+        if (HasAtLeastOneSameOffset)
+          CompleteAccessChain.push_back(Back);
+      }
+    }
+
+    const SmallVector<Instruction *> &getAccessChain() const {
+      return CompleteAccessChain;
+    }
+
----------------
jdoerfert wrote:

This does a second traversal even though we just traversed the instructions to get to the access. Let's track the instructions while we do the first traversal instead?

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


More information about the llvm-commits mailing list