MLIR 22.0.0git
TransformInterpreterUtils.h
Go to the documentation of this file.
1//===- TransformInterpreterUtils.h - Transform Utils ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_DIALECT_TRANSFORM_TRANSFORMS_TRANSFORMINTERPRETERUTILS_H
10#define MLIR_DIALECT_TRANSFORM_TRANSFORMS_TRANSFORMINTERPRETERUTILS_H
11
14#include "mlir/Pass/Pass.h"
15#include "mlir/Support/LLVM.h"
16#include <memory>
17
18namespace mlir {
19class MLIRContext;
20class ModuleOp;
21class Operation;
22template <typename>
23class OwningOpRef;
24class Region;
25
26namespace transform {
27namespace detail {
28
29/// Expands the given list of `paths` to a list of `.mlir` files.
30///
31/// Each entry in `paths` may either be a regular file, in which case it ends up
32/// in the result list, or a directory, in which case all (regular) `.mlir`
33/// files in that directory are added. Any other file types lead to a failure.
34LogicalResult expandPathsToMLIRFiles(ArrayRef<std::string> paths,
35 MLIRContext *context,
36 SmallVectorImpl<std::string> &fileNames);
37
38/// Utility to parse and verify the content of a `transformFileName` MLIR file
39/// containing a transform dialect specification.
40LogicalResult
41parseTransformModuleFromFile(MLIRContext *context,
42 llvm::StringRef transformFileName,
43 OwningOpRef<ModuleOp> &transformModule);
44
45/// Utility to parse, verify, aggregate and link the content of all mlir files
46/// nested under `transformLibraryPaths` and containing transform dialect
47/// specifications.
48LogicalResult
49assembleTransformLibraryFromPaths(MLIRContext *context,
50 ArrayRef<std::string> transformLibraryPaths,
51 OwningOpRef<ModuleOp> &transformModule);
52
53/// Utility to load a transform interpreter `module` from a module that has
54/// already been preloaded in the context.
55/// This mode is useful in cases where explicit parsing of a transform library
56/// from file is expected to be prohibitively expensive.
57/// In such cases, the transform module is expected to be found in the preloaded
58/// library modules of the transform dialect.
59/// Returns null if the module is not found.
60ModuleOp getPreloadedTransformModule(MLIRContext *context);
61
62/// Finds the first TransformOpInterface named `kTransformEntryPointSymbolName`
63/// that is either:
64/// 1. nested under `root` (takes precedence).
65/// 2. nested under `module`, if not found in `root`.
66/// Reports errors and returns null if no such operation found.
67TransformOpInterface findTransformEntryPoint(
68 Operation *root, ModuleOp module,
69 StringRef entryPoint = TransformDialect::kTransformEntryPointSymbolName);
70
71} // namespace detail
72
73/// Standalone util to apply the named sequence `transformRoot` to `payload` IR.
74/// This is done in 2 steps:
75/// 1. If `transformModule` is provided and is not nested under
76/// `transformRoot`, it will be "linked into" the IR containing
77/// `transformRoot` to resolve undefined named sequences.
78/// 2. The transforms specified in `transformRoot` are applied to `payload`,
79/// assuming the named sequence has a single argument handle that will be
80/// associated with `payload` on run.
81LogicalResult applyTransformNamedSequence(Operation *payload,
82 Operation *transformRoot,
83 ModuleOp transformModule,
85
86LogicalResult applyTransformNamedSequence(RaggedArray<MappedValue> bindings,
87 TransformOpInterface transformRoot,
88 ModuleOp transformModule,
90
91} // namespace transform
92} // namespace mlir
93
94#endif // MLIR_DIALECT_TRANSFORM_TRANSFORMS_TRANSFORMINTERPRETERUTILS_H
static llvm::ManagedStatic< PassManagerOptions > options
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
Definition OwningOpRef.h:29
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
Options controlling the application of transform operations by the TransformState.
LogicalResult assembleTransformLibraryFromPaths(MLIRContext *context, ArrayRef< std::string > transformLibraryPaths, OwningOpRef< ModuleOp > &transformModule)
Utility to parse, verify, aggregate and link the content of all mlir files nested under transformLibr...
LogicalResult parseTransformModuleFromFile(MLIRContext *context, llvm::StringRef transformFileName, OwningOpRef< ModuleOp > &transformModule)
Utility to parse and verify the content of a transformFileName MLIR file containing a transform diale...
ModuleOp getPreloadedTransformModule(MLIRContext *context)
Utility to load a transform interpreter module from a module that has already been preloaded in the c...
LogicalResult expandPathsToMLIRFiles(ArrayRef< std::string > paths, MLIRContext *context, SmallVectorImpl< std::string > &fileNames)
Expands the given list of paths to a list of .mlir files.
TransformOpInterface findTransformEntryPoint(Operation *root, ModuleOp module, StringRef entryPoint=TransformDialect::kTransformEntryPointSymbolName)
Finds the first TransformOpInterface named kTransformEntryPointSymbolName that is either:
LogicalResult applyTransformNamedSequence(Operation *payload, Operation *transformRoot, ModuleOp transformModule, const TransformOptions &options)
Standalone util to apply the named sequence transformRoot to payload IR.
Include the generated interface declarations.