[Mlir-commits] [mlir] 3e2e10b - Clarify the invariant of the MLIR pass pipeline around `Pass::initialize()`
Mehdi Amini
llvmlistbot at llvm.org
Mon Aug 7 18:46:24 PDT 2023
Author: Mehdi Amini
Date: 2023-08-07T18:46:08-07:00
New Revision: 3e2e10b55260befaa80ba837f69ff9ff92e65ad8
URL: https://github.com/llvm/llvm-project/commit/3e2e10b55260befaa80ba837f69ff9ff92e65ad8
DIFF: https://github.com/llvm/llvm-project/commit/3e2e10b55260befaa80ba837f69ff9ff92e65ad8.diff
LOG: 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
Added:
Modified:
mlir/include/mlir/Pass/Pass.h
mlir/lib/Pass/Pass.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h
index 714667c239a8aa..028ab4bc2cda92 100644
--- a/mlir/include/mlir/Pass/Pass.h
+++ b/mlir/include/mlir/Pass/Pass.h
@@ -180,8 +180,10 @@ class Pass {
/// should not rely on any state accessible during the execution of a pass.
/// For example, `getContext`/`getOperation`/`getAnalysis`/etc. should not be
/// invoked within this hook.
- /// Returns a LogicalResult to indicate failure, in which case the pass
- /// pipeline won't execute.
+ /// This method is invoked after all dependent dialects for the pipeline are
+ /// loaded, and is not allowed to load any further dialects (override the
+ /// `geDependentDialects()` for this purpose instead). Returns a LogicalResult
+ /// to indicate failure, in which case the pass pipeline won't execute.
virtual LogicalResult initialize(MLIRContext *context) { return success(); }
/// Indicate if the current pass can be scheduled on the given operation type.
diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index c7738a2248a103..fe4597f3df3d25 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -820,6 +820,9 @@ LogicalResult PassManager::run(Operation *op) {
if (failed(getImpl().finalizePassList(context)))
return failure();
+ // Notify the context that we start running a pipeline for book keeping.
+ context->enterMultiThreadedExecution();
+
// Initialize all of the passes within the pass manager with a new generation.
llvm::hash_code newInitKey = context->getRegistryHash();
if (newInitKey != initializationKey) {
@@ -831,9 +834,6 @@ LogicalResult PassManager::run(Operation *op) {
// Construct a top level analysis manager for the pipeline.
ModuleAnalysisManager am(op, instrumentor.get());
- // Notify the context that we start running a pipeline for book keeping.
- context->enterMultiThreadedExecution();
-
// If reproducer generation is enabled, run the pass manager with crash
// handling enabled.
LogicalResult result =
More information about the Mlir-commits
mailing list