From a7d067718c5006f4b20b177b9951ed8846e17425 Mon Sep 17 00:00:00 2001 From: Tom Eccles Date: Tue, 28 May 2024 15:19:15 +0000 Subject: [PATCH] [flang][Transforms][NFC] reduce boilerplate in func attr pass Use tablegen to automatically create the pass constructor. The purpose of this pass is to add attributes to functions, so it doesn't need to work on other top level operations. --- .../flang/Optimizer/Transforms/Passes.h | 12 +---------- .../flang/Optimizer/Transforms/Passes.td | 1 - flang/include/flang/Tools/CLOptions.inc | 14 ++++++------- .../lib/Optimizer/Transforms/FunctionAttr.cpp | 20 ------------------- 4 files changed, 7 insertions(+), 40 deletions(-) diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h index 4e978e6c9cdec..9fa819e2bf502 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.h +++ b/flang/include/flang/Optimizer/Transforms/Passes.h @@ -55,6 +55,7 @@ namespace fir { #define GEN_PASS_DECL_OMPMARKDECLARETARGETPASS #define GEN_PASS_DECL_OMPFUNCTIONFILTERING #define GEN_PASS_DECL_VSCALEATTR +#define GEN_PASS_DECL_FUNCTIONATTR #include "flang/Optimizer/Transforms/Passes.h.inc" std::unique_ptr createAffineDemotionPass(); @@ -75,17 +76,6 @@ std::unique_ptr createVScaleAttrPass(); std::unique_ptr createVScaleAttrPass(std::pair vscaleAttr); -struct FunctionAttrTypes { - mlir::LLVM::framePointerKind::FramePointerKind framePointerKind = - mlir::LLVM::framePointerKind::FramePointerKind::None; -}; - -std::unique_ptr createFunctionAttrPass(); -std::unique_ptr -createFunctionAttrPass(FunctionAttrTypes &functionAttr, bool noInfsFPMath, - bool noNaNsFPMath, bool approxFuncFPMath, - bool noSignedZerosFPMath, bool unsafeFPMath); - void populateCfgConversionRewrites(mlir::RewritePatternSet &patterns, bool forceLoopToExecuteOnce = false, bool setNSW = false); diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index 4e281e2846c56..7a3baca4c19da 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -394,7 +394,6 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, ]; - let constructor = "::fir::createFunctionAttrPass()"; } def AssumedRankOpConversion : Pass<"fir-assumed-rank-op", "mlir::ModuleOp"> { diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc index 528c51d8c1c44..2a0cfc04aa350 100644 --- a/flang/include/flang/Tools/CLOptions.inc +++ b/flang/include/flang/Tools/CLOptions.inc @@ -372,24 +372,22 @@ inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm, pm.addPass(fir::createVScaleAttr({{config.VScaleMin, config.VScaleMax}})); // Add function attributes - fir::FunctionAttrTypes functionAttrs; + mlir::LLVM::framePointerKind::FramePointerKind framePointerKind; if (config.FramePointerKind != llvm::FramePointerKind::None || config.NoInfsFPMath || config.NoNaNsFPMath || config.ApproxFuncFPMath || config.NoSignedZerosFPMath || config.UnsafeFPMath) { if (config.FramePointerKind == llvm::FramePointerKind::NonLeaf) - functionAttrs.framePointerKind = + framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::NonLeaf; else if (config.FramePointerKind == llvm::FramePointerKind::All) - functionAttrs.framePointerKind = - mlir::LLVM::framePointerKind::FramePointerKind::All; + framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::All; else - functionAttrs.framePointerKind = - mlir::LLVM::framePointerKind::FramePointerKind::None; + framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::None; - pm.addPass(fir::createFunctionAttrPass(functionAttrs, config.NoInfsFPMath, + pm.addPass(fir::createFunctionAttr({framePointerKind, config.NoInfsFPMath, config.NoNaNsFPMath, config.ApproxFuncFPMath, - config.NoSignedZerosFPMath, config.UnsafeFPMath)); + config.NoSignedZerosFPMath, config.UnsafeFPMath})); } fir::addFIRToLLVMPass(pm, config); diff --git a/flang/lib/Optimizer/Transforms/FunctionAttr.cpp b/flang/lib/Optimizer/Transforms/FunctionAttr.cpp index f54080f21b967..69c41595974ef 100644 --- a/flang/lib/Optimizer/Transforms/FunctionAttr.cpp +++ b/flang/lib/Optimizer/Transforms/FunctionAttr.cpp @@ -15,7 +15,6 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" namespace fir { -#define GEN_PASS_DECL_FUNCTIONATTR #define GEN_PASS_DEF_FUNCTIONATTR #include "flang/Optimizer/Transforms/Passes.h.inc" } // namespace fir @@ -76,22 +75,3 @@ void FunctionAttrPass::runOnOperation() { LLVM_DEBUG(llvm::dbgs() << "=== End " DEBUG_TYPE " ===\n"); } - -std::unique_ptr fir::createFunctionAttrPass( - fir::FunctionAttrTypes &functionAttr, bool noInfsFPMath, bool noNaNsFPMath, - bool approxFuncFPMath, bool noSignedZerosFPMath, bool unsafeFPMath) { - FunctionAttrOptions opts; - // Frame pointer - opts.framePointerKind = functionAttr.framePointerKind; - opts.noInfsFPMath = noInfsFPMath; - opts.noNaNsFPMath = noNaNsFPMath; - opts.approxFuncFPMath = approxFuncFPMath; - opts.noSignedZerosFPMath = noSignedZerosFPMath; - opts.unsafeFPMath = unsafeFPMath; - - return std::make_unique(opts); -} - -std::unique_ptr fir::createFunctionAttrPass() { - return std::make_unique(); -}