[llvm] 11b5b2a - [MachineInstr] Implement new operand accessors all_defs and all_uses
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 1 09:25:36 PDT 2023
Author: Jay Foad
Date: 2023-06-01T17:20:33+01:00
New Revision: 11b5b2a839c677bce9244893c9117706297b6025
URL: https://github.com/llvm/llvm-project/commit/11b5b2a839c677bce9244893c9117706297b6025
DIFF: https://github.com/llvm/llvm-project/commit/11b5b2a839c677bce9244893c9117706297b6025.diff
LOG: [MachineInstr] Implement new operand accessors all_defs and all_uses
Differential Revision: https://reviews.llvm.org/D151423
Added:
Modified:
llvm/include/llvm/CodeGen/MachineInstr.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index 411653abf6ae..5f4a38d2c920 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -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;
@@ -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();
More information about the llvm-commits
mailing list