[Mlir-commits] [mlir] a8c1d9d - Add a clear() method on the PassManager (NFC)
Mehdi Amini
llvmlistbot at llvm.org
Sun Oct 24 21:39:09 PDT 2021
Author: Mehdi Amini
Date: 2021-10-25T04:39:00Z
New Revision: a8c1d9d63e121f16d49b3f80c76f695dfcbcc142
URL: https://github.com/llvm/llvm-project/commit/a8c1d9d63e121f16d49b3f80c76f695dfcbcc142
DIFF: https://github.com/llvm/llvm-project/commit/a8c1d9d63e121f16d49b3f80c76f695dfcbcc142.diff
LOG: Add a clear() method on the PassManager (NFC)
This allows to clear an OpPassManager and populated it again with a new
pipeline, while preserving all the other options (including instrumentations).
Differential Revision: https://reviews.llvm.org/D112393
Added:
Modified:
mlir/include/mlir/Pass/PassManager.h
mlir/lib/Pass/Pass.cpp
mlir/unittests/Pass/PassManagerTest.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h
index 42215d4d18f15..4ab63ae06ab8f 100644
--- a/mlir/include/mlir/Pass/PassManager.h
+++ b/mlir/include/mlir/Pass/PassManager.h
@@ -85,6 +85,9 @@ class OpPassManager {
/// operation type, it must be the same type as this pass manager.
void addPass(std::unique_ptr<Pass> pass);
+ /// Clear the pipeline, but not the other options set on this OpPassManager.
+ void clear();
+
/// Add the given pass to a nested pass manager for the given operation kind
/// `OpT`.
template <typename OpT> void addNestedPass(std::unique_ptr<Pass> pass) {
diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 2e2df8b9ab333..9d0a0c18d56f4 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -98,6 +98,10 @@ struct OpPassManagerImpl {
/// operation type, it must be the same type as this pass manager.
void addPass(std::unique_ptr<Pass> pass);
+ /// Clear the list of passes in this pass manager, other options are
+ /// preserved.
+ void clear();
+
/// Coalesce adjacent AdaptorPasses into one large adaptor. This runs
/// recursively through the pipeline graph.
void coalesceAdjacentAdaptorPasses();
@@ -167,6 +171,8 @@ void OpPassManagerImpl::addPass(std::unique_ptr<Pass> pass) {
passes.emplace_back(std::move(pass));
}
+void OpPassManagerImpl::clear() { passes.clear(); }
+
void OpPassManagerImpl::coalesceAdjacentAdaptorPasses() {
// Bail out early if there are no adaptor passes.
if (llvm::none_of(passes, [](std::unique_ptr<Pass> &pass) {
@@ -261,6 +267,8 @@ void OpPassManager::addPass(std::unique_ptr<Pass> pass) {
impl->addPass(std::move(pass));
}
+void OpPassManager::clear() { impl->clear(); }
+
/// Returns the number of passes held by this manager.
size_t OpPassManager::size() const { return impl->passes.size(); }
diff --git a/mlir/unittests/Pass/PassManagerTest.cpp b/mlir/unittests/Pass/PassManagerTest.cpp
index 8db7e5e66cd8e..a3f8e210dcb2d 100644
--- a/mlir/unittests/Pass/PassManagerTest.cpp
+++ b/mlir/unittests/Pass/PassManagerTest.cpp
@@ -118,6 +118,11 @@ TEST(PassManagerTest, InvalidPass) {
diagnostic->str(),
"'invalid_op' op trying to schedule a pass on an unregistered operation");
+ // Check that clearing the pass manager effectively removed the pass.
+ pm.clear();
+ result = pm.run(module.get());
+ EXPECT_TRUE(succeeded(result));
+
// Check that adding the pass at the top-level triggers a fatal error.
ASSERT_DEATH(pm.addPass(std::make_unique<InvalidPass>()), "");
}
More information about the Mlir-commits
mailing list