1 //===-- ARMCallingConv.td - Calling Conventions for ARM ----*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // This describes the calling conventions for ARM architecture.
9 //===----------------------------------------------------------------------===//
11 /// CCIfAlign - Match of the original alignment of the arg
12 class CCIfAlign<string Align, CCAction A>:
13 CCIf<!strconcat("ArgFlags.getNonZeroOrigAlign() == ", Align), A>;
15 //===----------------------------------------------------------------------===//
16 // ARM APCS Calling Convention
17 //===----------------------------------------------------------------------===//
19 def CC_ARM_APCS : CallingConv<[
21 // Handles byval parameters.
22 CCIfByVal<CCPassByVal<4, 4>>,
24 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
26 // Pass SwiftSelf in a callee saved register.
27 CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
29 // A SwiftError is passed in R8.
30 CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
32 // Handle all vector types as either f64 or v2f64.
33 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
34 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
36 // f64 and v2f64 are passed in adjacent GPRs, possibly split onto the stack
37 CCIfType<[f64, v2f64], CCCustom<"CC_ARM_APCS_Custom_f64">>,
39 CCIfType<[f32], CCBitConvertToType<i32>>,
40 CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
42 CCIfType<[i32], CCAssignToStack<4, 4>>,
43 CCIfType<[f64], CCAssignToStack<8, 4>>,
44 CCIfType<[v2f64], CCAssignToStack<16, 4>>
48 def RetCC_ARM_APCS : CallingConv<[
49 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
50 CCIfType<[f32], CCBitConvertToType<i32>>,
52 // Pass SwiftSelf in a callee saved register.
53 CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
55 // A SwiftError is returned in R8.
56 CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
58 // Handle all vector types as either f64 or v2f64.
59 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
60 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
62 CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_APCS_Custom_f64">>,
64 CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
65 CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
68 //===----------------------------------------------------------------------===//
69 // ARM APCS Calling Convention for FastCC (when VFP2 or later is available)
70 //===----------------------------------------------------------------------===//
72 def FastCC_ARM_APCS : CallingConv<[
73 // Handle all vector types as either f64 or v2f64.
74 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
75 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
77 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
78 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
79 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
80 S9, S10, S11, S12, S13, S14, S15]>>,
82 // CPRCs may be allocated to co-processor registers or the stack - they
83 // may never be allocated to core registers.
84 CCIfType<[f32], CCAssignToStackWithShadow<4, 4, [Q0, Q1, Q2, Q3]>>,
85 CCIfType<[f64], CCAssignToStackWithShadow<8, 4, [Q0, Q1, Q2, Q3]>>,
86 CCIfType<[v2f64], CCAssignToStackWithShadow<16, 4, [Q0, Q1, Q2, Q3]>>,
88 CCDelegateTo<CC_ARM_APCS>
92 def RetFastCC_ARM_APCS : CallingConv<[
93 // Handle all vector types as either f64 or v2f64.
94 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
95 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
97 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
98 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
99 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
100 S9, S10, S11, S12, S13, S14, S15]>>,
101 CCDelegateTo<RetCC_ARM_APCS>
104 //===----------------------------------------------------------------------===//
105 // ARM APCS Calling Convention for GHC
106 //===----------------------------------------------------------------------===//
109 def CC_ARM_APCS_GHC : CallingConv<[
110 // Handle all vector types as either f64 or v2f64.
111 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
112 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
114 CCIfType<[v2f64], CCAssignToReg<[Q4, Q5]>>,
115 CCIfType<[f64], CCAssignToReg<[D8, D9, D10, D11]>>,
116 CCIfType<[f32], CCAssignToReg<[S16, S17, S18, S19, S20, S21, S22, S23]>>,
118 // Promote i8/i16 arguments to i32.
119 CCIfType<[i8, i16], CCPromoteToType<i32>>,
121 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, SpLim
122 CCIfType<[i32], CCAssignToReg<[R4, R5, R6, R7, R8, R9, R10, R11]>>
125 //===----------------------------------------------------------------------===//
126 // ARM AAPCS (EABI) Calling Convention, common parts
127 //===----------------------------------------------------------------------===//
129 def CC_ARM_AAPCS_Common : CallingConv<[
131 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
133 // i64/f64 is passed in even pairs of GPRs
134 // i64 is 8-aligned i32 here, so we may need to eat R1 as a pad register
135 // (and the same is true for f64 if VFP is not enabled)
136 CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0, R1]>>>,
137 CCIfType<[i32], CCIf<"ArgFlags.getNonZeroOrigAlign() != Align(8)",
138 CCAssignToReg<[R0, R1, R2, R3]>>>,
140 CCIfType<[i32], CCIfAlign<"8", CCAssignToStackWithShadow<4, 8, [R0, R1, R2, R3]>>>,
141 CCIfType<[i32], CCAssignToStackWithShadow<4, 4, [R0, R1, R2, R3]>>,
142 CCIfType<[f16, bf16, f32], CCAssignToStackWithShadow<4, 4, [Q0, Q1, Q2, Q3]>>,
143 CCIfType<[f64], CCAssignToStackWithShadow<8, 8, [Q0, Q1, Q2, Q3]>>,
144 CCIfType<[v2f64], CCIfAlign<"16",
145 CCAssignToStackWithShadow<16, 16, [Q0, Q1, Q2, Q3]>>>,
146 CCIfType<[v2f64], CCAssignToStackWithShadow<16, 8, [Q0, Q1, Q2, Q3]>>
149 def RetCC_ARM_AAPCS_Common : CallingConv<[
150 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
151 CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
152 CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
155 //===----------------------------------------------------------------------===//
156 // ARM AAPCS (EABI) Calling Convention
157 //===----------------------------------------------------------------------===//
160 def CC_ARM_AAPCS : CallingConv<[
161 // Handles byval parameters.
162 CCIfByVal<CCPassByVal<4, 4>>,
164 // The 'nest' parameter, if any, is passed in R12.
165 CCIfNest<CCAssignToReg<[R12]>>,
167 // Handle all vector types as either f64 or v2f64.
168 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
169 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
171 // Pass SwiftSelf in a callee saved register.
172 CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
174 // A SwiftError is passed in R8.
175 CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
177 CCIfType<[f64, v2f64], CCCustom<"CC_ARM_AAPCS_Custom_f64">>,
178 CCIfType<[f32], CCBitConvertToType<i32>>,
179 CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_Custom_f16">>,
180 CCDelegateTo<CC_ARM_AAPCS_Common>
184 def RetCC_ARM_AAPCS : CallingConv<[
185 // Handle all vector types as either f64 or v2f64.
186 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
187 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
189 // Pass SwiftSelf in a callee saved register.
190 CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
192 // A SwiftError is returned in R8.
193 CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
195 CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_AAPCS_Custom_f64">>,
196 CCIfType<[f32], CCBitConvertToType<i32>>,
197 CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_Custom_f16">>,
199 CCDelegateTo<RetCC_ARM_AAPCS_Common>
202 //===----------------------------------------------------------------------===//
203 // ARM AAPCS-VFP (EABI) Calling Convention
204 // Also used for FastCC (when VFP2 or later is available)
205 //===----------------------------------------------------------------------===//
208 def CC_ARM_AAPCS_VFP : CallingConv<[
209 // Handles byval parameters.
210 CCIfByVal<CCPassByVal<4, 4>>,
212 // Handle all vector types as either f64 or v2f64.
213 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
214 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
216 // Pass SwiftSelf in a callee saved register.
217 CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
219 // A SwiftError is passed in R8.
220 CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
222 // HFAs are passed in a contiguous block of registers, or on the stack
223 CCIfConsecutiveRegs<CCCustom<"CC_ARM_AAPCS_Custom_Aggregate">>,
225 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
226 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
227 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
228 S9, S10, S11, S12, S13, S14, S15]>>,
229 CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_VFP_Custom_f16">>,
230 CCDelegateTo<CC_ARM_AAPCS_Common>
234 def RetCC_ARM_AAPCS_VFP : CallingConv<[
235 // Handle all vector types as either f64 or v2f64.
236 CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
237 CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
239 // Pass SwiftSelf in a callee saved register.
240 CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
242 // A SwiftError is returned in R8.
243 CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
245 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
246 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
247 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
248 S9, S10, S11, S12, S13, S14, S15]>>,
249 CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_VFP_Custom_f16">>,
250 CCDelegateTo<RetCC_ARM_AAPCS_Common>
254 // Windows Control Flow Guard checks take a single argument (the target function
255 // address) and have no return value.
257 def CC_ARM_Win32_CFGuard_Check : CallingConv<[
258 CCIfType<[i32], CCAssignToReg<[R0]>>
263 //===----------------------------------------------------------------------===//
264 // Callee-saved register lists.
265 //===----------------------------------------------------------------------===//
267 def CSR_NoRegs : CalleeSavedRegs<(add)>;
268 def CSR_FPRegs : CalleeSavedRegs<(add (sequence "D%u", 0, 31))>;
270 def CSR_AAPCS : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, R5, R4,
271 (sequence "D%u", 15, 8))>;
273 // The Windows Control Flow Guard Check function preserves the same registers as
274 // AAPCS, and also preserves all floating point registers.
275 def CSR_Win_AAPCS_CFGuard_Check : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7,
276 R6, R5, R4, (sequence "D%u", 15, 0))>;
278 // R8 is used to pass swifterror, remove it from CSR.
279 def CSR_AAPCS_SwiftError : CalleeSavedRegs<(sub CSR_AAPCS, R8)>;
281 // R10 is used to pass swiftself, remove it from CSR.
282 def CSR_AAPCS_SwiftTail : CalleeSavedRegs<(sub CSR_AAPCS, R10)>;
284 // The order of callee-saved registers needs to match the order we actually push
285 // them in FrameLowering, because this order is what's used by
286 // PrologEpilogInserter to allocate frame index slots. So when R7 is the frame
287 // pointer, we use this ATPCS alternative.
288 def CSR_ATPCS_SplitPush : CalleeSavedRegs<(add LR, R7, R6, R5, R4,
290 (sequence "D%u", 15, 8))>;
292 def CSR_Win_SplitFP : CalleeSavedRegs<(add R10, R9, R8, R7, R6, R5, R4,
293 (sequence "D%u", 15, 8),
296 // R8 is used to pass swifterror, remove it from CSR.
297 def CSR_ATPCS_SplitPush_SwiftError : CalleeSavedRegs<(sub CSR_ATPCS_SplitPush,
300 // R10 is used to pass swifterror, remove it from CSR.
301 def CSR_ATPCS_SplitPush_SwiftTail : CalleeSavedRegs<(sub CSR_ATPCS_SplitPush,
304 // Sometimes we need to split the push of the callee-saved GPRs into two
305 // regions, to ensure that the frame chain record is set up correctly. These
306 // list the callee-saved registers in the order they end up on the stack, which
307 // depends on whether the frame pointer is r7 or r11.
308 def CSR_AAPCS_SplitPush_R11 : CalleeSavedRegs<(add R10, R9, R8, R7, R6, R5, R4,
310 (sequence "D%u", 15, 8))>;
311 def CSR_AAPCS_SplitPush_R7 : CalleeSavedRegs<(add LR, R11,
314 (sequence "D%u", 15, 8))>;
316 // Constructors and destructors return 'this' in the ARM C++ ABI; since 'this'
317 // and the pointer return value are both passed in R0 in these cases, this can
318 // be partially modelled by treating R0 as a callee-saved register
319 // Only the resulting RegMask is used; the SaveList is ignored
320 def CSR_AAPCS_ThisReturn : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6,
321 R5, R4, (sequence "D%u", 15, 8),
324 // iOS ABI deviates from ARM standard ABI. R9 is not a callee-saved register.
325 // Also save R7-R4 first to match the stack frame fixed spill areas.
326 def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>;
328 // R8 is used to pass swifterror, remove it from CSR.
329 def CSR_iOS_SwiftError : CalleeSavedRegs<(sub CSR_iOS, R8)>;
331 // R10 is used to pass swiftself, remove it from CSR.
332 def CSR_iOS_SwiftTail : CalleeSavedRegs<(sub CSR_iOS, R10)>;
334 def CSR_iOS_ThisReturn : CalleeSavedRegs<(add LR, R7, R6, R5, R4,
335 (sub CSR_AAPCS_ThisReturn, R9))>;
338 : CalleeSavedRegs<(add LR, SP, (sub(sequence "R%u", 12, 1), R9, R12),
339 (sequence "D%u", 31, 0))>;
341 // C++ TLS access function saves all registers except SP. Try to match
342 // the order of CSRs in CSR_iOS.
343 def CSR_iOS_CXX_TLS : CalleeSavedRegs<(add CSR_iOS, (sequence "R%u", 12, 1),
344 (sequence "D%u", 31, 0))>;
346 // CSRs that are handled by prologue, epilogue.
347 def CSR_iOS_CXX_TLS_PE : CalleeSavedRegs<(add LR, R12, R11, R7, R5, R4)>;
349 // CSRs that are handled explicitly via copies.
350 def CSR_iOS_CXX_TLS_ViaCopy : CalleeSavedRegs<(sub CSR_iOS_CXX_TLS,
351 CSR_iOS_CXX_TLS_PE)>;
353 // The "interrupt" attribute is used to generate code that is acceptable in
354 // exception-handlers of various kinds. It makes us use a different return
355 // instruction (handled elsewhere) and affects which registers we must return to
356 // our "caller" in the same state as we receive them.
358 // For most interrupts, all registers except SP and LR are shared with
359 // user-space. We mark LR to be saved anyway, since this is what the ARM backend
360 // generally does rather than tracking its liveness as a normal register.
361 def CSR_GenericInt : CalleeSavedRegs<(add LR, (sequence "R%u", 12, 0))>;
363 // The fast interrupt handlers have more private state and get their own copies
364 // of R8-R12, in addition to SP and LR. As before, mark LR for saving too.
366 // FIXME: we mark R11 as callee-saved since it's often the frame-pointer, and
367 // current frame lowering expects to encounter it while processing callee-saved
369 def CSR_FIQ : CalleeSavedRegs<(add LR, R11, (sequence "R%u", 7, 0))>;