-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][HLFIR] Adapt SimplifyHLFIRIntrinsics to run on all top level ops #92573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This means that this pass will also run on hlfir intrinsics 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).
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-flang-fir-hlfir Author: Tom Eccles (tblah) ChangesThis means that this pass will also run on hlfir intrinsics which are not inside of functions. See RFC: Some of the changes are from moving the declaration and definition of the constructor into tablegen (as requested during code review of another pass). Full diff: https://github.com/llvm/llvm-project/pull/92573.diff 6 Files Affected:
diff --git a/flang/include/flang/Optimizer/HLFIR/Passes.h b/flang/include/flang/Optimizer/HLFIR/Passes.h
index 3314e0b887f6e..ef47c94b67a89 100644
--- a/flang/include/flang/Optimizer/HLFIR/Passes.h
+++ b/flang/include/flang/Optimizer/HLFIR/Passes.h
@@ -25,7 +25,6 @@ namespace hlfir {
std::unique_ptr<mlir::Pass> createConvertHLFIRtoFIRPass();
std::unique_ptr<mlir::Pass> createBufferizeHLFIRPass();
std::unique_ptr<mlir::Pass> createLowerHLFIRIntrinsicsPass();
-std::unique_ptr<mlir::Pass> createSimplifyHLFIRIntrinsicsPass();
std::unique_ptr<mlir::Pass> createInlineElementalsPass();
std::unique_ptr<mlir::Pass> createLowerHLFIROrderedAssignmentsPass();
std::unique_ptr<mlir::Pass> createOptimizedBufferizationPass();
diff --git a/flang/include/flang/Optimizer/HLFIR/Passes.td b/flang/include/flang/Optimizer/HLFIR/Passes.td
index dae96b3f767ea..806d1f202975b 100644
--- a/flang/include/flang/Optimizer/HLFIR/Passes.td
+++ b/flang/include/flang/Optimizer/HLFIR/Passes.td
@@ -46,9 +46,8 @@ def LowerHLFIROrderedAssignments : Pass<"lower-hlfir-ordered-assignments", "::ml
];
}
-def SimplifyHLFIRIntrinsics : Pass<"simplify-hlfir-intrinsics", "::mlir::func::FuncOp"> {
+def SimplifyHLFIRIntrinsics : Pass<"simplify-hlfir-intrinsics"> {
let summary = "Simplify HLFIR intrinsic operations that don't need to result in runtime calls";
- let constructor = "hlfir::createSimplifyHLFIRIntrinsicsPass()";
}
def InlineElementals : Pass<"inline-elementals", "::mlir::func::FuncOp"> {
diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index 61e591f2086df..e0ab9d5f0429c 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -317,7 +317,8 @@ inline void createHLFIRToFIRPassPipeline(
mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel) {
if (optLevel.isOptimizingForSpeed()) {
addCanonicalizerPassWithoutRegionSimplification(pm);
- pm.addPass(hlfir::createSimplifyHLFIRIntrinsicsPass());
+ addNestedPassToAllTopLevelOperations(
+ pm, hlfir::createSimplifyHLFIRIntrinsics);
}
pm.addPass(hlfir::createInlineElementalsPass());
if (optLevel.isOptimizingForSpeed()) {
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
index b761563eba0f8..6153c82fa7347 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
@@ -94,7 +94,6 @@ class SimplifyHLFIRIntrinsics
: public hlfir::impl::SimplifyHLFIRIntrinsicsBase<SimplifyHLFIRIntrinsics> {
public:
void runOnOperation() override {
- mlir::func::FuncOp func = this->getOperation();
mlir::MLIRContext *context = &getContext();
mlir::RewritePatternSet patterns(context);
patterns.insert<TransposeAsElementalConversion>(context);
@@ -108,16 +107,12 @@ class SimplifyHLFIRIntrinsics
});
target.markUnknownOpDynamicallyLegal(
[](mlir::Operation *) { return true; });
- if (mlir::failed(
- mlir::applyFullConversion(func, target, std::move(patterns)))) {
- mlir::emitError(func->getLoc(),
+ if (mlir::failed(mlir::applyFullConversion(getOperation(), target,
+ std::move(patterns)))) {
+ mlir::emitError(getOperation()->getLoc(),
"failure in HLFIR intrinsic simplification");
signalPassFailure();
}
}
};
} // namespace
-
-std::unique_ptr<mlir::Pass> hlfir::createSimplifyHLFIRIntrinsicsPass() {
- return std::make_unique<SimplifyHLFIRIntrinsics>();
-}
diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90
index 4ebac7c3fb65c..7130024e43b9b 100644
--- a/flang/test/Driver/mlir-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-pass-pipeline.f90
@@ -13,9 +13,16 @@
! ALL: Fortran::lower::VerifierPass
! O2-NEXT: Canonicalizer
-! O2-NEXT: 'func.func' Pipeline
+! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! O2-NEXT: 'fir.global' Pipeline
+! O2-NEXT: SimplifyHLFIRIntrinsics
+! ALL: 'func.func' Pipeline
! O2-NEXT: SimplifyHLFIRIntrinsics
! ALL: InlineElementals
+! O2-NEXT: 'omp.declare_reduction' Pipeline
+! O2-NEXT: SimplifyHLFIRIntrinsics
+! O2-NEXT: 'omp.private' Pipeline
+! O2-NEXT: SimplifyHLFIRIntrinsics
! ALL: LowerHLFIROrderedAssignments
! ALL-NEXT: LowerHLFIRIntrinsics
! ALL-NEXT: BufferizeHLFIR
diff --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir
index 02fb84ed8c873..9e3d3c18337d9 100644
--- a/flang/test/Fir/basic-program.fir
+++ b/flang/test/Fir/basic-program.fir
@@ -17,9 +17,16 @@ func.func @_QQmain() {
// PASSES: Pass statistics report
// PASSES: Canonicalizer
+// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+// PASSES-NEXT: 'fir.global' Pipeline
+// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: InlineElementals
+// PASSES-NEXT: 'omp.declare_reduction' Pipeline
+// PASSES-NEXT: SimplifyHLFIRIntrinsics
+// PASSES-NEXT: 'omp.private' Pipeline
+// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: Canonicalizer
// PASSES-NEXT: CSE
// PASSES-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for all the changes on passes!
This means that this pass will also run on hlfir intrinsics 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).