[llvm] [NFC] [DSE] Refactor DSE (PR #100956)

Jan Voung via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 08:06:40 PDT 2024


================
@@ -806,6 +806,38 @@ bool canSkipDef(MemoryDef *D, bool DefVisibleToCaller) {
   return false;
 }
 
+// A memory location wrapper that represents a MemoryLocation, `MemLoc`,
+// defined by `MemDef`.
+class MemoryLocationWrapper {
+public:
+  MemoryLocationWrapper(MemoryLocation MemLoc, MemoryDef *MemDef)
+      : MemLoc(MemLoc), MemDef(MemDef) {
+    assert(MemLoc.Ptr && "MemLoc should be not null");
+    UnderlyingObject = getUnderlyingObject(MemLoc.Ptr);
+    DefInst = MemDef->getMemoryInst();
+  }
+
+  MemoryAccess *GetDefiningAccess() const {
+    return MemDef->getDefiningAccess();
+  }
+
+  MemoryLocation MemLoc;
+  const Value *UnderlyingObject;
+  MemoryDef *MemDef;
+  Instruction *DefInst;
+};
+
+// A memory def wrapper that represents a MemoryDef and the MemoryLocation(s)
+// defined by this MemoryDef.
+class MemoryDefWrapper {
+public:
+  MemoryDefWrapper(MemoryDef *MemDef, std::optional<MemoryLocation> MemLoc) {
+    if (MemLoc.has_value())
+      DefinedLocation = MemoryLocationWrapper(*MemLoc, MemDef);
+  }
+  std::optional<MemoryLocationWrapper> DefinedLocation = std::nullopt;
----------------
jvoung wrote:

In a later stage this becomes a SmallVector of MemoryLocationWrapper. Is that right?

Do the MemoryLocationWrapper all have the same MemoryDef and DefInst?
I wonder if that's actually worth bundling in MemoryLocationWrapper (and thus repeating), or if the SmallVector should just be the MemoryLocation and UnderlyingObject (the non-repeating parts)?

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


More information about the llvm-commits mailing list