Skip to content

Commit

Permalink
[MachineInstr] Implement new operand accessors all_defs and all_uses
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D151423
  • Loading branch information
jayfoad committed Jun 1, 2023
1 parent 06bb948 commit 11b5b2a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions llvm/include/llvm/CodeGen/MachineInstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ class MachineInstr
dumprImpl(const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth,
SmallPtrSetImpl<const MachineInstr *> &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;
Expand Down Expand Up @@ -702,6 +710,36 @@ class MachineInstr
operands_begin() + getNumExplicitOperands());
}

using filtered_mop_iterator =
filter_iterator<mop_iterator, std::function<bool(MachineOperand &)>>;
using filtered_const_mop_iterator =
filter_iterator<const_mop_iterator,
std::function<bool(const MachineOperand &)>>;

/// Returns an iterator range over all operands that are (explicit or
/// implicit) register defs.
iterator_range<filtered_mop_iterator> all_defs() {
return make_filter_range(operands(),
std::function<bool(MachineOperand &)>(opIsRegDef));
}
/// \copydoc all_defs()
iterator_range<filtered_const_mop_iterator> all_defs() const {
return make_filter_range(
operands(), std::function<bool(const MachineOperand &)>(opIsRegDef));
}

/// Returns an iterator range over all operands that are (explicit or
/// implicit) register uses.
iterator_range<filtered_mop_iterator> all_uses() {
return make_filter_range(uses(),
std::function<bool(MachineOperand &)>(opIsRegUse));
}
/// \copydoc all_uses()
iterator_range<filtered_const_mop_iterator> all_uses() const {
return make_filter_range(
uses(), std::function<bool(const MachineOperand &)>(opIsRegUse));
}

/// Returns the number of the operand iterator \p I points to.
unsigned getOperandNo(const_mop_iterator I) const {
return I - operands_begin();
Expand Down

0 comments on commit 11b5b2a

Please sign in to comment.