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

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 02:35:17 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(); }
----------------
jayfoad wrote:

Do we need this? Seems like a weird thing for an iterator to provide. If we do, the implementation could just delegate to `UI.atEnd()`.

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


More information about the llvm-commits mailing list