Files
clang-p2996/mlir/lib/Dialect/Transform/Transforms/PreloadLibraryPass.cpp
Ingo Müller 99c15eb49b [mlir][transform] Handle multiple library preloading passes. (#69705)
This is a new attempt at #69320.

The transform dialect stores a "library module" that the preload pass
can populate. Until now, each pass registered an additional module by
simply pushing it to a vector; however, the interpreter only used the
first of them. This commit turns the registration into "loading", i.e.,
each newly added module gets merged into the existing one. This allows
the loading to be split into several passes, and using the library in
the interpreter now takes all of them into account. While this design
avoids repeated merging every time the library is accessed, it requires
that the implementation of merging modules lives in the
TransformDialect target (since it at the dialect depend on each
other).

This resolves https://github.com/llvm/llvm-project/issues/69111.
2023-10-25 09:52:30 +02:00

42 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>();
if (failed(
dialect->loadIntoLibraryModule(std::move(mergedParsedLibraries))))
signalPassFailure();
}
};
} // namespace