Skip to content

Commit 6ff8236

Browse files
authored
[flang][HLFIR] Adapt InlineElementals to run on all top level ops (#92734)
This means that this pass will also run on hlfir elemental operations which are not inside of functions. See RFC: https://discourse.llvm.org/t/rfc-add-an-interface-for-top-level-container-operations Some of the changes are from moving the declaration and definition of the constructor into tablegen (as requested during code review of another pass). While I was updating the tests I noticed that the optimized bufferization pass and some cse were missing from the optimized pipeline in flang/test/Driver/mlir-pass-pipeline.f90. I fixed this in this commit.
1 parent b7d911b commit 6ff8236

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

flang/include/flang/Optimizer/HLFIR/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace hlfir {
2525
std::unique_ptr<mlir::Pass> createConvertHLFIRtoFIRPass();
2626
std::unique_ptr<mlir::Pass> createBufferizeHLFIRPass();
2727
std::unique_ptr<mlir::Pass> createLowerHLFIRIntrinsicsPass();
28-
std::unique_ptr<mlir::Pass> createInlineElementalsPass();
2928
std::unique_ptr<mlir::Pass> createLowerHLFIROrderedAssignmentsPass();
3029
std::unique_ptr<mlir::Pass> createOptimizedBufferizationPass();
3130

flang/include/flang/Optimizer/HLFIR/Passes.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ def SimplifyHLFIRIntrinsics : Pass<"simplify-hlfir-intrinsics"> {
5050
let summary = "Simplify HLFIR intrinsic operations that don't need to result in runtime calls";
5151
}
5252

53-
def InlineElementals : Pass<"inline-elementals", "::mlir::func::FuncOp"> {
53+
def InlineElementals : Pass<"inline-elementals"> {
5454
let summary = "Inline chained hlfir.elemental operations";
55-
let constructor = "hlfir::createInlineElementalsPass()";
5655
}
5756

5857
#endif //FORTRAN_DIALECT_HLFIR_PASSES

flang/include/flang/Tools/CLOptions.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ inline void createHLFIRToFIRPassPipeline(
320320
addNestedPassToAllTopLevelOperations(
321321
pm, hlfir::createSimplifyHLFIRIntrinsics);
322322
}
323-
pm.addPass(hlfir::createInlineElementalsPass());
323+
addNestedPassToAllTopLevelOperations(pm, hlfir::createInlineElementals);
324324
if (optLevel.isOptimizingForSpeed()) {
325325
addCanonicalizerPassWithoutRegionSimplification(pm);
326326
pm.addPass(mlir::createCSEPass());

flang/lib/Optimizer/HLFIR/Transforms/InlineElementals.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class InlineElementalsPass
115115
: public hlfir::impl::InlineElementalsBase<InlineElementalsPass> {
116116
public:
117117
void runOnOperation() override {
118-
mlir::func::FuncOp func = getOperation();
119118
mlir::MLIRContext *context = &getContext();
120119

121120
mlir::GreedyRewriteConfig config;
@@ -126,14 +125,11 @@ class InlineElementalsPass
126125
patterns.insert<InlineElementalConversion>(context);
127126

128127
if (mlir::failed(mlir::applyPatternsAndFoldGreedily(
129-
func, std::move(patterns), config))) {
130-
mlir::emitError(func->getLoc(), "failure in HLFIR elemental inlining");
128+
getOperation(), std::move(patterns), config))) {
129+
mlir::emitError(getOperation()->getLoc(),
130+
"failure in HLFIR elemental inlining");
131131
signalPassFailure();
132132
}
133133
}
134134
};
135135
} // namespace
136-
137-
std::unique_ptr<mlir::Pass> hlfir::createInlineElementalsPass() {
138-
return std::make_unique<InlineElementalsPass>();
139-
}

flang/test/Driver/mlir-debug-pass-pipeline.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@
2525
! ALL: Pass statistics report
2626

2727
! ALL: Fortran::lower::VerifierPass
28+
! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
29+
! ALL-NEXT: 'fir.global' Pipeline
30+
! ALL-NEXT: InlineElementals
2831
! ALL-NEXT: 'func.func' Pipeline
2932
! ALL-NEXT: InlineElementals
33+
! ALL-NEXT: 'omp.declare_reduction' Pipeline
34+
! ALL-NEXT: InlineElementals
35+
! ALL-NEXT: 'omp.private' Pipeline
36+
! ALL-NEXT: InlineElementals
3037
! ALL-NEXT: LowerHLFIROrderedAssignments
3138
! ALL-NEXT: LowerHLFIRIntrinsics
3239
! ALL-NEXT: BufferizeHLFIR

flang/test/Driver/mlir-pass-pipeline.f90

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@
1313

1414
! ALL: Fortran::lower::VerifierPass
1515
! O2-NEXT: Canonicalizer
16-
! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
17-
! O2-NEXT: 'fir.global' Pipeline
16+
! ALL: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
17+
! ALL-NEXT:'fir.global' Pipeline
1818
! O2-NEXT: SimplifyHLFIRIntrinsics
19-
! ALL: 'func.func' Pipeline
19+
! ALL: InlineElementals
20+
! ALL-NEXT:'func.func' Pipeline
2021
! O2-NEXT: SimplifyHLFIRIntrinsics
2122
! ALL: InlineElementals
22-
! O2-NEXT: 'omp.declare_reduction' Pipeline
23+
! ALL-NEXT:'omp.declare_reduction' Pipeline
2324
! O2-NEXT: SimplifyHLFIRIntrinsics
24-
! O2-NEXT: 'omp.private' Pipeline
25+
! ALL: InlineElementals
26+
! ALL-NEXT:'omp.private' Pipeline
2527
! O2-NEXT: SimplifyHLFIRIntrinsics
28+
! ALL: InlineElementals
29+
! O2-NEXT: Canonicalizer
30+
! O2-NEXT: CSE
31+
! O2-NEXT: (S) {{.*}} num-cse'd
32+
! O2-NEXT: (S) {{.*}} num-dce'd
33+
! O2-NEXT: 'func.func' Pipeline
34+
! O2-NEXT: OptimizedBufferization
2635
! ALL: LowerHLFIROrderedAssignments
2736
! ALL-NEXT: LowerHLFIRIntrinsics
2837
! ALL-NEXT: BufferizeHLFIR

flang/test/Fir/basic-program.fir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ func.func @_QQmain() {
2020
// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
2121
// PASSES-NEXT: 'fir.global' Pipeline
2222
// PASSES-NEXT: SimplifyHLFIRIntrinsics
23+
// PASSES-NEXT: InlineElementals
2324
// PASSES-NEXT: 'func.func' Pipeline
2425
// PASSES-NEXT: SimplifyHLFIRIntrinsics
2526
// PASSES-NEXT: InlineElementals
2627
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
2728
// PASSES-NEXT: SimplifyHLFIRIntrinsics
29+
// PASSES-NEXT: InlineElementals
2830
// PASSES-NEXT: 'omp.private' Pipeline
2931
// PASSES-NEXT: SimplifyHLFIRIntrinsics
32+
// PASSES-NEXT: InlineElementals
3033
// PASSES-NEXT: Canonicalizer
3134
// PASSES-NEXT: CSE
3235
// PASSES-NEXT: (S) 0 num-cse'd - Number of operations CSE'd

0 commit comments

Comments
 (0)