Skip to content

Commit

Permalink
Add front/back accessors to indexed_accessor_range.
Browse files Browse the repository at this point in the history
These map to the similar accessors on ArrayRef and other random access containers.

This fixes a compilation error on MLIR ODS for variadic operands/results, which relied on the availability of front in certain situations.
  • Loading branch information
River707 committed Jun 30, 2020
1 parent f01d9e6 commit 6b9a706
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,14 @@ class indexed_accessor_range_base {
assert(index < size() && "invalid index for value range");
return DerivedT::dereference_iterator(base, index);
}
ReferenceT front() const {
assert(!empty() && "expected non-empty range");
return (*this)[0];
}
ReferenceT back() const {
assert(!empty() && "expected non-empty range");
return (*this)[size() - 1];
}

/// Compare this range with another.
template <typename OtherT> bool operator==(const OtherT &other) const {
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/lib/Dialect/Test/TestOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ def MixedNormalVariadicOperandOp : TEST_Op<
Variadic<AnyTensor>:$input3
);
}
def VariadicWithSameOperandsResult :
TEST_Op<"variadic_with_same_operand_results",
[SameOperandsAndResultType]> {
let arguments = (ins Variadic<AnySignlessInteger>:$operands);
let results = (outs AnySignlessInteger:$result);
}

//===----------------------------------------------------------------------===//
// Test Results
Expand Down

0 comments on commit 6b9a706

Please sign in to comment.