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() {
107 registerAttributes();
108 registerLocationAttributes();
111#include "mlir/IR/BuiltinOps.cpp.inc"
114 auto &blobInterface = addInterface<BuiltinBlobManagerInterface>();
115 addInterface<BuiltinOpAsmDialectInterface>(blobInterface);
124 std::optional<StringRef> name) {
133ModuleOp ModuleOp::create(
Location loc, std::optional<StringRef> name) {
135 return ModuleOp::create(builder, loc, name);
138DataLayoutSpecInterface ModuleOp::getDataLayoutSpec() {
142 for (NamedAttribute attr :
143 getOperation()->getDiscardableAttrDictionary().getValue())
144 if (
auto spec = llvm::dyn_cast<DataLayoutSpecInterface>(attr.getValue()))
149TargetSystemSpecInterface ModuleOp::getTargetSystemSpec() {
153 for (NamedAttribute attr :
154 getOperation()->getDiscardableAttrDictionary().getValue())
155 if (
auto spec = llvm::dyn_cast<TargetSystemSpecInterface>(attr.getValue()))
160LogicalResult ModuleOp::verify() {
163 for (
auto attr : (*this)->getDiscardableAttrDictionary().getValue()) {
164 if (!attr.getName().strref().contains(
'.') &&
167 getSymNameAttrName().getValue(),
168 mlir::SymbolOpInterface::getDefaultVisibilityAttrName()},
169 attr.getName().strref()))
170 return emitOpError() <<
"can only contain attributes with "
171 "dialect-prefixed names, found: '"
172 << attr.getName().getValue() <<
"'";
176 StringRef layoutSpecAttrName;
177 DataLayoutSpecInterface layoutSpec;
178 for (
const NamedAttribute &na :
179 (*this)->getDiscardableAttrDictionary().getValue()) {
180 if (
auto spec = llvm::dyn_cast<DataLayoutSpecInterface>(na.getValue())) {
182 InFlightDiagnostic
diag =
183 emitOpError() <<
"expects at most one data layout attribute";
184 diag.attachNote() <<
"'" << layoutSpecAttrName
185 <<
"' is a data layout attribute";
186 diag.attachNote() <<
"'" << na.getName().getValue()
187 <<
"' is a data layout attribute";
189 layoutSpecAttrName = na.getName().strref();
202UnrealizedConversionCastOp::fold(FoldAdaptor adaptor,
208 foldResults.append(operands.begin(), operands.end());
212 if (operands.empty())
218 Value firstInput = operands.front();
219 auto inputOp = firstInput.
getDefiningOp<UnrealizedConversionCastOp>();
220 if (!inputOp || inputOp.getResults() != operands ||
221 inputOp.getOperandTypes() != results.
getTypes())
225 foldResults.append(inputOp->operand_begin(), inputOp->operand_end());
229LogicalResult UnrealizedConversionCastOp::verify() {
232 if (getNumResults() == 0)
233 return emitOpError() <<
"expected at least one result for cast operation";
241#define GET_OP_CLASSES
242#include "mlir/IR/BuiltinOps.cpp.inc"
ResourceBlobManagerDialectInterfaceBase< DenseResourceElementsHandle > BuiltinBlobManagerInterface
static std::string diag(const llvm::Value &value)
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)
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
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
This represents an operation in an abstracted form, suitable for use with the builder APIs.
Region * addRegion()
Create a region that should be attached to the operation.