ARMCallingConv.td 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. //===-- ARMCallingConv.td - Calling Conventions for ARM ----*- tablegen -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // This describes the calling conventions for ARM architecture.
  9. //===----------------------------------------------------------------------===//
  10. /// CCIfAlign - Match of the original alignment of the arg
  11. class CCIfAlign<string Align, CCAction A>:
  12. CCIf<!strconcat("ArgFlags.getNonZeroOrigAlign() == ", Align), A>;
  13. //===----------------------------------------------------------------------===//
  14. // ARM APCS Calling Convention
  15. //===----------------------------------------------------------------------===//
  16. let Entry = 1 in
  17. def CC_ARM_APCS : CallingConv<[
  18. // Handles byval parameters.
  19. CCIfByVal<CCPassByVal<4, 4>>,
  20. CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
  21. // Pass SwiftSelf in a callee saved register.
  22. CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
  23. // A SwiftError is passed in R8.
  24. CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
  25. // Handle all vector types as either f64 or v2f64.
  26. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  27. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  28. // f64 and v2f64 are passed in adjacent GPRs, possibly split onto the stack
  29. CCIfType<[f64, v2f64], CCCustom<"CC_ARM_APCS_Custom_f64">>,
  30. CCIfType<[f32], CCBitConvertToType<i32>>,
  31. CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
  32. CCIfType<[i32], CCAssignToStack<4, 4>>,
  33. CCIfType<[f64], CCAssignToStack<8, 4>>,
  34. CCIfType<[v2f64], CCAssignToStack<16, 4>>
  35. ]>;
  36. let Entry = 1 in
  37. def RetCC_ARM_APCS : CallingConv<[
  38. CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
  39. CCIfType<[f32], CCBitConvertToType<i32>>,
  40. // Pass SwiftSelf in a callee saved register.
  41. CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
  42. // A SwiftError is returned in R8.
  43. CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
  44. // Handle all vector types as either f64 or v2f64.
  45. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  46. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  47. CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_APCS_Custom_f64">>,
  48. CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
  49. CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
  50. ]>;
  51. //===----------------------------------------------------------------------===//
  52. // ARM APCS Calling Convention for FastCC (when VFP2 or later is available)
  53. //===----------------------------------------------------------------------===//
  54. let Entry = 1 in
  55. def FastCC_ARM_APCS : CallingConv<[
  56. // Handle all vector types as either f64 or v2f64.
  57. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  58. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  59. CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
  60. CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
  61. CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
  62. S9, S10, S11, S12, S13, S14, S15]>>,
  63. // CPRCs may be allocated to co-processor registers or the stack - they
  64. // may never be allocated to core registers.
  65. CCIfType<[f32], CCAssignToStackWithShadow<4, 4, [Q0, Q1, Q2, Q3]>>,
  66. CCIfType<[f64], CCAssignToStackWithShadow<8, 4, [Q0, Q1, Q2, Q3]>>,
  67. CCIfType<[v2f64], CCAssignToStackWithShadow<16, 4, [Q0, Q1, Q2, Q3]>>,
  68. CCDelegateTo<CC_ARM_APCS>
  69. ]>;
  70. let Entry = 1 in
  71. def RetFastCC_ARM_APCS : CallingConv<[
  72. // Handle all vector types as either f64 or v2f64.
  73. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  74. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  75. CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
  76. CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
  77. CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
  78. S9, S10, S11, S12, S13, S14, S15]>>,
  79. CCDelegateTo<RetCC_ARM_APCS>
  80. ]>;
  81. //===----------------------------------------------------------------------===//
  82. // ARM APCS Calling Convention for GHC
  83. //===----------------------------------------------------------------------===//
  84. let Entry = 1 in
  85. def CC_ARM_APCS_GHC : CallingConv<[
  86. // Handle all vector types as either f64 or v2f64.
  87. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  88. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  89. CCIfType<[v2f64], CCAssignToReg<[Q4, Q5]>>,
  90. CCIfType<[f64], CCAssignToReg<[D8, D9, D10, D11]>>,
  91. CCIfType<[f32], CCAssignToReg<[S16, S17, S18, S19, S20, S21, S22, S23]>>,
  92. // Promote i8/i16 arguments to i32.
  93. CCIfType<[i8, i16], CCPromoteToType<i32>>,
  94. // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, SpLim
  95. CCIfType<[i32], CCAssignToReg<[R4, R5, R6, R7, R8, R9, R10, R11]>>
  96. ]>;
  97. //===----------------------------------------------------------------------===//
  98. // ARM AAPCS (EABI) Calling Convention, common parts
  99. //===----------------------------------------------------------------------===//
  100. def CC_ARM_AAPCS_Common : CallingConv<[
  101. CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
  102. // i64/f64 is passed in even pairs of GPRs
  103. // i64 is 8-aligned i32 here, so we may need to eat R1 as a pad register
  104. // (and the same is true for f64 if VFP is not enabled)
  105. CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0, R1]>>>,
  106. CCIfType<[i32], CCIf<"ArgFlags.getNonZeroOrigAlign() != Align(8)",
  107. CCAssignToReg<[R0, R1, R2, R3]>>>,
  108. CCIfType<[i32], CCIfAlign<"8", CCAssignToStackWithShadow<4, 8, [R0, R1, R2, R3]>>>,
  109. CCIfType<[i32], CCAssignToStackWithShadow<4, 4, [R0, R1, R2, R3]>>,
  110. CCIfType<[f16, bf16, f32], CCAssignToStackWithShadow<4, 4, [Q0, Q1, Q2, Q3]>>,
  111. CCIfType<[f64], CCAssignToStackWithShadow<8, 8, [Q0, Q1, Q2, Q3]>>,
  112. CCIfType<[v2f64], CCIfAlign<"16",
  113. CCAssignToStackWithShadow<16, 16, [Q0, Q1, Q2, Q3]>>>,
  114. CCIfType<[v2f64], CCAssignToStackWithShadow<16, 8, [Q0, Q1, Q2, Q3]>>
  115. ]>;
  116. def RetCC_ARM_AAPCS_Common : CallingConv<[
  117. CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
  118. CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
  119. CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
  120. ]>;
  121. //===----------------------------------------------------------------------===//
  122. // ARM AAPCS (EABI) Calling Convention
  123. //===----------------------------------------------------------------------===//
  124. let Entry = 1 in
  125. def CC_ARM_AAPCS : CallingConv<[
  126. // Handles byval parameters.
  127. CCIfByVal<CCPassByVal<4, 4>>,
  128. // The 'nest' parameter, if any, is passed in R12.
  129. CCIfNest<CCAssignToReg<[R12]>>,
  130. // Handle all vector types as either f64 or v2f64.
  131. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  132. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  133. // Pass SwiftSelf in a callee saved register.
  134. CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
  135. // A SwiftError is passed in R8.
  136. CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
  137. CCIfType<[f64, v2f64], CCCustom<"CC_ARM_AAPCS_Custom_f64">>,
  138. CCIfType<[f32], CCBitConvertToType<i32>>,
  139. CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_Custom_f16">>,
  140. CCDelegateTo<CC_ARM_AAPCS_Common>
  141. ]>;
  142. let Entry = 1 in
  143. def RetCC_ARM_AAPCS : CallingConv<[
  144. // Handle all vector types as either f64 or v2f64.
  145. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  146. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  147. // Pass SwiftSelf in a callee saved register.
  148. CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
  149. // A SwiftError is returned in R8.
  150. CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
  151. CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_AAPCS_Custom_f64">>,
  152. CCIfType<[f32], CCBitConvertToType<i32>>,
  153. CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_Custom_f16">>,
  154. CCDelegateTo<RetCC_ARM_AAPCS_Common>
  155. ]>;
  156. //===----------------------------------------------------------------------===//
  157. // ARM AAPCS-VFP (EABI) Calling Convention
  158. // Also used for FastCC (when VFP2 or later is available)
  159. //===----------------------------------------------------------------------===//
  160. let Entry = 1 in
  161. def CC_ARM_AAPCS_VFP : CallingConv<[
  162. // Handles byval parameters.
  163. CCIfByVal<CCPassByVal<4, 4>>,
  164. // Handle all vector types as either f64 or v2f64.
  165. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  166. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  167. // Pass SwiftSelf in a callee saved register.
  168. CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
  169. // A SwiftError is passed in R8.
  170. CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
  171. // HFAs are passed in a contiguous block of registers, or on the stack
  172. CCIfConsecutiveRegs<CCCustom<"CC_ARM_AAPCS_Custom_Aggregate">>,
  173. CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
  174. CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
  175. CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
  176. S9, S10, S11, S12, S13, S14, S15]>>,
  177. CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_VFP_Custom_f16">>,
  178. CCDelegateTo<CC_ARM_AAPCS_Common>
  179. ]>;
  180. let Entry = 1 in
  181. def RetCC_ARM_AAPCS_VFP : CallingConv<[
  182. // Handle all vector types as either f64 or v2f64.
  183. CCIfType<[v1i64, v2i32, v4i16, v4f16, v4bf16, v8i8, v2f32], CCBitConvertToType<f64>>,
  184. CCIfType<[v2i64, v4i32, v8i16, v8f16, v8bf16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
  185. // Pass SwiftSelf in a callee saved register.
  186. CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>,
  187. // A SwiftError is returned in R8.
  188. CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>,
  189. CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
  190. CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
  191. CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
  192. S9, S10, S11, S12, S13, S14, S15]>>,
  193. CCIfType<[f16, bf16], CCCustom<"CC_ARM_AAPCS_VFP_Custom_f16">>,
  194. CCDelegateTo<RetCC_ARM_AAPCS_Common>
  195. ]>;
  196. // Windows Control Flow Guard checks take a single argument (the target function
  197. // address) and have no return value.
  198. let Entry = 1 in
  199. def CC_ARM_Win32_CFGuard_Check : CallingConv<[
  200. CCIfType<[i32], CCAssignToReg<[R0]>>
  201. ]>;
  202. //===----------------------------------------------------------------------===//
  203. // Callee-saved register lists.
  204. //===----------------------------------------------------------------------===//
  205. def CSR_NoRegs : CalleeSavedRegs<(add)>;
  206. def CSR_FPRegs : CalleeSavedRegs<(add (sequence "D%u", 0, 31))>;
  207. def CSR_AAPCS : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, R5, R4,
  208. (sequence "D%u", 15, 8))>;
  209. // The Windows Control Flow Guard Check function preserves the same registers as
  210. // AAPCS, and also preserves all floating point registers.
  211. def CSR_Win_AAPCS_CFGuard_Check : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7,
  212. R6, R5, R4, (sequence "D%u", 15, 0))>;
  213. // R8 is used to pass swifterror, remove it from CSR.
  214. def CSR_AAPCS_SwiftError : CalleeSavedRegs<(sub CSR_AAPCS, R8)>;
  215. // R10 is used to pass swiftself, remove it from CSR.
  216. def CSR_AAPCS_SwiftTail : CalleeSavedRegs<(sub CSR_AAPCS, R10)>;
  217. // The order of callee-saved registers needs to match the order we actually push
  218. // them in FrameLowering, because this order is what's used by
  219. // PrologEpilogInserter to allocate frame index slots. So when R7 is the frame
  220. // pointer, we use this ATPCS alternative.
  221. def CSR_ATPCS_SplitPush : CalleeSavedRegs<(add LR, R7, R6, R5, R4,
  222. R11, R10, R9, R8,
  223. (sequence "D%u", 15, 8))>;
  224. def CSR_Win_SplitFP : CalleeSavedRegs<(add R10, R9, R8, R7, R6, R5, R4,
  225. (sequence "D%u", 15, 8),
  226. LR, R11)>;
  227. // R8 is used to pass swifterror, remove it from CSR.
  228. def CSR_ATPCS_SplitPush_SwiftError : CalleeSavedRegs<(sub CSR_ATPCS_SplitPush,
  229. R8)>;
  230. // R10 is used to pass swifterror, remove it from CSR.
  231. def CSR_ATPCS_SplitPush_SwiftTail : CalleeSavedRegs<(sub CSR_ATPCS_SplitPush,
  232. R10)>;
  233. // When enforcing an AAPCS compliant frame chain, R11 is used as the frame
  234. // pointer even for Thumb targets, where split pushes are necessary.
  235. // This AAPCS alternative makes sure the frame index slots match the push
  236. // order in that case.
  237. def CSR_AAPCS_SplitPush : CalleeSavedRegs<(add LR, R11,
  238. R7, R6, R5, R4,
  239. R10, R9, R8,
  240. (sequence "D%u", 15, 8))>;
  241. // Constructors and destructors return 'this' in the ARM C++ ABI; since 'this'
  242. // and the pointer return value are both passed in R0 in these cases, this can
  243. // be partially modelled by treating R0 as a callee-saved register
  244. // Only the resulting RegMask is used; the SaveList is ignored
  245. def CSR_AAPCS_ThisReturn : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6,
  246. R5, R4, (sequence "D%u", 15, 8),
  247. R0)>;
  248. // iOS ABI deviates from ARM standard ABI. R9 is not a callee-saved register.
  249. // Also save R7-R4 first to match the stack frame fixed spill areas.
  250. def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>;
  251. // R8 is used to pass swifterror, remove it from CSR.
  252. def CSR_iOS_SwiftError : CalleeSavedRegs<(sub CSR_iOS, R8)>;
  253. // R10 is used to pass swiftself, remove it from CSR.
  254. def CSR_iOS_SwiftTail : CalleeSavedRegs<(sub CSR_iOS, R10)>;
  255. def CSR_iOS_ThisReturn : CalleeSavedRegs<(add LR, R7, R6, R5, R4,
  256. (sub CSR_AAPCS_ThisReturn, R9))>;
  257. def CSR_iOS_TLSCall
  258. : CalleeSavedRegs<(add LR, SP, (sub(sequence "R%u", 12, 1), R9, R12),
  259. (sequence "D%u", 31, 0))>;
  260. // C++ TLS access function saves all registers except SP. Try to match
  261. // the order of CSRs in CSR_iOS.
  262. def CSR_iOS_CXX_TLS : CalleeSavedRegs<(add CSR_iOS, (sequence "R%u", 12, 1),
  263. (sequence "D%u", 31, 0))>;
  264. // CSRs that are handled by prologue, epilogue.
  265. def CSR_iOS_CXX_TLS_PE : CalleeSavedRegs<(add LR, R12, R11, R7, R5, R4)>;
  266. // CSRs that are handled explicitly via copies.
  267. def CSR_iOS_CXX_TLS_ViaCopy : CalleeSavedRegs<(sub CSR_iOS_CXX_TLS,
  268. CSR_iOS_CXX_TLS_PE)>;
  269. // The "interrupt" attribute is used to generate code that is acceptable in
  270. // exception-handlers of various kinds. It makes us use a different return
  271. // instruction (handled elsewhere) and affects which registers we must return to
  272. // our "caller" in the same state as we receive them.
  273. // For most interrupts, all registers except SP and LR are shared with
  274. // user-space. We mark LR to be saved anyway, since this is what the ARM backend
  275. // generally does rather than tracking its liveness as a normal register.
  276. def CSR_GenericInt : CalleeSavedRegs<(add LR, (sequence "R%u", 12, 0))>;
  277. // The fast interrupt handlers have more private state and get their own copies
  278. // of R8-R12, in addition to SP and LR. As before, mark LR for saving too.
  279. // FIXME: we mark R11 as callee-saved since it's often the frame-pointer, and
  280. // current frame lowering expects to encounter it while processing callee-saved
  281. // registers.
  282. def CSR_FIQ : CalleeSavedRegs<(add LR, R11, (sequence "R%u", 7, 0))>;