9#ifndef MLIR_DIALECT_TRANSFORM_IR_TRANSFORMDIALECT_H
10#define MLIR_DIALECT_TRANSFORM_IR_TRANSFORMDIALECT_H
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/StringMap.h"
36 : typeID(typeID), ctx(ctx) {}
61template <
typename DerivedTy>
86#include "mlir/Dialect/Transform/IR/TransformDialect.h.inc"
116template <
typename DerivedTy,
typename... ExtraDialects>
119 using Initializer = std::function<
void(TransformDialect *)>;
126 ExtraDialects *...)
const final {
127 for (
const DialectLoader &loader : dialectLoaders)
133 for (
const DialectLoader &loader : generatedDialectLoaders)
136 for (
const Initializer &
init : initializers)
137 init(transformDialect);
146 : buildOnly(buildOnly) {
157 template <
typename Func>
160 dialectLoaders.push_back(
173 template <
typename DataTy,
typename Func>
175 static_assert(std::is_base_of_v<detail::TransformDialectDataBase, DataTy>,
176 "only classes deriving TransformDialectData are accepted");
178 std::function<
void(DataTy &)> initializer =
func;
179 initializers.push_back(
180 [
init = std::move(initializer)](TransformDialect *transformDialect) {
181 init(transformDialect->getOrCreateExtraData<DataTy>());
191 template <
typename... OpTys>
193 initializers.push_back([](TransformDialect *transformDialect) {
194 transformDialect->addOperationsChecked<OpTys...>();
203 template <
typename... TypeTys>
205 initializers.push_back([](TransformDialect *transformDialect) {
206 transformDialect->addTypesChecked<TypeTys...>();
218 template <
typename DialectTy>
220 dialectLoaders.push_back(
230 template <
typename DialectTy>
232 generatedDialectLoaders.push_back(
253template <
typename OpTy>
254void TransformDialect::addOperationIfNotRegistered() {
255 std::optional<RegisteredOperationName> opName =
258 addOperations<OpTy>();
260 StringRef name = OpTy::getOperationName();
269 reportDuplicateOpRegistration(OpTy::getOperationName());
272template <
typename Type>
273void TransformDialect::addTypeIfNotRegistered() {
276 StringRef mnemonic = Type::getMnemonic();
277 auto [it,
inserted] = typeParsingHooks.try_emplace(mnemonic, Type::parse);
279 const ExtensionTypeParsingHook &parsingHook = it->getValue();
280 if (parsingHook != &Type::parse)
281 reportDuplicateTypeRegistration(mnemonic);
285 typePrintingHooks.try_emplace(
287 printer << Type::getMnemonic();
288 cast<Type>(type).print(printer);
298template <
typename DataTy>
299DataTy &TransformDialect::getOrCreateExtraData() {
301 auto [it,
inserted] = extraData.try_emplace(typeID);
303 it->getSecond() = std::make_unique<DataTy>(
getContext());
304 return static_cast<DataTy &
>(*it->getSecond());
309template <
typename DerivedTy>
true
Given two iterators into the same block, return "true" if a is before `b.
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be inserted(the insertion happens right before the *insertion point). Since `begin` can itself be invalidated due to the memref *rewriting done from this method
MLIRContext is the top-level object for a collection of MLIR operations.
void loadDialect()
Load a dialect in the context.
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.
static TypeID get()
Construct a type info object for the given type T.
TransformDialectExtension(bool buildOnly=false)
Extension constructor.
TransformDialectExtension< DerivedTy, ExtraDialects... > Base
void registerTransformOps()
Injects the operations into the Transform dialect.
void declareDependentDialect()
Declares that this Transform dialect extension depends on the dialect provided as template parameter.
void declareGeneratedDialect()
Declares that the transformations associated with the operations registered by this dialect extension...
void addDialectDataInitializer(Func &&func)
Registers the given function as one of the initializers for the dialect-owned data of the kind specif...
void apply(MLIRContext *context, TransformDialect *transformDialect, ExtraDialects *...) const final
Extension application hook.
void registerTypes()
Injects the types into the Transform dialect.
void addCustomInitializationStep(Func &&func)
Registers a custom initialization step to be performed when the extension is applied to the dialect w...
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...