[compiler-rt] 36f9947 - [builtins][ARM] Replace call_apsr.S with inline asm

Ryan Prichard via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 16:54:08 PDT 2020


Author: Ryan Prichard
Date: 2020-07-13T16:53:07-07:00
New Revision: 36f9947aac9e09e783a5d29be31ef5b00723d747

URL: https://github.com/llvm/llvm-project/commit/36f9947aac9e09e783a5d29be31ef5b00723d747
DIFF: https://github.com/llvm/llvm-project/commit/36f9947aac9e09e783a5d29be31ef5b00723d747.diff

LOG: [builtins][ARM] Replace call_apsr.S with inline asm

The %arm_call_apsr expansion doesn't work when config.clang is a clang
driver defaulting to a non-ARM arch. Rather than fix it, replace
call_apsr.S with inline asm in call_apsr.h, which also resolves the
FIXME added in D31259.

Maybe the `__attribute__((noinline,pcs("aapcs")))` attributes are
unnecessary on the static functions, but I was unsure what liberty the
compiler had to insert instructions that modified the condition codes,
so it seemed helpful.

Differential Revision: https://reviews.llvm.org/D82147

Added: 
    

Modified: 
    compiler-rt/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c
    compiler-rt/test/builtins/Unit/arm/aeabi_cdcmple_test.c
    compiler-rt/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c
    compiler-rt/test/builtins/Unit/arm/aeabi_cfcmple_test.c
    compiler-rt/test/builtins/Unit/arm/call_apsr.h
    compiler-rt/test/builtins/Unit/lit.cfg.py

Removed: 
    compiler-rt/test/builtins/Unit/arm/call_apsr.S


################################################################################
diff  --git a/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c b/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c
index 9778e5918404..fb19e0c60191 100644
--- a/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c
+++ b/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c
@@ -1,6 +1,5 @@
 // REQUIRES: arm-target-arch || armv6m-target-arch
-// RUN: %arm_call_apsr -o %t.aspr.o
-// RUN: %clang_builtins %s %t.aspr.o %librt -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
 
 #include <stdint.h>
 #include <stdio.h>

diff  --git a/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmple_test.c b/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmple_test.c
index 1feeac5ffd7e..7dbf2acb2872 100644
--- a/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmple_test.c
+++ b/compiler-rt/test/builtins/Unit/arm/aeabi_cdcmple_test.c
@@ -1,6 +1,5 @@
 // REQUIRES: arm-target-arch || armv6m-target-arch
-// RUN: %arm_call_apsr -o %t.aspr.o
-// RUN: %clang_builtins %s  %t.aspr.o %librt -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
 
 #include <stdint.h>
 #include <stdio.h>

diff  --git a/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c b/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c
index 8da56071364b..bfd67d1eee4d 100644
--- a/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c
+++ b/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c
@@ -1,6 +1,5 @@
 // REQUIRES: arm-target-arch || armv6m-target-arch
-// RUN: %arm_call_apsr -o %t.aspr.o
-// RUN: %clang_builtins %s  %t.aspr.o %librt -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
 
 #include <stdint.h>
 #include <stdio.h>

diff  --git a/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmple_test.c b/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmple_test.c
index a9358c4cf5f7..d80c45d22447 100644
--- a/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmple_test.c
+++ b/compiler-rt/test/builtins/Unit/arm/aeabi_cfcmple_test.c
@@ -1,6 +1,5 @@
 // REQUIRES: arm-target-arch || armv6m-target-arch
-// RUN: %arm_call_apsr -o %t.aspr.o
-// RUN: %clang_builtins %s  %t.aspr.o %librt -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
 
 #include <stdint.h>
 #include <stdio.h>

