26 namespace sparse_tensor {
29 template <
typename ConcreteModel,
typename ConcreteOp>
30 struct SparseBufferizableOpInterfaceExternalModel
31 :
public BufferizableOpInterface::ExternalModel<ConcreteModel, ConcreteOp> {
32 LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
35 "sparse_tensor ops must be bufferized with the sparsifier");
39 struct ConcatenateOpInterface
40 : SparseBufferizableOpInterfaceExternalModel<ConcatenateOpInterface,
41 sparse_tensor::ConcatenateOp> {
42 bool bufferizesToAllocation(Operation *op, Value value)
const {
return true; }
44 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
49 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
59 bool isWritable(Operation *op, Value value,
65 struct ConvertOpInterface :
public SparseBufferizableOpInterfaceExternalModel<
66 ConvertOpInterface, sparse_tensor::ConvertOp> {
67 bool bufferizesToAllocation(Operation *op, Value value)
const {
73 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
78 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
88 bool isWritable(Operation *op, Value value,
94 struct LoadOpInterface
95 :
public SparseBufferizableOpInterfaceExternalModel<LoadOpInterface,
96 sparse_tensor::LoadOp> {
97 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
102 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
113 struct NewOpInterface
114 :
public SparseBufferizableOpInterfaceExternalModel<NewOpInterface,
115 sparse_tensor::NewOp> {
116 bool resultBufferizesToMemoryWrite(Operation *op, OpResult opResult,
122 bool bufferizesToAllocation(Operation *op, Value value)
const {
return true; }
125 struct AssembleOpInterface
126 :
public SparseBufferizableOpInterfaceExternalModel<
127 AssembleOpInterface, sparse_tensor::AssembleOp> {
128 bool bufferizesToAllocation(Operation *op, Value value)
const {
133 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
138 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
145 assert(op->getNumResults() == 1);
157 struct DisassembleOpInterface
158 :
public SparseBufferizableOpInterfaceExternalModel<
159 DisassembleOpInterface, sparse_tensor::DisassembleOp> {
160 bool bufferizesToAllocation(Operation *op, Value value)
const {
165 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
168 return opOperand.getOperandNumber() == 0;
171 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
174 assert(2 * (op->getNumOperands() - 1) == op->getNumResults());
175 return opOperand.getOperandNumber() > 0;
180 assert(2 * (op->getNumOperands() - 1) == op->getNumResults());
182 if (opOperand.getOperandNumber() == 0)
185 return {{op->getResult(opOperand.getOperandNumber() - 1),
190 struct ForeachOpInterface :
public SparseBufferizableOpInterfaceExternalModel<
191 ForeachOpInterface, sparse_tensor::ForeachOp> {
192 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
197 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
207 LogicalResult verifyAnalysis(Operation *op,
211 for (OpResult result : op->getResults()) {
212 if (isa<TensorType>(result.getType()))
213 return op->emitOpError(
"tensor results are not supported yet");
219 struct NumberOfEntriesOpInterface
220 :
public SparseBufferizableOpInterfaceExternalModel<
221 NumberOfEntriesOpInterface, sparse_tensor::NumberOfEntriesOp> {
222 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
227 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
238 struct ToCoordinatesBufferOpInterface
239 :
public SparseBufferizableOpInterfaceExternalModel<
240 ToCoordinatesBufferOpInterface,
241 sparse_tensor::ToCoordinatesBufferOp> {
242 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
247 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
260 struct ToCoordinatesOpInterface
261 :
public SparseBufferizableOpInterfaceExternalModel<
262 ToCoordinatesOpInterface, sparse_tensor::ToCoordinatesOp> {
263 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
268 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
281 struct ToPositionsOpInterface
282 :
public SparseBufferizableOpInterfaceExternalModel<
283 ToPositionsOpInterface, sparse_tensor::ToPositionsOp> {
284 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
289 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
302 struct ToValuesOpInterface
303 :
public SparseBufferizableOpInterfaceExternalModel<
304 ToValuesOpInterface, sparse_tensor::ToValuesOp> {
305 bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
310 bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
330 sparse_tensor::SparseTensorDialect *dialect) {
331 sparse_tensor::ConcatenateOp::attachInterface<ConcatenateOpInterface>(*ctx);
332 sparse_tensor::ConvertOp::attachInterface<ConvertOpInterface>(*ctx);
333 sparse_tensor::LoadOp::attachInterface<LoadOpInterface>(*ctx);
334 sparse_tensor::NewOp::attachInterface<NewOpInterface>(*ctx);
335 sparse_tensor::NumberOfEntriesOp::attachInterface<
336 NumberOfEntriesOpInterface>(*ctx);
337 sparse_tensor::AssembleOp::attachInterface<AssembleOpInterface>(*ctx);
338 sparse_tensor::DisassembleOp::attachInterface<DisassembleOpInterface>(*ctx);
339 sparse_tensor::ForeachOp::attachInterface<ForeachOpInterface>(*ctx);
340 sparse_tensor::ToCoordinatesBufferOp::attachInterface<
341 ToCoordinatesBufferOpInterface>(*ctx);
342 sparse_tensor::ToCoordinatesOp::attachInterface<ToCoordinatesOpInterface>(
344 sparse_tensor::ToPositionsOp::attachInterface<ToPositionsOpInterface>(*ctx);
345 sparse_tensor::ToValuesOp::attachInterface<ToValuesOpInterface>(*ctx);
static llvm::ManagedStatic< PassManagerOptions > options
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
AnalysisState provides a variety of helper functions for dealing with tensor values.
BufferRelation
Specifies a fine-grain relationship between buffers to enable more analysis.
void registerBufferizableOpInterfaceExternalModels(DialectRegistry ®istry)
Include the generated interface declarations.
Options for BufferizableOpInterface-based bufferization.