Skip to content

Commit 94a3092

Browse files
committed
[mlir][Pass] Make PassManager default to op-agnostic
Currently `PassManager` defaults to being anchored on `builtin.module`. Switching the default makes `PassManager` consistent with `OpPassManager` and avoids the implicit dependency on `builtin.module`. Specifying the anchor op type isn't strictly necessary when using explicit nesting (existing pipelines will continue to work), but I've updated most call sites to specify the anchor since it allows for better error-checking during pipeline construction. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D137731
1 parent d1b775d commit 94a3092

File tree

17 files changed

+51
-34
lines changed

17 files changed

+51
-34
lines changed

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ bool CodeGenAction::beginSourceFileAction() {
184184
lb.lower(parseTree, ci.getInvocation().getSemanticsContext());
185185

186186
// run the default passes.
187-
mlir::PassManager pm(mlirCtx.get(), mlir::OpPassManager::Nesting::Implicit);
187+
mlir::PassManager pm((*mlirModule)->getName(),
188+
mlir::OpPassManager::Nesting::Implicit);
188189
pm.enableVerifier(/*verifyPasses=*/true);
189190
pm.addPass(std::make_unique<Fortran::lower::VerifierPass>());
190191

@@ -535,7 +536,8 @@ void CodeGenAction::generateLLVMIR() {
535536
fir::support::registerLLVMTranslation(*mlirCtx);
536537

537538
// Set-up the MLIR pass manager
538-
mlir::PassManager pm(mlirCtx.get(), mlir::OpPassManager::Nesting::Implicit);
539+
mlir::PassManager pm((*mlirModule)->getName(),
540+
mlir::OpPassManager::Nesting::Implicit);
539541

540542
pm.addPass(std::make_unique<Fortran::lower::VerifierPass>());
541543
pm.enableVerifier(/*verifyPasses=*/true);

flang/tools/bbc/bbc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
249249
<< outputName;
250250

251251
// Otherwise run the default passes.
252-
mlir::PassManager pm(&ctx, mlir::OpPassManager::Nesting::Implicit);
252+
mlir::PassManager pm(mlirModule->getName(),
253+
mlir::OpPassManager::Nesting::Implicit);
253254
pm.enableVerifier(/*verifyPasses=*/true);
254255
mlir::applyPassManagerCLOptions(pm);
255256
if (passPipeline.hasAnyOccurrences()) {

flang/tools/tco/tco.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
103103
fir::KindMapping kindMap{&context};
104104
fir::setTargetTriple(*owningRef, targetTriple);
105105
fir::setKindMapping(*owningRef, kindMap);
106-
mlir::PassManager pm(&context, mlir::OpPassManager::Nesting::Implicit);
106+
mlir::PassManager pm((*owningRef)->getName(),
107+
mlir::OpPassManager::Nesting::Implicit);
107108
pm.enableVerifier(/*verifyPasses=*/true);
108109
mlir::applyPassManagerCLOptions(pm);
109110
if (emitFir) {

mlir/docs/PassManagement.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,8 @@ Below is an example of constructing a pipeline that operates on the above
399399
structure:
400400

401401
```c++
402-
// Create a top-level `PassManager` class. If an operation type is not
403-
// explicitly specific, the default is the builtin `module` operation.
404-
PassManager pm(ctx);
405-
// Note: We could also create the above `PassManager` this way.
406-
PassManager pm(ctx, /*operationName=*/"builtin.module");
402+
// Create a top-level `PassManager` class.
403+
auto pm = PassManager::on<ModuleOp>(ctx);
407404

408405
// Add a pass on the top-level module operation.
409406
pm.addPass(std::make_unique<MyModulePass>());

mlir/docs/Tutorials/Toy/Ch-3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pipeline. In MLIR, the optimizations are run through a `PassManager` in a
124124
similar way to LLVM:
125125
126126
```c++
127-
mlir::PassManager pm(module.getContext());
127+
mlir::PassManager pm(module->getName());
128128
pm.addNestedPass<mlir::toy::FuncOp>(mlir::createCanonicalizerPass());
129129
```
130130

mlir/examples/toy/Ch3/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int dumpMLIR() {
113113
return error;
114114

115115
if (enableOpt) {
116-
mlir::PassManager pm(&context);
116+
mlir::PassManager pm(module.get()->getName());
117117
// Apply any generic pass manager command line options and run the pipeline.
118118
applyPassManagerCLOptions(pm);
119119

mlir/examples/toy/Ch4/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int dumpMLIR() {
114114
return error;
115115

116116
if (enableOpt) {
117-
mlir::PassManager pm(&context);
117+
mlir::PassManager pm(module.get()->getName());
118118
// Apply any generic pass manager command line options and run the pipeline.
119119
applyPassManagerCLOptions(pm);
120120

mlir/examples/toy/Ch5/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int dumpMLIR() {
117117
if (int error = loadMLIR(sourceMgr, context, module))
118118
return error;
119119

120-
mlir::PassManager pm(&context);
120+
mlir::PassManager pm(module.get()->getName());
121121
// Apply any generic pass manager command line options and run the pipeline.
122122
applyPassManagerCLOptions(pm);
123123

mlir/examples/toy/Ch6/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
132132
if (int error = loadMLIR(context, module))
133133
return error;
134134

135-
mlir::PassManager pm(&context);
135+
mlir::PassManager pm(module.get()->getName());
136136
// Apply any generic pass manager command line options and run the pipeline.
137137
applyPassManagerCLOptions(pm);
138138

mlir/examples/toy/Ch7/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
132132
if (int error = loadMLIR(context, module))
133133
return error;
134134

135-
mlir::PassManager pm(&context);
135+
mlir::PassManager pm(module.get()->getName());
136136
// Apply any generic pass manager command line options and run the pipeline.
137137
applyPassManagerCLOptions(pm);
138138

0 commit comments

Comments
 (0)