-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][CodeGen][NFC] Reduce TargetRewrite pass boilerplate #94450
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
Tablegen can automatically generate the pass constructor. Tablegen will create a constructor for all of the pass options (not only the subset in the old constructor), but the pass options seem unused anyway. This pass does not require any modification to support alternative top-level ops. It walks all operations in the module. Functions have special handling (adding attributes, converting signatures) but this wouldn't make sense for top level operations in general.
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-flang-codegen Author: Tom Eccles (tblah) ChangesTablegen can automatically generate the pass constructor. Tablegen will create a constructor for all of the pass options (not only the subset in the old constructor), but the pass options seem unused anyway. This pass does not require any modification to support alternative top-level ops. It walks all operations in the module. Functions have special handling (adding attributes, converting signatures) but this wouldn't make sense for top level operations in general. Full diff: https://github.com/llvm/llvm-project/pull/94450.diff 4 Files Affected:
diff --git a/flang/include/flang/Optimizer/CodeGen/CGPasses.td b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
index df042187b2a71..9a4d327b33bad 100644
--- a/flang/include/flang/Optimizer/CodeGen/CGPasses.td
+++ b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
@@ -61,7 +61,6 @@ def TargetRewritePass : Pass<"target-rewrite", "mlir::ModuleOp"> {
Certain abstractions in the FIR dialect need to be rewritten to reflect
representations that may differ based on the target machine.
}];
- let constructor = "::fir::createFirTargetRewritePass()";
let dependentDialects = [ "fir::FIROpsDialect", "mlir::func::FuncDialect",
"mlir::DLTIDialect" ];
let options = [
diff --git a/flang/include/flang/Optimizer/CodeGen/CodeGen.h b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
index 3063bf1c0e020..06961819bb19c 100644
--- a/flang/include/flang/Optimizer/CodeGen/CodeGen.h
+++ b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
@@ -28,18 +28,6 @@ struct NameUniquer;
#define GEN_PASS_DECL_BOXEDPROCEDUREPASS
#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
-/// FirTargetRewritePass options.
-struct TargetRewriteOptions {
- bool noCharacterConversion{};
- bool noComplexConversion{};
- bool noStructConversion{};
-};
-
-/// Prerequiste pass for code gen. Perform intermediate rewrites to tailor the
-/// FIR for the chosen target.
-std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createFirTargetRewritePass(
- const TargetRewriteOptions &options = TargetRewriteOptions());
-
/// FIR to LLVM translation pass options.
struct FIRToLLVMPassOptions {
// Do not fail when type descriptors are not found when translating
diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index fb3ec75d4078a..c5c35e9a6a33f 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -182,9 +182,8 @@ inline void addCodeGenRewritePass(mlir::PassManager &pm, bool preserveDeclare) {
}
inline void addTargetRewritePass(mlir::PassManager &pm) {
- addPassConditionally(pm, disableTargetRewrite, []() {
- return fir::createFirTargetRewritePass(fir::TargetRewriteOptions{});
- });
+ addPassConditionally(pm, disableTargetRewrite,
+ []() { return fir::createTargetRewritePass(); });
}
inline mlir::LLVM::DIEmissionKind getEmissionKind(
diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
index 616de78d00260..8199c5ef7fa26 100644
--- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
@@ -76,11 +76,7 @@ struct FixupTy {
/// idioms that are used for distinct target processor and ABI combinations.
class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
public:
- TargetRewrite(const fir::TargetRewriteOptions &options) {
- noCharacterConversion = options.noCharacterConversion;
- noComplexConversion = options.noComplexConversion;
- noStructConversion = options.noStructConversion;
- }
+ using TargetRewritePassBase<TargetRewrite>::TargetRewritePassBase;
void runOnOperation() override final {
auto &context = getContext();
@@ -1255,8 +1251,3 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
mlir::func::FuncOp stackRestoreFn = nullptr;
};
} // namespace
-
-std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
-fir::createFirTargetRewritePass(const fir::TargetRewriteOptions &options) {
- return std::make_unique<TargetRewrite>(options);
-}
|
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.
Looks like we lost the ability to pass the TargetRewriteOptions programatically.
I need this capability. Could you restore it?
We have not lost the ability to pass struct TargetRewritePassOptions {
std::string forcedTargetTriple;
std::string forcedTargetCPU;
std::string forcedTargetFeatures;
bool noCharacterConversion = false;
bool noComplexConversion = false;
bool noStructConversion = false;
};
std::unique_ptr<::mlir::Pass> createTargetRewritePass(const TargetRewritePassOptions &options); (Re-posting here for the benefit of anyone reading later) |
Tablegen can automatically generate the pass constructor. Tablegen will create a constructor for all of the pass options (not only the subset in the old constructor), but the pass options seem unused anyway.
This pass does not require any modification to support alternative top-level ops. It walks all operations in the module. Functions have special handling (adding attributes, converting signatures) but this wouldn't make sense for top level operations in general.