diff  --git a/compiler-rt/test/builtins/Unit/arm/call_apsr.S b/compiler-rt/test/builtins/Unit/arm/call_apsr.S
deleted file mode 100644
index 116f930c6e1e..000000000000
--- a/compiler-rt/test/builtins/Unit/arm/call_apsr.S
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "../../../../lib/builtins/assembly.h"
-
-.syntax unified
-// __attribute__((pcs("aapcs")))
-// int32_t call_apsr_d(double a, double b, void(*fn)(double, double)) {
-//   fn(a, b);
-//   return apsr;
-// }
-
-DEFINE_COMPILERRT_PRIVATE_FUNCTION(call_apsr_d)
-    push {r7, lr}
-    ldr r7, [sp, #8]
-    blx r7
-    mrs r0, apsr
-    pop {r7, pc}
-END_COMPILERRT_FUNCTION(call_apsr_d)
-
-// __attribute__((pcs("aapcs")))
-// int32_t call_apsr_f(float a, float b, void(*fn)(float, float)) {
-//   fn(a, b);
-//   return apsr;
-// }
-
-DEFINE_COMPILERRT_PRIVATE_FUNCTION(call_apsr_f)
-    push {lr}
-    blx r2
-    mrs r0, apsr
-    pop {pc}
-END_COMPILERRT_FUNCTION(call_apsr_f)

diff  --git a/compiler-rt/test/builtins/Unit/arm/call_apsr.h b/compiler-rt/test/builtins/Unit/arm/call_apsr.h
index fa81e892e3f0..87a7a74cb2a5 100644
--- a/compiler-rt/test/builtins/Unit/arm/call_apsr.h
+++ b/compiler-rt/test/builtins/Unit/arm/call_apsr.h
@@ -16,10 +16,22 @@ union cpsr {
     uint32_t value;
 };
 
-extern __attribute__((pcs("aapcs")))
-uint32_t call_apsr_f(float a, float b, __attribute__((pcs("aapcs"))) void (*fn)(float, float));
+__attribute__((noinline, pcs("aapcs"))) static uint32_t call_apsr_f(float a, float b,
+                                                                    __attribute__((pcs("aapcs"))) void (*fn)(float, float)) {
+  uint32_t result;
+  fn(a, b);
+  asm volatile("mrs %0, apsr"
+               : "=r"(result));
+  return result;
+}
 
-extern __attribute__((pcs("aapcs")))
-uint32_t call_apsr_d(double a, double b, __attribute__((pcs("aapcs"))) void (*fn)(double, double));
+__attribute__((noinline, pcs("aapcs"))) static uint32_t call_apsr_d(double a, double b,
+                                                                    __attribute__((pcs("aapcs"))) void (*fn)(double, double)) {
+  uint32_t result;
+  fn(a, b);
+  asm volatile("mrs %0, apsr"
+               : "=r"(result));
+  return result;
+}
 
 #endif // CALL_APSR_H

diff  --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py
index c8888078be50..fa6dc86783d3 100644
--- a/compiler-rt/test/builtins/Unit/lit.cfg.py
+++ b/compiler-rt/test/builtins/Unit/lit.cfg.py
@@ -87,10 +87,6 @@ def build_invocation(compile_flags):
   return " " + " ".join([clang_wrapper, config.clang] + compile_flags) + " "
 
 
-target_arch = config.target_arch
-if (target_arch == "arm"):
-  target_arch = "armv7"
-
 config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
 config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
 config.substitutions.append( ("%clang_builtins ", \
@@ -98,14 +94,6 @@ def build_invocation(compile_flags):
 config.substitutions.append( ("%clangxx_builtins ", \
                               build_invocation(clang_builtins_cxxflags)))
 
-# FIXME: move the call_apsr.s into call_apsr.h as inline-asm.
-# some ARM tests needs call_apsr.s
-call_apsr_source = os.path.join(builtins_lit_source_dir, 'arm', 'call_apsr.S')
-march_flag = '-march=' + target_arch
-call_apsr_flags = ['-c', march_flag, call_apsr_source]
-config.substitutions.append( ("%arm_call_apsr ", \
-                              build_invocation(call_apsr_flags)) )
-
 # Default test suffixes.
 config.suffixes = ['.c', '.cpp']
 


        


More information about the llvm-commits mailing list