22 #include "mlir/Dialect/Bufferization/IR/BufferizationOpsDialect.cpp.inc"
26 constexpr const ::llvm::StringLiteral BufferizationDialect::kWritableAttrName;
30 constexpr const ::llvm::StringLiteral
31 BufferizationDialect::kBufferLayoutAttrName;
41 constexpr const ::llvm::StringLiteral BufferizationDialect::kManualDeallocation;
57 template <
typename Tensor>
58 struct BuiltinTensorExternalModel
59 : TensorLikeType::ExternalModel<BuiltinTensorExternalModel<Tensor>,
62 template <
typename MemRef>
63 struct BuiltinMemRefExternalModel
64 : BufferLikeType::ExternalModel<BuiltinMemRefExternalModel<MemRef>,
72 void mlir::bufferization::BufferizationDialect::initialize() {
75 #include "mlir/Dialect/Bufferization/IR/BufferizationOps.cpp.inc"
77 addInterfaces<BufferizationInlinerInterface>();
84 RankedTensorType::attachInterface<
85 BuiltinTensorExternalModel<RankedTensorType>>(*
getContext());
86 UnrankedTensorType::attachInterface<
87 BuiltinTensorExternalModel<UnrankedTensorType>>(*
getContext());
88 MemRefType::attachInterface<BuiltinMemRefExternalModel<MemRefType>>(
90 UnrankedMemRefType::attachInterface<
91 BuiltinMemRefExternalModel<UnrankedMemRefType>>(*
getContext());
94 LogicalResult BufferizationDialect::verifyRegionArgAttribute(
95 Operation *op,
unsigned ,
unsigned argIndex,
97 if (attr.
getName() == kWritableAttrName) {
98 if (!llvm::isa<BoolAttr>(attr.
getValue())) {
99 return op->
emitError() <<
"'" << kWritableAttrName
100 <<
"' is expected to be a boolean attribute";
102 if (!isa<FunctionOpInterface>(op))
103 return op->
emitError() <<
"expected '" << kWritableAttrName
104 <<
"' to be used on function-like operations";
105 if (cast<FunctionOpInterface>(op).isExternal())
106 return op->
emitError() <<
"'" << kWritableAttrName
107 <<
"' is invalid on external functions";
110 if (attr.
getName() == kBufferAccessAttrName) {
111 if (!llvm::isa<StringAttr>(attr.
getValue())) {
112 return op->
emitError() <<
"'" << kBufferAccessAttrName
113 <<
"' is expected to be a string attribute";
115 StringRef str = llvm::cast<StringAttr>(attr.
getValue()).getValue();
116 if (str !=
"none" && str !=
"read" && str !=
"write" && str !=
"read-write")
118 <<
"invalid value for '" << kBufferAccessAttrName <<
"'";
119 if (!isa<FunctionOpInterface>(op))
120 return op->
emitError() <<
"expected '" << kBufferAccessAttrName
121 <<
"' to be used on function-like operations";
124 if (attr.
getName() == kBufferLayoutAttrName) {
125 if (!llvm::isa<AffineMapAttr>(attr.
getValue())) {
126 return op->
emitError() <<
"'" << kBufferLayoutAttrName
127 <<
"' is expected to be a affine map attribute";
129 if (!isa<FunctionOpInterface>(op))
130 return op->
emitError() <<
"expected '" << kBufferLayoutAttrName
131 <<
"' to be used on function-like operations";
134 return op->
emitError() <<
"attribute '" << kBufferLayoutAttrName
135 <<
"' not supported as a region arg attribute by the "
136 "bufferization dialect";
140 BufferizationDialect::verifyOperationAttribute(
Operation *op,
142 using bufferization::BufferizableOpInterface;
144 if (attr.
getName() == kManualDeallocation) {
145 if (!mlir::hasEffect<MemoryEffects::Allocate>(op) &&
146 !mlir::hasEffect<MemoryEffects::Free>(op))
148 << kManualDeallocation
149 <<
"' can be used only on ops that have an allocation and/or free "
155 <<
"attribute '" << attr.
getName()
156 <<
"' not supported as an op attribute by the bufferization dialect";
static MLIRContext * getContext(OpFoldResult val)
static bool isLegalToInline(InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, IRMapping &valueMapping)
Utility to check that all of the operations within 'src' can be inlined.
This is the interface that must be implemented by the dialects of operations to be inlined.
DialectInlinerInterface(Dialect *dialect)
This is a utility class for mapping one set of IR entities to another.
NamedAttribute represents a combination of a name and an Attribute value.
StringAttr getName() const
Return the name of the attribute.
Attribute getValue() const
Return the value of the attribute.
Operation is the basic unit of execution within MLIR.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Include the generated interface declarations.