17 #include "llvm/Support/FormatVariadic.h"
18 #include "llvm/Support/MathExtras.h"
22 #define GEN_PASS_DEF_MEMREFEMULATEWIDEINT
23 #include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
38 matchAndRewrite(memref::AllocOp op, OpAdaptor adaptor,
40 Type newTy = getTypeConverter()->convertType(op.getType());
44 llvm::formatv(
"failed to convert memref type: {0}", op.getType()));
47 op, newTy, adaptor.getDynamicSizes(), adaptor.getSymbolOperands(),
48 adaptor.getAlignmentAttr());
61 matchAndRewrite(memref::LoadOp op, OpAdaptor adaptor,
63 Type newResTy = getTypeConverter()->convertType(op.getType());
66 op->
getLoc(), llvm::formatv(
"failed to convert memref type: {0}",
70 op, newResTy, adaptor.getMemref(), adaptor.getIndices(),
84 matchAndRewrite(memref::StoreOp op, OpAdaptor adaptor,
86 Type newTy = getTypeConverter()->convertType(op.getMemRefType());
89 op->
getLoc(), llvm::formatv(
"failed to convert memref type: {0}",
93 op, adaptor.getValue(), adaptor.getMemref(), adaptor.getIndices(),
103 struct EmulateWideIntPass final
104 : memref::impl::MemRefEmulateWideIntBase<EmulateWideIntPass> {
105 using MemRefEmulateWideIntBase::MemRefEmulateWideIntBase;
107 void runOnOperation()
override {
108 if (!llvm::isPowerOf2_32(widestIntSupported) || widestIntSupported < 2) {
116 arith::WideIntEmulationConverter typeConverter(widestIntSupported);
119 target.addDynamicallyLegalDialect<
120 arith::ArithDialect, memref::MemRefDialect, vector::VectorDialect>(
121 [&typeConverter](
Operation *op) {
return typeConverter.isLegal(op); });
144 patterns.
add<ConvertMemRefAlloc, ConvertMemRefLoad, ConvertMemRefStore>(
151 [&typeConverter](MemRefType ty) -> std::optional<Type> {
152 auto intTy = dyn_cast<IntegerType>(ty.getElementType());
156 if (intTy.getIntOrFloatBitWidth() <=
164 return ty.cloneWith(std::nullopt, newElemTy);
This class implements a pattern rewriter for use with ConversionPatterns.
LogicalResult notifyMatchFailure(Location loc, function_ref< void(Diagnostic &)> reasonCallback) override
PatternRewriter hook for notifying match failure reasons.
This class describes a specific conversion target.
MLIRContext is the top-level object for a collection of MLIR operations.
OpConversionPattern is a wrapper around ConversionPattern that allows for matching and rewriting agai...
OpConversionPattern(MLIRContext *context, PatternBenefit benefit=1)
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
Location getLoc()
The source location the operation was defined or derived from.
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replaces the result op with a new op that is created without verification.
void addConversion(FnT &&callback)
Register a conversion function.
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results) const
Convert the given type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Converts integer types that are too wide for the target by splitting them in two halves and thus turn...
unsigned getMaxTargetIntBitWidth() const
void populateArithWideIntEmulationPatterns(WideIntEmulationConverter &typeConverter, RewritePatternSet &patterns)
Adds patterns to emulate wide Arith and Function ops over integer types into supported ones.
void populateMemRefWideIntEmulationPatterns(arith::WideIntEmulationConverter &typeConverter, RewritePatternSet &patterns)
Appends patterns for emulating wide integer memref operations with ops over narrower integer types.
void populateMemRefWideIntEmulationConversions(arith::WideIntEmulationConverter &typeConverter)
Appends type conversions for emulating wide integer memref operations with ops over narrowe integer t...
Include the generated interface declarations.
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, DenseSet< Operation * > *unconvertedOps=nullptr)
Below we define several entry points for operation conversion.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.