diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp index 1f773e2a7e0fc..c08fca7c66b5c 100644 --- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -702,8 +702,13 @@ void ARMAsmPrinter::emitAttributes() { } // Set FP Denormals. - if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math", - DenormalMode::getPreserveSign())) + if (auto *DM = mdconst::extract_or_null( + MMI->getModule()->getModuleFlag("arm-eabi-fp-denormal"))) { + if (unsigned TagVal = DM->getZExtValue()) + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, TagVal); + } else if (checkDenormalAttributeConsistency(*MMI->getModule(), + "denormal-fp-math", + DenormalMode::getPreserveSign())) ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, ARMBuildAttrs::PreserveFPSign); else if (checkDenormalAttributeConsistency(*MMI->getModule(), @@ -743,9 +748,13 @@ void ARMAsmPrinter::emitAttributes() { } // Set FP exceptions and rounding - if (checkFunctionsAttributeConsistency(*MMI->getModule(), - "no-trapping-math", "true") || - TM.Options.NoTrappingFPMath) + if (auto *Ex = mdconst::extract_or_null( + MMI->getModule()->getModuleFlag("arm-eabi-fp-exceptions"))) { + if (unsigned TagVal = Ex->getZExtValue()) + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, Ex->getZExtValue()); + } else if (checkFunctionsAttributeConsistency(*MMI->getModule(), + "no-trapping-math", "true") || + TM.Options.NoTrappingFPMath) ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Not_Allowed); else { @@ -759,7 +768,11 @@ void ARMAsmPrinter::emitAttributes() { // TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the // equivalent of GCC's -ffinite-math-only flag. - if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath) + if (auto *NumModel = mdconst::extract_or_null( + MMI->getModule()->getModuleFlag("arm-eabi-fp-number-model"))) { + if (unsigned TagVal = NumModel->getZExtValue()) + ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model, TagVal); + } else if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath) ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model, ARMBuildAttrs::Allowed); else diff --git a/llvm/test/CodeGen/ARM/build-attributes-module.ll b/llvm/test/CodeGen/ARM/build-attributes-module.ll new file mode 100644 index 0000000000000..d7ac8e7df376f --- /dev/null +++ b/llvm/test/CodeGen/ARM/build-attributes-module.ll @@ -0,0 +1,14 @@ +; RUN: llc %s -mtriple=arm-none-none-eabi -o - | FileCheck %s + +define void @f() { + ret void +} + +!llvm.module.flags = !{!0, !1, !2} + +; CHECK: .eabi_attribute 20, 0 +!0 = !{i32 2, !"arm-eabi-fp-denormal", i32 0} +; CHECK: .eabi_attribute 21, 1 +!1 = !{i32 2, !"arm-eabi-fp-exceptions", i32 1} +; CHECK: .eabi_attribute 23, 1 +!2 = !{i32 2, !"arm-eabi-fp-number-model", i32 1}