From df364862d7f0700525c00156fa4c532e19088bfe Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Fri, 6 Dec 2024 13:30:23 -0800 Subject: [PATCH 1/3] [flang][cuda] Change how abstract result pass is scheduled on func.func and gpu.func --- flang/lib/Optimizer/Passes/Pipelines.cpp | 11 +++++++-- .../Optimizer/Transforms/AbstractResult.cpp | 15 ++++-------- flang/test/Driver/bbc-mlir-pass-pipeline.f90 | 9 ++----- .../test/Driver/mlir-debug-pass-pipeline.f90 | 19 +++++++-------- flang/test/Driver/mlir-pass-pipeline.f90 | 24 +++++++------------ flang/test/Fir/basic-program.fir | 24 +++++++------------ 6 files changed, 41 insertions(+), 61 deletions(-) diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp index 0743fb60aa847..ff79c811541c4 100644 --- a/flang/lib/Optimizer/Passes/Pipelines.cpp +++ b/flang/lib/Optimizer/Passes/Pipelines.cpp @@ -16,8 +16,14 @@ namespace fir { void addNestedPassToAllTopLevelOperations(mlir::PassManager &pm, PassConstructor ctor) { addNestedPassToOps(pm, ctor); + mlir::omp::PrivateClauseOp, fir::GlobalOp>(pm, ctor); +} + +template +void addNestedPassToNest(mlir::PassManager &pm, PassConstructor ctor) { + mlir::OpPassManager &nestPM = pm.nest(); + nestPM.addNestedPass(ctor()); + nestPM.addNestedPass(ctor()); } void addNestedPassToAllTopLevelOperationsConditionally( @@ -266,6 +272,7 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm, llvm::StringRef inputFilename) { fir::addBoxedProcedurePass(pm); addNestedPassToAllTopLevelOperations(pm, fir::createAbstractResultOpt); + addNestedPassToNest(pm, fir::createAbstractResultOpt); fir::addCodeGenRewritePass( pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo)); fir::addExternalNameConversionPass(pm, config.Underscoring); diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp index 2eca349110f3a..2ed66cc83eefb 100644 --- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp +++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp @@ -460,17 +460,10 @@ class AbstractResultOpt const bool shouldBoxResult = this->passResultAsBox.getValue(); mlir::TypeSwitch(op) - .Case([&](auto op) { - runOnSpecificOperation(op, shouldBoxResult, patterns, target); - }) - .Case([&](auto op) { - auto gpuMod = mlir::dyn_cast(*op); - for (auto funcOp : gpuMod.template getOps()) - runOnSpecificOperation(funcOp, shouldBoxResult, patterns, target); - for (auto gpuFuncOp : gpuMod.template getOps()) - runOnSpecificOperation(gpuFuncOp, shouldBoxResult, patterns, - target); - }); + .Case( + [&](auto op) { + runOnSpecificOperation(op, shouldBoxResult, patterns, target); + }); // Convert the calls and, if needed, the ReturnOp in the function body. target.addLegalDialect Date: Mon, 9 Dec 2024 08:24:26 -0800 Subject: [PATCH 2/3] Rename addNestedPassToNest to addPassToGPUModuleOperations --- flang/lib/Optimizer/Passes/Pipelines.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp index ff79c811541c4..116bf1f53ef30 100644 --- a/flang/lib/Optimizer/Passes/Pipelines.cpp +++ b/flang/lib/Optimizer/Passes/Pipelines.cpp @@ -19,8 +19,7 @@ void addNestedPassToAllTopLevelOperations(mlir::PassManager &pm, mlir::omp::PrivateClauseOp, fir::GlobalOp>(pm, ctor); } -template -void addNestedPassToNest(mlir::PassManager &pm, PassConstructor ctor) { +void addPassToGPUModuleOperations(mlir::PassManager &pm, PassConstructor ctor) { mlir::OpPassManager &nestPM = pm.nest(); nestPM.addNestedPass(ctor()); nestPM.addNestedPass(ctor()); @@ -272,7 +271,8 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm, llvm::StringRef inputFilename) { fir::addBoxedProcedurePass(pm); addNestedPassToAllTopLevelOperations(pm, fir::createAbstractResultOpt); - addNestedPassToNest(pm, fir::createAbstractResultOpt); + addPassToGPUModuleOperations( + pm, fir::createAbstractResultOpt); fir::addCodeGenRewritePass( pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo)); fir::addExternalNameConversionPass(pm, config.Underscoring); From e295462c343196ad92dbb32b0a451d114390d812 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Mon, 9 Dec 2024 09:22:52 -0800 Subject: [PATCH 3/3] Fix call --- flang/lib/Optimizer/Passes/Pipelines.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp index 116bf1f53ef30..90d5e962d826d 100644 --- a/flang/lib/Optimizer/Passes/Pipelines.cpp +++ b/flang/lib/Optimizer/Passes/Pipelines.cpp @@ -20,7 +20,7 @@ void addNestedPassToAllTopLevelOperations(mlir::PassManager &pm, } void addPassToGPUModuleOperations(mlir::PassManager &pm, PassConstructor ctor) { - mlir::OpPassManager &nestPM = pm.nest(); + mlir::OpPassManager &nestPM = pm.nest(); nestPM.addNestedPass(ctor()); nestPM.addNestedPass(ctor()); } @@ -271,8 +271,7 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm, llvm::StringRef inputFilename) { fir::addBoxedProcedurePass(pm); addNestedPassToAllTopLevelOperations(pm, fir::createAbstractResultOpt); - addPassToGPUModuleOperations( - pm, fir::createAbstractResultOpt); + addPassToGPUModuleOperations(pm, fir::createAbstractResultOpt); fir::addCodeGenRewritePass( pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo)); fir::addExternalNameConversionPass(pm, config.Underscoring);