24template <
typename Interface,
typename Op>
25struct ExternalModelBase
26 :
public BufferizableOpInterface::ExternalModel<Interface, Op> {
28 AliasingValueList getAliasingValues(Operation *, OpOperand &,
29 const AnalysisState &)
const {
33 BufferRelation bufferRelation(Operation *, OpResult,
34 const AnalysisState &)
const {
35 return BufferRelation::Unknown;
40struct GlobalOpInterface
41 :
public ExternalModelBase<GlobalOpInterface, GlobalOp> {
43 bool bufferizesToMemoryRead(Operation *, OpOperand &,
44 const AnalysisState &)
const {
48 bool bufferizesToMemoryWrite(Operation *, OpOperand &,
49 const AnalysisState &)
const {
53 bool hasTensorSemantics(Operation *)
const {
return true; }
55 LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
56 const BufferizationOptions &,
57 BufferizationState &state)
const {
58 auto globalOp = cast<GlobalOp>(op);
59 if (!globalOp.getValue().has_value())
60 return globalOp.emitError(
"global op must have a value");
64 auto tensorType = cast<TensorType>(globalOp.getType());
65 auto memrefType = getMemRefTypeWithStaticIdentityLayout(tensorType);
67 auto replacement = replaceOpWithNewBufferizedOp<memref::GlobalOp>(
68 rewriter, globalOp, globalOp.getSymName(),
69 globalOp.getSymVisibilityAttr(),
70 cast<MemRefType>(memrefType),
71 globalOp.getValue().value(),
72 !globalOp.getIsMutable(),
81struct GlobalLoadOpInterface
82 :
public ExternalModelBase<GlobalLoadOpInterface, GlobalLoadOp> {
84 bool bufferizesToMemoryRead(Operation *, OpOperand &,
85 const AnalysisState &)
const {
89 bool bufferizesToMemoryWrite(Operation *, OpOperand &,
90 const AnalysisState &)
const {
94 bool isWritable(Operation *, Value,
const AnalysisState &)
const {
98 LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
99 const BufferizationOptions &,
100 BufferizationState &state)
const {
101 auto globalLoadOp = cast<GlobalLoadOp>(op);
103 auto tensorType = cast<TensorType>(globalLoadOp.getType());
104 auto memrefType = getMemRefTypeWithStaticIdentityLayout(tensorType);
106 replaceOpWithNewBufferizedOp<memref::GetGlobalOp>(
107 rewriter, globalLoadOp, memrefType,
108 globalLoadOp.getGlobalAttr().getLeafReference());
116struct GlobalStoreOpInterface
117 :
public ExternalModelBase<GlobalStoreOpInterface, GlobalStoreOp> {
119 bool bufferizesToMemoryRead(Operation *, OpOperand &,
120 const AnalysisState &)
const {
124 bool bufferizesToMemoryWrite(Operation *, OpOperand &,
125 const AnalysisState &)
const {
129 LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
130 const BufferizationOptions &
options,
131 BufferizationState &state)
const {
132 auto globalStoreOp = cast<GlobalStoreOp>(op);
134 auto tensorType = cast<TensorType>(globalStoreOp.getValue().getType());
135 auto memrefType = getMemRefTypeWithStaticIdentityLayout(tensorType);
137 auto loc = globalStoreOp.getLoc();
138 auto targetMemref = memref::GetGlobalOp::create(
139 rewriter, loc, memrefType,
140 globalStoreOp.getGlobalAttr().getLeafReference());
143 getBuffer(rewriter, globalStoreOp.getValue(),
options, state);
144 if (
failed(sourceMemref)) {
149 options.createMemCpy(rewriter, loc, sourceMemref.value(), targetMemref);
153 rewriter.
eraseOp(globalStoreOp);
162 GlobalOp::attachInterface<GlobalOpInterface>(*ctx);
163 GlobalLoadOp::attachInterface<GlobalLoadOpInterface>(*ctx);
164 GlobalStoreOp::attachInterface<GlobalStoreOpInterface>(*ctx);
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be the output argument nBegin is set to its * replacement(set to `begin` if no invalidation happens). Since outgoing *copies could have been inserted at `end`
static llvm::ManagedStatic< PassManagerOptions > options
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
void insertSymbol(Operation *op, BufferizationState &state)
void removeSymbol(Operation *op, BufferizationState &state)
void registerBufferizableOpInterfaceExternalModels(DialectRegistry ®istry)
Include the generated interface declarations.