From 979ffe97b9bf925a9d1448d13aa4737cfda8fc35 Mon Sep 17 00:00:00 2001 From: Mogball Date: Fri, 25 Mar 2022 22:44:34 +0000 Subject: [PATCH] [mlir] Allow RegionRange to accept ArrayRef Adds another pointer to the union in RegionRange to allow RegionRange to work on ArrayRef (i.e. vectors of Region *). Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D122514 --- mlir/include/mlir/IR/Region.h | 12 ++++++++---- mlir/lib/IR/Region.cpp | 14 ++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mlir/include/mlir/IR/Region.h b/mlir/include/mlir/IR/Region.h index c2694ad..3a1e57b 100644 --- a/mlir/include/mlir/IR/Region.h +++ b/mlir/include/mlir/IR/Region.h @@ -321,11 +321,14 @@ private: /// parameter. class RegionRange : public llvm::detail::indexed_accessor_range_base< - RegionRange, PointerUnion *>, + RegionRange, + PointerUnion *, Region **>, Region *, Region *, Region *> { - /// The type representing the owner of this range. This is either a list of - /// values, operands, or results. - using OwnerT = PointerUnion *>; + /// The type representing the owner of this range. This is either an owning + /// list of regions, a list of region unique pointers, or a list of region + /// pointers. + using OwnerT = + PointerUnion *, Region **>; public: using RangeBaseT::RangeBaseT; @@ -339,6 +342,7 @@ public: : RegionRange(ArrayRef>(std::forward(arg))) { } RegionRange(ArrayRef> regions); + RegionRange(ArrayRef regions); private: /// See `llvm::detail::indexed_accessor_range_base` for details. diff --git a/mlir/lib/IR/Region.cpp b/mlir/lib/IR/Region.cpp index 8739b98..a5bca20 100644 --- a/mlir/lib/IR/Region.cpp +++ b/mlir/lib/IR/Region.cpp @@ -228,18 +228,24 @@ RegionRange::RegionRange(MutableArrayRef regions) : RegionRange(regions.data(), regions.size()) {} RegionRange::RegionRange(ArrayRef> regions) : RegionRange(regions.data(), regions.size()) {} +RegionRange::RegionRange(ArrayRef regions) + : RegionRange(const_cast(regions.data()), regions.size()) {} /// See `llvm::detail::indexed_accessor_range_base` for details. RegionRange::OwnerT RegionRange::offset_base(const OwnerT &owner, ptrdiff_t index) { - if (auto *operand = owner.dyn_cast *>()) - return operand + index; + if (auto *region = owner.dyn_cast *>()) + return region + index; + if (auto **region = owner.dyn_cast()) + return region + index; return &owner.get()[index]; } /// See `llvm::detail::indexed_accessor_range_base` for details. Region *RegionRange::dereference_iterator(const OwnerT &owner, ptrdiff_t index) { - if (auto *operand = owner.dyn_cast *>()) - return operand[index].get(); + if (auto *region = owner.dyn_cast *>()) + return region[index].get(); + if (auto **region = owner.dyn_cast()) + return region[index]; return &owner.get()[index]; } -- 2.7.4