#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
#include "mlir/Analysis/DataLayoutAnalysis.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Conversion/MemRefToLLVM/AllocLikeConversion.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/FunctionCallUtils.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/Support/MathExtras.h"
#include <optional>
namespace mlir {
#define GEN_PASS_DEF_FINALIZEMEMREFTOLLVMCONVERSIONPASS
#include "mlir/Conversion/Passes.h.inc"
}
usingnamespacemlir;
namespace {
bool isStaticStrideOrOffset(int64_t strideOrOffset) { … }
LLVM::LLVMFuncOp getFreeFn(const LLVMTypeConverter *typeConverter,
ModuleOp module) { … }
struct AllocOpLowering : public AllocLikeOpLLVMLowering { … };
struct AlignedAllocOpLowering : public AllocLikeOpLLVMLowering { … };
struct AllocaOpLowering : public AllocLikeOpLLVMLowering { … };
struct AllocaScopeOpLowering
: public ConvertOpToLLVMPattern<memref::AllocaScopeOp> { … };
struct AssumeAlignmentOpLowering
: public ConvertOpToLLVMPattern<memref::AssumeAlignmentOp> { … };
struct DeallocOpLowering : public ConvertOpToLLVMPattern<memref::DeallocOp> { … };
struct DimOpLowering : public ConvertOpToLLVMPattern<memref::DimOp> { … };
template <typename Derived>
struct LoadStoreOpLowering : public ConvertOpToLLVMPattern<Derived> { … };
struct GenericAtomicRMWOpLowering
: public LoadStoreOpLowering<memref::GenericAtomicRMWOp> { … };
static Type
convertGlobalMemrefTypeToLLVM(MemRefType type,
const LLVMTypeConverter &typeConverter) { … }
struct GlobalMemrefOpLowering
: public ConvertOpToLLVMPattern<memref::GlobalOp> { … };
struct GetGlobalMemrefOpLowering : public AllocLikeOpLLVMLowering { … };
struct LoadOpLowering : public LoadStoreOpLowering<memref::LoadOp> { … };
struct StoreOpLowering : public LoadStoreOpLowering<memref::StoreOp> { … };
struct PrefetchOpLowering : public LoadStoreOpLowering<memref::PrefetchOp> { … };
struct RankOpLowering : public ConvertOpToLLVMPattern<memref::RankOp> { … };
struct MemRefCastOpLowering : public ConvertOpToLLVMPattern<memref::CastOp> { … };
struct MemRefCopyOpLowering : public ConvertOpToLLVMPattern<memref::CopyOp> { … };
struct MemorySpaceCastOpLowering
: public ConvertOpToLLVMPattern<memref::MemorySpaceCastOp> { … };
static void extractPointersAndOffset(Location loc,
ConversionPatternRewriter &rewriter,
const LLVMTypeConverter &typeConverter,
Value originalOperand,
Value convertedOperand,
Value *allocatedPtr, Value *alignedPtr,
Value *offset = nullptr) { … }
struct MemRefReinterpretCastOpLowering
: public ConvertOpToLLVMPattern<memref::ReinterpretCastOp> { … };
struct MemRefReshapeOpLowering
: public ConvertOpToLLVMPattern<memref::ReshapeOp> { … };
template <typename ReshapeOp>
class ReassociatingReshapeOpConversion
: public ConvertOpToLLVMPattern<ReshapeOp> { … };
struct SubViewOpLowering : public ConvertOpToLLVMPattern<memref::SubViewOp> { … };
class TransposeOpLowering : public ConvertOpToLLVMPattern<memref::TransposeOp> { … };
struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> { … };
static std::optional<LLVM::AtomicBinOp>
matchSimpleAtomicOp(memref::AtomicRMWOp atomicOp) { … }
struct AtomicRMWOpLowering : public LoadStoreOpLowering<memref::AtomicRMWOp> { … };
class ConvertExtractAlignedPointerAsIndex
: public ConvertOpToLLVMPattern<memref::ExtractAlignedPointerAsIndexOp> { … };
class ExtractStridedMetadataOpLowering
: public ConvertOpToLLVMPattern<memref::ExtractStridedMetadataOp> { … };
}
void mlir::populateFinalizeMemRefToLLVMConversionPatterns(
const LLVMTypeConverter &converter, RewritePatternSet &patterns) { … }
namespace {
struct FinalizeMemRefToLLVMConversionPass
: public impl::FinalizeMemRefToLLVMConversionPassBase<
FinalizeMemRefToLLVMConversionPass> { … };
struct MemRefToLLVMDialectInterface : public ConvertToLLVMPatternInterface { … };
}
void mlir::registerConvertMemRefToLLVMInterface(DialectRegistry ®istry) { … }