16 #include "llvm/ADT/SCCIterator.h"
20 #include "mlir/Dialect/Transform/IR/TransformDialect.cpp.inc"
32 opName.
hasInterface<ConversionPatternDescriptorOpInterface>() ||
33 opName.
hasInterface<TypeConverterBuilderOpInterface>() ||
35 "non-terminator ops injected into the transform dialect must "
36 "implement TransformOpInterface or PatternDescriptorOpInterface or "
37 "ConversionPatternDescriptorOpInterface");
38 if (!opName.
hasInterface<PatternDescriptorOpInterface>() &&
39 !opName.
hasInterface<ConversionPatternDescriptorOpInterface>() &&
40 !opName.
hasInterface<TypeConverterBuilderOpInterface>()) {
42 "ops injected into the transform dialect must implement "
43 "MemoryEffectsOpInterface");
50 assert((abstractType.hasInterface(
51 TransformHandleTypeInterface::getInterfaceID()) ||
52 abstractType.hasInterface(
53 TransformParamTypeInterface::getInterfaceID()) ||
54 abstractType.hasInterface(
55 TransformValueHandleTypeInterface::getInterfaceID())) &&
56 "expected Transform dialect type to implement one of the three "
61 void transform::TransformDialect::initialize() {
66 #include "mlir/Dialect/Transform/IR/TransformOps.cpp.inc"
69 initializeLibraryModule();
78 auto it = typeParsingHooks.find(keyword);
79 if (it == typeParsingHooks.end()) {
80 parser.
emitError(loc) <<
"unknown type mnemonic: " << keyword;
84 return it->getValue()(parser);
89 auto it = typePrintingHooks.find(type.
getTypeID());
90 assert(it != typePrintingHooks.end() &&
"printing unknown type");
91 it->getSecond()(type, printer);
94 LogicalResult transform::TransformDialect::loadIntoLibraryModule(
99 void transform::TransformDialect::initializeLibraryModule() {
103 libraryModule = ModuleOp::create(loc,
"__transform_library");
104 libraryModule.get()->setAttr(TransformDialect::kWithNamedSequenceAttrName,
108 void transform::TransformDialect::reportDuplicateTypeRegistration(
109 StringRef mnemonic) {
111 llvm::raw_string_ostream msg(buffer);
112 msg <<
"extensible dialect type '" << mnemonic
113 <<
"' is already registered with a different implementation";
115 llvm::report_fatal_error(StringRef(buffer));
118 void transform::TransformDialect::reportDuplicateOpRegistration(
121 llvm::raw_string_ostream msg(buffer);
122 msg <<
"extensible dialect operation '" << opName
123 <<
"' is already registered with a mismatching TypeID";
125 llvm::report_fatal_error(StringRef(buffer));
128 LogicalResult transform::TransformDialect::verifyOperationAttribute(
130 if (attribute.
getName().getValue() == kWithNamedSequenceAttrName) {
133 <<
" attribute can only be attached to "
134 "operations with symbol tables";
138 for (
auto scc = llvm::scc_begin(&callgraph); !scc.isAtEnd(); ++scc) {
144 if ((*scc->begin())->isExternal())
145 return op->
emitOpError() <<
"contains a call to an external operation, "
146 "which is not allowed";
150 <<
"recursion not allowed in named sequences";
151 for (
auto it = std::next(scc->begin()); it != scc->end(); ++it) {
154 if ((*it)->isExternal()) {
155 return op->
emitOpError() <<
"contains a call to an external "
156 "operation, which is not allowed";
160 diag.attachNote(current->
getLoc()) <<
"operation on recursion stack";
166 if (attribute.
getName().getValue() == kTargetTagAttrName) {
167 if (!llvm::isa<StringAttr>(attribute.
getValue())) {
169 << attribute.
getName() <<
" attribute must be a string";
173 if (attribute.
getName().getValue() == kArgConsumedAttrName ||
174 attribute.
getName().getValue() == kArgReadOnlyAttrName) {
175 if (!llvm::isa<UnitAttr>(attribute.
getValue())) {
177 << attribute.
getName() <<
" must be a unit attribute";
181 if (attribute.
getName().getValue() ==
182 FindPayloadReplacementOpInterface::kSilenceTrackingFailuresAttrName) {
183 if (!llvm::isa<UnitAttr>(attribute.
getValue())) {
185 << attribute.
getName() <<
" must be a unit attribute";
190 <<
"unknown attribute: " << attribute.
getName();
static MLIRContext * getContext(OpFoldResult val)
static std::string diag(const llvm::Value &value)
static const AbstractType & lookup(TypeID typeID, MLIRContext *context)
Look up the specified abstract type in the MLIRContext and return a reference to it.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
The DialectAsmParser has methods for interacting with the asm parser when parsing attributes and type...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class represents a diagnostic that is inflight and set to be reported.
MLIRContext is the top-level object for a collection of MLIR operations.
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.
This class provides the API for ops that are known to be terminators.
A trait used to provide symbol table functionalities to a region operation.
bool hasTrait() const
Returns true if the operation was registered with a particular trait, e.g.
bool hasInterface() const
Returns true if this operation has the given interface registered to it.
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Location getLoc()
The source location the operation was defined or derived from.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
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 acts as an owning reference to an op, and will automatically destroy the held op on destru...
This is a "type erased" representation of a registered operation.
static std::optional< RegisteredOperationName > lookup(StringRef name, MLIRContext *ctx)
Lookup the registered operation information for the given operation.
This class provides an efficient unique identifier for a specific C++ type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
TypeID getTypeID()
Return a unique identifier for the concrete type.
void printType(Type type, AsmPrinter &printer)
Prints an LLVM Dialect type.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Type parseType(llvm::StringRef typeStr, MLIRContext *context, size_t *numRead=nullptr, bool isKnownNullTerminated=false)
This parses a single MLIR type to an MLIR context if it was valid.