[Mlir-commits] [mlir] [mlir][pass] Add composite pass utility (PR #87166)

Mehdi Amini llvmlistbot at llvm.org
Sun Mar 31 17:16:06 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;
----------------
joker-eph wrote:

```suggestion
    llvm::raw_string_ostream os(pipelineStr);
    dynamicPM->printAsTextualPipeline(os);
```

Wouldn't this do the same thing?

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


More information about the Mlir-commits mailing list