MLIR  19.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 
18 namespace mlir {
19 struct LogicalResult;
20 class MLIRContext;
21 class ModuleOp;
22 class Operation;
23 template <typename>
24 class OwningOpRef;
25 class Region;
26 
27 namespace transform {
28 namespace detail {
29 
30 /// Expands the given list of `paths` to a list of `.mlir` files.
31 ///
32 /// Each entry in `paths` may either be a regular file, in which case it ends up
33 /// in the result list, or a directory, in which case all (regular) `.mlir`
34 /// files in that directory are added. Any other file types lead to a failure.
35 LogicalResult expandPathsToMLIRFiles(ArrayRef<std::string> paths,
36  MLIRContext *context,
37  SmallVectorImpl<std::string> &fileNames);
38 
39 /// Utility to parse and verify the content of a `transformFileName` MLIR file
40 /// containing a transform dialect specification.
41 LogicalResult
42 parseTransformModuleFromFile(MLIRContext *context,
43  llvm::StringRef transformFileName,
44  OwningOpRef<ModuleOp> &transformModule);
45 
46 /// Utility to parse, verify, aggregate and link the content of all mlir files
47 /// nested under `transformLibraryPaths` and containing transform dialect
48 /// specifications.
49 LogicalResult
50 assembleTransformLibraryFromPaths(MLIRContext *context,
51  ArrayRef<std::string> transformLibraryPaths,
52  OwningOpRef<ModuleOp> &transformModule);
53 
54 /// Utility to load a transform interpreter `module` from a module that has
55 /// already been preloaded in the context.
56 /// This mode is useful in cases where explicit parsing of a transform library
57 /// from file is expected to be prohibitively expensive.
58 /// In such cases, the transform module is expected to be found in the preloaded
59 /// library modules of the transform dialect.
60 /// Returns null if the module is not found.
61 ModuleOp getPreloadedTransformModule(MLIRContext *context);
62 
63 /// Finds the first TransformOpInterface named `kTransformEntryPointSymbolName`
64 /// that is either:
65 /// 1. nested under `root` (takes precedence).
66 /// 2. nested under `module`, if not found in `root`.
67 /// Reports errors and returns null if no such operation found.
68 TransformOpInterface findTransformEntryPoint(
69  Operation *root, ModuleOp module,
70  StringRef entryPoint = TransformDialect::kTransformEntryPointSymbolName);
71 
72 } // namespace detail
73 
74 /// Standalone util to apply the named sequence `transformRoot` to `payload` IR.
75 /// This is done in 2 steps:
76 /// 1. If `transformModule` is provided and is not nested under
77 /// `transformRoot`, it will be "linked into" the IR containing
78 /// `transformRoot` to resolve undefined named sequences.
79 /// 2. The transforms specified in `transformRoot` are applied to `payload`,
80 /// assuming the named sequence has a single argument handle that will be
81 /// associated with `payload` on run.
82 LogicalResult applyTransformNamedSequence(Operation *payload,
83  Operation *transformRoot,
84  ModuleOp transformModule,
85  const TransformOptions &options);
86 
87 LogicalResult applyTransformNamedSequence(RaggedArray<MappedValue> bindings,
88  TransformOpInterface transformRoot,
89  ModuleOp transformModule,
90  const TransformOptions &options);
91 
92 } // namespace transform
93 } // namespace mlir
94 
95 #endif // MLIR_DIALECT_TRANSFORM_TRANSFORMS_TRANSFORMINTERPRETERUTILS_H
static llvm::ManagedStatic< PassManagerOptions > options
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.