[llvm] [SCEV] Introduce SCEVUse, use it instead of const SCEV * (NFCI) (WIP). (PR #91961)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 11:22:12 PST 2024


================
@@ -65,6 +65,117 @@ enum SCEVTypes : unsigned short;
 
 extern bool VerifySCEV;
 
+class SCEV;
+
+class SCEVUse : public PointerIntPair<const SCEV *, 3> {
+  bool computeIsCanonical() const;
+  const SCEV *computeCanonical(ScalarEvolution &SE) const;
+
+public:
+  SCEVUse() : PointerIntPair(nullptr, 0) {}
+  SCEVUse(const SCEV *S) : PointerIntPair(S, 0) {}
+  SCEVUse(const SCEV *S, int Flags) : PointerIntPair(S, Flags) {
+    if (Flags > 0)
+      setInt(Flags | 1);
+  }
+
+  operator const SCEV *() const { return getPointer(); }
+  const SCEV *operator->() const { return getPointer(); }
+  const SCEV *operator->() { return getPointer(); }
+
+  void *getRawPointer() const { return getOpaqueValue(); }
+
+  bool isCanonical() const {
+    assert(((getFlags() & 1) != 0 || computeIsCanonical()) &&
+           "Canonical bit set incorrectly");
+    return (getFlags() & 1) == 0;
+  }
+
+  const SCEV *getCanonical(ScalarEvolution &SE) {
+    if (isCanonical())
+      return getPointer();
+    return computeCanonical(SE);
----------------
fhahn wrote:

One problem with constructing the canonical form is that it needs access to a `ScalarEvolution` object, which currently isn't available in the constructors unfortunately, which makes this a bit cumbersome.

The latest version stores a pointer to the canonical version as suggested by @nikic , which avoids this

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


More information about the llvm-commits mailing list