Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMCallingConv.td - Calling Conventions for ARM ----*- tablegen -*-===// |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2 | // |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3 | // 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 Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 7 | // |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // This describes the calling conventions for ARM architecture. |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 12 | /// CCIfAlign - Match of the original alignment of the arg |
| 13 | class CCIfAlign<string Align, CCAction A>: |
| 14 | CCIf<!strconcat("ArgFlags.getOrigAlign() == ", Align), A>; |
| 15 | |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | // ARM APCS Calling Convention |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | def CC_ARM_APCS : CallingConv<[ |
| 20 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 21 | // Handles byval parameters. |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 22 | CCIfByVal<CCPassByVal<4, 4>>, |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 23 | |
Chad Rosier | 38f5c0d | 2011-11-05 00:02:56 +0000 | [diff] [blame] | 24 | CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 25 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 26 | // 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 Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 32 | |
| 33 | CCIfType<[f32], CCBitConvertToType<i32>>, |
Bob Wilson | 1c2c462 | 2009-04-24 16:55:25 +0000 | [diff] [blame] | 34 | CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 35 | |
Bob Wilson | 1c2c462 | 2009-04-24 16:55:25 +0000 | [diff] [blame] | 36 | CCIfType<[i32], CCAssignToStack<4, 4>>, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 37 | CCIfType<[f64], CCAssignToStack<8, 4>>, |
| 38 | CCIfType<[v2f64], CCAssignToStack<16, 4>> |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 39 | ]>; |
| 40 | |
| 41 | def RetCC_ARM_APCS : CallingConv<[ |
Chad Rosier | 0eff39f | 2011-11-08 00:03:32 +0000 | [diff] [blame] | 42 | CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 43 | CCIfType<[f32], CCBitConvertToType<i32>>, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 44 | |
| 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 Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 50 | |
| 51 | CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>, |
| 52 | CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>> |
| 53 | ]>; |
| 54 | |
| 55 | //===----------------------------------------------------------------------===// |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 56 | // ARM APCS Calling Convention for FastCC (when VFP2 or later is available) |
| 57 | //===----------------------------------------------------------------------===// |
| 58 | def 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 | |
| 70 | def 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 Christopher | e94ac88 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 82 | //===----------------------------------------------------------------------===// |
| 83 | // ARM APCS Calling Convention for GHC |
| 84 | //===----------------------------------------------------------------------===// |
| 85 | |
| 86 | def 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 Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 101 | |
| 102 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 103 | // ARM AAPCS (EABI) Calling Convention, common parts |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 104 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 105 | |
| 106 | def CC_ARM_AAPCS_Common : CallingConv<[ |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 107 | |
Chad Rosier | 62c8e8e | 2011-11-07 21:43:40 +0000 | [diff] [blame] | 108 | CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 109 | |
| 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 Wilson | 04746ea | 2009-05-19 10:02:36 +0000 | [diff] [blame] | 112 | // (and the same is true for f64 if VFP is not enabled) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 113 | CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0, R1]>>>, |
Stepan Dyatkovskiy | 78e3c90 | 2013-04-22 13:06:52 +0000 | [diff] [blame] | 114 | CCIfType<[i32], CCIf<"ArgFlags.getOrigAlign() != 8", |
Bob Wilson | 04746ea | 2009-05-19 10:02:36 +0000 | [diff] [blame] | 115 | CCAssignToReg<[R0, R1, R2, R3]>>>, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 116 | |
Rafael Espindola | 55e9587 | 2010-08-06 15:35:32 +0000 | [diff] [blame] | 117 | CCIfType<[i32], CCIfAlign<"8", CCAssignToStackWithShadow<4, 8, R3>>>, |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 118 | CCIfType<[i32, f32], CCAssignToStack<4, 4>>, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 119 | CCIfType<[f64], CCAssignToStack<8, 8>>, |
| 120 | CCIfType<[v2f64], CCAssignToStack<16, 8>> |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 121 | ]>; |
| 122 | |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 123 | def RetCC_ARM_AAPCS_Common : CallingConv<[ |
Chad Rosier | 0eff39f | 2011-11-08 00:03:32 +0000 | [diff] [blame] | 124 | CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, |
Anton Korobeynikov | 2e7ccfc | 2009-06-08 22:59:50 +0000 | [diff] [blame] | 125 | CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 126 | CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>> |
| 127 | ]>; |
| 128 | |
| 129 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 130 | // ARM AAPCS (EABI) Calling Convention |
| 131 | //===----------------------------------------------------------------------===// |
| 132 | |
| 133 | def CC_ARM_AAPCS : CallingConv<[ |
Manman Ren | d9b4512 | 2012-08-10 20:39:38 +0000 | [diff] [blame] | 134 | // Handles byval parameters. |
| 135 | CCIfByVal<CCPassByVal<4, 4>>, |
| 136 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 137 | // 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 Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 142 | CCIfType<[f32], CCBitConvertToType<i32>>, |
| 143 | CCDelegateTo<CC_ARM_AAPCS_Common> |
| 144 | ]>; |
| 145 | |
| 146 | def RetCC_ARM_AAPCS : CallingConv<[ |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 147 | // 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 Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 152 | CCIfType<[f32], CCBitConvertToType<i32>>, |
| 153 | CCDelegateTo<RetCC_ARM_AAPCS_Common> |
| 154 | ]>; |
| 155 | |
| 156 | //===----------------------------------------------------------------------===// |
| 157 | // ARM AAPCS-VFP (EABI) Calling Convention |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 158 | // Also used for FastCC (when VFP2 or later is available) |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 159 | //===----------------------------------------------------------------------===// |
| 160 | |
| 161 | def CC_ARM_AAPCS_VFP : CallingConv<[ |
Manman Ren | a41db53 | 2012-08-13 21:22:50 +0000 | [diff] [blame] | 162 | // Handles byval parameters. |
| 163 | CCIfByVal<CCPassByVal<4, 4>>, |
| 164 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 165 | // 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 Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 169 | CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>, |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 170 | 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 | |
| 176 | def RetCC_ARM_AAPCS_VFP : CallingConv<[ |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 177 | // 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 Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 181 | CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>, |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 182 | 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 Olesen | 3ee7d15 | 2012-01-17 23:09:00 +0000 | [diff] [blame] | 187 | |
| 188 | //===----------------------------------------------------------------------===// |
| 189 | // Callee-saved register lists. |
| 190 | //===----------------------------------------------------------------------===// |
| 191 | |
Chad Rosier | e7bd519 | 2012-11-06 23:05:24 +0000 | [diff] [blame] | 192 | def CSR_NoRegs : CalleeSavedRegs<(add)>; |
| 193 | |
Jakob Stoklund Olesen | 3ee7d15 | 2012-01-17 23:09:00 +0000 | [diff] [blame] | 194 | def CSR_AAPCS : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, R5, R4, |
| 195 | (sequence "D%u", 15, 8))>; |
| 196 | |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 197 | // 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 |
| 201 | def 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 Olesen | 3ee7d15 | 2012-01-17 23:09:00 +0000 | [diff] [blame] | 205 | // 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. |
| 207 | def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>; |
Eric Christopher | e94ac88 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 208 | |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 209 | def CSR_iOS_ThisReturn : CalleeSavedRegs<(add LR, R7, R6, R5, R4, |
| 210 | (sub CSR_AAPCS_ThisReturn, R9))>; |
| 211 | |
Eric Christopher | e94ac88 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 212 | // 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<()>; |
| 216 | def CSR_GHC : CalleeSavedRegs<(add)>; |