forked from OSchip/llvm-project
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
This commit is contained in:
parent
80e6aff6bb
commit
a8c1d9d63e
|
@ -85,6 +85,9 @@ public:
|
||||||
/// operation type, it must be the same type as this pass manager.
|
/// operation type, it must be the same type as this pass manager.
|
||||||
void addPass(std::unique_ptr<Pass> pass);
|
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
|
/// Add the given pass to a nested pass manager for the given operation kind
|
||||||
/// `OpT`.
|
/// `OpT`.
|
||||||
template <typename OpT> void addNestedPass(std::unique_ptr<Pass> pass) {
|
template <typename OpT> void addNestedPass(std::unique_ptr<Pass> pass) {
|
||||||
|
|
|
@ -98,6 +98,10 @@ struct OpPassManagerImpl {
|
||||||
/// operation type, it must be the same type as this pass manager.
|
/// operation type, it must be the same type as this pass manager.
|
||||||
void addPass(std::unique_ptr<Pass> pass);
|
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
|
/// Coalesce adjacent AdaptorPasses into one large adaptor. This runs
|
||||||
/// recursively through the pipeline graph.
|
/// recursively through the pipeline graph.
|
||||||
void coalesceAdjacentAdaptorPasses();
|
void coalesceAdjacentAdaptorPasses();
|
||||||
|
@ -167,6 +171,8 @@ void OpPassManagerImpl::addPass(std::unique_ptr<Pass> pass) {
|
||||||
passes.emplace_back(std::move(pass));
|
passes.emplace_back(std::move(pass));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpPassManagerImpl::clear() { passes.clear(); }
|
||||||
|
|
||||||
void OpPassManagerImpl::coalesceAdjacentAdaptorPasses() {
|
void OpPassManagerImpl::coalesceAdjacentAdaptorPasses() {
|
||||||
// Bail out early if there are no adaptor passes.
|
// Bail out early if there are no adaptor passes.
|
||||||
if (llvm::none_of(passes, [](std::unique_ptr<Pass> &pass) {
|
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));
|
impl->addPass(std::move(pass));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpPassManager::clear() { impl->clear(); }
|
||||||
|
|
||||||
/// Returns the number of passes held by this manager.
|
/// Returns the number of passes held by this manager.
|
||||||
size_t OpPassManager::size() const { return impl->passes.size(); }
|
size_t OpPassManager::size() const { return impl->passes.size(); }
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,11 @@ TEST(PassManagerTest, InvalidPass) {
|
||||||
diagnostic->str(),
|
diagnostic->str(),
|
||||||
"'invalid_op' op trying to schedule a pass on an unregistered operation");
|
"'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.
|
// Check that adding the pass at the top-level triggers a fatal error.
|
||||||
ASSERT_DEATH(pm.addPass(std::make_unique<InvalidPass>()), "");
|
ASSERT_DEATH(pm.addPass(std::make_unique<InvalidPass>()), "");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue