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 @@ -702,6 +702,33 @@ operands_begin() + getNumExplicitOperands()); } + /// Returns an iterator range over all operands that are (explicit or + /// implicit) register defs. + auto all_defs() { + return make_filter_range(operands(), [](MachineOperand &Op) { + return Op.isReg() && Op.isDef(); + }); + } + /// \copydoc all_defs() + auto all_defs() const { + return make_filter_range(operands(), [](const MachineOperand &Op) { + return Op.isReg() && Op.isDef(); + }); + } + + /// Returns an iterator range over all operands that are (explicit or + /// implicit) register uses. + auto all_uses() { + return make_filter_range( + uses(), [](MachineOperand &Op) { return Op.isReg() && Op.isUse(); }); + } + /// \copydoc all_uses() + auto all_uses() const { + return make_filter_range(uses(), [](const MachineOperand &Op) { + return Op.isReg() && Op.isUse(); + }); + } + /// Returns the number of the operand iterator \p I points to. unsigned getOperandNo(const_mop_iterator I) const { return I - operands_begin();