#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/ViewLikeInterfaceUtils.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
#include "mlir/Dialect/NVGPU/IR/NVGPUDialect.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#define DEBUG_TYPE …
#define DBGS() …
namespace mlir {
namespace memref {
#define GEN_PASS_DEF_FOLDMEMREFALIASOPS
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
}
}
usingnamespacemlir;
static LogicalResult
resolveSourceIndicesExpandShape(Location loc, PatternRewriter &rewriter,
memref::ExpandShapeOp expandShapeOp,
ValueRange indices,
SmallVectorImpl<Value> &sourceIndices) { … }
static LogicalResult
resolveSourceIndicesCollapseShape(Location loc, PatternRewriter &rewriter,
memref::CollapseShapeOp collapseShapeOp,
ValueRange indices,
SmallVectorImpl<Value> &sourceIndices) { … }
template <typename LoadOrStoreOpTy>
static Value getMemRefOperand(LoadOrStoreOpTy op) { … }
static Value getMemRefOperand(vector::TransferReadOp op) { … }
static Value getMemRefOperand(nvgpu::LdMatrixOp op) { … }
static Value getMemRefOperand(vector::LoadOp op) { … }
static Value getMemRefOperand(vector::StoreOp op) { … }
static Value getMemRefOperand(vector::MaskedLoadOp op) { … }
static Value getMemRefOperand(vector::MaskedStoreOp op) { … }
static Value getMemRefOperand(vector::TransferWriteOp op) { … }
static Value getMemRefOperand(gpu::SubgroupMmaLoadMatrixOp op) { … }
static Value getMemRefOperand(gpu::SubgroupMmaStoreMatrixOp op) { … }
namespace {
template <typename OpTy>
class LoadOpOfSubViewOpFolder final : public OpRewritePattern<OpTy> { … };
template <typename OpTy>
class LoadOpOfExpandShapeOpFolder final : public OpRewritePattern<OpTy> { … };
template <typename OpTy>
class LoadOpOfCollapseShapeOpFolder final : public OpRewritePattern<OpTy> { … };
template <typename OpTy>
class StoreOpOfSubViewOpFolder final : public OpRewritePattern<OpTy> { … };
template <typename OpTy>
class StoreOpOfExpandShapeOpFolder final : public OpRewritePattern<OpTy> { … };
template <typename OpTy>
class StoreOpOfCollapseShapeOpFolder final : public OpRewritePattern<OpTy> { … };
class SubViewOfSubViewFolder : public OpRewritePattern<memref::SubViewOp> { … };
class NVGPUAsyncCopyOpSubViewOpFolder final
: public OpRewritePattern<nvgpu::DeviceAsyncCopyOp> { … };
}
static SmallVector<Value>
calculateExpandedAccessIndices(AffineMap affineMap,
const SmallVector<Value> &indices, Location loc,
PatternRewriter &rewriter) { … }
template <typename XferOp>
static LogicalResult
preconditionsFoldSubViewOpImpl(RewriterBase &rewriter, XferOp xferOp,
memref::SubViewOp subviewOp) { … }
static LogicalResult preconditionsFoldSubViewOp(RewriterBase &rewriter,
Operation *op,
memref::SubViewOp subviewOp) { … }
static LogicalResult preconditionsFoldSubViewOp(RewriterBase &rewriter,
vector::TransferReadOp readOp,
memref::SubViewOp subviewOp) { … }
static LogicalResult preconditionsFoldSubViewOp(RewriterBase &rewriter,
vector::TransferWriteOp writeOp,
memref::SubViewOp subviewOp) { … }
template <typename OpTy>
LogicalResult LoadOpOfSubViewOpFolder<OpTy>::matchAndRewrite(
OpTy loadOp, PatternRewriter &rewriter) const { … }
template <typename OpTy>
LogicalResult LoadOpOfExpandShapeOpFolder<OpTy>::matchAndRewrite(
OpTy loadOp, PatternRewriter &rewriter) const { … }
template <typename OpTy>
LogicalResult LoadOpOfCollapseShapeOpFolder<OpTy>::matchAndRewrite(
OpTy loadOp, PatternRewriter &rewriter) const { … }
template <typename OpTy>
LogicalResult StoreOpOfSubViewOpFolder<OpTy>::matchAndRewrite(
OpTy storeOp, PatternRewriter &rewriter) const { … }
template <typename OpTy>
LogicalResult StoreOpOfExpandShapeOpFolder<OpTy>::matchAndRewrite(
OpTy storeOp, PatternRewriter &rewriter) const { … }
template <typename OpTy>
LogicalResult StoreOpOfCollapseShapeOpFolder<OpTy>::matchAndRewrite(
OpTy storeOp, PatternRewriter &rewriter) const { … }
LogicalResult NVGPUAsyncCopyOpSubViewOpFolder::matchAndRewrite(
nvgpu::DeviceAsyncCopyOp copyOp, PatternRewriter &rewriter) const { … }
void memref::populateFoldMemRefAliasOpPatterns(RewritePatternSet &patterns) { … }
namespace {
struct FoldMemRefAliasOpsPass final
: public memref::impl::FoldMemRefAliasOpsBase<FoldMemRefAliasOpsPass> { … };
}
void FoldMemRefAliasOpsPass::runOnOperation() { … }
std::unique_ptr<Pass> memref::createFoldMemRefAliasOpsPass() { … }