28 matchAndRewrite(memref::AllocaOp op, OpAdaptor operands,
31 if (!op.getType().hasStaticShape()) {
33 op.getLoc(),
"cannot transform alloca with dynamic shape");
36 if (op.getAlignment().value_or(1) > 1) {
40 op.getLoc(),
"cannot transform alloca with alignment requirement");
43 auto resultTy = getTypeConverter()->convertType(op.getType());
57 matchAndRewrite(memref::GlobalOp op, OpAdaptor operands,
60 if (!op.getType().hasStaticShape()) {
62 op.getLoc(),
"cannot transform global with dynamic shape");
65 if (op.getAlignment().value_or(1) > 1) {
68 op.getLoc(),
"global variable with alignment requirement is "
69 "currently not supported");
71 auto resultTy = getTypeConverter()->convertType(op.getType());
74 "cannot convert result type");
82 "only public and private visibility is currently supported");
87 bool externSpecifier = !staticSpecifier;
89 Attribute initialValue = operands.getInitialValueAttr();
90 if (isa_and_present<UnitAttr>(initialValue))
94 op, operands.getSymName(), resultTy, initialValue, externSpecifier,
95 staticSpecifier, operands.getConstant());
100 struct ConvertGetGlobal final
105 matchAndRewrite(memref::GetGlobalOp op, OpAdaptor operands,
108 auto resultTy = getTypeConverter()->convertType(op.getType());
111 "cannot convert result type");
114 operands.getNameAttr());
123 matchAndRewrite(memref::LoadOp op, OpAdaptor operands,
126 auto resultTy = getTypeConverter()->convertType(op.getType());
132 dyn_cast<TypedValue<emitc::ArrayType>>(operands.getMemref());
137 auto subscript = rewriter.
create<emitc::SubscriptOp>(
138 op.getLoc(), arrayValue, operands.getIndices());
149 matchAndRewrite(memref::StoreOp op, OpAdaptor operands,
152 dyn_cast<TypedValue<emitc::ArrayType>>(operands.getMemref());
157 auto subscript = rewriter.
create<emitc::SubscriptOp>(
158 op.getLoc(), arrayValue, operands.getIndices());
160 operands.getValue());
168 [&](MemRefType memRefType) -> std::optional<Type> {
169 if (!memRefType.hasStaticShape() ||
170 !memRefType.getLayout().isIdentity() || memRefType.getRank() == 0 ||
171 llvm::any_of(memRefType.getShape(),
172 [](int64_t dim) { return dim == 0; })) {
175 Type convertedElementType =
176 typeConverter.
convertType(memRefType.getElementType());
177 if (!convertedElementType)
180 convertedElementType);
static MLIRContext * getContext(OpFoldResult val)
Attributes are known-constant values of operations.
This class implements a pattern rewriter for use with ConversionPatterns.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
OpConversionPattern is a wrapper around ConversionPattern that allows for matching and rewriting agai...
OpConversionPattern(MLIRContext *context, PatternBenefit benefit=1)
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
static Visibility getSymbolVisibility(Operation *symbol)
Returns the visibility of the given symbol operation.
Visibility
An enumeration detailing the different visibility types that a symbol may have.
@ Public
The symbol is public and may be referenced anywhere internal or external to the visible references in...
@ Private
The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the...
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...
Include the generated interface declarations.
void populateMemRefToEmitCTypeConversion(TypeConverter &typeConverter)
const FrozenRewritePatternSet & patterns
void populateMemRefToEmitCConversionPatterns(RewritePatternSet &patterns, const TypeConverter &converter)
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...