llvm-project/mlir/lib/Dialect/Vector/Transforms/SubsetOpInterfaceImpl.cpp
Andrzej Warzyński c45cc3e420
[mlir][vector] Standardize base Naming Across Vector Ops (NFC) (#137859)
[mlir][vector] Standardize base Naming Across Vector Ops (NFC)

This change standardizes the naming convention for the argument
representing the value to read from or write to in Vector ops that
interface with Tensors or MemRefs. Specifically, it ensures that all
such ops use the name `base` (i.e., the base address or location to
which offsets are applied).

Updated operations:

* `vector.transfer_read`,
* `vector.transfer_write`.

For reference, these ops already use `base`:

* `vector.load`, `vector.store`, `vector.scatter`, `vector.gather`,
  `vector.expandload`, `vector.compressstore`, `vector.maskedstore`,
  `vector.maskedload`.

This is a non-functional change (NFC) and does not alter the semantics of these
operations. However, it does require users of the XFer ops to switch from
`op.getSource()` to `op.getBase()`.

To ease the transition, this PR temporarily adds a `getSource()` interface
method for compatibility. This is intended for downstream use only and should
not be relied on upstream. The method will be removed prior to the LLVM 21
release.

Implements #131602
2025-05-12 09:44:50 +01:00

83 lines
2.9 KiB
C++

//===- SubsetOpInterfaceImpl.cpp - Tensor subsets -------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Vector/Transforms/SubsetOpInterfaceImpl.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Interfaces/SubsetOpInterface.h"
using namespace mlir;
using namespace mlir::vector;
namespace {
template <typename OpTy>
struct XferOpSubsetOpInterface
: public SubsetOpInterface::ExternalModel<XferOpSubsetOpInterface<OpTy>,
OpTy> {
FailureOr<HyperrectangularSlice>
getAccessedHyperrectangularSlice(Operation *op) const {
auto xferOp = cast<OpTy>(op);
Builder b(xferOp->getContext());
SmallVector<OpFoldResult> offsets = llvm::map_to_vector(
xferOp.getIndices(), [](Value v) -> OpFoldResult { return v; });
SmallVector<OpFoldResult> sizes = llvm::map_to_vector(
xferOp.getTransferChunkAccessed(),
[&](int64_t sz) -> OpFoldResult { return b.getIndexAttr(sz); });
return HyperrectangularSlice(offsets, sizes);
}
};
struct TransferReadOpSubsetExtractionOpInterface
: public SubsetExtractionOpInterface::ExternalModel<
TransferReadOpSubsetExtractionOpInterface, vector::TransferReadOp> {
OpOperand &getSourceOperand(Operation *op) const {
return cast<vector::TransferReadOp>(op).getBaseMutable();
}
};
struct TransferWriteOpSubsetInsertionOpInterface
: public SubsetInsertionOpInterface::ExternalModel<
TransferWriteOpSubsetInsertionOpInterface, vector::TransferWriteOp> {
OpOperand &getSourceOperand(Operation *op) const {
return cast<vector::TransferWriteOp>(op).getValueToStoreMutable();
}
OpOperand &getDestinationOperand(Operation *op) const {
return cast<vector::TransferWriteOp>(op).getBaseMutable();
}
Value buildSubsetExtraction(Operation *op, OpBuilder &builder,
Location loc) const {
// TODO: Implement when needed.
return Value();
}
SmallVector<Value>
getValuesNeededToBuildSubsetExtraction(Operation *op) const {
// TODO: Implement when needed.
return {};
}
};
} // namespace
void mlir::vector::registerSubsetOpInterfaceExternalModels(
DialectRegistry &registry) {
registry.addExtension(+[](MLIRContext *ctx, vector::VectorDialect *dialect) {
TransferReadOp::attachInterface<XferOpSubsetOpInterface<TransferReadOp>>(
*ctx);
TransferReadOp::attachInterface<TransferReadOpSubsetExtractionOpInterface>(
*ctx);
TransferWriteOp::attachInterface<XferOpSubsetOpInterface<TransferWriteOp>>(
*ctx);
TransferWriteOp::attachInterface<TransferWriteOpSubsetInsertionOpInterface>(
*ctx);
});
}