Add front/back accessors to indexed_accessor_range.
authorRiver Riddle <riddleriver@gmail.com>
Tue, 30 Jun 2020 05:37:05 +0000 (22:37 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Tue, 30 Jun 2020 05:41:15 +0000 (22:41 -0700)
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.

llvm/include/llvm/ADT/STLExtras.h
mlir/test/lib/Dialect/Test/TestOps.td

index 1bc4c0c..b2e709f 100644 (file)
@@ -1121,6 +1121,14 @@ public:
     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 {
index 6aa18c1..bc8f2ff 100644 (file)
@@ -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