summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR
diff options
context:
space:
mode:
authorRiver Riddle <riverriddle@google.com>2019-12-07 10:35:01 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-07 10:35:41 -0800
commitd6ee6a031063cb99ca9828f1698a60536ffbb38a (patch)
treeb8b1b6ecf500d93818366914f56dc818054339f3 /mlir/lib/IR
parent9d1a0c72b4ae54b97809966257bd1b9cb3140dfe (diff)
downloadbcm5719-llvm-d6ee6a031063cb99ca9828f1698a60536ffbb38a.tar.gz
bcm5719-llvm-d6ee6a031063cb99ca9828f1698a60536ffbb38a.zip
Update the builder API to take ValueRange instead of ArrayRef<Value *>
This allows for users to provide operand_range and result_range in builder.create<> calls, instead of requiring an explicit copy into a separate data structure like SmallVector/std::vector. PiperOrigin-RevId: 284360710
Diffstat (limited to 'mlir/lib/IR')
-rw-r--r--mlir/lib/IR/Operation.cpp32
-rw-r--r--mlir/lib/IR/OperationSupport.cpp14
2 files changed, 45 insertions, 1 deletions
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 3ebc7129305..26f20d324f0 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -323,6 +323,13 @@ void Operation::replaceUsesOfWith(Value *from, Value *to) {
operand.set(to);
}
+/// Replace the current operands of this operation with the ones provided in
+/// 'operands'. If the operands list is not resizable, the size of 'operands'
+/// must be less than or equal to the current number of operands.
+void Operation::setOperands(ValueRange operands) {
+ getOperandStorage().setOperands(this, operands);
+}
+
//===----------------------------------------------------------------------===//
// Diagnostics
//===----------------------------------------------------------------------===//
@@ -760,6 +767,31 @@ ValueRange::ValueRange(llvm::iterator_range<ResultIterator> values)
}
}
+/// Drop the first N elements, and keep M elements.
+ValueRange ValueRange::slice(unsigned n, unsigned m) const {
+ assert(n + m <= size() && "Invalid specifier");
+ OwnerT newOwner;
+ if (OpOperand *operand = owner.dyn_cast<OpOperand *>())
+ newOwner = operand + n;
+ else if (OpResult *result = owner.dyn_cast<OpResult *>())
+ newOwner = result + n;
+ else
+ newOwner = owner.get<Value *const *>() + n;
+ return ValueRange(newOwner, m);
+}
+
+/// Drop the first n elements.
+ValueRange ValueRange::drop_front(unsigned n) const {
+ assert(size() >= n && "Dropping more elements than exist");
+ return slice(n, size() - n);
+}
+
+/// Drop the last n elements.
+ValueRange ValueRange::drop_back(unsigned n) const {
+ assert(size() >= n && "Dropping more elements than exist");
+ return ValueRange(owner, size() - n);
+}
+
ValueRange::Iterator::Iterator(OwnerT owner, unsigned curIndex)
: indexed_accessor_iterator<Iterator, OwnerT, Value *, Value *, Value *>(
owner, curIndex) {}
diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp
index ab665f50c67..2c9a9cce86b 100644
--- a/mlir/lib/IR/OperationSupport.cpp
+++ b/mlir/lib/IR/OperationSupport.cpp
@@ -50,6 +50,18 @@ OperationState::OperationState(Location location, StringRef name,
this->regions.push_back(std::move(r));
}
+void OperationState::addOperands(ValueRange newOperands) {
+ assert(successors.empty() && "Non successor operands should be added first.");
+ operands.append(newOperands.begin(), newOperands.end());
+}
+
+void OperationState::addSuccessor(Block *successor, ValueRange succOperands) {
+ successors.push_back(successor);
+ // Insert a sentinel operand to mark a barrier between successor operands.
+ operands.push_back(nullptr);
+ operands.append(succOperands.begin(), succOperands.end());
+}
+
Region *OperationState::addRegion() {
regions.emplace_back(new Region);
return regions.back().get();
@@ -66,7 +78,7 @@ void OperationState::addRegion(std::unique_ptr<Region> &&region) {
/// Replace the operands contained in the storage with the ones provided in
/// 'operands'.
void detail::OperandStorage::setOperands(Operation *owner,
- ArrayRef<Value *> operands) {
+ ValueRange operands) {
// If the number of operands is less than or equal to the current amount, we
// can just update in place.
if (operands.size() <= numOperands) {
OpenPOWER on IntegriCloud