[llvm] [SelectionDAG] Split sd_use_iterator into sd_user_iterator and sd_use_iterator. (PR #120531)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 07:42:32 PST 2024


================
@@ -837,29 +835,72 @@ END_TWO_BYTE_PACK()
     }
   };
 
+  class user_iterator {
+    friend class SDNode;
+    use_iterator UI;
+
+    explicit user_iterator(SDUse *op) : UI(op) {};
+
+  public:
+    using iterator_category = std::forward_iterator_tag;
+    using value_type = SDNode *;
+    using difference_type = std::ptrdiff_t;
+    using pointer = value_type *;
+    using reference = value_type &;
+
+    user_iterator() = default;
+
+    bool operator==(const user_iterator &x) const { return UI == x.UI; }
+    bool operator!=(const user_iterator &x) const { return !operator==(x); }
+
+    // /// Return true if this iterator is at the end of the uses list.
+    bool atEnd() const { return *this == user_iterator(); }
+
+    user_iterator &operator++() { // Preincrement
+      ++UI;
+      return *this;
+    }
+
+    user_iterator operator++(int) { // Postincrement
+      auto tmp = *this;
+      ++*this;
+      return tmp;
+    }
+
+    // Retrieve a pointer to the current User.
+    SDNode *operator*() const { return UI->getUser(); }
+
+    SDNode *operator->() const { return operator*(); }
+
+    SDUse &getUse() const { return *UI; }
----------------
topperc wrote:

I think I used it in one place where I changed the iterator from use_iterator to user_iterator, but I could change that. I put it in the interface because it exists in the IR equivalent.

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


More information about the llvm-commits mailing list