diff options
| author | River Riddle <riverriddle@google.com> | 2019-12-23 11:18:53 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-12-23 15:44:00 -0800 |
| commit | f603a50109107b447b835dac11f0eb541288393e (patch) | |
| tree | a36f5e8e36cb4408819a9f7ab570fda449558e5f /mlir/lib/IR | |
| parent | 56222a0694e4caf35e892d70591417c39fef1185 (diff) | |
| download | bcm5719-llvm-f603a50109107b447b835dac11f0eb541288393e.tar.gz bcm5719-llvm-f603a50109107b447b835dac11f0eb541288393e.zip | |
ReImplement the Value classes as value-typed objects wrapping an internal pointer storage.
This will enable future commits to reimplement the internal implementation of OpResult without needing to change all of the existing users. This is part of a chain of commits optimizing the size of operation results.
PiperOrigin-RevId: 286919966
Diffstat (limited to 'mlir/lib/IR')
| -rw-r--r-- | mlir/lib/IR/AsmPrinter.cpp | 6 | ||||
| -rw-r--r-- | mlir/lib/IR/Block.cpp | 11 | ||||
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 26 | ||||
| -rw-r--r-- | mlir/lib/IR/OperationSupport.cpp | 15 | ||||
| -rw-r--r-- | mlir/lib/IR/TypeUtilities.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/IR/Value.cpp | 4 |
6 files changed, 34 insertions, 32 deletions
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index a574f87c530..4eeb5e4e95c 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -1612,7 +1612,7 @@ void OperationPrinter::numberValuesInRegion(Region ®ion) { void OperationPrinter::numberValuesInBlock(Block &block) { auto setArgNameFn = [&](ValuePtr arg, StringRef name) { assert(!valueIDs.count(arg) && "arg numbered multiple times"); - assert(cast<BlockArgument>(arg)->getOwner() == &block && + assert(arg.cast<BlockArgument>()->getOwner() == &block && "arg not defined in 'block'"); setValueName(arg, name); }; @@ -1658,7 +1658,7 @@ void OperationPrinter::numberValuesInOp(Operation &op) { setValueName(result, name); // Record the result number for groups not anchored at 0. - if (int resultNo = cast<OpResult>(result)->getResultNumber()) + if (int resultNo = result.cast<OpResult>()->getResultNumber()) resultGroups.push_back(resultNo); }; @@ -1831,7 +1831,7 @@ void OperationPrinter::printValueIDImpl(ValuePtr value, bool printResultNo, // If this is a reference to the result of a multi-result operation or // operation, print out the # identifier and make sure to map our lookup // to the first result of the operation. - if (OpResultPtr result = dyn_cast<OpResult>(value)) + if (OpResultPtr result = value.dyn_cast<OpResult>()) getResultIDAndNumber(result, lookupValue, resultNo); auto it = valueIDs.find(lookupValue); diff --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp index b168a8facd2..3abbe1027ce 100644 --- a/mlir/lib/IR/Block.cpp +++ b/mlir/lib/IR/Block.cpp @@ -16,10 +16,10 @@ using namespace mlir; //===----------------------------------------------------------------------===// /// Returns the number of this argument. -unsigned BlockArgument::getArgNumber() { +unsigned BlockArgument::getArgNumber() const { // Arguments are not stored in place, so we have to find it within the list. auto argList = getOwner()->getArguments(); - return std::distance(argList.begin(), llvm::find(argList, this)); + return std::distance(argList.begin(), llvm::find(argList, *this)); } //===----------------------------------------------------------------------===// @@ -29,7 +29,8 @@ unsigned BlockArgument::getArgNumber() { Block::~Block() { assert(!verifyOpOrder() && "Expected valid operation ordering."); clear(); - llvm::DeleteContainerPointers(arguments); + for (BlockArgument arg : arguments) + arg.destroy(); } Region *Block::getParent() const { return parentValidOpOrderPair.getPointer(); } @@ -143,7 +144,7 @@ void Block::recomputeOpOrder() { //===----------------------------------------------------------------------===// BlockArgumentPtr Block::addArgument(Type type) { - auto *arg = new BlockArgument(type, this); + BlockArgument arg = BlockArgument::create(type, this); arguments.push_back(arg); return arg; } @@ -163,7 +164,7 @@ void Block::eraseArgument(unsigned index, bool updatePredTerms) { assert(index < arguments.size()); // Delete the argument. - delete arguments[index]; + arguments[index].destroy(); arguments.erase(arguments.begin() + index); // If we aren't updating predecessors, there is nothing left to do. diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 1dc7cb4bafd..77288b228aa 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -68,23 +68,29 @@ OperationName OperationName::getFromOpaquePointer(void *pointer) { //===----------------------------------------------------------------------===// /// Return the result number of this result. -unsigned OpResult::getResultNumber() { - // Results are always stored consecutively, so use pointer subtraction to - // figure out what number this is. - return this - &getOwner()->getOpResults()[0]; +unsigned OpResult::getResultNumber() const { + // Results are not stored in place, so we have to find it within the list. + auto resList = getOwner()->getOpResults(); + return std::distance(resList.begin(), llvm::find(resList, *this)); } //===----------------------------------------------------------------------===// // OpOperand //===----------------------------------------------------------------------===// -// TODO: This namespace is only required because of a bug in GCC<7.0. -namespace mlir { +OpOperand::OpOperand(Operation *owner, Value value) + : IROperand(owner, value.impl) {} + +/// Return the current value being used by this operand. +Value OpOperand::get() { return (detail::ValueImpl *)IROperand::get(); } + +/// Set the current value being used by this operand. +void OpOperand::set(Value newValue) { IROperand::set(newValue.impl); } + /// Return which operand this is in the operand list. -template <> unsigned OpOperand::getOperandNumber() { +unsigned OpOperand::getOperandNumber() { return this - &getOwner()->getOpOperands()[0]; } -} // end namespace mlir //===----------------------------------------------------------------------===// // BlockOperand @@ -179,7 +185,7 @@ Operation *Operation::create(Location location, OperationName name, auto instResults = op->getOpResults(); for (unsigned i = 0, e = resultTypes.size(); i != e; ++i) - new (&instResults[i]) OpResult(resultTypes[i], op); + new (&instResults[i]) OpResult(OpResult::create(resultTypes[i], op)); auto opOperands = op->getOpOperands(); @@ -256,7 +262,7 @@ Operation::~Operation() { getOperandStorage().~OperandStorage(); for (auto &result : getOpResults()) - result.~OpResult(); + result.destroy(); // Explicitly run the destructors for the successors. for (auto &successor : getBlockOperands()) diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp index 1c68686a0cb..5dfd3b02cc6 100644 --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -155,7 +155,7 @@ ResultRange::ResultRange(Operation *op) //===----------------------------------------------------------------------===// // ValueRange -ValueRange::ValueRange(ArrayRef<ValuePtr> values) +ValueRange::ValueRange(ArrayRef<Value> values) : ValueRange(values.data(), values.size()) {} ValueRange::ValueRange(OperandRange values) : ValueRange(values.begin().getBase(), values.size()) {} @@ -167,19 +167,18 @@ ValueRange::OwnerT ValueRange::offset_base(const OwnerT &owner, ptrdiff_t index) { if (OpOperand *operand = owner.dyn_cast<OpOperand *>()) return operand + index; - if (OpResultPtr result = owner.dyn_cast<OpResultPtr>()) + if (OpResult *result = owner.dyn_cast<OpResult *>()) return result + index; - return owner.get<ValuePtr const *>() + index; + return owner.get<const Value *>() + index; } /// See `detail::indexed_accessor_range_base` for details. -ValuePtr ValueRange::dereference_iterator(const OwnerT &owner, - ptrdiff_t index) { +Value ValueRange::dereference_iterator(const OwnerT &owner, ptrdiff_t index) { // Operands access the held value via 'get'. if (OpOperand *operand = owner.dyn_cast<OpOperand *>()) return operand[index].get(); // An OpResult is a value, so we can return it directly. - if (OpResultPtr result = owner.dyn_cast<OpResultPtr>()) - return &result[index]; + if (OpResult *result = owner.dyn_cast<OpResult *>()) + return result[index]; // Otherwise, this is a raw value array so just index directly. - return owner.get<ValuePtr const *>()[index]; + return owner.get<const Value *>()[index]; } diff --git a/mlir/lib/IR/TypeUtilities.cpp b/mlir/lib/IR/TypeUtilities.cpp index 8bc67e46fdc..1fa13a85c51 100644 --- a/mlir/lib/IR/TypeUtilities.cpp +++ b/mlir/lib/IR/TypeUtilities.cpp @@ -28,10 +28,6 @@ Type mlir::getElementTypeOrSelf(ValuePtr val) { return getElementTypeOrSelf(val->getType()); } -Type mlir::getElementTypeOrSelf(ValueRef val) { - return getElementTypeOrSelf(val.getType()); -} - Type mlir::getElementTypeOrSelf(Attribute attr) { return getElementTypeOrSelf(attr.getType()); } diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp index d723eec8b29..ffb9601f1c9 100644 --- a/mlir/lib/IR/Value.cpp +++ b/mlir/lib/IR/Value.cpp @@ -13,8 +13,8 @@ using namespace mlir; /// If this value is the result of an Operation, return the operation that /// defines it. -Operation *Value::getDefiningOp() { - if (auto *result = dyn_cast<OpResult>()) +Operation *Value::getDefiningOp() const { + if (auto result = dyn_cast<OpResult>()) return result->getOwner(); return nullptr; } |

