[PATCH] D151423: [MachineInstr] Implement new operand accessors all_defs and all_uses

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 09:25:46 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG11b5b2a839c6: [MachineInstr] Implement new operand accessors all_defs and all_uses (authored by foad).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151423/new/

https://reviews.llvm.org/D151423

Files:
  llvm/include/llvm/CodeGen/MachineInstr.h


Index: llvm/include/llvm/CodeGen/MachineInstr.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineInstr.h
+++ llvm/include/llvm/CodeGen/MachineInstr.h
@@ -304,6 +304,14 @@
   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 @@
                       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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151423.527455.patch
Type: text/x-patch
Size: 2204 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230601/ab225131/attachment.bin>


More information about the llvm-commits mailing list