Skip to content

Commit 46deaf9

Browse files
committed
[ARM] Recognize some module flags
1 parent 84e4c06 commit 46deaf9

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

llvm/lib/Target/ARM/ARMAsmPrinter.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,21 @@ void ARMAsmPrinter::emitAttributes() {
701701
ARMBuildAttrs::AddressDirect);
702702
}
703703

704+
Metadata *MDEx = nullptr;
705+
Metadata *MDNM = nullptr;
706+
Metadata *MDDM = nullptr;
707+
if (const Module *M = MMI->getModule()) {
708+
MDEx = M->getModuleFlag("arm-eabi-fp-exceptions");
709+
MDNM = M->getModuleFlag("arm-eabi-fp-denormal");
710+
MDDM = M->getModuleFlag("arm-eabi-fp-number-model");
711+
}
712+
704713
// Set FP Denormals.
705-
if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math",
706-
DenormalMode::getPreserveSign()))
714+
if (auto *DM = mdconst::extract_or_null<ConstantInt>(MDDM))
715+
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, DM->getZExtValue());
716+
else if (checkDenormalAttributeConsistency(*MMI->getModule(),
717+
"denormal-fp-math",
718+
DenormalMode::getPreserveSign()))
707719
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
708720
ARMBuildAttrs::PreserveFPSign);
709721
else if (checkDenormalAttributeConsistency(*MMI->getModule(),
@@ -743,9 +755,11 @@ void ARMAsmPrinter::emitAttributes() {
743755
}
744756

745757
// Set FP exceptions and rounding
746-
if (checkFunctionsAttributeConsistency(*MMI->getModule(),
747-
"no-trapping-math", "true") ||
748-
TM.Options.NoTrappingFPMath)
758+
if (auto *Ex = mdconst::extract_or_null<ConstantInt>(MDEx))
759+
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, Ex->getZExtValue());
760+
else if (checkFunctionsAttributeConsistency(*MMI->getModule(),
761+
"no-trapping-math", "true") ||
762+
TM.Options.NoTrappingFPMath)
749763
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
750764
ARMBuildAttrs::Not_Allowed);
751765
else {
@@ -759,7 +773,9 @@ void ARMAsmPrinter::emitAttributes() {
759773

760774
// TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
761775
// equivalent of GCC's -ffinite-math-only flag.
762-
if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
776+
if (auto *NM = mdconst::extract_or_null<ConstantInt>(MDNM))
777+
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model, NM->getZExtValue());
778+
else if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
763779
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
764780
ARMBuildAttrs::Allowed);
765781
else
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc %s -mtriple=arm-none-none-eabi -o - | FileCheck %s
2+
3+
; CHECK: .eabi_attribute 20, 0
4+
!{i32 2, !"arm-eabi-fp-denormal", i32 0}
5+
6+
; CHECK: .eabi_attribute 21, 1
7+
!{i32 2, !"arm-eabi-fp-exceptions", i32 1}
8+
9+
; CHECK: .eabi_attribute 23, 1
10+
!{i32 2, !"arm-eabi-fp-number-model", i32 1}
11+
12+
define void @f() {
13+
ret void
14+
}

0 commit comments

Comments
 (0)