13 #include "mlir/Interfaces/SubsetOpInterface.cpp.inc"
18 auto dstOp = dyn_cast<DestinationStyleOpInterface>(op);
19 assert(dstOp &&
"getDestination must be implemented for non-DPS ops");
21 dstOp.getNumDpsInits() == 1 &&
22 "getDestination must be implemented for ops with 0 or more than 1 init");
23 return *dstOp.getDpsInitOperand(0);
27 auto dstOp = dyn_cast<DestinationStyleOpInterface>(op);
28 assert(dstOp &&
"getUpdatedDestination must be implemented for non-DPS ops");
29 auto insertionOp = cast<SubsetInsertionOpInterface>(op);
30 return dstOp.getTiedOpResult(&insertionOp.getDestinationOperand());
36 assert(isa<SubsetInsertionOpInterface>(op) &&
37 "expected SubsetInsertionOpInterface");
40 return cast<SubsetOpInterface>(op).operatesOnEquivalentSubset(
45 Operation *op, SubsetOpInterface candidate,
47 auto subsetOp = cast<SubsetOpInterface>(op);
48 FailureOr<HyperrectangularSlice> slice =
49 subsetOp.getAccessedHyperrectangularSlice();
50 assert(succeeded(slice) &&
51 "operatesOnEquivalentSubset must be implemented if "
52 "getAccessedHyperrectangularSlice is not implemented");
53 FailureOr<HyperrectangularSlice> otherSlice =
54 candidate.getAccessedHyperrectangularSlice();
55 if (failed(otherSlice))
57 if (!equivalenceFn(subsetOp.getTensorContainer(),
58 candidate.getTensorContainer()))
62 return succeeded(equivalent) && *equivalent;
66 Operation *op, SubsetOpInterface candidate,
68 auto subsetOp = cast<SubsetOpInterface>(op);
69 FailureOr<HyperrectangularSlice> slice =
70 subsetOp.getAccessedHyperrectangularSlice();
71 assert(succeeded(slice) &&
72 "defaultOperatesOnDisjointSubset must be implemented if "
73 "getAccessedHyperrectangularSlice is not implemented");
74 FailureOr<HyperrectangularSlice> otherSlice =
75 candidate.getAccessedHyperrectangularSlice();
76 if (failed(otherSlice))
78 if (!equivalenceFn(subsetOp.getTensorContainer(),
79 candidate.getTensorContainer()))
83 return succeeded(overlapping) && !*overlapping;
87 if (
auto insertionOp = dyn_cast<::mlir::SubsetInsertionOpInterface>(op))
88 return insertionOp.getDestinationOperand().get();
89 return cast<::mlir::SubsetExtractionOpInterface>(op).getSourceOperand().get();
93 if (!(isa<SubsetExtractionOpInterface>(op.getOperation()) ^
94 isa<SubsetInsertionOpInterface>(op.getOperation())))
95 return op->emitOpError(
96 "SubsetOpInterface ops must implement either "
97 "SubsetExtractionOpInterface or SubsetInsertionOpInterface");
103 if (op->getNumResults() != 1)
104 return op->emitOpError(
105 "SubsetExtractionOpInterface ops must have one result");
This class represents an operand of an operation.
This is a value defined by a result of an operation.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
static FailureOr< bool > areEquivalentSlices(MLIRContext *ctx, HyperrectangularSlice slice1, HyperrectangularSlice slice2)
Return "true" if the given slices are guaranteed to be equivalent.
static FailureOr< bool > areOverlappingSlices(MLIRContext *ctx, HyperrectangularSlice slice1, HyperrectangularSlice slice2)
Return "true" if the given slices are guaranteed to be overlapping.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
LogicalResult verifySubsetExtractionOpInterface(SubsetExtractionOpInterface op)
Verify SubsetExtractionOpInterface.
bool defaultOperatesOnDisjointSubset(Operation *op, SubsetOpInterface candidate, function_ref< bool(Value, Value)> equivalenceFn)
Default implementation of SubsetOpInterface::operatesOnDisjointSubset.
bool defaultOperatesOnEquivalentSubset(Operation *op, SubsetOpInterface candidate, function_ref< bool(Value, Value)> equivalenceFn)
Default implementation of SubsetOpInterface::operatesOnEquivalentSubset.
Value getTensorContainer(Operation *op)
Return the container that the given subset op is operating on.
OpResult defaultGetUpdatedDestination(Operation *op)
Return the updated destination result of the op if it implements the DestinationStyleOpInterface.
LogicalResult verifySubsetOpInterface(SubsetOpInterface op)
Verify SubsetOpInterface.
bool defaultIsEquivalentSubset(Operation *op, Value candidate, function_ref< bool(Value, Value)> equivalenceFn)
Default implementation of SubsetInsertionOpInterface::isEquivalentSubset.
OpOperand & defaultGetDestinationOperand(Operation *op)
Return the destination/"init" operand of the op if it implements the DestinationStyleOpInterface and ...
Include the generated interface declarations.