blob: bda1517685b1278fcaccc95b0c585ba7a593e39d [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]>>>,
Bob Wilson04746ea2009-05-19 10:02:36 +0000114 CCIfType<[i32], CCIf<"State.getNextStackOffset() == 0 &&"
115 "ArgFlags.getOrigAlign() != 8",
116 CCAssignToReg<[R0, R1, R2, R3]>>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000117
Rafael Espindola55e95872010-08-06 15:35:32 +0000118 CCIfType<[i32], CCIfAlign<"8", CCAssignToStackWithShadow<4, 8, R3>>>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000119 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
Bob Wilson5bafff32009-06-22 23:27:02 +0000120 CCIfType<[f64], CCAssignToStack<8, 8>>,
121 CCIfType<[v2f64], CCAssignToStack<16, 8>>
Bob Wilson1f595bb2009-04-17 19:07:39 +0000122]>;
123
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000124def RetCC_ARM_AAPCS_Common : CallingConv<[
Chad Rosier0eff39f2011-11-08 00:03:32 +0000125 CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
Anton Korobeynikov2e7ccfc2009-06-08 22:59:50 +0000126 CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000127 CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
128]>;
129
130//===----------------------------------------------------------------------===//
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000131// ARM AAPCS (EABI) Calling Convention
132//===----------------------------------------------------------------------===//
133
134def CC_ARM_AAPCS : CallingConv<[
Manman Rend9b45122012-08-10 20:39:38 +0000135 // Handles byval parameters.
136 CCIfByVal<CCPassByVal<4, 4>>,
137
Bob Wilson5bafff32009-06-22 23:27:02 +0000138 // Handle all vector types as either f64 or v2f64.
139 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
140 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
141
142 CCIfType<[f64, v2f64], CCCustom<"CC_ARM_AAPCS_Custom_f64">>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000143 CCIfType<[f32], CCBitConvertToType<i32>>,
144 CCDelegateTo<CC_ARM_AAPCS_Common>
145]>;
146
147def RetCC_ARM_AAPCS : CallingConv<[
Bob Wilson5bafff32009-06-22 23:27:02 +0000148 // Handle all vector types as either f64 or v2f64.
149 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
150 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
151
152 CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_AAPCS_Custom_f64">>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000153 CCIfType<[f32], CCBitConvertToType<i32>>,
154 CCDelegateTo<RetCC_ARM_AAPCS_Common>
155]>;
156
157//===----------------------------------------------------------------------===//
158// ARM AAPCS-VFP (EABI) Calling Convention
Evan Cheng76f920d2010-10-22 18:23:05 +0000159// Also used for FastCC (when VFP2 or later is available)
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000160//===----------------------------------------------------------------------===//
161
162def CC_ARM_AAPCS_VFP : CallingConv<[
Manman Rena41db532012-08-13 21:22:50 +0000163 // Handles byval parameters.
164 CCIfByVal<CCPassByVal<4, 4>>,
165
Bob Wilson5bafff32009-06-22 23:27:02 +0000166 // Handle all vector types as either f64 or v2f64.
167 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
168 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
169
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000170 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000171 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
172 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
173 S9, S10, S11, S12, S13, S14, S15]>>,
174 CCDelegateTo<CC_ARM_AAPCS_Common>
175]>;
176
177def RetCC_ARM_AAPCS_VFP : CallingConv<[
Bob Wilson5bafff32009-06-22 23:27:02 +0000178 // Handle all vector types as either f64 or v2f64.
179 CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
180 CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
181
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000182 CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>,
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000183 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>,
184 CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8,
185 S9, S10, S11, S12, S13, S14, S15]>>,
186 CCDelegateTo<RetCC_ARM_AAPCS_Common>
187]>;
Jakob Stoklund Olesen3ee7d152012-01-17 23:09:00 +0000188
189//===----------------------------------------------------------------------===//
190// Callee-saved register lists.
191//===----------------------------------------------------------------------===//
192
193def CSR_AAPCS : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, R5, R4,
194 (sequence "D%u", 15, 8))>;
195
196// iOS ABI deviates from ARM standard ABI. R9 is not a callee-saved register.
197// Also save R7-R4 first to match the stack frame fixed spill areas.
198def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>;
Eric Christophere94ac882012-08-03 00:05:53 +0000199
200// GHC set of callee saved regs is empty as all those regs are
201// used for passing STG regs around
202// add is a workaround for not being able to compile empty list:
203// def CSR_GHC : CalleeSavedRegs<()>;
204def CSR_GHC : CalleeSavedRegs<(add)>;