Skip to content

Commit 6b9a706

Browse files
committed
Add front/back accessors to indexed_accessor_range.
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.
1 parent f01d9e6 commit 6b9a706

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,14 @@ class indexed_accessor_range_base {
11211121
assert(index < size() && "invalid index for value range");
11221122
return DerivedT::dereference_iterator(base, index);
11231123
}
1124+
ReferenceT front() const {
1125+
assert(!empty() && "expected non-empty range");
1126+
return (*this)[0];
1127+
}
1128+
ReferenceT back() const {
1129+
assert(!empty() && "expected non-empty range");
1130+
return (*this)[size() - 1];
1131+
}
11241132

11251133
/// Compare this range with another.
11261134
template <typename OtherT> bool operator==(const OtherT &other) const {

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ def MixedNormalVariadicOperandOp : TEST_Op<
124124
Variadic<AnyTensor>:$input3
125125
);
126126
}
127+
def VariadicWithSameOperandsResult :
128+
TEST_Op<"variadic_with_same_operand_results",
129+
[SameOperandsAndResultType]> {
130+
let arguments = (ins Variadic<AnySignlessInteger>:$operands);
131+
let results = (outs AnySignlessInteger:$result);
132+
}
127133

128134
//===----------------------------------------------------------------------===//
129135
// Test Results

0 commit comments

Comments
 (0)