Skip to content

Commit 3e2e10b

Browse files
committed
Clarify the invariant of the MLIR pass pipeline around Pass::initialize()
This method should not load new dialect or affect the context itself. Differential Revision: https://reviews.llvm.org/D157198
1 parent 0bdbe7b commit 3e2e10b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mlir/include/mlir/Pass/Pass.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ class Pass {
180180
/// should not rely on any state accessible during the execution of a pass.
181181
/// For example, `getContext`/`getOperation`/`getAnalysis`/etc. should not be
182182
/// invoked within this hook.
183-
/// Returns a LogicalResult to indicate failure, in which case the pass
184-
/// pipeline won't execute.
183+
/// This method is invoked after all dependent dialects for the pipeline are
184+
/// loaded, and is not allowed to load any further dialects (override the
185+
/// `geDependentDialects()` for this purpose instead). Returns a LogicalResult
186+
/// to indicate failure, in which case the pass pipeline won't execute.
185187
virtual LogicalResult initialize(MLIRContext *context) { return success(); }
186188

187189
/// Indicate if the current pass can be scheduled on the given operation type.

mlir/lib/Pass/Pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,9 @@ LogicalResult PassManager::run(Operation *op) {
820820
if (failed(getImpl().finalizePassList(context)))
821821
return failure();
822822

823+
// Notify the context that we start running a pipeline for book keeping.
824+
context->enterMultiThreadedExecution();
825+
823826
// Initialize all of the passes within the pass manager with a new generation.
824827
llvm::hash_code newInitKey = context->getRegistryHash();
825828
if (newInitKey != initializationKey) {
@@ -831,9 +834,6 @@ LogicalResult PassManager::run(Operation *op) {
831834
// Construct a top level analysis manager for the pipeline.
832835
ModuleAnalysisManager am(op, instrumentor.get());
833836

834-
// Notify the context that we start running a pipeline for book keeping.
835-
context->enterMultiThreadedExecution();
836-
837837
// If reproducer generation is enabled, run the pass manager with crash
838838
// handling enabled.
839839
LogicalResult result =

0 commit comments

Comments
 (0)