summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR
diff options
context:
space:
mode:
authorJacques Pienaar <jpienaar@google.com>2019-12-09 08:57:27 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-09 08:57:56 -0800
commit70aeb4566e35541ffeef28050babc1c9580b43eb (patch)
tree5955edd534f872ecc7ef626436e5ac63224acc17 /mlir/lib/IR
parent7b19bd5411a68399db4bcf3c2804a67f1d0b3a62 (diff)
downloadbcm5719-llvm-70aeb4566e35541ffeef28050babc1c9580b43eb.tar.gz
bcm5719-llvm-70aeb4566e35541ffeef28050babc1c9580b43eb.zip
Add RegionRange for when need to abstract over different region iteration
Follows ValueRange in representing a generic abstraction over the different ways to represent a range of Regions. This wrapper is not as ValueRange and only considers the current cases of interest: MutableArrayRef<Region> and ArrayRef<std::unique_ptr<Region>> as occurs during op construction vs op region querying. Note: ArrayRef<std::unique_ptr<Region>> allows for unset regions, so this range returns a pointer to a Region instead of a Region. PiperOrigin-RevId: 284563229
Diffstat (limited to 'mlir/lib/IR')
-rw-r--r--mlir/lib/IR/Operation.cpp3
-rw-r--r--mlir/lib/IR/Region.cpp18
2 files changed, 19 insertions, 2 deletions
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 26f20d324f0..ae635d108b2 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -136,8 +136,7 @@ Operation *Operation::create(Location location, OperationName name,
ArrayRef<Type> resultTypes,
ArrayRef<Value *> operands,
NamedAttributeList attributes,
- ArrayRef<Block *> successors,
- ArrayRef<std::unique_ptr<Region>> regions,
+ ArrayRef<Block *> successors, RegionRange regions,
bool resizableOperandList) {
unsigned numRegions = regions.size();
Operation *op = create(location, name, resultTypes, operands, attributes,
diff --git a/mlir/lib/IR/Region.cpp b/mlir/lib/IR/Region.cpp
index a91d36b1e48..a5a19cbcbf2 100644
--- a/mlir/lib/IR/Region.cpp
+++ b/mlir/lib/IR/Region.cpp
@@ -213,3 +213,21 @@ void llvm::ilist_traits<::mlir::Block>::transferNodesFromList(
for (; first != last; ++first)
first->parentValidOpOrderPair.setPointer(curParent);
}
+
+//===----------------------------------------------------------------------===//
+// RegionRange
+//===----------------------------------------------------------------------===//
+RegionRange::RegionRange(MutableArrayRef<Region> regions)
+ : owner(regions.data()), count(regions.size()) {}
+RegionRange::RegionRange(ArrayRef<std::unique_ptr<Region>> regions)
+ : owner(regions.data()), count(regions.size()) {}
+RegionRange::Iterator::Iterator(OwnerT owner, unsigned curIndex)
+ : indexed_accessor_iterator<Iterator, OwnerT, Region *, Region *, Region *>(
+ owner, curIndex) {}
+
+Region *RegionRange::Iterator::operator*() const {
+ if (const std::unique_ptr<Region> *operand =
+ object.dyn_cast<const std::unique_ptr<Region> *>())
+ return operand[index].get();
+ return &object.get<Region *>()[index];
+}
OpenPOWER on IntegriCloud