17 #include "llvm/ADT/SCCIterator.h"
18 #include "llvm/ADT/TypeSwitch.h"
22 #include "mlir/Dialect/Transform/IR/TransformDialect.cpp.inc"
24 #define GET_ATTRDEF_CLASSES
25 #include "mlir/Dialect/Transform/IR/TransformAttrs.cpp.inc"
37 opName.
hasInterface<ConversionPatternDescriptorOpInterface>() ||
38 opName.
hasInterface<TypeConverterBuilderOpInterface>() ||
40 "non-terminator ops injected into the transform dialect must "
41 "implement TransformOpInterface or PatternDescriptorOpInterface or "
42 "ConversionPatternDescriptorOpInterface");
43 if (!opName.
hasInterface<PatternDescriptorOpInterface>() &&
44 !opName.
hasInterface<ConversionPatternDescriptorOpInterface>() &&
45 !opName.
hasInterface<TypeConverterBuilderOpInterface>()) {
47 "ops injected into the transform dialect must implement "
48 "MemoryEffectsOpInterface");
55 assert((abstractType.hasInterface(
56 TransformHandleTypeInterface::getInterfaceID()) ||
57 abstractType.hasInterface(
58 TransformParamTypeInterface::getInterfaceID()) ||
59 abstractType.hasInterface(
60 TransformValueHandleTypeInterface::getInterfaceID())) &&
61 "expected Transform dialect type to implement one of the three "
66 void transform::TransformDialect::initialize() {
71 #include "mlir/Dialect/Transform/IR/TransformOps.cpp.inc"
75 #define GET_ATTRDEF_LIST
76 #include "mlir/Dialect/Transform/IR/TransformAttrs.cpp.inc"
78 initializeLibraryModule();
87 auto it = typeParsingHooks.find(keyword);
88 if (it == typeParsingHooks.end()) {
89 parser.
emitError(loc) <<
"unknown type mnemonic: " << keyword;
93 return it->getValue()(parser);
98 auto it = typePrintingHooks.find(type.
getTypeID());
99 assert(it != typePrintingHooks.end() &&
"printing unknown type");
100 it->getSecond()(type, printer);
103 LogicalResult transform::TransformDialect::loadIntoLibraryModule(
108 void transform::TransformDialect::initializeLibraryModule() {
112 libraryModule = ModuleOp::create(loc,
"__transform_library");
113 libraryModule.get()->setAttr(TransformDialect::kWithNamedSequenceAttrName,
117 void transform::TransformDialect::reportDuplicateTypeRegistration(
118 StringRef mnemonic) {
120 llvm::raw_string_ostream msg(buffer);
121 msg <<
"extensible dialect type '" << mnemonic
122 <<
"' is already registered with a different implementation";
123 llvm::report_fatal_error(StringRef(buffer));
126 void transform::TransformDialect::reportDuplicateOpRegistration(
129 llvm::raw_string_ostream msg(buffer);
130 msg <<
"extensible dialect operation '" << opName
131 <<
"' is already registered with a mismatching TypeID";
132 llvm::report_fatal_error(StringRef(buffer));
135 LogicalResult transform::TransformDialect::verifyOperationAttribute(
137 if (attribute.
getName().getValue() == kWithNamedSequenceAttrName) {
140 <<
" attribute can only be attached to "
141 "operations with symbol tables";
148 if (!isa<CallableOpInterface, CallOpInterface>(nested))
159 for (
auto scc = llvm::scc_begin(&callgraph); !scc.isAtEnd(); ++scc) {
165 if ((*scc->begin())->isExternal())
166 return op->
emitOpError() <<
"contains a call to an external operation, "
167 "which is not allowed";
171 <<
"recursion not allowed in named sequences";
172 for (
auto it = std::next(scc->begin()); it != scc->end(); ++it) {
175 if ((*it)->isExternal()) {
176 return op->
emitOpError() <<
"contains a call to an external "
177 "operation, which is not allowed";
181 diag.attachNote(current->
getLoc()) <<
"operation on recursion stack";
187 if (attribute.
getName().getValue() == kTargetTagAttrName) {
188 if (!llvm::isa<StringAttr>(attribute.
getValue())) {
190 << attribute.
getName() <<
" attribute must be a string";
194 if (attribute.
getName().getValue() == kArgConsumedAttrName ||
195 attribute.
getName().getValue() == kArgReadOnlyAttrName) {
196 if (!llvm::isa<UnitAttr>(attribute.
getValue())) {
198 << attribute.
getName() <<
" must be a unit attribute";
202 if (attribute.
getName().getValue() ==
203 FindPayloadReplacementOpInterface::kSilenceTrackingFailuresAttrName) {
204 if (!llvm::isa<UnitAttr>(attribute.
getValue())) {
206 << attribute.
getName() <<
" must be a unit attribute";
211 <<
"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...
static FileLineColLoc get(StringAttr filename, unsigned line, unsigned column)
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.
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
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.
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
bool wasInterrupted() const
Returns true if the walk was interrupted.
static WalkResult interrupt()
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.
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...