27 LogicalResult matchAndRewrite(tosa::VariableOp op,
30 auto newVariable = rewriter.create<mlir::ml_program::GlobalOp>(
31 op.getLoc(), op.getName(), variableType,
true,
32 op.getInitialValueAttr(),
nullptr);
33 newVariable.setPrivate();
34 rewriter.replaceOp(op, newVariable);
39 class VariableWriteOpConverter
44 LogicalResult matchAndRewrite(tosa::VariableWriteOp op,
46 auto globalSymbolRef =
48 auto newVariableWrite = rewriter.create<ml_program::GlobalStoreOp>(
49 op.getLoc(), globalSymbolRef, op.getInput1());
50 rewriter.replaceOp(op, newVariableWrite);
55 class VariableReadOpConverter :
public OpRewritePattern<tosa::VariableReadOp> {
59 LogicalResult matchAndRewrite(tosa::VariableReadOp op,
61 auto globalSymbolRef =
63 auto newVariableRead = rewriter.create<ml_program::GlobalLoadOp>(
64 op.getLoc(), op.getType(), globalSymbolRef);
65 rewriter.replaceOp(op, newVariableRead);
75 patterns->add<VariableOpConverter, VariableWriteOpConverter,
76 VariableReadOpConverter>(
patterns->getContext());
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
RankedTensorType getVariableType(VariableOp variableOp)
void populateTosaToMLProgramConversionPatterns(RewritePatternSet *patterns)
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...