[Mlir-commits] [mlir] [mlir][pass] Add composite pass utility (PR #87166)
Ivan Butygin
llvmlistbot at llvm.org
Sun Mar 31 17:18:59 PDT 2024
================
@@ -0,0 +1,100 @@
+//===- CompositePass.cpp - Composite pass code ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// CompositePass allows to run set of passes until fixed point is reached.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Transforms/Passes.h"
+
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassManager.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_COMPOSITEFIXEDPOINTPASS
+#include "mlir/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+
+namespace {
+struct CompositeFixedPointPass final
+ : public impl::CompositeFixedPointPassBase<CompositeFixedPointPass> {
+ using CompositeFixedPointPassBase::CompositeFixedPointPassBase;
+
+ CompositeFixedPointPass(
+ std::string name_, llvm::function_ref<void(OpPassManager &)> populateFunc,
+ unsigned maxIterations)
+ : dynamicPM(std::make_shared<OpPassManager>()) {
+ name = std::move(name_);
+ maxIter = maxIterations;
+ populateFunc(*dynamicPM);
+ std::string pipeline;
+ llvm::raw_string_ostream os(pipeline);
+ dynamicPM->printAsTextualPipeline(os);
+ os.flush();
+ pipelineStr = pipeline;
+ }
+
+ LogicalResult initializeOptions(StringRef options) override {
+ if (failed(CompositeFixedPointPassBase::initializeOptions(options)))
+ return failure();
+
+ dynamicPM = std::make_shared<OpPassManager>();
+ if (failed(parsePassPipeline(pipelineStr, *dynamicPM))) {
+ llvm::errs() << "Failed to parse composite pass pipeline\n";
+ return failure();
+ }
+
+ return success();
+ }
+
+ void getDependentDialects(DialectRegistry ®istry) const override {
+ dynamicPM->getDependentDialects(registry);
+ }
+
+ void runOnOperation() override {
+ auto op = getOperation();
+ OperationFingerPrint fp(op);
+
+ unsigned currentIter = 0;
+ unsigned maxIterVal = maxIter;
+ while (true) {
+ if (failed(runPipeline(*dynamicPM, op)))
----------------
Hardcode84 wrote:
I have no idea, actually :), I can try to change it to copy.
https://github.com/llvm/llvm-project/pull/87166
More information about the Mlir-commits
mailing list