[llvm] [ARM] Recognize abi tag module flags (PR #161306)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 9 22:19:26 PDT 2025
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/161306
>From b13083e888b4941d8d077dae13e12d06238ea723 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Mon, 29 Sep 2025 12:32:42 +0800
Subject: [PATCH 1/2] [ARM] Recognize some module flags
---
llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 28 +++++++++++++++----
.../CodeGen/ARM/build-attributes-module.ll | 14 ++++++++++
2 files changed, 36 insertions(+), 6 deletions(-)
create mode 100644 llvm/test/CodeGen/ARM/build-attributes-module.ll
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 1f773e2a7e0fc..125c002682012 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -701,9 +701,21 @@ void ARMAsmPrinter::emitAttributes() {
ARMBuildAttrs::AddressDirect);
}
+ Metadata *MDEx = nullptr;
+ Metadata *MDDM = nullptr;
+ Metadata *MDNM = nullptr;
+ if (const Module *M = MMI->getModule()) {
+ 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(),
@@ -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 {
@@ -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
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}
>From 4f04d8917ecebfc17a674dd0a69e10acc8899253 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Tue, 7 Oct 2025 13:31:51 +0800
Subject: [PATCH 2/2] address comments
---
llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 41 +++++++++----------
.../CodeGen/ARM/build-attributes-fn-attr4.ll | 2 +-
2 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 125c002682012..6b59fe5ed5794 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -701,21 +701,14 @@ void ARMAsmPrinter::emitAttributes() {
ARMBuildAttrs::AddressDirect);
}
- Metadata *MDEx = nullptr;
- Metadata *MDDM = nullptr;
- Metadata *MDNM = nullptr;
- if (const Module *M = MMI->getModule()) {
- 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 (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()))
+ if (auto *DM = mdconst::extract_or_null<ConstantInt>(
+ 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(),
@@ -755,11 +748,13 @@ void ARMAsmPrinter::emitAttributes() {
}
// Set FP exceptions and rounding
- 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)
+ if (auto *Ex = mdconst::extract_or_null<ConstantInt>(
+ MMI->getModule()->getModuleFlag("arm-eabi-fp-exceptions"))) {
+ if (unsigned TagVal = Ex->getZExtValue())
+ ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, TagVal);
+ } else if (checkFunctionsAttributeConsistency(*MMI->getModule(),
+ "no-trapping-math", "true") ||
+ TM.Options.NoTrappingFPMath)
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
ARMBuildAttrs::Not_Allowed);
else {
@@ -773,9 +768,11 @@ void ARMAsmPrinter::emitAttributes() {
// TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
// equivalent of GCC's -ffinite-math-only flag.
- 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)
+ if (auto *NumModel = mdconst::extract_or_null<ConstantInt>(
+ 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-fn-attr4.ll b/llvm/test/CodeGen/ARM/build-attributes-fn-attr4.ll
index 9c8dd8d95c61c..8f185d50b1b04 100644
--- a/llvm/test/CodeGen/ARM/build-attributes-fn-attr4.ll
+++ b/llvm/test/CodeGen/ARM/build-attributes-fn-attr4.ll
@@ -6,7 +6,7 @@
; RUN: llc < %s -mtriple=armv7-linux-gnueabi -mcpu=cortex-a15 | FileCheck %s
-; CHECK: .eabi_attribute 20, 0
+; CHECK-NOT: .eabi_attribute 20
define i32 @foo1() local_unnamed_addr #0 {
entry:
More information about the llvm-commits
mailing list