29#include "mlir/IR/BuiltinDialect.cpp.inc"
43struct BuiltinOpAsmDialectInterface :
public OpAsmDialectInterface {
44 BuiltinOpAsmDialectInterface(
Dialect *dialect,
46 : OpAsmDialectInterface(dialect), blobManager(mgr) {}
49 if (llvm::isa<LocationAttr>(attr)) {
51 return AliasResult::OverridableAlias;
53 if (
auto distinct = llvm::dyn_cast<DistinctAttr>(attr))
54 if (!llvm::isa<UnitAttr>(distinct.getReferencedAttr())) {
56 return AliasResult::OverridableAlias;
62 if (
auto tupleType = llvm::dyn_cast<TupleType>(type)) {
63 if (tupleType.size() > 16) {
65 return AliasResult::OverridableAlias;
77 return cast<DenseResourceElementsHandle>(handle).getKey().str();
79 FailureOr<AsmDialectResourceHandle>
80 declareResource(StringRef key)
const final {
81 return blobManager.insert(key);
84 FailureOr<AsmResourceBlob> blob = entry.
parseAsBlob();
89 blobManager.update(entry.
getKey(), std::move(*blob));
96 blobManager.buildResources(provider, referencedResources.getArrayRef());
105void BuiltinDialect::initialize() {
108 registerAttributes();
109 registerLocationAttributes();
112#include "mlir/IR/BuiltinOps.cpp.inc"
115 auto &blobInterface = addInterface<BuiltinBlobManagerInterface>();
116 addInterface<BuiltinOpAsmDialectInterface>(blobInterface);
125 std::optional<StringRef> name) {
134ModuleOp ModuleOp::create(
Location loc, std::optional<StringRef> name) {
136 return ModuleOp::create(builder, loc, name);
146 FailureOr<const DialectVersion *> maybeVersion =
148 if (
failed(maybeVersion) ||
149 static_cast<const BuiltinDialectVersion *
>(*maybeVersion)->getVersion() <
156 Properties &properties = getProperties();
160 FailureOr<const DialectVersion *> maybeVersion =
162 if (succeeded(maybeVersion) &&
163 static_cast<const BuiltinDialectVersion *
>(*maybeVersion)->getVersion() <
169DataLayoutSpecInterface ModuleOp::getDataLayoutSpec() {
173 for (NamedAttribute attr :
174 getOperation()->getDiscardableAttrDictionary().getValue())
175 if (
auto spec = llvm::dyn_cast<DataLayoutSpecInterface>(attr.getValue()))
180TargetSystemSpecInterface ModuleOp::getTargetSystemSpec() {
184 for (NamedAttribute attr :
185 getOperation()->getDiscardableAttrDictionary().getValue())
186 if (
auto spec = llvm::dyn_cast<TargetSystemSpecInterface>(attr.getValue()))
191LogicalResult ModuleOp::verify() {
194 for (
auto attr : (*this)->getDiscardableAttrDictionary().getValue()) {
195 if (!attr.getName().strref().contains(
'.') &&
198 getSymNameAttrName().getValue(),
199 mlir::SymbolOpInterface::getDefaultVisibilityAttrName()},
200 attr.getName().strref()))
201 return emitOpError() <<
"can only contain attributes with "
202 "dialect-prefixed names, found: '"
203 << attr.getName().getValue() <<
"'";
207 StringRef layoutSpecAttrName;
208 DataLayoutSpecInterface layoutSpec;
209 for (
const NamedAttribute &na :
210 (*this)->getDiscardableAttrDictionary().getValue()) {
211 if (
auto spec = llvm::dyn_cast<DataLayoutSpecInterface>(na.getValue())) {
213 InFlightDiagnostic diag =
214 emitOpError() <<
"expects at most one data layout attribute";
215 diag.
attachNote() <<
"'" << layoutSpecAttrName
216 <<
"' is a data layout attribute";
217 diag.
attachNote() <<
"'" << na.getName().getValue()
218 <<
"' is a data layout attribute";
220 layoutSpecAttrName = na.getName().strref();
233UnrealizedConversionCastOp::fold(FoldAdaptor adaptor,
239 foldResults.append(operands.begin(), operands.end());
243 if (operands.empty())
249 Value firstInput = operands.front();
250 auto inputOp = firstInput.
getDefiningOp<UnrealizedConversionCastOp>();
251 if (!inputOp || inputOp.getResults() != operands ||
252 inputOp.getOperandTypes() != results.
getTypes())
256 foldResults.append(inputOp->operand_begin(), inputOp->operand_end());
260LogicalResult UnrealizedConversionCastOp::verify() {
263 if (getNumResults() == 0)
264 return emitOpError() <<
"expected at least one result for cast operation";
272#define GET_OP_CLASSES
273#include "mlir/IR/BuiltinOps.cpp.inc"
ResourceBlobManagerDialectInterfaceBase< DenseResourceElementsHandle > BuiltinBlobManagerInterface
The possible results of an alias query.
@ NoAlias
The two locations do not alias at all.
This class represents an opaque handle to a dialect resource entry.
This class represents a single parsed resource entry.
virtual FailureOr< AsmResourceBlob > parseAsBlob(BlobAllocatorFn allocator) const =0
Parse the resource entry represented by a binary blob.
virtual StringRef getKey() const =0
Return the key of the resource entry.
This class is used to build resource entries for use by the printer.
Attributes are known-constant values of operations.
MLIRContext * getContext() const
Return the context this attribute belongs to.
StringAttr getStringAttr(const Twine &bytes)
NamedAttribute getNamedAttr(StringRef name, Attribute val)
This class defines a virtual interface for reading a bytecode stream, providing hooks into the byteco...
virtual FailureOr< const DialectVersion * > getDialectVersion(StringRef dialectName) const =0
Retrieve the dialect version by name if available.
virtual LogicalResult readOptionalAttribute(Attribute &attr)=0
Read an optional reference to the given attribute.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
virtual FailureOr< const DialectVersion * > getDialectVersion(StringRef dialectName) const =0
Retrieve the dialect version by name if available.
virtual void writeOptionalAttribute(Attribute attr)=0
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Diagnostic & attachNote(std::optional< Location > noteLoc=std::nullopt)
Attaches a note to this diagnostic.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
void push_back(NamedAttribute newAttribute)
Add an attribute with the specified name.
This class helps build Operations.
This class implements the operand iterators for the Operation class.
type_range getType() const
Operation is the basic unit of execution within MLIR.
This class provides a base class for dialects implementing the resource blob interface.
This class implements the result iterators for the Operation class.
type_range getTypes() const
type_range getType() const
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
void addBytecodeInterface(BuiltinDialect *dialect)
Add the interfaces necessary for encoding the builtin dialect components in bytecode.
Include the generated interface declarations.
llvm::SetVector< T, Vector, Set, N > SetVector
static BuiltinDialectVersion getCurrentVersion()
This represents an operation in an abstracted form, suitable for use with the builder APIs.
T & getOrAddProperties()
Get (or create) the properties of the provided type to be set on the operation on creation.
Region * addRegion()
Create a region that should be attached to the operation.