Skip to content

Commit 11b5b2a

Browse files
committed
[MachineInstr] Implement new operand accessors all_defs and all_uses
Differential Revision: https://reviews.llvm.org/D151423
1 parent 06bb948 commit 11b5b2a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ class MachineInstr
304304
dumprImpl(const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth,
305305
SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const;
306306

307+
static bool opIsRegDef(const MachineOperand &Op) {
308+
return Op.isReg() && Op.isDef();
309+
}
310+
311+
static bool opIsRegUse(const MachineOperand &Op) {
312+
return Op.isReg() && Op.isUse();
313+
}
314+
307315
public:
308316
MachineInstr(const MachineInstr &) = delete;
309317
MachineInstr &operator=(const MachineInstr &) = delete;
@@ -702,6 +710,36 @@ class MachineInstr
702710
operands_begin() + getNumExplicitOperands());
703711
}
704712

713+
using filtered_mop_iterator =
714+
filter_iterator<mop_iterator, std::function<bool(MachineOperand &)>>;
715+
using filtered_const_mop_iterator =
716+
filter_iterator<const_mop_iterator,
717+
std::function<bool(const MachineOperand &)>>;
718+
719+
/// Returns an iterator range over all operands that are (explicit or
720+
/// implicit) register defs.
721+
iterator_range<filtered_mop_iterator> all_defs() {
722+
return make_filter_range(operands(),
723+
std::function<bool(MachineOperand &)>(opIsRegDef));
724+
}
725+
/// \copydoc all_defs()
726+
iterator_range<filtered_const_mop_iterator> all_defs() const {
727+
return make_filter_range(
728+
operands(), std::function<bool(const MachineOperand &)>(opIsRegDef));
729+
}
730+
731+
/// Returns an iterator range over all operands that are (explicit or
732+
/// implicit) register uses.
733+
iterator_range<filtered_mop_iterator> all_uses() {
734+
return make_filter_range(uses(),
735+
std::function<bool(MachineOperand &)>(opIsRegUse));
736+
}
737+
/// \copydoc all_uses()
738+
iterator_range<filtered_const_mop_iterator> all_uses() const {
739+
return make_filter_range(
740+
uses(), std::function<bool(const MachineOperand &)>(opIsRegUse));
741+
}
742+
705743
/// Returns the number of the operand iterator \p I points to.
706744
unsigned getOperandNo(const_mop_iterator I) const {
707745
return I - operands_begin();

0 commit comments

Comments
 (0)