[Mlir-commits] [mlir] 0009811 - [MLIR] Use make_isa_range to implement getOps (NFC). (#224051)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 17 03:08:30 PDT 2026


Author: Florian Hahn
Date: 2026-09-17T11:08:24+01:00
New Revision: 00098111a304d7d16a0f91ac88a2052c32ea8b3a

URL: https://github.com/llvm/llvm-project/commit/00098111a304d7d16a0f91ac88a2052c32ea8b3a
DIFF: https://github.com/llvm/llvm-project/commit/00098111a304d7d16a0f91ac88a2052c32ea8b3a.diff

LOG: [MLIR] Use make_isa_range to implement getOps (NFC). (#224051)

Simplify implementation using make_isa_range from
https://github.com/llvm/llvm-project/pull/223414.

PR: https://github.com/llvm/llvm-project/pull/224051

Added: 
    

Modified: 
    mlir/include/mlir/IR/Block.h
    mlir/include/mlir/IR/BlockSupport.h
    mlir/include/mlir/IR/Region.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h
index c84921db220af..3638595358e25 100644
--- a/mlir/include/mlir/IR/Block.h
+++ b/mlir/include/mlir/IR/Block.h
@@ -16,6 +16,7 @@
 #include "mlir/IR/BlockSupport.h"
 #include "mlir/IR/Visitors.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 
 namespace llvm {
@@ -206,26 +207,11 @@ class alignas(8) Block : public IRObjectWithUseList<BlockOperand>,
   /// Recomputes the ordering of child operations within the block.
   void recomputeOpOrder();
 
-  /// This class provides iteration over the held operations of a block for a
-  /// specific operation type.
-  template <typename OpT>
-  using op_iterator = detail::op_iterator<OpT, iterator>;
-
   /// Return an iterator range over the operations within this block that are of
   /// 'OpT'.
   template <typename OpT>
-  iterator_range<op_iterator<OpT>> getOps() {
-    auto endIt = end();
-    return {detail::op_filter_iterator<OpT, iterator>(begin(), endIt),
-            detail::op_filter_iterator<OpT, iterator>(endIt, endIt)};
-  }
-  template <typename OpT>
-  op_iterator<OpT> op_begin() {
-    return detail::op_filter_iterator<OpT, iterator>(begin(), end());
-  }
-  template <typename OpT>
-  op_iterator<OpT> op_end() {
-    return detail::op_filter_iterator<OpT, iterator>(end(), end());
+  auto getOps() {
+    return llvm::make_isa_range<OpT>(*this);
   }
 
   /// Return an iterator range over the operation within this block excluding

diff  --git a/mlir/include/mlir/IR/BlockSupport.h b/mlir/include/mlir/IR/BlockSupport.h
index 782e977adbd7f..9468d800077c1 100644
--- a/mlir/include/mlir/IR/BlockSupport.h
+++ b/mlir/include/mlir/IR/BlockSupport.h
@@ -135,40 +135,6 @@ class BlockRange final
 // Operation Iterators
 //===----------------------------------------------------------------------===//
 
-namespace detail {
-/// A utility iterator that filters out operations that are not 'OpT'.
-template <typename OpT, typename IteratorT>
-class op_filter_iterator
-    : public llvm::filter_iterator<IteratorT, bool (*)(Operation &)> {
-  static bool filter(Operation &op) { return llvm::isa<OpT>(op); }
-
-public:
-  op_filter_iterator(IteratorT it, IteratorT end)
-      : llvm::filter_iterator<IteratorT, bool (*)(Operation &)>(it, end,
-                                                                &filter) {}
-
-  /// Allow implicit conversion to the underlying iterator.
-  operator const IteratorT &() const { return this->wrapped(); }
-};
-
-/// This class provides iteration over the held operations of a block for a
-/// specific operation type.
-template <typename OpT, typename IteratorT>
-class op_iterator
-    : public llvm::mapped_iterator<op_filter_iterator<OpT, IteratorT>,
-                                   OpT (*)(Operation &)> {
-  static OpT unwrap(Operation &op) { return cast<OpT>(op); }
-
-public:
-  /// Initializes the iterator to the specified filter iterator.
-  op_iterator(op_filter_iterator<OpT, IteratorT> it)
-      : llvm::mapped_iterator<op_filter_iterator<OpT, IteratorT>,
-                              OpT (*)(Operation &)>(it, &unwrap) {}
-
-  /// Allow implicit conversion to the underlying block iterator.
-  operator const IteratorT &() const { return this->wrapped(); }
-};
-} // namespace detail
 } // namespace mlir
 
 namespace llvm {

diff  --git a/mlir/include/mlir/IR/Region.h b/mlir/include/mlir/IR/Region.h
index a61eaaa54d401..1e433e759005c 100644
--- a/mlir/include/mlir/IR/Region.h
+++ b/mlir/include/mlir/IR/Region.h
@@ -173,32 +173,17 @@ class Region {
     Block::iterator operation;
   };
 
-  /// This class provides iteration over the held operations of a region for a
-  /// specific operation type.
-  template <typename OpT>
-  using op_iterator = detail::op_iterator<OpT, OpIterator>;
-
   /// Return iterators that walk the operations nested directly within this
   /// region.
   OpIterator op_begin() { return OpIterator(this); }
   OpIterator op_end() { return OpIterator(this, /*end=*/true); }
   iterator_range<OpIterator> getOps() { return {op_begin(), op_end()}; }
 
-  /// Return iterators that walk operations of type 'T' nested directly within
-  /// this region.
-  template <typename OpT>
-  op_iterator<OpT> op_begin() {
-    return detail::op_filter_iterator<OpT, OpIterator>(op_begin(), op_end());
-  }
-  template <typename OpT>
-  op_iterator<OpT> op_end() {
-    return detail::op_filter_iterator<OpT, OpIterator>(op_end(), op_end());
-  }
+  /// Return an iterator range over the operations nested directly within this
+  /// region that are of type 'OpT'.
   template <typename OpT>
-  iterator_range<op_iterator<OpT>> getOps() {
-    auto endIt = op_end();
-    return {detail::op_filter_iterator<OpT, OpIterator>(op_begin(), endIt),
-            detail::op_filter_iterator<OpT, OpIterator>(endIt, endIt)};
+  auto getOps() {
+    return llvm::make_isa_range<OpT>(llvm::make_range(op_begin(), op_end()));
   }
 
   //===--------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list