xref: /llvm-project/mlir/lib/Dialect/Transform/Transforms/PreloadLibraryPass.cpp (revision 99c15eb49ba0b607314b3bd221f0760049130d97)
11bf08709SNicolas Vasilache //===- PreloadLibraryPass.cpp - Pass to preload a transform library -------===//
21bf08709SNicolas Vasilache //
31bf08709SNicolas Vasilache // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
41bf08709SNicolas Vasilache // See https://llvm.org/LICENSE.txt for license information.
51bf08709SNicolas Vasilache // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
61bf08709SNicolas Vasilache //
71bf08709SNicolas Vasilache //===----------------------------------------------------------------------===//
81bf08709SNicolas Vasilache 
91bf08709SNicolas Vasilache #include "mlir/Dialect/Transform/IR/TransformDialect.h"
101bf08709SNicolas Vasilache #include "mlir/Dialect/Transform/Transforms/Passes.h"
111bf08709SNicolas Vasilache #include "mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h"
121bf08709SNicolas Vasilache 
131bf08709SNicolas Vasilache using namespace mlir;
141bf08709SNicolas Vasilache 
151bf08709SNicolas Vasilache namespace mlir {
161bf08709SNicolas Vasilache namespace transform {
171bf08709SNicolas Vasilache #define GEN_PASS_DEF_PRELOADLIBRARYPASS
181bf08709SNicolas Vasilache #include "mlir/Dialect/Transform/Transforms/Passes.h.inc"
191bf08709SNicolas Vasilache } // namespace transform
201bf08709SNicolas Vasilache } // namespace mlir
211bf08709SNicolas Vasilache 
221bf08709SNicolas Vasilache namespace {
231bf08709SNicolas Vasilache class PreloadLibraryPass
241bf08709SNicolas Vasilache     : public transform::impl::PreloadLibraryPassBase<PreloadLibraryPass> {
251bf08709SNicolas Vasilache public:
261bf08709SNicolas Vasilache   using Base::Base;
271bf08709SNicolas Vasilache 
runOnOperation()281bf08709SNicolas Vasilache   void runOnOperation() override {
291bf08709SNicolas Vasilache     OwningOpRef<ModuleOp> mergedParsedLibraries;
301bf08709SNicolas Vasilache     if (failed(transform::detail::assembleTransformLibraryFromPaths(
311bf08709SNicolas Vasilache             &getContext(), transformLibraryPaths, mergedParsedLibraries)))
321bf08709SNicolas Vasilache       return signalPassFailure();
331bf08709SNicolas Vasilache     // TODO: investigate using a resource blob if some ownership mode allows it.
341bf08709SNicolas Vasilache     auto *dialect =
351bf08709SNicolas Vasilache         getContext().getOrLoadDialect<transform::TransformDialect>();
36*99c15eb4SIngo Müller     if (failed(
37*99c15eb4SIngo Müller             dialect->loadIntoLibraryModule(std::move(mergedParsedLibraries))))
38*99c15eb4SIngo Müller       signalPassFailure();
391bf08709SNicolas Vasilache   }
401bf08709SNicolas Vasilache };
411bf08709SNicolas Vasilache } // namespace
42