Skip to content

Commit a6129a5

Browse files
authored
[flang][Transforms][NFC] reduce boilerplate in func attr pass (#94739)
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.
1 parent 81469a2 commit a6129a5

File tree

4 files changed

+7
-40
lines changed

4 files changed

+7
-40
lines changed

flang/include/flang/Optimizer/Transforms/Passes.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace fir {
5555
#define GEN_PASS_DECL_OMPMARKDECLARETARGETPASS
5656
#define GEN_PASS_DECL_OMPFUNCTIONFILTERING
5757
#define GEN_PASS_DECL_VSCALEATTR
58+
#define GEN_PASS_DECL_FUNCTIONATTR
5859
#include "flang/Optimizer/Transforms/Passes.h.inc"
5960

6061
std::unique_ptr<mlir::Pass> createAffineDemotionPass();
@@ -75,17 +76,6 @@ std::unique_ptr<mlir::Pass> createVScaleAttrPass();
7576
std::unique_ptr<mlir::Pass>
7677
createVScaleAttrPass(std::pair<unsigned, unsigned> vscaleAttr);
7778

78-
struct FunctionAttrTypes {
79-
mlir::LLVM::framePointerKind::FramePointerKind framePointerKind =
80-
mlir::LLVM::framePointerKind::FramePointerKind::None;
81-
};
82-
83-
std::unique_ptr<mlir::Pass> createFunctionAttrPass();
84-
std::unique_ptr<mlir::Pass>
85-
createFunctionAttrPass(FunctionAttrTypes &functionAttr, bool noInfsFPMath,
86-
bool noNaNsFPMath, bool approxFuncFPMath,
87-
bool noSignedZerosFPMath, bool unsafeFPMath);
88-
8979
void populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
9080
bool forceLoopToExecuteOnce = false,
9181
bool setNSW = false);

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> {
394394
"bool", /*default=*/"false",
395395
"Set the unsafe-fp-math attribute on functions in the module.">,
396396
];
397-
let constructor = "::fir::createFunctionAttrPass()";
398397
}
399398

400399
def AssumedRankOpConversion : Pass<"fir-assumed-rank-op", "mlir::ModuleOp"> {

flang/include/flang/Tools/CLOptions.inc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,24 +372,22 @@ inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
372372
pm.addPass(fir::createVScaleAttr({{config.VScaleMin, config.VScaleMax}}));
373373

374374
// Add function attributes
375-
fir::FunctionAttrTypes functionAttrs;
375+
mlir::LLVM::framePointerKind::FramePointerKind framePointerKind;
376376

377377
if (config.FramePointerKind != llvm::FramePointerKind::None ||
378378
config.NoInfsFPMath || config.NoNaNsFPMath || config.ApproxFuncFPMath ||
379379
config.NoSignedZerosFPMath || config.UnsafeFPMath) {
380380
if (config.FramePointerKind == llvm::FramePointerKind::NonLeaf)
381-
functionAttrs.framePointerKind =
381+
framePointerKind =
382382
mlir::LLVM::framePointerKind::FramePointerKind::NonLeaf;
383383
else if (config.FramePointerKind == llvm::FramePointerKind::All)
384-
functionAttrs.framePointerKind =
385-
mlir::LLVM::framePointerKind::FramePointerKind::All;
384+
framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::All;
386385
else
387-
functionAttrs.framePointerKind =
388-
mlir::LLVM::framePointerKind::FramePointerKind::None;
386+
framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::None;
389387

390-
pm.addPass(fir::createFunctionAttrPass(functionAttrs, config.NoInfsFPMath,
388+
pm.addPass(fir::createFunctionAttr({framePointerKind, config.NoInfsFPMath,
391389
config.NoNaNsFPMath, config.ApproxFuncFPMath,
392-
config.NoSignedZerosFPMath, config.UnsafeFPMath));
390+
config.NoSignedZerosFPMath, config.UnsafeFPMath}));
393391
}
394392

395393
fir::addFIRToLLVMPass(pm, config);

flang/lib/Optimizer/Transforms/FunctionAttr.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1616

1717
namespace fir {
18-
#define GEN_PASS_DECL_FUNCTIONATTR
1918
#define GEN_PASS_DEF_FUNCTIONATTR
2019
#include "flang/Optimizer/Transforms/Passes.h.inc"
2120
} // namespace fir
@@ -76,22 +75,3 @@ void FunctionAttrPass::runOnOperation() {
7675

7776
LLVM_DEBUG(llvm::dbgs() << "=== End " DEBUG_TYPE " ===\n");
7877
}
79-
80-
std::unique_ptr<mlir::Pass> fir::createFunctionAttrPass(
81-
fir::FunctionAttrTypes &functionAttr, bool noInfsFPMath, bool noNaNsFPMath,
82-
bool approxFuncFPMath, bool noSignedZerosFPMath, bool unsafeFPMath) {
83-
FunctionAttrOptions opts;
84-
// Frame pointer
85-
opts.framePointerKind = functionAttr.framePointerKind;
86-
opts.noInfsFPMath = noInfsFPMath;
87-
opts.noNaNsFPMath = noNaNsFPMath;
88-
opts.approxFuncFPMath = approxFuncFPMath;
89-
opts.noSignedZerosFPMath = noSignedZerosFPMath;
90-
opts.unsafeFPMath = unsafeFPMath;
91-
92-
return std::make_unique<FunctionAttrPass>(opts);
93-
}
94-
95-
std::unique_ptr<mlir::Pass> fir::createFunctionAttrPass() {
96-
return std::make_unique<FunctionAttrPass>();
97-
}

0 commit comments

Comments
 (0)