Index: llvm/include/llvm/CodeGen/CommandFlags.h =================================================================== --- llvm/include/llvm/CodeGen/CommandFlags.h +++ llvm/include/llvm/CodeGen/CommandFlags.h @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/FloatingPointMode.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" @@ -62,7 +63,7 @@ bool getEnableNoTrappingFPMath(); -llvm::FPDenormal::DenormalMode getDenormalFPMath(); +DenormalMode::DenormalModeKind getDenormalFPMath(); bool getEnableHonorSignDependentRoundingFPMath(); Index: llvm/include/llvm/Target/TargetOptions.h =================================================================== --- llvm/include/llvm/Target/TargetOptions.h +++ llvm/include/llvm/Target/TargetOptions.h @@ -14,11 +14,13 @@ #ifndef LLVM_TARGET_TARGETOPTIONS_H #define LLVM_TARGET_TARGETOPTIONS_H +#include "llvm/ADT/FloatingPointMode.h" #include "llvm/MC/MCTargetOptions.h" #include namespace llvm { + struct fltSemantics; class MachineFunction; class MemoryBuffer; class Module; @@ -57,15 +59,6 @@ }; } - namespace FPDenormal { - enum DenormalMode { - IEEE, // IEEE 754 denormal numbers - PreserveSign, // the sign of a flushed-to-zero number is preserved in - // the sign of 0 - PositiveZero // denormals are flushed to positive zero - }; - } - enum class BasicBlockSection { All, // Use Basic Block Sections for all basic blocks. A section // for every basic block can significantly bloat object file sizes. @@ -135,7 +128,8 @@ EmitStackSizeSection(false), EnableMachineOutliner(false), SupportsDefaultOutlining(false), EmitAddrsig(false), EmitCallSiteInfo(false), EnableDebugEntryValues(false), - ForceDwarfFrameSection(false) {} + ForceDwarfFrameSection(false), + FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {} /// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// option is specified on the command line, and should enable debugging @@ -328,9 +322,32 @@ /// Which debugger to tune for. DebuggerKind DebuggerTuning = DebuggerKind::Default; - /// FPDenormalMode - This flags specificies which denormal numbers the code - /// is permitted to require. - FPDenormal::DenormalMode FPDenormalMode = FPDenormal::IEEE; + private: + /// Flushing mode to assume in default FP environment. + DenormalMode FPDenormalMode; + + /// Flushing mode to assume in default FP environment, for float/vector of + /// float. + DenormalMode FP32DenormalMode; + + public: + void setFPDenormalMode(DenormalMode Mode) { + FPDenormalMode = Mode; + } + + void setFP32DenormalMode(DenormalMode Mode) { + FP32DenormalMode = Mode; + } + + DenormalMode getRawFPDenormalMode() const { + return FPDenormalMode; + } + + DenormalMode getRawFP32DenormalMode() const { + return FP32DenormalMode; + } + + DenormalMode getDenormalMode(const fltSemantics &FPType) const; /// What exception model to use ExceptionHandling ExceptionModel = ExceptionHandling::None; Index: llvm/lib/CodeGen/CommandFlags.cpp =================================================================== --- llvm/lib/CodeGen/CommandFlags.cpp +++ llvm/lib/CodeGen/CommandFlags.cpp @@ -54,7 +54,7 @@ CGOPT(bool, EnableNoNaNsFPMath) CGOPT(bool, EnableNoSignedZerosFPMath) CGOPT(bool, EnableNoTrappingFPMath) -CGOPT(FPDenormal::DenormalMode, DenormalFPMath) +CGOPT(DenormalMode::DenormalModeKind, DenormalFPMath) CGOPT(bool, EnableHonorSignDependentRoundingFPMath) CGOPT(FloatABI::ABIType, FloatABIForCalls) CGOPT(FPOpFusion::FPOpFusionMode, FuseFPOps) @@ -212,17 +212,17 @@ cl::init(false)); CGBINDOPT(EnableNoTrappingFPMath); - static cl::opt DenormalFPMath( + static cl::opt DenormalFPMath( "denormal-fp-math", cl::desc( "Select which denormal numbers the code is permitted to require"), - cl::init(FPDenormal::IEEE), + cl::init(DenormalMode::IEEE), cl::values( - clEnumValN(FPDenormal::IEEE, "ieee", "IEEE 754 denormal numbers"), - clEnumValN(FPDenormal::PreserveSign, "preserve-sign", + clEnumValN(DenormalMode::IEEE, "ieee", "IEEE 754 denormal numbers"), + clEnumValN(DenormalMode::PreserveSign, "preserve-sign", "the sign of a flushed-to-zero number is preserved " "in the sign of 0"), - clEnumValN(FPDenormal::PositiveZero, "positive-zero", + clEnumValN(DenormalMode::PositiveZero, "positive-zero", "denormals are flushed to positive zero"))); CGBINDOPT(DenormalFPMath); @@ -425,7 +425,12 @@ Options.NoNaNsFPMath = getEnableNoNaNsFPMath(); Options.NoSignedZerosFPMath = getEnableNoSignedZerosFPMath(); Options.NoTrappingFPMath = getEnableNoTrappingFPMath(); - Options.FPDenormalMode = getDenormalFPMath(); + + DenormalMode::DenormalModeKind DenormKind = getDenormalFPMath(); + +// FIXME: Should have separate input and output flags + Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind)); + Options.HonorSignDependentRoundingFPMathOption = getEnableHonorSignDependentRoundingFPMath(); if (getFloatABIForCalls() != FloatABI::Default) @@ -563,6 +568,15 @@ HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math"); HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math"); + if (DenormalFPMathView->getNumOccurrences() > 0 && + !F.hasFnAttribute("denormal-fp-math")) { + DenormalMode::DenormalModeKind DenormKind = getDenormalFPMath(); + + // FIXME: Command line flag should expose separate input/output modes. + NewAttrs.addAttribute("denormal-fp-math", + DenormalMode(DenormKind, DenormKind).str()); + } + if (TrapFuncNameView->getNumOccurrences() > 0) for (auto &B : F) for (auto &I : B) Index: llvm/lib/Target/ARM/ARMAsmPrinter.cpp =================================================================== --- llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -654,14 +654,12 @@ // Set FP Denormals. if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math", - DenormalMode::getPreserveSign()) || - TM.Options.FPDenormalMode == FPDenormal::PreserveSign) + DenormalMode::getPreserveSign())) ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, ARMBuildAttrs::PreserveFPSign); else if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math", - DenormalMode::getPositiveZero()) || - TM.Options.FPDenormalMode == FPDenormal::PositiveZero) + DenormalMode::getPositiveZero())) ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, ARMBuildAttrs::PositiveZero); else if (!TM.Options.UnsafeFPMath)