[PATCH] D35538: [CodeGen][ARM] ARM runtime helper functions are not always soft-fp

Peter Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 18 03:32:25 PDT 2017


peter.smith created this revision.
Herald added subscribers: kristof.beyls, aemerson.

The ARM Runtime ABI document (IHI0043) defines the AEABI floating point helper functions in section 4.1 Floating-point library. These functions always use the base PCS (soft-fp). However helper functions defined outside of this document such as the complex-number multiply and divide helpers are not covered by this requirement and should use hard-float PCS if the target is hard-float. All of the floating point helper functions that are explicitly soft float are expanded in the llvm ARM backend. This change makes clang not force the BuiltinCC to AAPCS for AAPCS_VFP.

With this change clang matches the behavior of gcc and the expected calling convention of the hard-float compiled compiler-rt and libgcc.a libraries as these functions do not have the __attribute__((__pcs__("aapcs"))).

fixes https://bugs.llvm.org/show_bug.cgi?id=28164
fixes test failures in compiler-rt for a hard-float target "divtc3_test.c, divdc3_test.c, divxc3_test.c"

I'm very new to clang so the way this has been fixed maybe a bit too simplistic. At present none of the builtins that produce calls in clang must use the base PCS. If clang ever needs to make a call to one of the AEABI defined functions that need base AAPCS then we'll need to identify the function when choosing a calling convention.

References:

- GCC list of functions that must be base AAPCS https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/arm/arm.c?view=co&content-type=text%2Fplain
- Runtime ABI for the ARM Architecture http://infocenter.arm.com/help/topic/com.arm.doc.ihi0043d/IHI0043D_rtabi.pdf


https://reviews.llvm.org/D35538

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/complex-math.c


Index: test/CodeGen/complex-math.c
===================================================================
--- test/CodeGen/complex-math.c
+++ test/CodeGen/complex-math.c
@@ -2,7 +2,8 @@
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple x86_64-pc-win64 -o - | FileCheck %s --check-prefix=X86
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple i686-unknown-unknown -o - | FileCheck %s --check-prefix=X86
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple powerpc-unknown-unknown -o - | FileCheck %s --check-prefix=PPC
-// RUN: %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARM
+// RUN %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM
+// RUN: %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s --check-prefix=ARM7K
 
 float _Complex add_float_rr(float a, float b) {
@@ -476,8 +477,15 @@
 
 // Check that the libcall will obtain proper calling convention on ARM
 _Complex double foo(_Complex double a, _Complex double b) {
+  // These functions are not defined as floating point helper functions in
+  // Run-time ABI for the ARM architecture document so they must not always
+  // use the base AAPCS
+
   // ARM-LABEL: @foo(
-  // ARM: call arm_aapcscc { double, double } @__muldc3
+  // ARM: call void { double, double } @__muldc3
+
+  // ARMHF-LABEL: @foo(
+  // ARMHF: call { double, double } @__muldc3
 
   // ARM7K-LABEL: @foo(
   // ARM7K: call { double, double } @__muldc3
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -5573,17 +5573,14 @@
   // AAPCS apparently requires runtime support functions to be soft-float, but
   // that's almost certainly for historic reasons (Thumb1 not supporting VFP
   // most likely). It's more convenient for AAPCS16_VFP to be hard-float.
-  switch (getABIKind()) {
-  case APCS:
-  case AAPCS16_VFP:
-    if (abiCC != getLLVMDefaultCC())
+
+  // The Run-time ABI for the ARM Architecture section 4.1.2 requires
+  // AEABI-complying FP helper functions to use the base AAPCS
+  // These AEABI functions are expanded in the ARM llvm backend, all the builtin
+  // support functions emitted by clang such as the _Complex helpers follow the
+  // abiCC.
+  if (abiCC != getLLVMDefaultCC())
       BuiltinCC = abiCC;
-    break;
-  case AAPCS:
-  case AAPCS_VFP:
-    BuiltinCC = llvm::CallingConv::ARM_AAPCS;
-    break;
-  }
 }
 
 ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35538.107041.patch
Type: text/x-patch
Size: 2701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170718/c732ef49/attachment.bin>


More information about the cfe-commits mailing list