mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[sil] Add a new API ValueBase::getSingleUser()
This API returns nullptr if the ValueBase has more than one user and an Operand * otherwise.
This commit is contained in:
@@ -174,6 +174,7 @@ public:
|
||||
bool use_empty() const { return FirstUse == nullptr; }
|
||||
|
||||
using use_iterator = ValueBaseUseIterator;
|
||||
using use_range = iterator_range<use_iterator>;
|
||||
|
||||
inline use_iterator use_begin() const;
|
||||
inline use_iterator use_end() const;
|
||||
@@ -181,13 +182,17 @@ public:
|
||||
/// Returns a range of all uses, which is useful for iterating over all uses.
|
||||
/// To ignore debug-info instructions use swift::getNonDebugUses instead
|
||||
/// (see comment in DebugUtils.h).
|
||||
inline iterator_range<use_iterator> getUses() const;
|
||||
inline use_range getUses() const;
|
||||
|
||||
/// Returns true if this value has exactly one use.
|
||||
/// To ignore debug-info instructions use swift::hasOneNonDebugUse instead
|
||||
/// (see comment in DebugUtils.h).
|
||||
inline bool hasOneUse() const;
|
||||
|
||||
/// Returns .some(single user) if this value has a single user. Returns .none
|
||||
/// otherwise.
|
||||
inline Operand *getSingleUse() const;
|
||||
|
||||
/// Pretty-print the value.
|
||||
void dump() const;
|
||||
void print(raw_ostream &OS) const;
|
||||
@@ -499,6 +504,13 @@ inline bool ValueBase::hasOneUse() const {
|
||||
if (I == E) return false;
|
||||
return ++I == E;
|
||||
}
|
||||
inline Operand *ValueBase::getSingleUse() const {
|
||||
auto I = use_begin(), E = use_end();
|
||||
if (I == E) return nullptr;
|
||||
++I;
|
||||
if (I != E) return nullptr;
|
||||
return *I;
|
||||
}
|
||||
|
||||
/// A constant-size list of the operands of an instruction.
|
||||
template <unsigned N> class FixedOperandList {
|
||||
|
||||
Reference in New Issue
Block a user