20 using namespace linalg;
27 bufferizeDestinationStyleOpInterface(
RewriterBase &rewriter,
28 DestinationStyleOpInterface op,
35 if (op.hasBufferSemantics())
40 if (!op.hasTensorSemantics())
41 return op->
emitError() <<
"op does not have tensor semantics";
45 newInputBuffers.reserve(op.getNumDpsInputs());
46 for (
OpOperand *opOperand : op.getDpsInputOperands()) {
47 if (op.isScalar(opOperand)) {
48 newInputBuffers.push_back(opOperand->get());
54 newInputBuffers.push_back(*buffer);
60 OpOperand *opOperand = op.getDpsInitOperand(opResult.getResultNumber());
65 newOutputBuffers.push_back(*resultBuffer);
70 newOperands.append(newOutputBuffers.begin(), newOutputBuffers.end());
77 assert(op->
getNumRegions() == 1 &&
"expected that op has 1 region");
81 newOp->getRegion(0).
begin());
91 template <
typename OpTy>
92 struct LinalgOpInterface
98 auto linalgOp = cast<linalg::LinalgOp>(op);
99 return linalgOp.payloadUsesValueFromOperand(&opOperand);
105 auto dpsOp = cast<DestinationStyleOpInterface>(op);
106 return dpsOp.isDpsInit(&opOperand);
111 auto linalgOp = cast<linalg::LinalgOp>(op);
114 if (linalgOp.getNumLoops() != linalgOp.getNumParallelLoops())
119 assert(linalgOp->getNumOperands() == indexingMaps.size() &&
120 "unexpected number of indexing maps");
121 for (
auto [operand, map] :
122 llvm::zip(linalgOp->getOpOperands(), indexingMaps)) {
125 if (!isa<RankedTensorType, MemRefType>(operand.get().getType()))
128 if (llvm::find(opOperands, &operand) == opOperands.end())
132 if (!map.isIdentity())
141 return bufferizeDestinationStyleOpInterface(
142 rewriter, cast<DestinationStyleOpInterface>(op),
options);
148 template <
typename... Ops>
149 struct LinalgOpInterfaceHelper {
150 static void registerOpInterface(
MLIRContext *ctx) {
151 (Ops::template attachInterface<LinalgOpInterface<Ops>>(*ctx), ...);
162 LinalgOpInterfaceHelper<
164 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
165 >::registerOpInterface(ctx);
static llvm::ManagedStatic< PassManagerOptions > options
Base class for generic analysis states.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtension(std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
This class provides support for representing a failure result, or a valid value of type T.
IRValueT get() const
Return the current value being used by this operand.
MLIRContext is the top-level object for a collection of MLIR operations.
RAII guard to reset the insertion point of the builder when destroyed.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
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.
unsigned getNumRegions()
Returns the number of regions held by this operation.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
result_range getOpResults()
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
virtual void inlineRegionBefore(Region ®ion, Region &parent, Region::iterator before)
Move the blocks that belong to "region" before the given position in another region "parent".
This class provides an abstraction over the various different ranges of value types.
void replaceOpWithBufferizedValues(RewriterBase &rewriter, Operation *op, ValueRange values)
Replace an op with replacement values.
FailureOr< Value > getBuffer(RewriterBase &rewriter, Value value, const BufferizationOptions &options)
Lookup the buffer for the given value.
void registerBufferizableOpInterfaceExternalModels(DialectRegistry ®istry)
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Operation * cloneWithoutRegions(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.
Options for BufferizableOpInterface-based bufferization.
Bufferizable ops that implement the DestinationStyleOpInterface can use this external model base clas...