MLIR  19.0.0git
SubsetOpInterfaceImpl.cpp
Go to the documentation of this file.
1 //===- SubsetOpInterfaceImpl.cpp - Tensor subsets -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
13 
14 using namespace mlir;
15 using namespace mlir::vector;
16 
17 namespace {
18 
19 template <typename OpTy>
20 struct XferOpSubsetOpInterface
21  : public SubsetOpInterface::ExternalModel<XferOpSubsetOpInterface<OpTy>,
22  OpTy> {
24  getAccessedHyperrectangularSlice(Operation *op) const {
25  auto xferOp = cast<OpTy>(op);
26  Builder b(xferOp->getContext());
27  SmallVector<OpFoldResult> offsets = llvm::map_to_vector(
28  xferOp.getIndices(), [](Value v) -> OpFoldResult { return v; });
29  SmallVector<OpFoldResult> sizes = llvm::map_to_vector(
30  xferOp.getTransferChunkAccessed(),
31  [&](int64_t sz) -> OpFoldResult { return b.getIndexAttr(sz); });
32  return HyperrectangularSlice(offsets, sizes);
33  }
34 };
35 
36 struct TransferReadOpSubsetExtractionOpInterface
37  : public SubsetExtractionOpInterface::ExternalModel<
38  TransferReadOpSubsetExtractionOpInterface, vector::TransferReadOp> {
39  OpOperand &getSourceOperand(Operation *op) const {
40  return cast<vector::TransferReadOp>(op).getSourceMutable();
41  }
42 };
43 
44 struct TransferWriteOpSubsetInsertionOpInterface
45  : public SubsetInsertionOpInterface::ExternalModel<
46  TransferWriteOpSubsetInsertionOpInterface, vector::TransferWriteOp> {
47  OpOperand &getSourceOperand(Operation *op) const {
48  return cast<vector::TransferWriteOp>(op).getVectorMutable();
49  }
50 
51  OpOperand &getDestinationOperand(Operation *op) const {
52  return cast<vector::TransferWriteOp>(op).getSourceMutable();
53  }
54 
55  Value buildSubsetExtraction(Operation *op, OpBuilder &builder,
56  Location loc) const {
57  // TODO: Implement when needed.
58  return Value();
59  }
60 
62  getValuesNeededToBuildSubsetExtraction(Operation *op) const {
63  // TODO: Implement when needed.
64  return {};
65  }
66 };
67 
68 } // namespace
69 
71  DialectRegistry &registry) {
72  registry.addExtension(+[](MLIRContext *ctx, vector::VectorDialect *dialect) {
73  TransferReadOp::attachInterface<XferOpSubsetOpInterface<TransferReadOp>>(
74  *ctx);
75  TransferReadOp::attachInterface<TransferReadOpSubsetExtractionOpInterface>(
76  *ctx);
77  TransferWriteOp::attachInterface<XferOpSubsetOpInterface<TransferWriteOp>>(
78  *ctx);
79  TransferWriteOp::attachInterface<TransferWriteOpSubsetInsertionOpInterface>(
80  *ctx);
81  });
82 }
This class is a general helper class for creating context-global objects like types,...
Definition: Builders.h:50
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.
Definition: LogicalResult.h:78
A hyperrectangular slice, represented as a list of offsets, sizes and strides.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
This class helps build Operations.
Definition: Builders.h:209
This class represents a single result from folding an operation.
Definition: OpDefinition.h:266
This class represents an operand of an operation.
Definition: Value.h:263
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
void registerSubsetOpInterfaceExternalModels(DialectRegistry &registry)
Include the generated interface declarations.