@@ -304,6 +304,14 @@ class MachineInstr
304
304
dumprImpl (const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth,
305
305
SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const ;
306
306
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
+
307
315
public:
308
316
MachineInstr (const MachineInstr &) = delete ;
309
317
MachineInstr &operator =(const MachineInstr &) = delete ;
@@ -702,6 +710,36 @@ class MachineInstr
702
710
operands_begin () + getNumExplicitOperands ());
703
711
}
704
712
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
+
705
743
// / Returns the number of the operand iterator \p I points to.
706
744
unsigned getOperandNo (const_mop_iterator I) const {
707
745
return I - operands_begin ();
0 commit comments