diff options
Diffstat (limited to 'flang/lib/Optimizer')
-rw-r--r-- | flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/flang/lib/Optimizer/Transforms/FunctionAttr.cpp b/flang/lib/Optimizer/Transforms/FunctionAttr.cpp index 55b908b..f54080f 100644 --- a/flang/lib/Optimizer/Transforms/FunctionAttr.cpp +++ b/flang/lib/Optimizer/Transforms/FunctionAttr.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "flang/Optimizer/Transforms/Passes.h" #include "mlir/Dialect/LLVMIR/LLVMAttrs.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" namespace fir { #define GEN_PASS_DECL_FUNCTIONATTR @@ -27,6 +28,11 @@ class FunctionAttrPass : public fir::impl::FunctionAttrBase<FunctionAttrPass> { public: FunctionAttrPass(const fir::FunctionAttrOptions &options) { framePointerKind = options.framePointerKind; + noInfsFPMath = options.noInfsFPMath; + noNaNsFPMath = options.noNaNsFPMath; + approxFuncFPMath = options.approxFuncFPMath; + noSignedZerosFPMath = options.noSignedZerosFPMath; + unsafeFPMath = options.unsafeFPMath; } FunctionAttrPass() {} void runOnOperation() override; @@ -45,14 +51,43 @@ void FunctionAttrPass::runOnOperation() { func->setAttr("frame_pointer", mlir::LLVM::FramePointerKindAttr::get( context, framePointerKind)); + auto llvmFuncOpName = + mlir::OperationName(mlir::LLVM::LLVMFuncOp::getOperationName(), context); + if (noInfsFPMath) + func->setAttr( + mlir::LLVM::LLVMFuncOp::getNoInfsFpMathAttrName(llvmFuncOpName), + mlir::BoolAttr::get(context, true)); + if (noNaNsFPMath) + func->setAttr( + mlir::LLVM::LLVMFuncOp::getNoNansFpMathAttrName(llvmFuncOpName), + mlir::BoolAttr::get(context, true)); + if (approxFuncFPMath) + func->setAttr( + mlir::LLVM::LLVMFuncOp::getApproxFuncFpMathAttrName(llvmFuncOpName), + mlir::BoolAttr::get(context, true)); + if (noSignedZerosFPMath) + func->setAttr( + mlir::LLVM::LLVMFuncOp::getNoSignedZerosFpMathAttrName(llvmFuncOpName), + mlir::BoolAttr::get(context, true)); + if (unsafeFPMath) + func->setAttr( + mlir::LLVM::LLVMFuncOp::getUnsafeFpMathAttrName(llvmFuncOpName), + mlir::BoolAttr::get(context, true)); + LLVM_DEBUG(llvm::dbgs() << "=== End " DEBUG_TYPE " ===\n"); } -std::unique_ptr<mlir::Pass> -fir::createFunctionAttrPass(fir::FunctionAttrTypes &functionAttr) { +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); } |