Skip to content

[mlir][IR] Change MutableOperandRange::operator[] to return an OpOperand & #66515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mlir/include/mlir/IR/ValueRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ class MutableOperandRange {
/// elements attribute, which contains the sizes of the sub ranges.
MutableOperandRangeRange split(NamedAttribute segmentSizes) const;

/// Returns the value at the given index.
Value operator[](unsigned index) const {
return operator OperandRange()[index];
}
/// Returns the OpOperand at the given index.
OpOperand &operator[](unsigned index) const;

OperandRange::iterator begin() const {
return static_cast<OperandRange>(*this).begin();
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SuccessorOperands {
Value operator[](unsigned index) const {
if (isOperandProduced(index))
return Value();
return forwardedOperands[index - producedOperandCount];
return forwardedOperands[index - producedOperandCount].get();
}

/// Get the range of operands that are simply forwarded to the successor.
Expand Down
10 changes: 3 additions & 7 deletions mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,22 +549,18 @@ LogicalResult DeallocTensorOp::bufferize(RewriterBase &rewriter,

bool MaterializeInDestinationOp::bufferizesToMemoryRead(
OpOperand &opOperand, const AnalysisState &state) {
if (&opOperand == &getOperation()->getOpOperand(0) /*source*/)
return true;
return false;
return &opOperand == &getSourceMutable()[0];
}

bool MaterializeInDestinationOp::bufferizesToMemoryWrite(
OpOperand &opOperand, const AnalysisState &state) {
if (&opOperand == &getOperation()->getOpOperand(1) /*dest*/)
return true;
return false;
return &opOperand == &getDestMutable()[0];
}

AliasingValueList
MaterializeInDestinationOp::getAliasingValues(OpOperand &opOperand,
const AnalysisState &state) {
if (&opOperand == &getOperation()->getOpOperand(1) /*dest*/)
if (&opOperand == &getDestMutable()[0])
return {{getOperation()->getResult(0), BufferRelation::Equivalent}};
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ struct FoldReshapeWithGenericOpByExpansion
reshapeOp, "failed preconditions of fusion with producer generic op");
}

if (!controlFoldingReshapes(&reshapeOp->getOpOperand(0))) {
if (!controlFoldingReshapes(&reshapeOp.getSrcMutable()[0])) {
return rewriter.notifyMatchFailure(reshapeOp,
"fusion blocked by control function");
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ mlir::scf::tileAndFuseProducerOfSlice(RewriterBase &rewriter,
// 1. Get the producer of the source (potentially walking through
// `iter_args` of nested `scf.for`)
auto [fusableProducer, destinationIterArg] =
getUntiledProducerFromSliceSource(&candidateSliceOp->getOpOperand(0),
getUntiledProducerFromSliceSource(&candidateSliceOp.getSourceMutable()[0],
loops);
if (!fusableProducer)
return std::nullopt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ struct InsertSliceOpInterface
RankedTensorType destType = insertSliceOp.getDestType();

// The source is always read.
if (&opOperand == &op->getOpOperand(0) /*src*/)
if (&opOperand == &insertSliceOp.getSourceMutable()[0])
return true;

// For the destination, it depends...
assert(&opOperand == &insertSliceOp->getOpOperand(1) && "expected dest");
assert(&opOperand == &insertSliceOp.getDestMutable()[0] && "expected dest");

// Dest is not read if it is entirely overwritten. E.g.:
// tensor.insert_slice %a into %t[0][10][1] : ... into tensor<10xf32>
Expand Down Expand Up @@ -851,9 +851,8 @@ struct ReshapeOpInterface
tensor::ReshapeOp> {
bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
const AnalysisState &state) const {
if (&opOperand == &op->getOpOperand(1) /* shape */)
return true;
return false;
auto reshapeOp = cast<tensor::ReshapeOp>(op);
return &opOperand == &reshapeOp.getShapeMutable()[0];
}

bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
Expand Down Expand Up @@ -915,7 +914,8 @@ struct ParallelInsertSliceOpInterface

bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
const AnalysisState &state) const {
return &opOperand == &op->getOpOperand(1) /*dest*/;
auto parallelInsertSliceOp = cast<ParallelInsertSliceOp>(op);
return &opOperand == &parallelInsertSliceOp.getDestMutable()[0];
}

LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
Expand Down
5 changes: 5 additions & 0 deletions mlir/lib/IR/OperationSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ void MutableOperandRange::updateLength(unsigned newLength) {
}
}

OpOperand &MutableOperandRange::operator[](unsigned index) const {
assert(index < length && "index is out of bounds");
return owner->getOpOperand(start + index);
}

//===----------------------------------------------------------------------===//
// MutableOperandRangeRange

Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/Transforms/Utils/CFGToSCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ class EdgeMultiplexer {
if (index >= result->second &&
index < result->second + edge.getSuccessor()->getNumArguments()) {
// Original block arguments to the entry block.
newSuccOperands[index] = successorOperands[index - result->second];
newSuccOperands[index] =
successorOperands[index - result->second].get();
continue;
}

Expand Down