[flang-commits] [flang] [ARM][flang] Generate arm abi related module flag (PR #161308)

via flang-commits flang-commits at lists.llvm.org
Mon Sep 29 21:48:04 PDT 2025


https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/161308

>From 33cd876cbec55b549a987e75c5eb979aec23320c Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Tue, 30 Sep 2025 11:09:23 +0800
Subject: [PATCH] [ARM][flang] Generate arm abi related module flag
 UnsafeFPMath related options in LLVM CodeGen part will be removed in future,
 generate related module flags as hints.

---
 flang/lib/Frontend/FrontendActions.cpp    | 10 ++++++++++
 flang/test/Lower/Arm/build-attributes.f90 |  9 +++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 flang/test/Lower/Arm/build-attributes.f90

diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index d5e0325911adf..8b12e901b34cf 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -58,6 +58,7 @@
 #include "llvm/Passes/StandardInstrumentations.h"
 #include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/AMDGPUAddrSpace.h"
+#include "llvm/Support/ARMBuildAttributes.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -837,6 +838,15 @@ void CodeGenAction::generateLLVMIR() {
                                 opts.CodeObjectVersion);
     }
   }
+
+  if ((triple.isARM() || triple.isThumb()) && triple.isTargetAEABI() &&
+      triple.isOSBinFormatELF()) {
+    llvmModule->addModuleFlag(llvm::Module::Warning, "arm-eabi-fp-number-model",
+                              mathOpts.getNoHonorInfs() &&
+                                      mathOpts.getNoHonorNaNs()
+                                  ? llvm::ARMBuildAttrs::AllowIEEENormal
+                                  : llvm::ARMBuildAttrs::AllowIEEE754);
+  }
 }
 
 static std::unique_ptr<llvm::raw_pwrite_stream>
diff --git a/flang/test/Lower/Arm/build-attributes.f90 b/flang/test/Lower/Arm/build-attributes.f90
new file mode 100644
index 0000000000000..57ed37ea9f050
--- /dev/null
+++ b/flang/test/Lower/Arm/build-attributes.f90
@@ -0,0 +1,9 @@
+! REQUIRES: arm-registered-target
+! RUN: %flang_fc1 -triple arm-none-eabi -emit-llvm -o - %s | FileCheck %s --check-prefix=IEEE
+! RUN: %flang_fc1 -triple arm-none-eabi -menable-no-infs -menable-no-nans -emit-llvm -o - %s | FileCheck %s --check-prefix=NORMAL
+
+subroutine func
+end subroutine func
+
+! IEEE: !{i32 2, !"arm-eabi-fp-number-model", i32 3}
+! NORMAL: !{i32 2, !"arm-eabi-fp-number-model", i32 1}



More information about the flang-commits mailing list