Skip to content

Commit

Permalink
[flang] Schedule InlineHLFIRAssign after BufferizeHLFIR. (llvm#121863)
Browse files Browse the repository at this point in the history
This helps to get rid of *some* calls to AssignTemporary runtime
that are appearing due to temporary_lhs hlfir.assign produced
in BufferizeHLFIR. I only tested it on `tonto`, and did not see
any performance changes. I will run more performance testing
before merging this.
  • Loading branch information
vzakhari authored Jan 7, 2025
1 parent 9374453 commit 611c96a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions flang/lib/Optimizer/Passes/Pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ void createHLFIRToFIRPassPipeline(mlir::PassManager &pm, bool enableOpenMP,
pm.addPass(hlfir::createLowerHLFIROrderedAssignments());
pm.addPass(hlfir::createLowerHLFIRIntrinsics());
pm.addPass(hlfir::createBufferizeHLFIR());
// Run hlfir.assign inlining again after BufferizeHLFIR,
// because the latter may introduce new hlfir.assign operations,
// e.g. for copying an array into a temporary due to
// hlfir.associate.
// TODO: we can remove the previous InlineHLFIRAssign, when
// FIR AliasAnalysis is good enough to say that a temporary
// array does not alias with any user object.
if (optLevel.isOptimizingForSpeed())
addNestedPassToAllTopLevelOperations<PassConstructor>(
pm, hlfir::createInlineHLFIRAssign);
pm.addPass(hlfir::createConvertHLFIRtoFIR());
if (enableOpenMP)
pm.addPass(flangomp::createLowerWorkshare());
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Driver/mlir-pass-pipeline.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
! ALL: LowerHLFIROrderedAssignments
! ALL-NEXT: LowerHLFIRIntrinsics
! ALL-NEXT: BufferizeHLFIR
! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
! O2-NEXT: 'fir.global' Pipeline
! O2-NEXT: InlineHLFIRAssign
! O2-NEXT: 'func.func' Pipeline
! O2-NEXT: InlineHLFIRAssign
! O2-NEXT: 'omp.declare_reduction' Pipeline
! O2-NEXT: InlineHLFIRAssign
! O2-NEXT: 'omp.private' Pipeline
! O2-NEXT: InlineHLFIRAssign
! ALL-NEXT: ConvertHLFIRtoFIR
! ALL-NEXT: CSE
! Ideally, we need an output with only the pass names, but
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Fir/basic-program.fir
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func.func @_QQmain() {
// PASSES-NEXT: LowerHLFIROrderedAssignments
// PASSES-NEXT: LowerHLFIRIntrinsics
// PASSES-NEXT: BufferizeHLFIR
// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
// PASSES-NEXT: 'fir.global' Pipeline
// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: 'omp.private' Pipeline
// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: ConvertHLFIRtoFIR
// PASSES-NEXT: LowerWorkshare
// PASSES-NEXT: CSE
Expand Down

0 comments on commit 611c96a

Please sign in to comment.