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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 22 12:29:25 PDT 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);
+  }
+
+  unsigned getFlags() const { return getInt(); }
+
+  bool operator==(const SCEVUse &RHS) const;
+  bool operator==(const SCEV *RHS) const;
+  /// Print out the internal representation of this scalar to the specified
+  /// stream.  This should really only be used for debugging purposes.
+  void print(raw_ostream &OS) const;
+
+  /// This method is used for debugging.
+  void dump() const;
+};
+
+/// Provide PointerLikeTypeTraits for SCEVUse, so it can be used with
+/// SmallPtrSet, among others.
+template <> struct PointerLikeTypeTraits<SCEVUse> {
----------------
artagnon wrote:

I don't think there's a way to escape PointerLikeTraits, as SmallPtrSet needs to work.

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


More information about the llvm-commits mailing list