29 auto newVariable = rewriter.create<mlir::ml_program::GlobalOp>(
31 op.getInitialValueAttr(),
nullptr);
32 newVariable.setPrivate();
33 rewriter.replaceOp(op, newVariable);
38 class VariableWriteOpConverter
45 auto globalSymbolRef =
47 auto newVariableWrite = rewriter.create<ml_program::GlobalStoreOp>(
48 op.
getLoc(), globalSymbolRef, op.getValue());
49 rewriter.replaceOp(op, newVariableWrite);
54 class VariableReadOpConverter :
public OpRewritePattern<tosa::VariableReadOp> {
60 auto globalSymbolRef =
62 auto newVariableRead = rewriter.create<ml_program::GlobalLoadOp>(
63 op.
getLoc(), op.getType(), globalSymbolRef);
64 rewriter.replaceOp(op, newVariableRead);
74 patterns->
add<VariableOpConverter, VariableWriteOpConverter,
75 VariableReadOpConverter>(patterns->
getContext());
Location getLoc()
The source location the operation was defined or derived from.
OperationName getName()
The name of an operation is the key identifier for it.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
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.
void populateTosaToMLProgramConversionPatterns(RewritePatternSet *patterns)
Include the generated interface declarations.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This class represents an efficient way to signal success or failure.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...