Index: llvm/include/llvm/CodeGen/CommandFlags.inc =================================================================== --- llvm/include/llvm/CodeGen/CommandFlags.inc +++ llvm/include/llvm/CodeGen/CommandFlags.inc @@ -151,16 +151,17 @@ "attribute not to use exceptions"), cl::init(false)); -static cl::opt DenormalFPMath( +// FIXME: Doesn't have way to specify separate input and output modes. +static cl::opt DenormalFPMath( "denormal-fp-math", cl::desc("Select which denormal numbers the code is permitted to require"), - cl::init(FPDenormal::IEEE), - cl::values(clEnumValN(FPDenormal::IEEE, "ieee", + cl::init(DenormalMode::IEEE), + cl::values(clEnumValN(DenormalMode::IEEE, "ieee", "IEEE 754 denormal numbers"), - clEnumValN(FPDenormal::PreserveSign, "preserve-sign", + 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"))); static cl::opt EnableHonorSignDependentRoundingFPMath( @@ -301,7 +302,10 @@ Options.NoNaNsFPMath = EnableNoNaNsFPMath; Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath; Options.NoTrappingFPMath = EnableNoTrappingFPMath; - Options.FPDenormalMode = DenormalFPMath; + + // FIXME: Should have separate input and output flags + Options.setFPDenormalMode(DenormalMode(DenormalFPMath, DenormalFPMath)); + Options.HonorSignDependentRoundingFPMathOption = EnableHonorSignDependentRoundingFPMath; if (FloatABIForCalls != FloatABI::Default) @@ -437,6 +441,13 @@ HANDLE_BOOL_ATTR(EnableNoNaNsFPMath, "no-nans-fp-math"); HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMath, "no-signed-zeros-fp-math"); + if (DenormalFPMath.getNumOccurrences() > 0 && + !F.hasFnAttribute("denormal-fp-math")) { + // FIXME: Command line flag should expose separate input/output modes. + NewAttrs.addAttribute("denormal-fp-math", + DenormalMode(DenormalFPMath, DenormalFPMath).str()); + } + if (TrapFuncName.getNumOccurrences() > 0) for (auto &B : F) for (auto &I : B) Index: llvm/include/llvm/Target/TargetOptions.h =================================================================== --- llvm/include/llvm/Target/TargetOptions.h +++ llvm/include/llvm/Target/TargetOptions.h @@ -14,9 +14,11 @@ #ifndef LLVM_TARGET_TARGETOPTIONS_H #define LLVM_TARGET_TARGETOPTIONS_H +#include "llvm/ADT/FloatingPointMode.h" #include "llvm/MC/MCTargetOptions.h" namespace llvm { + struct fltSemantics; class MachineFunction; class Module; @@ -54,15 +56,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 EABI { Unknown, Default, // Default means not specified @@ -120,7 +113,8 @@ EmitStackSizeSection(false), EnableMachineOutliner(false), SupportsDefaultOutlining(false), EmitAddrsig(false), EmitCallSiteInfo(false), SupportsDebugEntryValues(false), - EnableDebugEntryValues(false), ForceDwarfFrameSection(false) {} + EnableDebugEntryValues(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 @@ -311,9 +305,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/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)