Skip to content

Commit

Permalink
[flang][Transforms][NFC] reduce boilerplate in func attr pass (#94739)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tblah authored Jun 10, 2024
1 parent 81469a2 commit a6129a5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 40 deletions.
12 changes: 1 addition & 11 deletions flang/include/flang/Optimizer/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<mlir::Pass> createAffineDemotionPass();
Expand All @@ -75,17 +76,6 @@ std::unique_ptr<mlir::Pass> createVScaleAttrPass();
std::unique_ptr<mlir::Pass>
createVScaleAttrPass(std::pair<unsigned, unsigned> vscaleAttr);

struct FunctionAttrTypes {
mlir::LLVM::framePointerKind::FramePointerKind framePointerKind =
mlir::LLVM::framePointerKind::FramePointerKind::None;
};

std::unique_ptr<mlir::Pass> createFunctionAttrPass();
std::unique_ptr<mlir::Pass>
createFunctionAttrPass(FunctionAttrTypes &functionAttr, bool noInfsFPMath,
bool noNaNsFPMath, bool approxFuncFPMath,
bool noSignedZerosFPMath, bool unsafeFPMath);

void populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
bool forceLoopToExecuteOnce = false,
bool setNSW = false);
Expand Down
1 change: 0 additions & 1 deletion flang/include/flang/Optimizer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -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"> {
Expand Down
14 changes: 6 additions & 8 deletions flang/include/flang/Tools/CLOptions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 0 additions & 20 deletions flang/lib/Optimizer/Transforms/FunctionAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,22 +75,3 @@ void FunctionAttrPass::runOnOperation() {

LLVM_DEBUG(llvm::dbgs() << "=== End " DEBUG_TYPE " ===\n");
}

std::unique_ptr<mlir::Pass> 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<FunctionAttrPass>(opts);
}

std::unique_ptr<mlir::Pass> fir::createFunctionAttrPass() {
return std::make_unique<FunctionAttrPass>();
}

0 comments on commit a6129a5

Please sign in to comment.