This revision provides the ability to use an arbitrary named sequence op as the entry point to a transform dialect strategy. It is also a step towards better transform dialect usage in pass pipelines that need to preload a transform library rather thanparse it on the fly. The interpreter itself is significantly simpler than its testing counterpart by avoiding payload/debug root tags and multiple shared modules. In the process, the NamedSequenceOp::apply function is adapted to allow it being an entry point. NamedSequenceOp is **not** extended to take the PossibleTopLevelTrait at this time, because the implementation of the trait is specific to allowing one top-level dangling op with a region such as SequenceOp or AlternativesOp. In particular, the verifier of PossibleTopLevelTrait does not allow for an empty body, which is necessary to declare a NamedSequenceOp that gets linked in separately before application. In the future, we should dispense with the PossibleTopLevelTrait altogether and always enter the interpreter with a NamedSequenceOp. Lastly, relevant TD linking utilities are moved to TransformInterpreterUtils and reused from there.
40 lines
1.4 KiB
C++
40 lines
1.4 KiB
C++
//===- PreloadLibraryPass.cpp - Pass to preload a transform library -------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/Transform/IR/TransformDialect.h"
|
|
#include "mlir/Dialect/Transform/Transforms/Passes.h"
|
|
#include "mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h"
|
|
|
|
using namespace mlir;
|
|
|
|
namespace mlir {
|
|
namespace transform {
|
|
#define GEN_PASS_DEF_PRELOADLIBRARYPASS
|
|
#include "mlir/Dialect/Transform/Transforms/Passes.h.inc"
|
|
} // namespace transform
|
|
} // namespace mlir
|
|
|
|
namespace {
|
|
class PreloadLibraryPass
|
|
: public transform::impl::PreloadLibraryPassBase<PreloadLibraryPass> {
|
|
public:
|
|
using Base::Base;
|
|
|
|
void runOnOperation() override {
|
|
OwningOpRef<ModuleOp> mergedParsedLibraries;
|
|
if (failed(transform::detail::assembleTransformLibraryFromPaths(
|
|
&getContext(), transformLibraryPaths, mergedParsedLibraries)))
|
|
return signalPassFailure();
|
|
// TODO: investigate using a resource blob if some ownership mode allows it.
|
|
auto *dialect =
|
|
getContext().getOrLoadDialect<transform::TransformDialect>();
|
|
dialect->registerLibraryModule(std::move(mergedParsedLibraries));
|
|
}
|
|
};
|
|
} // namespace
|