diff options
author | Sjoerd Meijer <sjoerd.meijer@arm.com> | 2016-08-31 14:17:38 +0000 |
---|---|---|
committer | Sjoerd Meijer <sjoerd.meijer@arm.com> | 2016-08-31 14:17:38 +0000 |
commit | 46b5b8838759324c25affab9e6d0285898d9ae0a (patch) | |
tree | 4cdab85bdc7f6372ff9c99fb753d0bdbd27ef48f /llvm/lib | |
parent | 3042713b4b7a22e8a0c42266668e8eb5cefc4844 (diff) | |
download | bcm5719-llvm-46b5b8838759324c25affab9e6d0285898d9ae0a.tar.gz bcm5719-llvm-46b5b8838759324c25affab9e6d0285898d9ae0a.zip |
Clang patch r280064 introduced ways to set the FP exceptions and denormal
types. This is the LLVM counterpart and it adds options that map onto FP
exceptions and denormal build attributes allowing better fp math library
selections.
Differential Revision: https://reviews.llvm.org/D24070
llvm-svn: 280246
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 41 | ||||
-rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 10 |
2 files changed, 41 insertions, 10 deletions
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp index 53b2c3da9c2..9e3d1ee8602 100644 --- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -451,8 +451,16 @@ void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) { OutStreamer->EmitAssemblerFlag(MCAF_SyntaxUnified); // Emit ARM Build Attributes - if (TT.isOSBinFormatELF()) + if (TT.isOSBinFormatELF()) { + if (!M.empty()) { + // FIXME: this is a hack, but it is not more broken than + // resetTargetOptions already was. The purpose of reading the target + // options here is to read function attributes denormal and trapping-math + // that we want to map onto build attributes. + TM.resetTargetOptions(*M.begin()); + } emitAttributes(); + } // Use the triple's architecture and subarchitecture to determine // if we're thumb for the purposes of the top level code16 assembler @@ -750,17 +758,17 @@ void ARMAsmPrinter::emitAttributes() { ARMBuildAttrs::AddressDirect); } - // Signal various FP modes. - if (!TM.Options.UnsafeFPMath) { + // Set FP Denormals. + if (TM.Options.FPDenormalType == FPDenormal::PreserveSign) + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, + ARMBuildAttrs::PreserveFPSign); + else if (TM.Options.FPDenormalType == FPDenormal::PositiveZero) + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, + ARMBuildAttrs::PositiveZero); + else if (!TM.Options.UnsafeFPMath) ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, ARMBuildAttrs::IEEEDenormals); - ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed); - - // If the user has permitted this code to choose the IEEE 754 - // rounding at run-time, emit the rounding attribute. - if (TM.Options.HonorSignDependentRoundingFPMathOption) - ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding, ARMBuildAttrs::Allowed); - } else { + else { if (!STI.hasVFP2()) { // When the target doesn't have an FPU (by design or // intention), the assumptions made on the software support @@ -786,6 +794,19 @@ void ARMAsmPrinter::emitAttributes() { // absence of its emission implies zero). } + // Set FP exceptions and rounding + if (TM.Options.NoTrappingFPMath) + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, + ARMBuildAttrs::Not_Allowed); + else if (!TM.Options.UnsafeFPMath) { + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed); + + // If the user has permitted this code to choose the IEEE 754 + // rounding at run-time, emit the rounding attribute. + if (TM.Options.HonorSignDependentRoundingFPMathOption) + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding, ARMBuildAttrs::Allowed); + } + // TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the // equivalent of GCC's -ffinite-math-only flag. if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath) diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index 82c68505c4e..60505f49a6b 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -77,6 +77,16 @@ void TargetMachine::resetTargetOptions(const Function &F) const { RESET_OPTION(UnsafeFPMath, "unsafe-fp-math"); RESET_OPTION(NoInfsFPMath, "no-infs-fp-math"); RESET_OPTION(NoNaNsFPMath, "no-nans-fp-math"); + RESET_OPTION(NoTrappingFPMath, "no-trapping-math"); + + StringRef Denormal = + F.getFnAttribute("denormal-fp-math").getValueAsString(); + if (Denormal == "ieee") + Options.FPDenormalType = FPDenormal::IEEE; + else if (Denormal == "preserve-sign") + Options.FPDenormalType = FPDenormal::PreserveSign; + else if (Denormal == "positive-zero") + Options.FPDenormalType = FPDenormal::PositiveZero; } /// Returns the code generation relocation model. The choices are static, PIC, |