blob: 8ff666ed2844a73de60e91f6a8ebae665fb06de8 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- ARMCallingConv.td - Calling Conventions for ARM ----*- tablegen -*-===//
Bob Wilsondee46d72009-04-17 20:35:10 +00002//
Bob Wilson1f595bb2009-04-17 19:07:39 +00003// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bob Wilsondee46d72009-04-17 20:35:10 +00007//
Bob Wilson1f595bb2009-04-17 19:07:39 +00008//===----------------------------------------------------------------------===//
9// This describes the calling conventions for ARM architecture.
10//===----------------------------------------------------------------------===//
11
Bob Wilson1f595bb2009-04-17 19:07:39 +000012/// CCIfAlign - Match of the original alignment of the arg
13class CCIfAlign<string Align, CCAction A>:
14 CCIf<!strconcat("ArgFlags.getOrigAlign() == ", Align), A>;
15
16//===----------------------------------------------------------------------===//
17// ARM APCS Calling Convention
18//===----------------------------------------------------------------------===//
19def CC_ARM_APCS : CallingConv<[
20
Stuart Hastingsf222e592011-02-28 17:17:53 +000021 // Handles byval parameters.
Stuart Hastingsc7315872011-04-20 16:47:52 +000022 CCIfByVal<CCPassByVal<4, 4>>,
Stuart Hastingsf222e592011-02-28 17:17:53 +000023
Chad Rosier38f5c0d2011-11-05 00:02:56 +000024 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +000025
Bob Wilson5bafff32009-06-22 23:27:02 +000026 // Handle all vector types as either f64 or v2f64.
27 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
28 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
29
30 // f64 and v2f64 are passed in adjacent GPRs, possibly split onto the stack
31 CCIfType<[f64, v2f64], CCCustom<"CC_ARM_APCS_Custom_f64">>,
Bob Wilson1f595bb2009-04-17 19:07:39 +000032
33 CCIfType<[f32], CCBitConvertToType<i32>>,
Bob Wilson1c2c4622009-04-24 16:55:25 +000034 CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +000035
Bob Wilson1c2c4622009-04-24 16:55:25 +000036 CCIfType<[i32], CCAssignToStack<4, 4>>,
Bob Wilson5bafff32009-06-22 23:27:02 +000037 CCIfType<[f64], CCAssignToStack<8, 4>>,
38 CCIfType<[v2f64], CCAssignToStack<16, 4>>
Bob Wilson1f595bb2009-04-17 19:07:39 +000039]>;
40
41def RetCC_ARM_APCS : CallingConv<[
Chad Rosier0eff39f2011-11-08 00:03:32 +000042 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +000043 CCIfType<[f32], CCBitConvertToType<i32>>,
Bob Wilson5bafff32009-06-22 23:27:02 +000044
45 // Handle all vector types as either f64 or v2f64.
46 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
47 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
48
49 CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_APCS_Custom_f64">>,
Bob Wilson1f595bb2009-04-17 19:07:39 +000050
51 CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
52 CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
53]>;
54
55//===----------------------------------------------------------------------===//
Evan Cheng76f920d2010-10-22 18:23:05 +000056// ARM APCS Calling Convention for FastCC (when VFP2 or later is available)
57//===----------------------------------------------------------------------===//
58def FastCC_ARM_APCS : CallingConv<[
59 // Handle all vector types as either f64 or v2f64.
60 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
61 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
62
63 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
64 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
65 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
66 S9, S10, S11, S12, S13, S14, S15]>>,
67 CCDelegateTo<CC_ARM_APCS>
68]>;
69
70def RetFastCC_ARM_APCS : CallingConv<[
71 // Handle all vector types as either f64 or v2f64.
72 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
73 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
74
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
Eric Christophere94ac882012-08-03 00:05:53 +000082//===----------------------------------------------------------------------===//
83// ARM APCS Calling Convention for GHC
84//===----------------------------------------------------------------------===//
85
86def CC_ARM_APCS_GHC : CallingConv<[
87 // Handle all vector types as either f64 or v2f64.
88 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
89 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
90
91 CCIfType<[v2f64], CCAssignToReg<[Q4, Q5]>>,
92 CCIfType<[f64], CCAssignToReg<[D8, D9, D10, D11]>>,
93 CCIfType<[f32], CCAssignToReg<[S16, S17, S18, S19, S20, S21, S22, S23]>>,
94
95 // Promote i8/i16 arguments to i32.
96 CCIfType<[i8, i16], CCPromoteToType<i32>>,
97
98 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, SpLim
99 CCIfType<[i32], CCAssignToReg<[R4, R5, R6, R7, R8, R9, R10, R11]>>
100]>;
Evan Cheng76f920d2010-10-22 18:23:05 +0000101
102//===----------------------------------------------------------------------===//
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000103// ARM AAPCS (EABI) Calling Convention, common parts
Bob Wilson1f595bb2009-04-17 19:07:39 +0000104//===----------------------------------------------------------------------===//
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000105
106def CC_ARM_AAPCS_Common : CallingConv<[
Bob Wilson1f595bb2009-04-17 19:07:39 +0000107
Chad Rosier62c8e8e2011-11-07 21:43:40 +0000108 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000109
110 // i64/f64 is passed in even pairs of GPRs
111 // i64 is 8-aligned i32 here, so we may need to eat R1 as a pad register
Bob Wilson04746ea2009-05-19 10:02:36 +0000112 // (and the same is true for f64 if VFP is not enabled)
Bob Wilson1f595bb2009-04-17 19:07:39 +0000113 CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0, R1]>>>,
Stepan Dyatkovskiy78e3c902013-04-22 13:06:52 +0000114 CCIfType<[i32], CCIf<"ArgFlags.getOrigAlign() != 8",
Bob Wilson04746ea2009-05-19 10:02:36 +0000115 CCAssignToReg<[R0, R1, R2, R3]>>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000116
Rafael Espindola55e95872010-08-06 15:35:32 +0000117 CCIfType<[i32], CCIfAlign<"8", CCAssignToStackWithShadow<4, 8, R3>>>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000118 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
Bob Wilson5bafff32009-06-22 23:27:02 +0000119 CCIfType<[f64], CCAssignToStack<8, 8>>,
120 CCIfType<[v2f64], CCAssignToStack<16, 8>>
Bob Wilson1f595bb2009-04-17 19:07:39 +0000121]>;
122
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000123def RetCC_ARM_AAPCS_Common : CallingConv<[
Chad Rosier0eff39f2011-11-08 00:03:32 +0000124 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
Anton Korobeynikov2e7ccfc2009-06-08 22:59:50 +0000125 CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000126 CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
127]>;
128
129//===----------------------------------------------------------------------===//
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000130// ARM AAPCS (EABI) Calling Convention
131//===----------------------------------------------------------------------===//
132
133def CC_ARM_AAPCS : CallingConv<[
Manman Rend9b45122012-08-10 20:39:38 +0000134 // Handles byval parameters.
135 CCIfByVal<CCPassByVal<4, 4>>,
136
Bob Wilson5bafff32009-06-22 23:27:02 +0000137 // Handle all vector types as either f64 or v2f64.
138 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
139 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
140
141 CCIfType<[f64, v2f64], CCCustom<"CC_ARM_AAPCS_Custom_f64">>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000142 CCIfType<[f32], CCBitConvertToType<i32>>,
143 CCDelegateTo<CC_ARM_AAPCS_Common>
144]>;
145
146def RetCC_ARM_AAPCS : CallingConv<[
Bob Wilson5bafff32009-06-22 23:27:02 +0000147 // Handle all vector types as either f64 or v2f64.
148 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
149 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
150
151 CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_AAPCS_Custom_f64">>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000152 CCIfType<[f32], CCBitConvertToType<i32>>,
153 CCDelegateTo<RetCC_ARM_AAPCS_Common>
154]>;
155
156//===----------------------------------------------------------------------===//
157// ARM AAPCS-VFP (EABI) Calling Convention
Evan Cheng76f920d2010-10-22 18:23:05 +0000158// Also used for FastCC (when VFP2 or later is available)
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000159//===----------------------------------------------------------------------===//
160
161def CC_ARM_AAPCS_VFP : CallingConv<[
Manman Rena41db532012-08-13 21:22:50 +0000162 // Handles byval parameters.
163 CCIfByVal<CCPassByVal<4, 4>>,
164
Bob Wilson5bafff32009-06-22 23:27:02 +0000165 // Handle all vector types as either f64 or v2f64.
166 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
167 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
168
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000169 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000170 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
171 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
172 S9, S10, S11, S12, S13, S14, S15]>>,
173 CCDelegateTo<CC_ARM_AAPCS_Common>
174]>;
175
176def RetCC_ARM_AAPCS_VFP : CallingConv<[
Bob Wilson5bafff32009-06-22 23:27:02 +0000177 // Handle all vector types as either f64 or v2f64.
178 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
179 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
180
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000181 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000182 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
183 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
184 S9, S10, S11, S12, S13, S14, S15]>>,
185 CCDelegateTo<RetCC_ARM_AAPCS_Common>
186]>;
Jakob Stoklund Olesen3ee7d152012-01-17 23:09:00 +0000187
188//===----------------------------------------------------------------------===//
189// Callee-saved register lists.
190//===----------------------------------------------------------------------===//
191
Chad Rosiere7bd5192012-11-06 23:05:24 +0000192def CSR_NoRegs : CalleeSavedRegs<(add)>;
193
Jakob Stoklund Olesen3ee7d152012-01-17 23:09:00 +0000194def CSR_AAPCS : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, R5, R4,
195 (sequence "D%u", 15, 8))>;
196
Stephen Lin456ca042013-04-20 05:14:40 +0000197// Constructors and destructors return 'this' in the ARM C++ ABI; since 'this'
198// and the pointer return value are both passed in R0 in these cases, this can
199// be partially modelled by treating R0 as a callee-saved register
200// Only the resulting RegMask is used; the SaveList is ignored
201def CSR_AAPCS_ThisReturn : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6,
202 R5, R4, (sequence "D%u", 15, 8),
203 R0)>;
204
Jakob Stoklund Olesen3ee7d152012-01-17 23:09:00 +0000205// iOS ABI deviates from ARM standard ABI. R9 is not a callee-saved register.
206// Also save R7-R4 first to match the stack frame fixed spill areas.
207def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>;
Eric Christophere94ac882012-08-03 00:05:53 +0000208
Stephen Lin456ca042013-04-20 05:14:40 +0000209def CSR_iOS_ThisReturn : CalleeSavedRegs<(add LR, R7, R6, R5, R4,
210 (sub CSR_AAPCS_ThisReturn, R9))>;
211
Eric Christophere94ac882012-08-03 00:05:53 +0000212// GHC set of callee saved regs is empty as all those regs are
213// used for passing STG regs around
214// add is a workaround for not being able to compile empty list:
215// def CSR_GHC : CalleeSavedRegs<()>;
216def CSR_GHC : CalleeSavedRegs<(add)>;