From 6b9a706200cbb27e5e863cfd41fb3684ee616e23 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Mon, 29 Jun 2020 22:37:05 -0700 Subject: [PATCH] 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. --- llvm/include/llvm/ADT/STLExtras.h | 8 ++++++++ mlir/test/lib/Dialect/Test/TestOps.td | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 1bc4c0c..b2e709f 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -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 bool operator==(const OtherT &other) const { diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 6aa18c1..bc8f2ff 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -124,6 +124,12 @@ def MixedNormalVariadicOperandOp : TEST_Op< Variadic:$input3 ); } +def VariadicWithSameOperandsResult : + TEST_Op<"variadic_with_same_operand_results", + [SameOperandsAndResultType]> { + let arguments = (ins Variadic:$operands); + let results = (outs AnySignlessInteger:$result); +} //===----------------------------------------------------------------------===// // Test Results -- 2.7.4