[Mlir-commits] [mlir] [mlir] remove test-tranfsorm-dialect-interpreter (PR #89931)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu May 2 05:52:40 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Oleksandr "Alex" Zinenko (ftynse)

<details>
<summary>Changes</summary>

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

---

Patch is 55.94 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/89931.diff


12 Files Affected:

- (removed) mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterPassBase.h (-216) 
- (modified) mlir/lib/Dialect/Transform/Transforms/CMakeLists.txt (-1) 
- (removed) mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp (-457) 
- (removed) mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-and-schedule.mlir (-20) 
- (removed) mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-dir.mlir (-28) 
- (removed) mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl-invalid.mlir (-57) 
- (removed) mlir/test/Dialect/Transform/test-interpreter-external-symbol-decl.mlir (-71) 
- (removed) mlir/test/Dialect/Transform/test-interpreter-module-generation.mlir (-4) 
- (removed) mlir/test/Dialect/Transform/test-interpreter-multiple-top-level-ops.mlir (-26) 
- (removed) mlir/test/Dialect/Transform/test-repro-dump.mlir (-32) 
- (modified) mlir/test/lib/Dialect/Transform/TestTransformDialectInterpreter.cpp (-218) 
- (modified) mlir/tools/mlir-opt/mlir-opt.cpp (-2) 


``````````diff
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 contai...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/89931


More information about the Mlir-commits mailing list