diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc --- a/flang/include/flang/Tools/CLOptions.inc +++ b/flang/include/flang/Tools/CLOptions.inc @@ -66,6 +66,8 @@ "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 @@ } #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 @@ 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 --- /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 --- /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 --- 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 @@ // 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 --- a/flang/tools/tco/tco.cpp +++ b/flang/tools/tco/tco.cpp @@ -131,6 +131,10 @@ } 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();