From 62cd7511f3e146c699e3e60ce7a43a14b5ece9ce Mon Sep 17 00:00:00 2001 From: River Riddle Date: Mon, 1 Apr 2019 10:03:18 -0700 Subject: [PATCH] Rewrite ResultTypeIterator to be a mapped_iterator instead of an IndexedAccessorIterator. IndexedAccessorIterator makes some assumptions about the element type that do not hold for the result type, i.e. pointer elements. A mapped_iterator also better models the behavior of a ResultTypeIterator. -- PiperOrigin-RevId: 241345949 --- mlir/include/mlir/IR/Operation.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index 74a21fd..22005a0 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -554,18 +554,15 @@ public: }; /// This class implements the result type iterators for the Operation -/// class in terms of getResult(idx)->getType(). +/// class in terms of result_iterator->getType(). class ResultTypeIterator final - : public IndexedAccessorIterator { -public: - /// Initializes the result type iterator to the specified index. - ResultTypeIterator(Operation *object, unsigned index) - : IndexedAccessorIterator(object, - index) {} + : public llvm::mapped_iterator { + static Type unwrap(Value *value) { return value->getType(); } - Type operator*() const { - return this->object->getResult(this->index)->getType(); - } +public: + /// Initializes the result type iterator to the specified result iterator. + ResultTypeIterator(ResultIterator it) + : llvm::mapped_iterator(it, &unwrap) {} }; // Implement the inline result iterator methods. @@ -582,11 +579,11 @@ inline auto Operation::getResults() -> llvm::iterator_range { } inline auto Operation::result_type_begin() -> result_type_iterator { - return result_type_iterator(this, 0); + return result_type_iterator(result_begin()); } inline auto Operation::result_type_end() -> result_type_iterator { - return result_type_iterator(this, getNumResults()); + return result_type_iterator(result_end()); } inline auto Operation::getResultTypes() -- 2.7.4