From: Jay Foad Date: Wed, 24 May 2023 13:19:33 +0000 (+0100) Subject: [MachineInstr] Implement new operand accessors all_defs and all_uses X-Git-Tag: upstream/17.0.6~6468 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11b5b2a839c677bce9244893c9117706297b6025;p=platform%2Fupstream%2Fllvm.git [MachineInstr] Implement new operand accessors all_defs and all_uses Differential Revision: https://reviews.llvm.org/D151423 --- diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index 411653a..5f4a38d 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -304,6 +304,14 @@ private: 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 @@ public: 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();