[llvm] [SandboxIR] sandboxir::Use operands (part 1) and uses (part 2) (PR #98251)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 14:16:30 PDT 2024
================
@@ -123,9 +215,77 @@ class Value {
virtual ~Value() = default;
ClassID getSubclassID() const { return SubclassID; }
+ using use_iterator = UserUseIterator;
+ using const_use_iterator = UserUseIterator;
+
+ use_iterator use_begin();
+ const_use_iterator use_begin() const {
+ return const_cast<Value *>(this)->use_begin();
+ }
+ use_iterator use_end() { return use_iterator(Use(nullptr, nullptr, Ctx)); }
+ const_use_iterator use_end() const {
+ return const_cast<Value *>(this)->use_end();
+ }
+
+ iterator_range<use_iterator> uses() {
+ return make_range<use_iterator>(use_begin(), use_end());
+ }
+ iterator_range<const_use_iterator> uses() const {
+ return make_range<const_use_iterator>(use_begin(), use_end());
+ }
+
+ /// Helper for mapped_iterator.
+ struct UseToUser {
+ User *operator()(const Use &Use) const { return &*Use.getUser(); }
+ };
+
+ using user_iterator = mapped_iterator<sandboxir::UserUseIterator, UseToUser>;
+ using const_user_iterator = user_iterator;
+
+ user_iterator user_begin();
+ user_iterator user_end() {
+ return user_iterator(Use(nullptr, nullptr, Ctx), UseToUser());
+ }
+ const_user_iterator user_begin() const {
+ return const_cast<Value *>(this)->user_begin();
+ }
+ const_user_iterator user_end() const {
+ return const_cast<Value *>(this)->user_end();
+ }
+
+ iterator_range<user_iterator> users() {
+ return make_range<user_iterator>(user_begin(), user_end());
+ }
+ iterator_range<const_user_iterator> users() const {
+ return make_range<const_user_iterator>(user_begin(), user_end());
+ }
+ /// \Returns the number of user edges (not necessarily to unique users).
+ /// WARNING: This is a linear-time operation.
+ unsigned getNumUses() const;
+ /// Return true if this value has N uses or more.
+ /// This is logically equivalent to getNumUses() >= N.
+ /// WARNING: This can be expensive, as it is linear to the number of users.
+ bool hasNUsesOrMore(unsigned Num) const {
----------------
vporpo wrote:
I think they may be used in the vectorizer to skip instructions with too many uses.
https://github.com/llvm/llvm-project/pull/98251
More information about the llvm-commits
mailing list