From f1d4cef8528eceef4d6aaaae1f99d927fd5c370d Mon Sep 17 00:00:00 2001 From: Diana Picus Date: Wed, 2 Mar 2022 11:02:59 +0000 Subject: [PATCH] [flang] Add ExternalNameConversionPass to pass pipeline This seems to be the consensus in https://github.com/flang-compiler/f18-llvm-project/issues/1316 The patch adds ExternalNameConversion to the default FIR CodeGen pass pipeline, right before the FIRtoLLVM pass. It also adds a flag to optionally disable it, and sets it in `tco`. In other words, `flang-new` and `flang-new -fc1` will both run the pass by default, whereas `tco` will not, so none of the tests need to be updated. Differential Revision: https://reviews.llvm.org/D121171 --- flang/include/flang/Tools/CLOptions.inc | 8 +++++++ flang/test/Driver/disable-ext-name-interop.f90 | 9 ++++++++ flang/test/Driver/mlir-pass-pipeline.f90 | 32 ++++++++++++++++++++++++++ flang/test/Fir/basic-program.fir | 29 +++++++++++++++++++++++ flang/tools/tco/tco.cpp | 4 ++++ 5 files changed, 82 insertions(+) create mode 100644 flang/test/Driver/disable-ext-name-interop.f90 create mode 100644 flang/test/Driver/mlir-pass-pipeline.f90 diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc index 2a5a670..66e0818 100644 --- a/flang/include/flang/Tools/CLOptions.inc +++ b/flang/include/flang/Tools/CLOptions.inc @@ -66,6 +66,8 @@ DisableOption(BoxedProcedureRewrite, "boxed-procedure-rewrite", "rewrite boxed procedures"); #endif +DisableOption(ExternalNameConversion, "external-name-interop", "convert names with external convention"); + /// Generic for adding a pass to the pass manager if it is not disabled. template void addPassConditionally( @@ -139,6 +141,11 @@ inline void addBoxedProcedurePass(mlir::PassManager &pm) { } #endif +inline void addExternalNameConversionPass(mlir::PassManager &pm) { + addPassConditionally(pm, disableExternalNameConversion, + [&]() { return fir::createExternalNameConversionPass(); }); +} + /// Create a pass pipeline for running default optimization passes for /// incremental conversion of FIR. /// @@ -174,6 +181,7 @@ inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm) { pm.addNestedPass(fir::createAbstractResultOptPass()); fir::addCodeGenRewritePass(pm); fir::addTargetRewritePass(pm); + fir::addExternalNameConversionPass(pm); fir::addFIRToLLVMPass(pm); } diff --git a/flang/test/Driver/disable-ext-name-interop.f90 b/flang/test/Driver/disable-ext-name-interop.f90 new file mode 100644 index 0000000..0c59a5b --- /dev/null +++ b/flang/test/Driver/disable-ext-name-interop.f90 @@ -0,0 +1,9 @@ +! Test that we can disable the ExternalNameConversion pass in flang-new. + +! RUN: %flang_fc1 -S %s -o - 2>&1 | FileCheck %s --check-prefix=EXTNAMES +! RUN: %flang_fc1 -S -mmlir -disable-external-name-interop %s -o - 2>&1 | FileCheck %s --check-prefix=INTNAMES + +! EXTNAMES: test_ext_names_ +! INTNAMES: _QPtest_ext_names +subroutine test_ext_names +end subroutine diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90 new file mode 100644 index 0000000..ba006f7 --- /dev/null +++ b/flang/test/Driver/mlir-pass-pipeline.f90 @@ -0,0 +1,32 @@ +! Test the MLIR pass pipeline + +! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o - 2>&1 | FileCheck %s +end program + +! CHECK: Pass statistics report + +! CHECK-LABEL: 'func.func' Pipeline +! CHECK: ArrayValueCopy +! CHECK: CharacterConversion +! CHECK: Canonicalizer +! CHECK: SimplifyRegionLite + +! CHECK-LABEL: 'func.func' Pipeline +! CHECK: MemoryAllocationOpt +! CHECK: Inliner +! CHECK: CSE + +! CHECK-LABEL: 'func.func' Pipeline +! CHECK: CFGConversion +! CHECK: SCFToControlFlow +! CHECK: Canonicalizer +! CHECK: SimplifyRegionLite +! CHECK: BoxedProcedurePass + +! CHECK-LABEL: 'func.func' Pipeline +! CHECK: AbstractResultOpt +! CHECK: CodeGenRewrite +! CHECK: TargetRewrite +! CHECK: ExternalNameConversion +! CHECK: FIRToLLVMLowering +! CHECK-NOT: LLVMIRLoweringPass diff --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir index 0f22629..e646ddd 100644 --- a/flang/test/Fir/basic-program.fir +++ b/flang/test/Fir/basic-program.fir @@ -1,6 +1,8 @@ // RUN: tco %s | FileCheck %s +// RUN: tco %s --mlir-pass-statistics --mlir-pass-statistics-display=pipeline 2>&1 | FileCheck %s --check-prefix=PASSES // Check that tco is working with a basic test. +// Also check the passes in the default pipeline. func @_QQmain() { return @@ -9,3 +11,30 @@ func @_QQmain() { // CHECK: ; ModuleID = 'FIRModule' // CHECK-LABEL: define void @_QQmain() // CHECK: ret void + +// PASSES: Pass statistics report + +// PASSES-LABEL: 'func.func' Pipeline +// PASSES: ArrayValueCopy +// PASSES: CharacterConversion +// PASSES: Canonicalizer +// PASSES: SimplifyRegionLite + +// PASSES-LABEL: 'func.func' Pipeline +// PASSES: MemoryAllocationOpt +// PASSES: Inliner +// PASSES: CSE + +// PASSES-LABEL: 'func.func' Pipeline +// PASSES: CFGConversion +// PASSES: SCFToControlFlow +// PASSES: Canonicalizer +// PASSES: SimplifyRegionLite +// PASSES: BoxedProcedurePass + +// PASSES-LABEL: 'func.func' Pipeline +// PASSES: AbstractResultOpt +// PASSES: CodeGenRewrite +// PASSES: TargetRewrite +// PASSES: FIRToLLVMLowering +// PASSES: LLVMIRLoweringPass diff --git a/flang/tools/tco/tco.cpp b/flang/tools/tco/tco.cpp index e35325c..0c9e2f5 100644 --- a/flang/tools/tco/tco.cpp +++ b/flang/tools/tco/tco.cpp @@ -131,6 +131,10 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) { } int main(int argc, char **argv) { + // Disable the ExternalNameConversion pass by default until all the tests have + // been updated to pass with it enabled. + disableExternalNameConversion = true; + [[maybe_unused]] InitLLVM y(argc, argv); fir::support::registerMLIRPassesForFortranTools(); fir::registerOptCodeGenPasses(); -- 2.7.4