[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
This commit is contained in:
Diana Picus 2022-03-02 11:02:59 +00:00
parent 1616bd9ef4
commit f1d4cef852
5 changed files with 82 additions and 0 deletions

View file

@ -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 <typename F>
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<mlir::func::FuncOp>(fir::createAbstractResultOptPass());
fir::addCodeGenRewritePass(pm);
fir::addTargetRewritePass(pm);
fir::addExternalNameConversionPass(pm);
fir::addFIRToLLVMPass(pm);
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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();