diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -304,6 +304,14 @@ dumprImpl(const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth, SmallPtrSetImpl &AlreadySeenInstrs) const; + static bool opIsRegDef(const MachineOperand &Op) { + return Op.isReg() && Op.isDef(); + } + + static bool opIsRegUse(const MachineOperand &Op) { + return Op.isReg() && Op.isUse(); + } + public: MachineInstr(const MachineInstr &) = delete; MachineInstr &operator=(const MachineInstr &) = delete; @@ -702,6 +710,36 @@ operands_begin() + getNumExplicitOperands()); } + using filtered_mop_iterator = + filter_iterator>; + using filtered_const_mop_iterator = + filter_iterator>; + + /// Returns an iterator range over all operands that are (explicit or + /// implicit) register defs. + iterator_range all_defs() { + return make_filter_range(operands(), + std::function(opIsRegDef)); + } + /// \copydoc all_defs() + iterator_range all_defs() const { + return make_filter_range( + operands(), std::function(opIsRegDef)); + } + + /// Returns an iterator range over all operands that are (explicit or + /// implicit) register uses. + iterator_range all_uses() { + return make_filter_range(uses(), + std::function(opIsRegUse)); + } + /// \copydoc all_uses() + iterator_range all_uses() const { + return make_filter_range( + uses(), std::function(opIsRegUse)); + } + /// Returns the number of the operand iterator \p I points to. unsigned getOperandNo(const_mop_iterator I) const { return I - operands_begin();