Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions llvm/lib/Target/ARM/ARMAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,21 @@ void ARMAsmPrinter::emitAttributes() {
ARMBuildAttrs::AddressDirect);
}

Metadata *MDEx = nullptr;
Metadata *MDDM = nullptr;
Metadata *MDNM = nullptr;
if (const Module *M = MMI->getModule()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ever possible for MMI->getModule() to be nullptr when writing build attributes? In the existing code for checkDenormalConsistency it is universally dereferenced?

If it isn't possible then I think it would be worth moving the M->getModuleFlag() calls closer to where they are used. I find it difficult to tell MDDM and MDNM apart with my eyesight.

For example (using SourceModule instead of M, as SourceModule is used on line 801).

const Module *SourceModule = MMI->getModule();
// Set FP Denormals
Metadata *MDDM = SourceModule->getModuleFlag("arm-eabi-fp-denormal");
if (auto *DM = mdconst::extract_or_null<ConstantInt>(MDDM))
  ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, DM->getZExtValue());
else if (checkDenormalAttributeConsistency(*SourceModule,
                                             "denormal-fp-math",
                                             DenormalMode::getPreserveSign()))

If we do have to preserve the if (const Module *M = MMI->getModule()) can you expand the MDDM and MDNM a bit? perhaps MDDenorm and MDNumModel .

MDEx = M->getModuleFlag("arm-eabi-fp-exceptions");
MDDM = M->getModuleFlag("arm-eabi-fp-denormal");
MDNM = M->getModuleFlag("arm-eabi-fp-number-model");
}

// Set FP Denormals.
if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math",
DenormalMode::getPreserveSign()))
if (auto *DM = mdconst::extract_or_null<ConstantInt>(MDDM))
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal, DM->getZExtValue());
else if (checkDenormalAttributeConsistency(*MMI->getModule(),
"denormal-fp-math",
DenormalMode::getPreserveSign()))
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
ARMBuildAttrs::PreserveFPSign);
else if (checkDenormalAttributeConsistency(*MMI->getModule(),
Expand Down Expand Up @@ -743,9 +755,11 @@ 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<ConstantInt>(MDEx))
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 {
Expand All @@ -759,7 +773,9 @@ 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 *NM = mdconst::extract_or_null<ConstantInt>(MDNM))
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model, NM->getZExtValue());
else if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
ARMBuildAttrs::Allowed);
else
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/ARM/build-attributes-module.ll
Original file line number Diff line number Diff line change
@@ -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}