diff options
| author | River Riddle <riverriddle@google.com> | 2020-01-02 14:28:37 -0800 |
|---|---|---|
| committer | River Riddle <riverriddle@google.com> | 2020-01-02 14:40:09 -0800 |
| commit | fd01d8626cdcce9f34caab060f8d3fd35f6661cc (patch) | |
| tree | 10181d726e607c5eaff7ff3428f2d6b9f2dd5eeb /mlir/lib/IR/OperationSupport.cpp | |
| parent | 1c45852c828dae0dd15136cda3d7fd6af0f75dc7 (diff) | |
| download | bcm5719-llvm-fd01d8626cdcce9f34caab060f8d3fd35f6661cc.tar.gz bcm5719-llvm-fd01d8626cdcce9f34caab060f8d3fd35f6661cc.zip | |
[mlir] Rewrite the internal representation of OpResult to be optimized for memory.
Summary:
This changes the implementation of OpResult to have some of the results be represented inline in Value, via a pointer int pair of Operation*+result number, and the rest being trailing objects on the main operation. The full details of the new representation is detailed in the proposal here:
https://groups.google.com/a/tensorflow.org/g/mlir/c/XXzzKhqqF_0/m/v6bKb08WCgAJ
The only difference between here and the above proposal is that we only steal 2-bits for the Value kind instead of 3. This means that we can only fit 2-results inline instead of 6. This allows for other users to steal the final bit for PointerUnion/etc. If necessary, we can always steal this bit back in the future to save more space if 3-6 results are common enough.
Reviewed By: jpienaar
Differential Revision: https://reviews.llvm.org/D72020
Diffstat (limited to 'mlir/lib/IR/OperationSupport.cpp')
| -rw-r--r-- | mlir/lib/IR/OperationSupport.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp index 5dfd3b02cc6..436c8325cb6 100644 --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -150,7 +150,12 @@ OperandRange::OperandRange(Operation *op) // ResultRange ResultRange::ResultRange(Operation *op) - : ResultRange(op->getOpResults().data(), op->getNumResults()) {} + : ResultRange(op, /*startIndex=*/0, op->getNumResults()) {} + +/// See `detail::indexed_accessor_range_base` for details. +OpResult ResultRange::dereference_iterator(Operation *op, ptrdiff_t index) { + return op->getResult(index); +} //===----------------------------------------------------------------------===// // ValueRange @@ -160,25 +165,26 @@ ValueRange::ValueRange(ArrayRef<Value> values) ValueRange::ValueRange(OperandRange values) : ValueRange(values.begin().getBase(), values.size()) {} ValueRange::ValueRange(ResultRange values) - : ValueRange(values.begin().getBase(), values.size()) {} + : ValueRange( + {values.getBase(), static_cast<unsigned>(values.getStartIndex())}, + values.size()) {} /// See `detail::indexed_accessor_range_base` for details. ValueRange::OwnerT ValueRange::offset_base(const OwnerT &owner, ptrdiff_t index) { - if (OpOperand *operand = owner.dyn_cast<OpOperand *>()) - return operand + index; - if (OpResult *result = owner.dyn_cast<OpResult *>()) - return result + index; - return owner.get<const Value *>() + index; + if (auto *value = owner.ptr.dyn_cast<const Value *>()) + return {value + index}; + if (auto *operand = owner.ptr.dyn_cast<OpOperand *>()) + return {operand + index}; + Operation *operation = reinterpret_cast<Operation *>(owner.ptr.get<void *>()); + return {operation, owner.startIndex + static_cast<unsigned>(index)}; } /// See `detail::indexed_accessor_range_base` for details. Value ValueRange::dereference_iterator(const OwnerT &owner, ptrdiff_t index) { - // Operands access the held value via 'get'. - if (OpOperand *operand = owner.dyn_cast<OpOperand *>()) + if (auto *value = owner.ptr.dyn_cast<const Value *>()) + return value[index]; + if (auto *operand = owner.ptr.dyn_cast<OpOperand *>()) return operand[index].get(); - // An OpResult is a value, so we can return it directly. - if (OpResult *result = owner.dyn_cast<OpResult *>()) - return result[index]; - // Otherwise, this is a raw value array so just index directly. - return owner.get<const Value *>()[index]; + Operation *operation = reinterpret_cast<Operation *>(owner.ptr.get<void *>()); + return operation->getResult(owner.startIndex + index); } |

