[Mlir-commits] [mlir] a2e1f54 - [mlir] remove test-tranfsorm-dialect-interpreter (#89931)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu May 2 05:52:20 PDT 2024
Author: Oleksandr "Alex" Zinenko
Date: 2024-05-02T14:52:17+02:00
New Revision: a2e1f54bb7beff7ce84151353490c8b484da0a45
URL: https://github.com/llvm/llvm-project/commit/a2e1f54bb7beff7ce84151353490c8b484da0a45
DIFF: https://github.com/llvm/llvm-project/commit/a2e1f54bb7beff7ce84151353490c8b484da0a45.diff
LOG: [mlir] remove test-tranfsorm-dialect-interpreter (#89931)
This pass has been deprecated for more than two months, alternative is
available via `-transform-interpreter` and `-transform-preload-library`.
https://discourse.llvm.org/t/psa-deprecating-test-transform-dialect-interpreter/76904
Added:
Modified:
mlir/lib/Dialect/Transform/Transforms/CMakeLists.txt
mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp
mlir/tools/mlir-opt/mlir-opt.cpp
Removed:
mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterPassBase.h
mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp
mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-and-schedule.mlir
mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-dir.mlir
mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-invalid.mlir
mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl.mlir
mlir/test/Dialect/Transform/test-interpreter-module-generation.mlir
mlir/test/Dialect/Transform/test-interpreter-multiple-top-level-ops.mlir
mlir/test/Dialect/Transform/test-repro-dump.mlir
################################################################################
diff --git a/mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterPassBase.h b/mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterPassBase.h
deleted file mode 100644
index 3a4b391fd7f4ae..00000000000000
--- a/mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterPassBase.h
+++ /dev/null
@@ -1,216 +0,0 @@
-//===- TransformInterpreterPassBase.h ---------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Base class with shared implementation for transform dialect interpreter
-// passes.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_DIALECT_TRANSFORM_TRANSFORMS_TRANSFORMINTERPRETERPASSBASE_H
-#define MLIR_DIALECT_TRANSFORM_TRANSFORMS_TRANSFORMINTERPRETERPASSBASE_H
-
-#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
-#include "mlir/Pass/Pass.h"
-#include "mlir/Support/LLVM.h"
-#include <memory>
-
-namespace mlir {
-struct LogicalResult;
-class MLIRContext;
-class ModuleOp;
-class Operation;
-template <typename>
-class OwningOpRef;
-class Region;
-
-namespace transform {
-namespace detail {
-/// Template-free implementation of TransformInterpreterPassBase::initialize.
-LogicalResult interpreterBaseInitializeImpl(
- MLIRContext *context, StringRef transformFileName,
- ArrayRef<std::string> transformLibraryPaths,
- std::shared_ptr<OwningOpRef<ModuleOp>> &module,
- std::shared_ptr<OwningOpRef<ModuleOp>> &libraryModule,
- function_ref<std::optional<LogicalResult>(OpBuilder &, Location)>
- moduleBuilder = nullptr);
-
-/// Template-free implementation of
-/// TransformInterpreterPassBase::runOnOperation.
-LogicalResult interpreterBaseRunOnOperationImpl(
- Operation *target, StringRef passName,
- const std::shared_ptr<OwningOpRef<ModuleOp>> &sharedTransformModule,
- const std::shared_ptr<OwningOpRef<ModuleOp>> &libraryModule,
- const RaggedArray<MappedValue> &extraMappings,
- const TransformOptions &options,
- const Pass::Option<std::string> &transformFileName,
- const Pass::ListOption<std::string> &transformLibraryPaths,
- const Pass::Option<std::string> &debugPayloadRootTag,
- const Pass::Option<std::string> &debugTransformRootTag,
- StringRef binaryName);
-} // namespace detail
-
-/// Base class for transform dialect interpreter passes that can consume and
-/// dump transform dialect scripts in separate files. The pass is controlled by
-/// three string options:
-///
-/// - transformFileName: if non-empty, the name of the file containing the
-/// transform script. If empty, `debugTransformRootTag` is considered or the
-/// pass root operation must contain a single top-level transform op that
-/// will be interpreted.
-/// - transformLibraryPaths: if non-empty, the modules in these files will be
-/// merged into the main transform script run by the interpreter before
-/// execution. This allows to provide definitions for external functions
-/// used in the main script. Other public symbols in the library modules may
-/// lead to collisions with public symbols in the main script and among each
-/// other.
-/// - debugPayloadRootTag: if non-empty, the value of the attribute named
-/// `kTransformDialectTagAttrName` indicating the single op that is
-/// considered the payload root of the transform interpreter; otherwise, the
-/// root operation of the pass is used.
-/// - debugTransformRootTag: if non-empty, the value of the attribute named
-/// `kTransformDialectTagAttrName` indicating the single top-level transform
-/// op contained in the payload root to be used as the entry point by the
-/// transform interpreter; mutually exclusive with `transformFileName`.
-///
-/// The pass runs the transform dialect interpreter as directed by the options.
-/// It also provides the mechanism to dump reproducers into stderr
-/// (-debug-only=transform-dialect-dump-repro) or into a temporary file
-/// (-debug-only=transform-dialect-save-repro) that can be used with this
-/// pass in a standalone mode.
-///
-/// Concrete passes must derive from this class instead of their generated base
-/// class (or PassWrapper), and supply themselves and the generated base class
-/// as template arguments. They are *not* expected to to implement `initialize`
-/// or `runOnOperation`. They *are* expected to call the copy constructor of
-/// this class in their copy constructors, short of which the file-based
-/// transform dialect script injection facility will become non-operational.
-///
-/// Concrete passes may implement the `runBeforeInterpreter` and
-/// `runAfterInterpreter` to customize the behavior of the pass.
-template <typename Concrete, template <typename> typename GeneratedBase>
-class TransformInterpreterPassBase : public GeneratedBase<Concrete> {
-public:
- explicit TransformInterpreterPassBase(
- const TransformOptions &options = TransformOptions())
- : options(options) {}
-
- TransformInterpreterPassBase(const TransformInterpreterPassBase &pass) {
- sharedTransformModule = pass.sharedTransformModule;
- transformLibraryModule = pass.transformLibraryModule;
- options = pass.options;
- }
-
- static StringLiteral getBinaryName() { return "mlir-opt"; }
-
- LogicalResult initialize(MLIRContext *context) override {
-
-#define REQUIRE_PASS_OPTION(NAME) \
- static_assert( \
- std::is_same_v< \
- std::remove_reference_t<decltype(std::declval<Concrete &>().NAME)>, \
- Pass::Option<std::string>>, \
- "required " #NAME " string pass option is missing")
-
- REQUIRE_PASS_OPTION(transformFileName);
- REQUIRE_PASS_OPTION(debugPayloadRootTag);
- REQUIRE_PASS_OPTION(debugTransformRootTag);
-
-#undef REQUIRE_PASS_OPTION
-
-#define REQUIRE_PASS_LIST_OPTION(NAME) \
- static_assert( \
- std::is_same_v< \
- std::remove_reference_t<decltype(std::declval<Concrete &>().NAME)>, \
- Pass::ListOption<std::string>>, \
- "required " #NAME " string pass option is missing")
-
- REQUIRE_PASS_LIST_OPTION(transformLibraryPaths);
-
-#undef REQUIRE_PASS_LIST_OPTION
-
- StringRef transformFileName =
- static_cast<Concrete *>(this)->transformFileName;
- ArrayRef<std::string> transformLibraryPaths =
- static_cast<Concrete *>(this)->transformLibraryPaths;
- return detail::interpreterBaseInitializeImpl(
- context, transformFileName, transformLibraryPaths,
- sharedTransformModule, transformLibraryModule,
- [this](OpBuilder &builder, Location loc) {
- return static_cast<Concrete *>(this)->constructTransformModule(
- builder, loc);
- });
- }
-
- /// Hook for passes to run additional logic in the pass before the
- /// interpreter. If failure is returned, the pass fails and the interpreter is
- /// not run.
- LogicalResult runBeforeInterpreter(Operation *) { return success(); }
-
- /// Hook for passes to run additional logic in the pass after the interpreter.
- /// Only runs if everything succeeded before. If failure is returned, the pass
- /// fails.
- LogicalResult runAfterInterpreter(Operation *) { return success(); }
-
- /// Hook for passes to run custom logic to construct the transform module.
- /// This will run during initialization. If the external script is provided,
- /// it overrides the construction, which will not be called.
- std::optional<LogicalResult> constructTransformModule(OpBuilder &builder,
- Location loc) {
- return std::nullopt;
- }
-
- void runOnOperation() override {
- auto *pass = static_cast<Concrete *>(this);
- Operation *op = pass->getOperation();
- StringRef binaryName = Concrete::getBinaryName();
- if (failed(pass->runBeforeInterpreter(op)) ||
- failed(detail::interpreterBaseRunOnOperationImpl(
- op, pass->getArgument(), sharedTransformModule,
- transformLibraryModule,
- /*extraMappings=*/{}, options, pass->transformFileName,
- pass->transformLibraryPaths, pass->debugPayloadRootTag,
- pass->debugTransformRootTag, binaryName)) ||
- failed(pass->runAfterInterpreter(op))) {
- return pass->signalPassFailure();
- }
- }
-
-protected:
- /// Transform interpreter options.
- TransformOptions options;
-
- /// Returns a read-only reference to shared transform module.
- const std::shared_ptr<OwningOpRef<ModuleOp>> &
- getSharedTransformModule() const {
- return sharedTransformModule;
- }
-
- /// Returns a read-only reference to the transform library module.
- const std::shared_ptr<OwningOpRef<ModuleOp>> &
- getTransformLibraryModule() const {
- return transformLibraryModule;
- }
-
-private:
- /// The separate transform module to be used for transformations, shared
- /// across multiple instances of the pass if it is applied in parallel to
- /// avoid potentially expensive cloning. MUST NOT be modified after the pass
- /// has been initialized.
- std::shared_ptr<OwningOpRef<ModuleOp>> sharedTransformModule = nullptr;
-
- /// The transform module containing symbol definitions that become available
- /// in the transform scripts. Similar to dynamic linking for binaries. This is
- /// shared across multiple instances of the pass and therefore MUST NOT be
- /// modified after the pass has been initialized.
- std::shared_ptr<OwningOpRef<ModuleOp>> transformLibraryModule = nullptr;
-};
-
-} // namespace transform
-} // namespace mlir
-
-#endif // MLIR_DIALECT_TRANSFORM_TRANSFORMS_TRANSFORMINTERPRETERPASSBASE_H
diff --git a/mlir/lib/Dialect/Transform/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Transform/Transforms/CMakeLists.txt
index f0f57874f5e703..9fed8c6b5caa9b 100644
--- a/mlir/lib/Dialect/Transform/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/Transform/Transforms/CMakeLists.txt
@@ -3,7 +3,6 @@ add_mlir_dialect_library(MLIRTransformDialectTransforms
InferEffects.cpp
InterpreterPass.cpp
PreloadLibraryPass.cpp
- TransformInterpreterPassBase.cpp
TransformInterpreterUtils.cpp
DEPENDS
diff --git a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp b/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp
deleted file mode 100644
index efb9359e19951b..00000000000000
--- a/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp
+++ /dev/null
@@ -1,457 +0,0 @@
-//===- TransformInterpreterPassBase.cpp -----------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Base class with shared implementation for transform dialect interpreter
-// passes.
-//
-//===----------------------------------------------------------------------===//
-
-#include "mlir/Dialect/Transform/Transforms/TransformInterpreterPassBase.h"
-#include "mlir/Dialect/Transform/IR/TransformDialect.h"
-#include "mlir/Dialect/Transform/IR/TransformOps.h"
-#include "mlir/Dialect/Transform/IR/Utils.h"
-#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
-#include "mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h"
-#include "mlir/IR/BuiltinOps.h"
-#include "mlir/IR/Verifier.h"
-#include "mlir/IR/Visitors.h"
-#include "mlir/Interfaces/FunctionInterfaces.h"
-#include "mlir/Parser/Parser.h"
-#include "mlir/Pass/Pass.h"
-#include "mlir/Support/FileUtilities.h"
-#include "llvm/ADT/ScopeExit.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/Mutex.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace mlir;
-
-#define DEBUG_TYPE "transform-dialect-interpreter"
-#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE << "]: ")
-#define DEBUG_TYPE_DUMP_STDERR "transform-dialect-dump-repro"
-#define DEBUG_TYPE_DUMP_FILE "transform-dialect-save-repro"
-
-/// Name of the attribute used for targeting the transform dialect interpreter
-/// at specific operations.
-constexpr static llvm::StringLiteral kTransformDialectTagAttrName =
- "transform.target_tag";
-/// Value of the attribute indicating the root payload operation.
-constexpr static llvm::StringLiteral kTransformDialectTagPayloadRootValue =
- "payload_root";
-/// Value of the attribute indicating the container of transform operations
-/// (containing the top-level transform operation).
-constexpr static llvm::StringLiteral
- kTransformDialectTagTransformContainerValue = "transform_container";
-
-/// Finds the single top-level transform operation with `root` as ancestor.
-/// Reports an error if there is more than one such operation and returns the
-/// first one found. Reports an error returns nullptr if no such operation
-/// found.
-static Operation *
-findTopLevelTransform(Operation *root, StringRef filenameOption,
- mlir::transform::TransformOptions options) {
- ::mlir::transform::TransformOpInterface topLevelTransform = nullptr;
- root->walk<WalkOrder::PreOrder>(
- [&](::mlir::transform::TransformOpInterface transformOp) {
- if (!transformOp
- ->hasTrait<transform::PossibleTopLevelTransformOpTrait>())
- return WalkResult::skip();
- if (!topLevelTransform) {
- topLevelTransform = transformOp;
- return WalkResult::skip();
- }
- if (options.getEnforceSingleToplevelTransformOp()) {
- auto diag = transformOp.emitError()
- << "more than one top-level transform op";
- diag.attachNote(topLevelTransform.getLoc())
- << "previous top-level transform op";
- return WalkResult::interrupt();
- }
- return WalkResult::skip();
- });
- if (!topLevelTransform) {
- auto diag = root->emitError()
- << "could not find a nested top-level transform op";
- diag.attachNote() << "use the '" << filenameOption
- << "' option to provide transform as external file";
- return nullptr;
- }
- return topLevelTransform;
-}
-
-/// Finds an operation nested in `root` that has the transform dialect tag
-/// attribute with the value specified as `tag`. Assumes only one operation
-/// may have the tag. Returns nullptr if there is no such operation.
-static Operation *findOpWithTag(Operation *root, StringRef tagKey,
- StringRef tagValue) {
- Operation *found = nullptr;
- WalkResult walkResult = root->walk<WalkOrder::PreOrder>(
- [tagKey, tagValue, &found, root](Operation *op) {
- auto attr = op->getAttrOfType<StringAttr>(tagKey);
- if (!attr || attr.getValue() != tagValue)
- return WalkResult::advance();
-
- if (found) {
- InFlightDiagnostic diag = root->emitError()
- << "more than one operation with " << tagKey
- << "=\"" << tagValue << "\" attribute";
- diag.attachNote(found->getLoc()) << "first operation";
- diag.attachNote(op->getLoc()) << "other operation";
- return WalkResult::interrupt();
- }
-
- found = op;
- return WalkResult::advance();
- });
- if (walkResult.wasInterrupted())
- return nullptr;
-
- if (!found) {
- root->emitError() << "could not find the operation with " << tagKey << "=\""
- << tagValue << "\" attribute";
- }
- return found;
-}
-
-/// Returns the ancestor of `target` that doesn't have a parent.
-static Operation *getRootOperation(Operation *target) {
- Operation *root = target;
- while (root->getParentOp())
- root = root->getParentOp();
- return root;
-}
-
-/// Prints the CLI command running the repro with the current path.
-// TODO: make binary name optional by querying LLVM command line API for the
-// name of the current binary.
-static llvm::raw_ostream &
-printReproCall(llvm::raw_ostream &os, StringRef rootOpName, StringRef passName,
- const Pass::Option<std::string> &debugPayloadRootTag,
- const Pass::Option<std::string> &debugTransformRootTag,
- StringRef binaryName) {
- os << llvm::formatv(
- "{6} --pass-pipeline=\"{0}({1}{{{2}={3} {4}={5}})\"", rootOpName,
- passName, debugPayloadRootTag.getArgStr(),
- debugPayloadRootTag.empty()
- ? StringRef(kTransformDialectTagPayloadRootValue)
- : debugPayloadRootTag,
- debugTransformRootTag.getArgStr(),
- debugTransformRootTag.empty()
- ? StringRef(kTransformDialectTagTransformContainerValue)
- : debugTransformRootTag,
- binaryName);
- return os;
-}
-
-/// Prints the module rooted at `root` to `os` and appends
-/// `transformContainer` if it is not nested in `root`.
-static llvm::raw_ostream &printModuleForRepro(llvm::raw_ostream &os,
- Operation *root,
- Operation *transform) {
- root->print(os);
- if (!root->isAncestor(transform))
- transform->print(os);
- return os;
-}
-
-/// Saves the payload and the transform IR into a temporary file and reports
-/// the file name to `os`.
-[[maybe_unused]] static void
-saveReproToTempFile(llvm::raw_ostream &os, Operation *target,
- Operation *transform, StringRef passName,
- const Pass::Option<std::string> &debugPayloadRootTag,
- const Pass::Option<std::string> &debugTransformRootTag,
- const Pass::ListOption<std::string> &transformLibraryPaths,
- StringRef binaryName) {
- using llvm::sys::fs::TempFile;
- Operation *root = getRootOperation(target);
-
- SmallVector<char, 128> tmpPath;
- llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true, tmpPath);
- llvm::sys::path::append(tmpPath, "transform_dialect_%%%%%%.mlir");
- llvm::Expected<TempFile> tempFile = TempFile::create(tmpPath);
- if (!tempFile) {
- os << "could not open temporary file to save the repro\n";
- return;
- }
-
- llvm::raw_fd_ostream fout(tempFile->FD, /*shouldClose=*/false);
- printModuleForRepro(fout, root, transform);
- fout.flush();
- std::string filename = tempFile->TmpName;
-
- if (tempFile->keep()) {
- os << "could not preserve the temporary file with the repro\n";
- return;
- }
-
- os << "=== Transform Interpreter Repro ===\n";
- printReproCall(os, root->getName().getStringRef(), passName,
- debugPayloadRootTag, debugTransformRootTag, binaryName)
- << " " << filename << "\n";
- os << "===================================\n";
-}
-
-// Optionally perform debug actions requested by the user to dump IR and a
-// repro to stderr and/or a file.
-static void performOptionalDebugActions(
- Operation *target, Operation *transform, StringRef passName,
- const Pass::Option<std::string> &debugPayloadRootTag,
- const Pass::Option<std::string> &debugTransformRootTag,
- const Pass::ListOption<std::string> &transformLibraryPaths,
- StringRef binaryName) {
- MLIRContext *context = target->getContext();
-
- // If we are not planning to print, bail early.
- bool hasDebugFlags = false;
- DEBUG_WITH_TYPE(DEBUG_TYPE_DUMP_STDERR, { hasDebugFlags = true; });
- DEBUG_WITH_TYPE(DEBUG_TYPE_DUMP_FILE, { hasDebugFlags = true; });
- if (!hasDebugFlags)
- return;
-
- // We will be mutating the IR to set attributes. If this is running
- // concurrently on several parts of a container or using a shared transform
- // script, this would create a race. Bail in multithreaded mode and require
- // the user to disable threading to dump repros.
- static llvm::sys::SmartMutex<true> dbgStreamMutex;
- if (target->getContext()->isMultithreadingEnabled()) {
- llvm::sys::SmartScopedLock<true> lock(dbgStreamMutex);
- llvm::dbgs() << "=======================================================\n";
- llvm::dbgs() << "| Transform reproducers cannot be produced |\n";
- llvm::dbgs() << "| in multi-threaded mode! |\n";
- llvm::dbgs() << "=======================================================\n";
- return;
- }
-
- Operation *root = getRootOperation(target);
-
- // Add temporary debug / repro attributes, these must never leak out.
- if (debugPayloadRootTag.empty()) {
- target->setAttr(
- kTransformDialectTagAttrName,
- StringAttr::get(context, kTransformDialectTagPayloadRootValue));
- }
- if (debugTransformRootTag.empty()) {
- transform->setAttr(
- kTransformDialectTagAttrName,
- StringAttr::get(context, kTransformDialectTagTransformContainerValue));
- }
-
- DEBUG_WITH_TYPE(DEBUG_TYPE_DUMP_STDERR, {
- llvm::dbgs() << "=== Transform Interpreter Repro ===\n";
- printReproCall(llvm::dbgs() << "cat <<EOF | ",
- root->getName().getStringRef(), passName,
- debugPayloadRootTag, debugTransformRootTag, binaryName)
- << "\n";
- printModuleForRepro(llvm::dbgs(), root, transform);
- llvm::dbgs() << "\nEOF\n";
- llvm::dbgs() << "===================================\n";
- });
- (void)root;
- DEBUG_WITH_TYPE(DEBUG_TYPE_DUMP_FILE, {
- saveReproToTempFile(llvm::dbgs(), target, transform, passName,
- debugPayloadRootTag, debugTransformRootTag,
- transformLibraryPaths, binaryName);
- });
-
- // Remove temporary attributes if they were set.
- if (debugPayloadRootTag.empty())
- target->removeAttr(kTransformDialectTagAttrName);
- if (debugTransformRootTag.empty())
- transform->removeAttr(kTransformDialectTagAttrName);
-}
-
-LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
- Operation *target, StringRef passName,
- const std::shared_ptr<OwningOpRef<ModuleOp>> &sharedTransformModule,
- const std::shared_ptr<OwningOpRef<ModuleOp>> &transformLibraryModule,
- const RaggedArray<MappedValue> &extraMappings,
- const TransformOptions &options,
- const Pass::Option<std::string> &transformFileName,
- const Pass::ListOption<std::string> &transformLibraryPaths,
- const Pass::Option<std::string> &debugPayloadRootTag,
- const Pass::Option<std::string> &debugTransformRootTag,
- StringRef binaryName) {
- bool hasSharedTransformModule =
- sharedTransformModule && *sharedTransformModule;
- bool hasTransformLibraryModule =
- transformLibraryModule && *transformLibraryModule;
- assert((!hasSharedTransformModule || !hasTransformLibraryModule) &&
- "at most one of shared or library transform module can be set");
-
- // Step 1
- // ------
- // If debugPayloadRootTag was passed, then we are in user-specified selection
- // of the transformed IR. This corresponds to REPL debug mode. Otherwise, just
- // apply to `target`.
- Operation *payloadRoot = target;
- if (!debugPayloadRootTag.empty()) {
- payloadRoot = findOpWithTag(target, kTransformDialectTagAttrName,
- debugPayloadRootTag);
- if (!payloadRoot)
- return failure();
- }
-
- // Step 2
- // ------
- // If a shared transform was specified separately, use it. Otherwise, the
- // transform is embedded in the payload IR. If debugTransformRootTag was
- // passed, then we are in user-specified selection of the transforming IR.
- // This corresponds to REPL debug mode.
- Operation *transformContainer =
- hasSharedTransformModule ? sharedTransformModule->get() : target;
- Operation *transformRoot =
- debugTransformRootTag.empty()
- ? findTopLevelTransform(transformContainer,
- transformFileName.getArgStr(), options)
- : findOpWithTag(transformContainer, kTransformDialectTagAttrName,
- debugTransformRootTag);
- if (!transformRoot)
- return failure();
-
- if (!transformRoot->hasTrait<PossibleTopLevelTransformOpTrait>()) {
- return emitError(transformRoot->getLoc())
- << "expected the transform entry point to be a top-level transform "
- "op";
- }
-
- // Step 3
- // ------
- // Copy external defintions for symbols if provided. Be aware of potential
- // concurrent execution (normally, the error shouldn't be triggered unless the
- // transform IR modifies itself in a pass, which is also forbidden elsewhere).
- if (hasTransformLibraryModule) {
- if (!target->isProperAncestor(transformRoot)) {
- InFlightDiagnostic diag =
- transformRoot->emitError()
- << "cannot inject transform definitions next to pass anchor op";
- diag.attachNote(target->getLoc()) << "pass anchor op";
- return diag;
- }
- InFlightDiagnostic diag = detail::mergeSymbolsInto(
- SymbolTable::getNearestSymbolTable(transformRoot),
- transformLibraryModule->get()->clone());
- if (failed(diag)) {
- diag.attachNote(transformRoot->getLoc())
- << "failed to merge library symbols into transform root";
- return diag;
- }
- }
-
- // Step 4
- // ------
- // Optionally perform debug actions requested by the user to dump IR and a
- // repro to stderr and/or a file.
- performOptionalDebugActions(target, transformRoot, passName,
- debugPayloadRootTag, debugTransformRootTag,
- transformLibraryPaths, binaryName);
-
- // Step 5
- // ------
- // Apply the transform to the IR
- return applyTransforms(payloadRoot, cast<TransformOpInterface>(transformRoot),
- extraMappings, options);
-}
-
-LogicalResult transform::detail::interpreterBaseInitializeImpl(
- MLIRContext *context, StringRef transformFileName,
- ArrayRef<std::string> transformLibraryPaths,
- std::shared_ptr<OwningOpRef<ModuleOp>> &sharedTransformModule,
- std::shared_ptr<OwningOpRef<ModuleOp>> &transformLibraryModule,
- function_ref<std::optional<LogicalResult>(OpBuilder &, Location)>
- moduleBuilder) {
- auto unknownLoc = UnknownLoc::get(context);
-
- // Parse module from file.
- OwningOpRef<ModuleOp> moduleFromFile;
- {
- auto loc = FileLineColLoc::get(context, transformFileName, 0, 0);
- if (failed(detail::parseTransformModuleFromFile(context, transformFileName,
- moduleFromFile)))
- return emitError(loc) << "failed to parse transform module";
- if (moduleFromFile && failed(mlir::verify(*moduleFromFile)))
- return emitError(loc) << "failed to verify transform module";
- }
-
- // Assemble list of library files.
- SmallVector<std::string> libraryFileNames;
- if (failed(expandPathsToMLIRFiles(transformLibraryPaths, context,
- libraryFileNames)))
- return failure();
-
- // Parse modules from library files.
- SmallVector<OwningOpRef<ModuleOp>> parsedLibraries;
- for (const std::string &libraryFileName : libraryFileNames) {
- OwningOpRef<ModuleOp> parsedLibrary;
- auto loc = FileLineColLoc::get(context, libraryFileName, 0, 0);
- if (failed(detail::parseTransformModuleFromFile(context, libraryFileName,
- parsedLibrary)))
- return emitError(loc) << "failed to parse transform library module";
- if (parsedLibrary && failed(mlir::verify(*parsedLibrary)))
- return emitError(loc) << "failed to verify transform library module";
- parsedLibraries.push_back(std::move(parsedLibrary));
- }
-
- // Build shared transform module.
- if (moduleFromFile) {
- sharedTransformModule =
- std::make_shared<OwningOpRef<ModuleOp>>(std::move(moduleFromFile));
- } else if (moduleBuilder) {
- auto loc = FileLineColLoc::get(context, "<shared-transform-module>", 0, 0);
- auto localModule = std::make_shared<OwningOpRef<ModuleOp>>(
- ModuleOp::create(unknownLoc, "__transform"));
-
- OpBuilder b(context);
- b.setInsertionPointToEnd(localModule->get().getBody());
- if (std::optional<LogicalResult> result = moduleBuilder(b, loc)) {
- if (failed(*result))
- return (*localModule)->emitError()
- << "failed to create shared transform module";
- sharedTransformModule = std::move(localModule);
- }
- }
-
- if (parsedLibraries.empty())
- return success();
-
- // Merge parsed libraries into one module.
- auto loc = FileLineColLoc::get(context, "<shared-library-module>", 0, 0);
- OwningOpRef<ModuleOp> mergedParsedLibraries =
- ModuleOp::create(loc, "__transform");
- {
- mergedParsedLibraries.get()->setAttr("transform.with_named_sequence",
- UnitAttr::get(context));
- IRRewriter rewriter(context);
- // TODO: extend `mergeSymbolsInto` to support multiple `other` modules.
- for (OwningOpRef<ModuleOp> &parsedLibrary : parsedLibraries) {
- if (failed(detail::mergeSymbolsInto(mergedParsedLibraries.get(),
- std::move(parsedLibrary))))
- return mergedParsedLibraries->emitError()
- << "failed to verify merged transform module";
- }
- }
-
- // Use parsed libaries to resolve symbols in shared transform module or return
- // as separate library module.
- if (sharedTransformModule && *sharedTransformModule) {
- if (failed(detail::mergeSymbolsInto(sharedTransformModule->get(),
- std::move(mergedParsedLibraries))))
- return (*sharedTransformModule)->emitError()
- << "failed to merge symbols from library files "
- "into shared transform module";
- } else {
- transformLibraryModule = std::make_shared<OwningOpRef<ModuleOp>>(
- std::move(mergedParsedLibraries));
- }
- return success();
-}
diff --git a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-and-schedule.mlir b/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-and-schedule.mlir
deleted file mode 100644
index 9e50ec1efac946..00000000000000
--- a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-and-schedule.mlir
+++ /dev/null
@@ -1,20 +0,0 @@
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-file-name=%p%{fs-sep}test-interpreter-external-symbol-decl.mlir transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library/definitions-self-contained.mlir})" \
-// RUN: --verify-diagnostics
-
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-file-name=%p%{fs-sep}test-interpreter-external-symbol-decl.mlir transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library/definitions-self-contained.mlir}, test-transform-dialect-interpreter{transform-file-name=%p%{fs-sep}test-interpreter-external-symbol-decl.mlir transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library/definitions-self-contained.mlir})" \
-// RUN: --verify-diagnostics
-
-// The external transform script has a declaration to the named sequence @foo,
-// the definition of which is provided in another file. Repeated application
-// of the same pass should not be a problem. Note that the same diagnostic
-// produced twice at the same location only needs to be matched once.
-
-// expected-remark @below {{message}}
-// expected-remark @below {{unannotated}}
-// expected-remark @below {{internal colliding (without suffix)}}
-// expected-remark @below {{internal colliding_0}}
-// expected-remark @below {{internal colliding_1}}
-// expected-remark @below {{internal colliding_3}}
-// expected-remark @below {{internal colliding_4}}
-// expected-remark @below {{internal colliding_5}}
-module {}
diff --git a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-dir.mlir b/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-dir.mlir
deleted file mode 100644
index 3681b913dc5b97..00000000000000
--- a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-dir.mlir
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library})" \
-// RUN: --verify-diagnostics --split-input-file | FileCheck %s
-
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library/definitions-self-contained.mlir,%p%{fs-sep}include%{fs-sep}test-interpreter-library/definitions-with-unresolved.mlir})" \
-// RUN: --verify-diagnostics --split-input-file | FileCheck %s
-
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library}, test-transform-dialect-interpreter)" \
-// RUN: --verify-diagnostics --split-input-file | FileCheck %s
-
-// The definition of the @foo named sequence is provided in another file. It
-// will be included because of the pass option. Repeated application of the
-// same pass, with or without the library option, should not be a problem.
-// Note that the same diagnostic produced twice at the same location only
-// needs to be matched once.
-
-// expected-remark @below {{message}}
-module attributes {transform.with_named_sequence} {
- // CHECK: transform.named_sequence @print_message
- transform.named_sequence @print_message(%arg0: !transform.any_op {transform.readonly})
-
- transform.named_sequence @reference_other_module(!transform.any_op {transform.readonly})
-
- transform.sequence failures(propagate) {
- ^bb0(%arg0: !transform.any_op):
- include @print_message failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @reference_other_module failures(propagate) (%arg0) : (!transform.any_op) -> ()
- }
-}
diff --git a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-invalid.mlir b/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-invalid.mlir
deleted file mode 100644
index df6739a2ec6c0b..00000000000000
--- a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-invalid.mlir
+++ /dev/null
@@ -1,57 +0,0 @@
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-external-symbol-def-invalid.mlir}, test-transform-dialect-interpreter)" \
-// RUN: --verify-diagnostics --split-input-file
-
-// The definition of the @print_message named sequence is provided in another file. It
-// will be included because of the pass option.
-
-module attributes {transform.with_named_sequence} {
- // expected-error @below {{external definition has a mismatching signature}}
- transform.named_sequence private @print_message(!transform.op<"builtin.module"> {transform.readonly})
-
- // expected-note @below {{failed to merge library symbols into transform root}}
- transform.sequence failures(propagate) {
- ^bb0(%arg0: !transform.op<"builtin.module">):
- include @print_message failures(propagate) (%arg0) : (!transform.op<"builtin.module">) -> ()
- }
-}
-
-// -----
-
-module attributes {transform.with_named_sequence} {
- transform.named_sequence private @undefined_sequence()
-
- transform.sequence failures(suppress) {
- ^bb0(%arg0: !transform.any_op):
- // expected-error @below {{unresolved external named sequence}}
- include @undefined_sequence failures(suppress) () : () -> ()
- }
-}
-
-// -----
-
-module attributes {transform.with_named_sequence} {
- // expected-error @below {{external definition has mismatching consumption annotations for argument #0}}
- transform.named_sequence private @consuming(%arg0: !transform.any_op {transform.readonly})
-
- // expected-note @below {{failed to merge library symbols into transform root}}
- transform.sequence failures(suppress) {
- ^bb0(%arg0: !transform.any_op):
- include @consuming failures(suppress) (%arg0) : (!transform.any_op) -> ()
- }
-}
-
-// -----
-
-module attributes {transform.with_named_sequence} {
- // expected-error @below {{doubly defined symbol @print_message}}
- transform.named_sequence @print_message(%arg0: !transform.any_op {transform.readonly}) {
- transform.debug.emit_remark_at %arg0, "message" : !transform.any_op
- transform.yield
- }
-
- // expected-note @below {{failed to merge library symbols into transform root}}
- transform.sequence failures(suppress) {
- ^bb0(%arg0: !transform.any_op):
- include @print_message failures(propagate) (%arg0) : (!transform.any_op) -> ()
- }
-}
diff --git a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl.mlir b/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl.mlir
deleted file mode 100644
index d7b35e462f61e9..00000000000000
--- a/mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl.mlir
+++ /dev/null
@@ -1,71 +0,0 @@
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library/definitions-self-contained.mlir})" \
-// RUN: --verify-diagnostics --split-input-file | FileCheck %s
-
-// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{transform-library-paths=%p%{fs-sep}include%{fs-sep}test-interpreter-library/definitions-self-contained.mlir}, test-transform-dialect-interpreter)" \
-// RUN: --verify-diagnostics --split-input-file | FileCheck %s
-
-// The definition of the @print_message named sequence is provided in another
-// file. It will be included because of the pass option. Subsequent application
-// of the same pass works but only without the library file (since the first
-// application loads external symbols and loading them again woul make them
-// clash).
-// Note that the same diagnostic produced twice at the same location only
-// needs to be matched once.
-
-// expected-remark @below {{message}}
-// expected-remark @below {{unannotated}}
-// expected-remark @below {{internal colliding (without suffix)}}
-// expected-remark @below {{internal colliding_0}}
-// expected-remark @below {{internal colliding_1}}
-// expected-remark @below {{internal colliding_3}}
-// expected-remark @below {{internal colliding_4}}
-// expected-remark @below {{internal colliding_5}}
-module attributes {transform.with_named_sequence} {
- // CHECK-DAG: transform.named_sequence @print_message(
- // CHECK-DAG: transform.include @private_helper
- transform.named_sequence private @print_message(!transform.any_op {transform.readonly})
-
- // These ops collide with ops from the other module before or after renaming.
- transform.named_sequence private @colliding(%arg0: !transform.any_op {transform.readonly}) {
- transform.debug.emit_remark_at %arg0, "internal colliding (without suffix)" : !transform.any_op
- transform.yield
- }
- transform.named_sequence private @colliding_0(%arg0: !transform.any_op {transform.readonly}) {
- transform.debug.emit_remark_at %arg0, "internal colliding_0" : !transform.any_op
- transform.yield
- }
- transform.named_sequence private @colliding_1(%arg0: !transform.any_op {transform.readonly}) {
- transform.debug.emit_remark_at %arg0, "internal colliding_1" : !transform.any_op
- transform.yield
- }
- transform.named_sequence private @colliding_3(%arg0: !transform.any_op {transform.readonly}) {
- transform.debug.emit_remark_at %arg0, "internal colliding_3" : !transform.any_op
- transform.yield
- }
- // This symbol is public and thus can't be renamed.
- // CHECK-DAG: transform.named_sequence @colliding_4(
- transform.named_sequence @colliding_4(%arg0: !transform.any_op {transform.readonly}) {
- transform.debug.emit_remark_at %arg0, "internal colliding_4" : !transform.any_op
- transform.yield
- }
- transform.named_sequence private @colliding_5(%arg0: !transform.any_op {transform.readonly}) {
- transform.debug.emit_remark_at %arg0, "internal colliding_5" : !transform.any_op
- transform.yield
- }
-
- // CHECK-DAG: transform.named_sequence @unannotated(
- // CHECK-DAG: transform.debug.emit_remark_at %{{.*}}, "unannotated"
- transform.named_sequence @unannotated(!transform.any_op {transform.readonly})
-
- transform.sequence failures(propagate) {
- ^bb0(%arg0: !transform.any_op):
- include @print_message failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @unannotated failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @colliding failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @colliding_0 failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @colliding_1 failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @colliding_3 failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @colliding_4 failures(propagate) (%arg0) : (!transform.any_op) -> ()
- include @colliding_5 failures(propagate) (%arg0) : (!transform.any_op) -> ()
- }
-}
diff --git a/mlir/test/Dialect/Transform/test-interpreter-module-generation.mlir b/mlir/test/Dialect/Transform/test-interpreter-module-generation.mlir
deleted file mode 100644
index 159aed720964dc..00000000000000
--- a/mlir/test/Dialect/Transform/test-interpreter-module-generation.mlir
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: mlir-opt %s --test-transform-dialect-interpreter=test-module-generation=1 --verify-diagnostics
-
-// expected-remark @below {{remark from generated}}
-module {}
diff --git a/mlir/test/Dialect/Transform/test-interpreter-multiple-top-level-ops.mlir b/mlir/test/Dialect/Transform/test-interpreter-multiple-top-level-ops.mlir
deleted file mode 100644
index a3e3f057817cb5..00000000000000
--- a/mlir/test/Dialect/Transform/test-interpreter-multiple-top-level-ops.mlir
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: mlir-opt %s --test-transform-dialect-interpreter='enforce-single-top-level-transform-op=0' -allow-unregistered-dialect --split-input-file --verify-diagnostics | FileCheck %s
-
-transform.sequence failures(propagate) {
-// CHECK: transform.sequence
-^bb0(%arg0: !transform.any_op):
-}
-
-transform.sequence failures(propagate) {
-// CHECK: transform.sequence
-^bb0(%arg0: !transform.any_op):
-}
-
-// -----
-
-transform.sequence failures(propagate) {
-^bb0(%arg0: !transform.any_op):
- %match = transform.structured.match ops{["transform.get_parent_op"]} in %arg0 : (!transform.any_op) -> !transform.any_op
- transform.debug.emit_remark_at %match, "found get_parent_op" : !transform.any_op
-}
-
-transform.sequence failures(propagate) {
-^bb0(%arg0: !transform.any_op):
- %op = transform.structured.match ops{[]} in %arg0 : (!transform.any_op) -> !transform.any_op
- // expected-remark @below{{found get_parent_op}}
- %1 = transform.get_parent_op %op : (!transform.any_op) -> !transform.any_op
-}
diff --git a/mlir/test/Dialect/Transform/test-repro-dump.mlir b/mlir/test/Dialect/Transform/test-repro-dump.mlir
deleted file mode 100644
index 89624da7efd073..00000000000000
--- a/mlir/test/Dialect/Transform/test-repro-dump.mlir
+++ /dev/null
@@ -1,32 +0,0 @@
-// REQUIRES: asserts
-// RUN: mlir-opt %s --test-transform-dialect-interpreter \
-// RUN: --mlir-disable-threading \
-// RUN: --debug-only=transform-dialect-dump-repro 2>&1 \
-// RUN: | FileCheck %s
-
-module {
- transform.sequence failures(propagate) {
- ^bb0(%arg0: !transform.any_op):
- transform.debug.emit_remark_at %arg0, "remark" : !transform.any_op
- }
-}
-
-// Verify that the repro string is dumped.
-
-// CHECK: Transform Interpreter Repro
-// CHECK: cat <<EOF | mlir-opt --pass-pipeline="builtin.module(test-transform-dialect-interpreter{debug-payload-root-tag=payload_root debug-transform-root-tag=transform_container})"
-
-// Verify that the IR is dumped with tags.
-
-// CHECK: module
-// CHECK-SAME: transform.target_tag = "payload_root"
-// CHECK: transform.sequence
-// CHECK-SAME: transform.target_tag = "transform_container"
-// CHECK: EOF
-
-// Verify that the actual IR after the pass doesn't have the tags.
-
-// CHECK: module
-// CHECK-NOT: transform.target_tag = "payload_root"
-// CHECK: transform.sequence
-// CHECK-NOT: transform.target_tag = "transform_container"
diff --git a/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp b/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp
index e936ac5b852bd8..1273414cd4dfc7 100644
--- a/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp
+++ b/mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp
@@ -11,230 +11,16 @@
//
//===----------------------------------------------------------------------===//
-#include "TestTransformDialectExtension.h"
-#include "mlir/Dialect/Transform/DebugExtension/DebugExtensionOps.h"
-#include "mlir/Dialect/Transform/IR/TransformOps.h"
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
-#include "mlir/Dialect/Transform/Transforms/TransformInterpreterPassBase.h"
-#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
namespace {
-/// Simple pass that applies transform dialect ops directly contained in a
-/// module.
-
template <typename Derived>
class OpPassWrapper : public PassWrapper<Derived, OperationPass<>> {};
-class TestTransformDialectInterpreterPass
- : public transform::TransformInterpreterPassBase<
- TestTransformDialectInterpreterPass, OpPassWrapper> {
-public:
- MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
- TestTransformDialectInterpreterPass)
-
- TestTransformDialectInterpreterPass() = default;
- TestTransformDialectInterpreterPass(
- const TestTransformDialectInterpreterPass &pass)
- : TransformInterpreterPassBase(pass) {}
-
- StringRef getArgument() const override {
- return "test-transform-dialect-interpreter";
- }
-
- StringRef getDescription() const override {
- return "apply transform dialect operations one by one";
- }
-
- void getDependentDialects(DialectRegistry ®istry) const override {
- registry.insert<transform::TransformDialect>();
- }
-
- void findOperationsByName(Operation *root, StringRef name,
- SmallVectorImpl<Operation *> &operations) {
- root->walk([&](Operation *op) {
- if (op->getName().getStringRef() == name) {
- operations.push_back(op);
- }
- });
- }
-
- void createParameterMapping(MLIRContext &context, ArrayRef<int> values,
- RaggedArray<transform::MappedValue> &result) {
- SmallVector<transform::MappedValue> storage =
- llvm::to_vector(llvm::map_range(values, [&](int v) {
- Builder b(&context);
- return transform::MappedValue(b.getI64IntegerAttr(v));
- }));
- result.push_back(std::move(storage));
- }
-
- void
- createOpResultMapping(Operation *root, StringRef name,
- RaggedArray<transform::MappedValue> &extraMapping) {
- SmallVector<Operation *> operations;
- findOperationsByName(root, name, operations);
- SmallVector<Value> results;
- for (Operation *op : operations)
- llvm::append_range(results, op->getResults());
- extraMapping.push_back(results);
- }
-
- unsigned numberOfSetOptions(const Option<std::string> &ops,
- const ListOption<int> ¶ms,
- const Option<std::string> &values) {
- unsigned numSetValues = 0;
- numSetValues += !ops.empty();
- numSetValues += !params.empty();
- numSetValues += !values.empty();
- return numSetValues;
- }
-
- std::optional<LogicalResult> constructTransformModule(OpBuilder &builder,
- Location loc) {
- if (!testModuleGeneration)
- return std::nullopt;
-
- builder.create<transform::SequenceOp>(
- loc, TypeRange(), transform::FailurePropagationMode::Propagate,
- builder.getType<transform::AnyOpType>(),
- [](OpBuilder &b, Location nested, Value rootH) {
- b.create<transform::DebugEmitRemarkAtOp>(nested, rootH,
- "remark from generated");
- b.create<transform::YieldOp>(nested, ValueRange());
- });
- return success();
- }
-
- void runOnOperation() override {
- unsigned firstSetOptions =
- numberOfSetOptions(bindFirstExtraToOps, bindFirstExtraToParams,
- bindFirstExtraToResultsOfOps);
- unsigned secondSetOptions =
- numberOfSetOptions(bindSecondExtraToOps, bindSecondExtraToParams,
- bindSecondExtraToResultsOfOps);
- auto loc = UnknownLoc::get(&getContext());
- if (firstSetOptions > 1) {
- emitError(loc) << "cannot bind the first extra top-level argument to "
- "multiple entities";
- return signalPassFailure();
- }
- if (secondSetOptions > 1) {
- emitError(loc) << "cannot bind the second extra top-level argument to "
- "multiple entities";
- return signalPassFailure();
- }
- if (firstSetOptions == 0 && secondSetOptions != 0) {
- emitError(loc) << "cannot bind the second extra top-level argument "
- "without bindings the first";
- }
-
- RaggedArray<transform::MappedValue> extraMapping;
- if (!bindFirstExtraToOps.empty()) {
- SmallVector<Operation *> operations;
- findOperationsByName(getOperation(), bindFirstExtraToOps.getValue(),
- operations);
- extraMapping.push_back(operations);
- } else if (!bindFirstExtraToParams.empty()) {
- createParameterMapping(getContext(), bindFirstExtraToParams,
- extraMapping);
- } else if (!bindFirstExtraToResultsOfOps.empty()) {
- createOpResultMapping(getOperation(), bindFirstExtraToResultsOfOps,
- extraMapping);
- }
-
- if (!bindSecondExtraToOps.empty()) {
- SmallVector<Operation *> operations;
- findOperationsByName(getOperation(), bindSecondExtraToOps, operations);
- extraMapping.push_back(operations);
- } else if (!bindSecondExtraToParams.empty()) {
- createParameterMapping(getContext(), bindSecondExtraToParams,
- extraMapping);
- } else if (!bindSecondExtraToResultsOfOps.empty()) {
- createOpResultMapping(getOperation(), bindSecondExtraToResultsOfOps,
- extraMapping);
- }
-
- options = options.enableExpensiveChecks(enableExpensiveChecks);
- options = options.enableEnforceSingleToplevelTransformOp(
- enforceSingleToplevelTransformOp);
- if (failed(transform::detail::interpreterBaseRunOnOperationImpl(
- getOperation(), getArgument(), getSharedTransformModule(),
- getTransformLibraryModule(), extraMapping, options,
- transformFileName, transformLibraryPaths, debugPayloadRootTag,
- debugTransformRootTag, getBinaryName())))
- return signalPassFailure();
- }
-
- Option<bool> enableExpensiveChecks{
- *this, "enable-expensive-checks", llvm::cl::init(false),
- llvm::cl::desc("perform expensive checks to better report errors in the "
- "transform IR")};
- Option<bool> enforceSingleToplevelTransformOp{
- *this, "enforce-single-top-level-transform-op", llvm::cl::init(true),
- llvm::cl::desc("Ensure that only a single top-level transform op is "
- "present in the IR.")};
-
- Option<std::string> bindFirstExtraToOps{
- *this, "bind-first-extra-to-ops",
- llvm::cl::desc("bind the first extra argument of the top-level op to "
- "payload operations of the given kind")};
- ListOption<int> bindFirstExtraToParams{
- *this, "bind-first-extra-to-params",
- llvm::cl::desc("bind the first extra argument of the top-level op to "
- "the given integer parameters")};
- Option<std::string> bindFirstExtraToResultsOfOps{
- *this, "bind-first-extra-to-results-of-ops",
- llvm::cl::desc("bind the first extra argument of the top-level op to "
- "results of payload operations of the given kind")};
-
- Option<std::string> bindSecondExtraToOps{
- *this, "bind-second-extra-to-ops",
- llvm::cl::desc("bind the second extra argument of the top-level op to "
- "payload operations of the given kind")};
- ListOption<int> bindSecondExtraToParams{
- *this, "bind-second-extra-to-params",
- llvm::cl::desc("bind the second extra argument of the top-level op to "
- "the given integer parameters")};
- Option<std::string> bindSecondExtraToResultsOfOps{
- *this, "bind-second-extra-to-results-of-ops",
- llvm::cl::desc("bind the second extra argument of the top-level op to "
- "results of payload operations of the given kind")};
-
- Option<std::string> transformFileName{
- *this, "transform-file-name", llvm::cl::init(""),
- llvm::cl::desc(
- "Optional filename containing a transform dialect specification to "
- "apply. If left empty, the IR is assumed to contain one top-level "
- "transform dialect operation somewhere in the module.")};
- Option<std::string> debugPayloadRootTag{
- *this, "debug-payload-root-tag", llvm::cl::init(""),
- llvm::cl::desc(
- "Select the operation with 'transform.target_tag' attribute having "
- "the given value as payload IR root. If empty select the pass anchor "
- "operation as the payload IR root.")};
- Option<std::string> debugTransformRootTag{
- *this, "debug-transform-root-tag", llvm::cl::init(""),
- llvm::cl::desc(
- "Select the operation with 'transform.target_tag' attribute having "
- "the given value as container IR for top-level transform ops. This "
- "allows user control on what transformation to apply. If empty, "
- "select the container of the top-level transform op.")};
- ListOption<std::string> transformLibraryPaths{
- *this, "transform-library-paths", llvm::cl::ZeroOrMore,
- llvm::cl::desc("Optional paths to files with modules that should be "
- "merged into the transform module to provide the "
- "definitions of external named sequences.")};
-
- Option<bool> testModuleGeneration{
- *this, "test-module-generation", llvm::cl::init(false),
- llvm::cl::desc("test the generation of the transform module during pass "
- "initialization, overridden by parsing")};
-};
-
struct TestTransformDialectEraseSchedulePass
: public PassWrapper<TestTransformDialectEraseSchedulePass,
OperationPass<ModuleOp>> {
@@ -267,9 +53,5 @@ namespace test {
void registerTestTransformDialectEraseSchedulePass() {
PassRegistration<TestTransformDialectEraseSchedulePass> reg;
}
-/// Registers the test pass for applying transform dialect ops.
-void registerTestTransformDialectInterpreterPass() {
- PassRegistration<TestTransformDialectInterpreterPass> reg;
-}
} // namespace test
} // namespace mlir
diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index 237ebeb166dc99..7e39cb62965e26 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -140,7 +140,6 @@ void registerTestTensorCopyInsertionPass();
void registerTestTensorTransforms();
void registerTestTopologicalSortAnalysisPass();
void registerTestTransformDialectEraseSchedulePass();
-void registerTestTransformDialectInterpreterPass();
void registerTestWrittenToPass();
void registerTestVectorLowerings();
void registerTestVectorReductionToSPIRVDotProd();
@@ -269,7 +268,6 @@ void registerTestPasses() {
mlir::test::registerTestTensorTransforms();
mlir::test::registerTestTopologicalSortAnalysisPass();
mlir::test::registerTestTransformDialectEraseSchedulePass();
- mlir::test::registerTestTransformDialectInterpreterPass();
mlir::test::registerTestVectorLowerings();
mlir::test::registerTestVectorReductionToSPIRVDotProd();
mlir::test::registerTestNvgpuLowerings();
More information about the Mlir-commits
mailing list