Skip to content

Commit 8e7d984

Browse files
committed
[SIL] NFC: Added ValueBase::getUsers.
Make iterating user instructions a bit easier.
1 parent 45b5b4c commit 8e7d984

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

include/swift/SIL/SILValue.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,15 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
466466
/// entire use list.
467467
inline bool hasTwoUses() const;
468468

469-
/// Helper struct for DowncastUserFilterRange
469+
/// Helper struct for DowncastUserFilterRange and UserRange
470470
struct UseToUser;
471471

472+
using UserRange =
473+
llvm::iterator_range<llvm::mapped_iterator<swift::ValueBaseUseIterator,
474+
swift::ValueBase::UseToUser,
475+
swift::SILInstruction *>>;
476+
inline UserRange getUsers() const;
477+
472478
template <typename Subclass>
473479
using DowncastUserFilterRange =
474480
DowncastFilterRange<Subclass,
@@ -1439,6 +1445,10 @@ struct ValueBase::UseToUser {
14391445
SILInstruction *operator()(Operand &use) { return use.getUser(); }
14401446
};
14411447

1448+
inline ValueBase::UserRange ValueBase::getUsers() const {
1449+
return llvm::map_range(getUses(), ValueBase::UseToUser());
1450+
}
1451+
14421452
template <typename T>
14431453
inline ValueBase::DowncastUserFilterRange<T> ValueBase::getUsersOfType() const {
14441454
auto begin = llvm::map_iterator(use_begin(), UseToUser());

0 commit comments

Comments
 (0)