Skip to content

Commit 311bc66

Browse files
[AArch64][compiler-rt] Only build SME ABI routines when compiler supports asm. (#68991)
This also adds the .variant_pcs directive to some functions from which it was previously missing.
1 parent 649c2f6 commit 311bc66

File tree

2 files changed

+25
-43
lines changed

2 files changed

+25
-43
lines changed

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,14 @@ set(aarch64_SOURCES
551551
${GENERIC_SOURCES}
552552
cpu_model.c
553553
aarch64/fp_mode.c
554-
aarch64/sme-abi.S
555-
aarch64/sme-abi-init.c
556554
)
557555

556+
if(COMPILER_RT_HAS_ASM_SME)
557+
list(APPEND aarch64_SOURCES aarch64/sme-abi.S aarch64/sme-abi-init.c)
558+
else()
559+
message(STATUS "AArch64 SME ABI routines disabled")
560+
endif()
561+
558562
# Generate outline atomics helpers from lse.S base
559563
set(OA_HELPERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/outline_atomic_helpers.dir")
560564
file(MAKE_DIRECTORY "${OA_HELPERS_DIR}")
@@ -782,7 +786,6 @@ else ()
782786
endif()
783787

784788
append_list_if(COMPILER_RT_HAS_ASM_LSE HAS_ASM_LSE BUILTIN_DEFS)
785-
append_list_if(COMPILER_RT_HAS_ASM_SME HAS_ASM_SME BUILTIN_DEFS)
786789

787790
foreach (arch ${BUILTIN_SUPPORTED_ARCH})
788791
if (CAN_TARGET_${arch})

compiler-rt/lib/builtins/aarch64/sme-abi.S

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,6 @@
88

99
#include "../assembly.h"
1010

11-
#ifdef HAS_ASM_SME
12-
#define ARCH armv9-a+sme
13-
#define SMSTOP_SM smstop sm
14-
#define SMSTOP_ZA smstop za
15-
#define REG_TPIDR2_EL0 TPIDR2_EL0
16-
#define REG_SVCR SVCR
17-
#define ADDSVL_X16_X16_1 addsvl x16, x16, #1
18-
#define LDR_ZA_W15_0_X16 ldr za[w15,0], [x16]
19-
#define STR_ZA_W15_0_X16 str za[w15,0], [x16]
20-
#define CNTD_X0 cntd x0
21-
#define CFI_OFFSET_VG_MINUS_16 .cfi_offset vg, -16
22-
#else
23-
#define ARCH armv8-a
24-
#define SMSTOP_SM .inst 0xd503427f
25-
#define SMSTOP_ZA .inst 0xd503447f
26-
#define REG_TPIDR2_EL0 S3_3_C13_C0_5
27-
#define REG_SVCR S3_3_C4_C2_2
28-
#define ADDSVL_X16_X16_1 .inst 0x04305830
29-
#define LDR_ZA_W15_0_X16 .inst 0xe1006200
30-
#define STR_ZA_W15_0_X16 .inst 0xe1206200
31-
#define CNTD_X0 .inst 0x04e0e3e0
32-
#define CFI_OFFSET_VG_MINUS_16 .cfi_escape 0x10, 0x2e, 0x03, 0x11, 0x70, 0x22 // $vg @ cfa - 16
33-
#endif
3411

3512
#if !defined(__APPLE__)
3613
#define TPIDR2_SYMBOL SYMBOL_NAME(__aarch64_has_sme_and_tpidr2_el0)
@@ -42,27 +19,27 @@
4219
#define TPIDR2_SYMBOL_OFFSET SYMBOL_NAME(__aarch64_has_sme_and_tpidr2_el0)@pageoff
4320
#endif
4421

45-
.arch ARCH
22+
.arch armv9-a+sme
4623

4724
// Utility function which calls a system's abort() routine. Because the function
4825
// is streaming-compatible it should disable streaming-SVE mode before calling
4926
// abort(). Note that there is no need to preserve any state before the call,
5027
// because the function does not return.
5128
DEFINE_COMPILERRT_PRIVATE_FUNCTION(do_abort)
5229
.cfi_startproc
53-
.variant_pcs SYMBOL_NAME(do_abort)
30+
.variant_pcs SYMBOL_NAME(do_abort)
5431
stp x29, x30, [sp, #-32]!
55-
CNTD_X0
32+
cntd x0
5633
// Store VG to a stack location that we describe with .cfi_offset
5734
str x0, [sp, #16]
5835
.cfi_def_cfa_offset 32
5936
.cfi_offset w30, -24
6037
.cfi_offset w29, -32
61-
CFI_OFFSET_VG_MINUS_16
38+
.cfi_offset vg, -16
6239
bl __arm_sme_state
6340
tbz x0, #0, 2f
6441
1:
65-
SMSTOP_SM
42+
smstop sm
6643
2:
6744
// We can't make this into a tail-call because the unwinder would
6845
// need to restore the value of VG.
@@ -74,7 +51,7 @@ END_COMPILERRT_FUNCTION(do_abort)
7451
// that is set as part of the compiler-rt startup code.
7552
// __aarch64_has_sme_and_tpidr2_el0
7653
DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sme_state)
77-
.variant_pcs __arm_sme_state
54+
.variant_pcs __arm_sme_state
7855
mov x0, xzr
7956
mov x1, xzr
8057

@@ -83,18 +60,18 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sme_state)
8360
cbz w16, 1f
8461
0:
8562
orr x0, x0, #0xC000000000000000
86-
mrs x16, REG_SVCR
63+
mrs x16, SVCR
8764
bfxil x0, x16, #0, #2
88-
mrs x1, REG_TPIDR2_EL0
65+
mrs x1, TPIDR2_EL0
8966
1:
9067
ret
9168
END_COMPILERRT_OUTLINE_FUNCTION(__arm_sme_state)
9269

9370
DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
94-
.variant_pcs __arm_tpidr2_restore
71+
.variant_pcs __arm_tpidr2_restore
9572
// If TPIDR2_EL0 is nonnull, the subroutine aborts in some platform-specific
9673
// manner.
97-
mrs x14, REG_TPIDR2_EL0
74+
mrs x14, TPIDR2_EL0
9875
cbnz x14, 2f
9976

10077
// If any of the reserved bytes in the first 16 bytes of BLK are nonzero,
@@ -114,8 +91,8 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
11491

11592
mov x15, xzr
11693
0:
117-
LDR_ZA_W15_0_X16
118-
ADDSVL_X16_X16_1
94+
ldr za[w15,0], [x16]
95+
addsvl x16, x16, #1
11996
add x15, x15, #1
12097
cmp x14, x15
12198
b.ne 0b
@@ -126,14 +103,15 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
126103
END_COMPILERRT_OUTLINE_FUNCTION(__arm_tpidr2_restore)
127104

128105
DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
106+
.variant_pcs __arm_tpidr2_restore
129107
// If the current thread does not have access to TPIDR2_EL0, the subroutine
130108
// does nothing.
131109
adrp x14, TPIDR2_SYMBOL
132110
ldrb w14, [x14, TPIDR2_SYMBOL_OFFSET]
133111
cbz w14, 1f
134112

135113
// If TPIDR2_EL0 is null, the subroutine does nothing.
136-
mrs x16, REG_TPIDR2_EL0
114+
mrs x16, TPIDR2_EL0
137115
cbz x16, 1f
138116

139117
// If any of the reserved bytes in the first 16 bytes of the TPIDR2 block are
@@ -153,8 +131,8 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
153131

154132
mov x15, xzr
155133
0:
156-
STR_ZA_W15_0_X16
157-
ADDSVL_X16_X16_1
134+
str za[w15,0], [x16]
135+
addsvl x16, x16, #1
158136
add x15, x15, #1
159137
cmp x14, x15
160138
b.ne 0b
@@ -165,6 +143,7 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
165143
END_COMPILERRT_OUTLINE_FUNCTION(__arm_tpidr2_save)
166144

167145
DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_za_disable)
146+
.variant_pcs __arm_tpidr2_restore
168147
// If the current thread does not have access to SME, the subroutine does
169148
// nothing.
170149
adrp x14, TPIDR2_SYMBOL
@@ -182,10 +161,10 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_za_disable)
182161
bl __arm_tpidr2_save
183162

184163
// * Set TPIDR2_EL0 to null.
185-
msr REG_TPIDR2_EL0, xzr
164+
msr TPIDR2_EL0, xzr
186165

187166
// * Set PSTATE.ZA to 0.
188-
SMSTOP_ZA
167+
smstop za
189168

190169
.cfi_def_cfa wsp, 16
191170
ldp x29, x30, [sp], #16

0 commit comments

Comments
 (0)