[llvm] r280534 - Setting fp trapping mode and denormal type: this an improvement of
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 2 12:51:34 PDT 2016
Author: sjoerdmeijer
Date: Fri Sep 2 14:51:34 2016
New Revision: 280534
URL: http://llvm.org/viewvc/llvm-project?rev=280534&view=rev
Log:
Setting fp trapping mode and denormal type: this an improvement of
r280246 and calculates compatibility of functions attributes in
a better way.
Differential Revision: https://reviews.llvm.org/D24070
Modified:
llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=280534&r1=280533&r2=280534&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Fri Sep 2 14:51:34 2016
@@ -451,16 +451,8 @@ void ARMAsmPrinter::EmitStartOfAsmFile(M
OutStreamer->EmitAssemblerFlag(MCAF_SyntaxUnified);
// Emit ARM Build Attributes
- 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());
- }
+ if (TT.isOSBinFormatELF())
emitAttributes();
- }
// Use the triple's architecture and subarchitecture to determine
// if we're thumb for the purposes of the top level code16 assembler
@@ -622,6 +614,17 @@ static ARMBuildAttrs::CPUArch getArchFor
return ARMBuildAttrs::v4;
}
+// Returns true if all functions have the same function attribute value
+static bool haveAllFunctionsAttribute(const Module &M, StringRef Attr,
+ StringRef Value) {
+ for (auto &F : M)
+ if (F.getFnAttribute(Attr).getValueAsString() != Value)
+ return false;
+
+ return true;
+}
+
+
void ARMAsmPrinter::emitAttributes() {
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
@@ -759,12 +762,16 @@ void ARMAsmPrinter::emitAttributes() {
}
// 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);
+ if (haveAllFunctionsAttribute(*MMI->getModule(), "denormal-fp-math",
+ "preserve-sign") ||
+ TM.Options.FPDenormalType == FPDenormal::PreserveSign)
+ ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
+ ARMBuildAttrs::PreserveFPSign);
+ else if (haveAllFunctionsAttribute(*MMI->getModule(), "denormal-fp-math",
+ "positive-zero") ||
+ 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);
@@ -795,7 +802,8 @@ void ARMAsmPrinter::emitAttributes() {
}
// Set FP exceptions and rounding
- if (TM.Options.NoTrappingFPMath)
+ if (haveAllFunctionsAttribute(*MMI->getModule(), "no-trapping-math", "true") ||
+ TM.Options.NoTrappingFPMath)
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
ARMBuildAttrs::Not_Allowed);
else if (!TM.Options.UnsafeFPMath) {
More information about the llvm-commits
mailing list