diff options
Diffstat (limited to 'mlir/lib/IR/Operation.cpp')
-rw-r--r-- | mlir/lib/IR/Operation.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
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()) |