31 if (op.hasBufferSemantics())
36 if (!op.hasTensorSemantics())
37 return op->emitError() <<
"op does not have tensor semantics";
41 newInputBuffers.reserve(op.getNumInputs());
42 for (
OpOperand *opOperand : op.getInputOperands()) {
43 if (op.isScalar(opOperand)) {
44 newInputBuffers.push_back(opOperand->get());
50 newInputBuffers.push_back(*buffer);
55 for (
OpResult opResult : op->getOpResults()) {
56 OpOperand *opOperand = op.getOutputOperand(opResult.getResultNumber());
61 newOutputBuffers.push_back(*resultBuffer);
66 newOperands.append(newOutputBuffers.begin(), newOutputBuffers.end());
73 assert(op->getNumRegions() == 1 &&
"expected that op has 1 region");
74 auto newOp = cast<LinalgOp>(op.cloneWithoutRegions(
75 rewriter, op.getLoc(),
TypeRange{}, newOperands));
77 newOp->getRegion(0).begin());
87 template <
typename OpTy>
88 struct LinalgOpInterface
89 :
public BufferizableOpInterface::ExternalModel<LinalgOpInterface<OpTy>,
94 auto genericOp = cast<linalg::LinalgOp>(op);
95 return genericOp.payloadUsesValueFromOperand(&opOperand);
101 auto bufferizableOp = cast<BufferizableOpInterface>(op);
102 return !bufferizableOp.getAliasingOpResult(opOperand, state).empty();
108 auto genericOp = cast<linalg::LinalgOp>(op);
116 auto genericOp = cast<linalg::LinalgOp>(op);
119 if (genericOp.isOutputTensor(&opOperand))
120 return {genericOp.getTiedOpResult(&opOperand)};
126 return BufferRelation::Equivalent;
131 return bufferizeLinalgOp(rewriter, cast<LinalgOp>(op), options);
137 template <
typename... Ops>
138 struct LinalgOpInterfaceHelper {
139 static void registerOpInterface(
MLIRContext *ctx) {
140 (Ops::template attachInterface<LinalgOpInterface<Ops>>(*ctx), ...);
151 LinalgOpInterfaceHelper<
153 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" 154 >::registerOpInterface(ctx);
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
FailureOr< Value > getBuffer(RewriterBase &rewriter, Value value, const BufferizationOptions &options)
Lookup the buffer for the given value.
This is a value defined by a result of an operation.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
void replaceOpWithBufferizedValues(RewriterBase &rewriter, Operation *op, ValueRange values)
Replace an op with replacement values.
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"...
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
void addExtension(std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
This class represents an efficient way to signal success or failure.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
This class provides support for representing a failure result, or a valid value of type T...
unsigned getResultNumber() const
Returns the number of this result.
This class provides an abstraction over the various different ranges of value types.
void registerBufferizableOpInterfaceExternalModels(DialectRegistry ®istry)
IRValueT get() const
Return the current value being used by this operand.
Options for BufferizableOpInterface-based bufferization.
static llvm::ManagedStatic< PassManagerOptions > options
RAII guard to reset the insertion point of the builder when destroyed.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents an operand of an operation.
BufferRelation
Specify fine-grain relationship between buffers to enable more analysis.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Base class for generic analysis states.