Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 1 | //===-- MipsCallingConv.td - Calling Conventions for Mips --*- tablegen -*-===// |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 2 | // |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 7 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 9 | // This describes the calling conventions for Mips architecture. |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 10 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 11 | |
| 12 | /// CCIfSubtarget - Match if the current subtarget has a feature F. |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 13 | class CCIfSubtarget<string F, CCAction A>: |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 14 | CCIf<!strconcat("State.getTarget().getSubtarget<MipsSubtarget>().", F), A>; |
| 15 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 17 | // Mips O32 Calling Convention |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 18 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 19 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 20 | // Only the return rules are defined here for O32. The rules for argument |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 21 | // passing are defined in MipsISelLowering.cpp. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 22 | def RetCC_MipsO32 : CallingConv<[ |
Akira Hatanaka | 805569f | 2011-06-21 01:28:11 +0000 | [diff] [blame] | 23 | // i32 are returned in registers V0, V1, A0, A1 |
| 24 | CCIfType<[i32], CCAssignToReg<[V0, V1, A0, A1]>>, |
Bruno Cardoso Lopes | 64cf160 | 2008-08-03 15:37:43 +0000 | [diff] [blame] | 25 | |
Bruno Cardoso Lopes | e5ebd5f | 2010-01-19 12:37:35 +0000 | [diff] [blame] | 26 | // f32 are returned in registers F0, F2 |
| 27 | CCIfType<[f32], CCAssignToReg<[F0, F2]>>, |
Bruno Cardoso Lopes | 64cf160 | 2008-08-03 15:37:43 +0000 | [diff] [blame] | 28 | |
Bruno Cardoso Lopes | e5ebd5f | 2010-01-19 12:37:35 +0000 | [diff] [blame] | 29 | // f64 are returned in register D0, D1 |
| 30 | CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()", CCAssignToReg<[D0, D1]>>> |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 31 | ]>; |
| 32 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 34 | // Mips N32/64 Calling Convention |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | |
| 37 | def CC_MipsN : CallingConv<[ |
Akira Hatanaka | 38bdc57 | 2012-02-17 02:20:26 +0000 | [diff] [blame] | 38 | // Promote i8/i16 arguments to i32. |
| 39 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 40 | |
| 41 | // Integer arguments are passed in integer registers. |
Akira Hatanaka | 38bdc57 | 2012-02-17 02:20:26 +0000 | [diff] [blame] | 42 | CCIfType<[i32], CCAssignToRegWithShadow<[A0, A1, A2, A3, |
| 43 | T0, T1, T2, T3], |
| 44 | [F12, F13, F14, F15, |
| 45 | F16, F17, F18, F19]>>, |
| 46 | |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 47 | CCIfType<[i64], CCAssignToRegWithShadow<[A0_64, A1_64, A2_64, A3_64, |
| 48 | T0_64, T1_64, T2_64, T3_64], |
| 49 | [D12_64, D13_64, D14_64, D15_64, |
| 50 | D16_64, D17_64, D18_64, D19_64]>>, |
| 51 | |
| 52 | // f32 arguments are passed in single precision FP registers. |
| 53 | CCIfType<[f32], CCAssignToRegWithShadow<[F12, F13, F14, F15, |
| 54 | F16, F17, F18, F19], |
| 55 | [A0_64, A1_64, A2_64, A3_64, |
| 56 | T0_64, T1_64, T2_64, T3_64]>>, |
| 57 | |
| 58 | // f64 arguments are passed in double precision FP registers. |
| 59 | CCIfType<[f64], CCAssignToRegWithShadow<[D12_64, D13_64, D14_64, D15_64, |
| 60 | D16_64, D17_64, D18_64, D19_64], |
| 61 | [A0_64, A1_64, A2_64, A3_64, |
| 62 | T0_64, T1_64, T2_64, T3_64]>>, |
| 63 | |
| 64 | // All stack parameter slots become 64-bit doublewords and are 8-byte aligned. |
Akira Hatanaka | 38bdc57 | 2012-02-17 02:20:26 +0000 | [diff] [blame] | 65 | CCIfType<[i32, f32], CCAssignToStack<4, 8>>, |
| 66 | CCIfType<[i64, f64], CCAssignToStack<8, 8>> |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 67 | ]>; |
| 68 | |
Akira Hatanaka | 4961709 | 2011-11-14 19:02:54 +0000 | [diff] [blame] | 69 | // N32/64 variable arguments. |
| 70 | // All arguments are passed in integer registers. |
| 71 | def CC_MipsN_VarArg : CallingConv<[ |
Akira Hatanaka | 38bdc57 | 2012-02-17 02:20:26 +0000 | [diff] [blame] | 72 | // Promote i8/i16 arguments to i32. |
| 73 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
| 74 | |
| 75 | CCIfType<[i32, f32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3]>>, |
Akira Hatanaka | 4961709 | 2011-11-14 19:02:54 +0000 | [diff] [blame] | 76 | |
| 77 | CCIfType<[i64, f64], CCAssignToReg<[A0_64, A1_64, A2_64, A3_64, |
| 78 | T0_64, T1_64, T2_64, T3_64]>>, |
| 79 | |
Akira Hatanaka | 4961709 | 2011-11-14 19:02:54 +0000 | [diff] [blame] | 80 | // All stack parameter slots become 64-bit doublewords and are 8-byte aligned. |
Akira Hatanaka | 38bdc57 | 2012-02-17 02:20:26 +0000 | [diff] [blame] | 81 | CCIfType<[i32, f32], CCAssignToStack<4, 8>>, |
| 82 | CCIfType<[i64, f64], CCAssignToStack<8, 8>> |
Akira Hatanaka | 4961709 | 2011-11-14 19:02:54 +0000 | [diff] [blame] | 83 | ]>; |
| 84 | |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 85 | def RetCC_MipsN : CallingConv<[ |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 86 | // i32 are returned in registers V0, V1 |
| 87 | CCIfType<[i32], CCAssignToReg<[V0, V1]>>, |
| 88 | |
| 89 | // i64 are returned in registers V0_64, V1_64 |
| 90 | CCIfType<[i64], CCAssignToReg<[V0_64, V1_64]>>, |
| 91 | |
| 92 | // f32 are returned in registers F0, F2 |
| 93 | CCIfType<[f32], CCAssignToReg<[F0, F2]>>, |
| 94 | |
| 95 | // f64 are returned in registers D0, D2 |
| 96 | CCIfType<[f64], CCAssignToReg<[D0_64, D2_64]>> |
| 97 | ]>; |
| 98 | |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 99 | // In soft-mode, register A0_64, instead of V1_64, is used to return a long |
| 100 | // double value. |
| 101 | def RetCC_F128Soft : CallingConv<[ |
| 102 | CCIfType<[i64], CCAssignToReg<[V0_64, A0_64]>> |
| 103 | ]>; |
| 104 | |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 105 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 106 | // Mips EABI Calling Convention |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 107 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 108 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 109 | def CC_MipsEABI : CallingConv<[ |
| 110 | // Promote i8/i16 arguments to i32. |
| 111 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
| 112 | |
| 113 | // Integer arguments are passed in integer registers. |
| 114 | CCIfType<[i32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3]>>, |
| 115 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 116 | // Single fp arguments are passed in pairs within 32-bit mode |
| 117 | CCIfType<[f32], CCIfSubtarget<"isSingleFloat()", |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 118 | CCAssignToReg<[F12, F13, F14, F15, F16, F17, F18, F19]>>>, |
| 119 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 120 | CCIfType<[f32], CCIfSubtarget<"isNotSingleFloat()", |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 121 | CCAssignToReg<[F12, F14, F16, F18]>>>, |
| 122 | |
Duncan Sands | d03bcc1 | 2011-04-25 06:21:43 +0000 | [diff] [blame] | 123 | // The first 4 double fp arguments are passed in single fp registers. |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 124 | CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()", |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 125 | CCAssignToReg<[D6, D7, D8, D9]>>>, |
| 126 | |
| 127 | // Integer values get stored in stack slots that are 4 bytes in |
| 128 | // size and 4-byte aligned. |
| 129 | CCIfType<[i32, f32], CCAssignToStack<4, 4>>, |
| 130 | |
| 131 | // Integer values get stored in stack slots that are 8 bytes in |
| 132 | // size and 8-byte aligned. |
| 133 | CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()", CCAssignToStack<8, 8>>> |
| 134 | ]>; |
| 135 | |
| 136 | def RetCC_MipsEABI : CallingConv<[ |
| 137 | // i32 are returned in registers V0, V1 |
| 138 | CCIfType<[i32], CCAssignToReg<[V0, V1]>>, |
| 139 | |
| 140 | // f32 are returned in registers F0, F1 |
| 141 | CCIfType<[f32], CCAssignToReg<[F0, F1]>>, |
| 142 | |
| 143 | // f64 are returned in register D0 |
| 144 | CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()", CCAssignToReg<[D0]>>> |
| 145 | ]>; |
| 146 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 147 | //===----------------------------------------------------------------------===// |
Akira Hatanaka | 777a120 | 2012-06-13 18:06:00 +0000 | [diff] [blame] | 148 | // Mips FastCC Calling Convention |
| 149 | //===----------------------------------------------------------------------===// |
| 150 | def CC_MipsO32_FastCC : CallingConv<[ |
| 151 | // f64 arguments are passed in double-precision floating pointer registers. |
| 152 | CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7, D8, D9]>>, |
| 153 | |
| 154 | // Stack parameter slots for f64 are 64-bit doublewords and 8-byte aligned. |
| 155 | CCIfType<[f64], CCAssignToStack<8, 8>> |
| 156 | ]>; |
| 157 | |
| 158 | def CC_MipsN_FastCC : CallingConv<[ |
| 159 | // Integer arguments are passed in integer registers. |
| 160 | CCIfType<[i64], CCAssignToReg<[A0_64, A1_64, A2_64, A3_64, T0_64, T1_64, |
| 161 | T2_64, T3_64, T4_64, T5_64, T6_64, T7_64, |
| 162 | T8_64, V1_64]>>, |
| 163 | |
| 164 | // f64 arguments are passed in double-precision floating pointer registers. |
| 165 | CCIfType<[f64], CCAssignToReg<[D0_64, D1_64, D2_64, D3_64, D4_64, D5_64, |
| 166 | D6_64, D7_64, D8_64, D9_64, D10_64, D11_64, |
| 167 | D12_64, D13_64, D14_64, D15_64, D16_64, D17_64, |
| 168 | D18_64, D19_64]>>, |
| 169 | |
| 170 | // Stack parameter slots for i64 and f64 are 64-bit doublewords and |
| 171 | // 8-byte aligned. |
| 172 | CCIfType<[i64, f64], CCAssignToStack<8, 8>> |
| 173 | ]>; |
| 174 | |
| 175 | def CC_Mips_FastCC : CallingConv<[ |
| 176 | // Handles byval parameters. |
| 177 | CCIfByVal<CCPassByVal<4, 4>>, |
| 178 | |
| 179 | // Promote i8/i16 arguments to i32. |
| 180 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
| 181 | |
| 182 | // Integer arguments are passed in integer registers. All scratch registers, |
| 183 | // except for AT, V0 and T9, are available to be used as argument registers. |
| 184 | CCIfType<[i32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, |
| 185 | T7, T8, V1]>>, |
| 186 | |
| 187 | // f32 arguments are passed in single-precision floating pointer registers. |
| 188 | CCIfType<[f32], CCAssignToReg<[F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, |
| 189 | F11, F12, F13, F14, F15, F16, F17, F18, F19]>>, |
| 190 | |
| 191 | // Stack parameter slots for i32 and f32 are 32-bit words and 4-byte aligned. |
| 192 | CCIfType<[i32, f32], CCAssignToStack<4, 4>>, |
| 193 | |
| 194 | CCIfSubtarget<"isABI_EABI()", CCDelegateTo<CC_MipsEABI>>, |
| 195 | CCIfSubtarget<"isABI_O32()", CCDelegateTo<CC_MipsO32_FastCC>>, |
| 196 | CCDelegateTo<CC_MipsN_FastCC> |
| 197 | ]>; |
| 198 | |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 199 | //== |
| 200 | |
| 201 | def CC_Mips16RetHelper : CallingConv<[ |
| 202 | // Integer arguments are passed in integer registers. |
| 203 | CCIfType<[i32], CCAssignToReg<[V0, V1, A0, A1]>> |
| 204 | ]>; |
| 205 | |
Akira Hatanaka | 777a120 | 2012-06-13 18:06:00 +0000 | [diff] [blame] | 206 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 207 | // Mips Calling Convention Dispatch |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 208 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 209 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 210 | def RetCC_Mips : CallingConv<[ |
| 211 | CCIfSubtarget<"isABI_EABI()", CCDelegateTo<RetCC_MipsEABI>>, |
Akira Hatanaka | 45b73e2 | 2011-09-23 19:08:15 +0000 | [diff] [blame] | 212 | CCIfSubtarget<"isABI_N32()", CCDelegateTo<RetCC_MipsN>>, |
| 213 | CCIfSubtarget<"isABI_N64()", CCDelegateTo<RetCC_MipsN>>, |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 214 | CCDelegateTo<RetCC_MipsO32> |
| 215 | ]>; |
Akira Hatanaka | b2930b9 | 2012-03-01 22:27:29 +0000 | [diff] [blame] | 216 | |
| 217 | //===----------------------------------------------------------------------===// |
| 218 | // Callee-saved register lists. |
| 219 | //===----------------------------------------------------------------------===// |
| 220 | |
| 221 | def CSR_SingleFloatOnly : CalleeSavedRegs<(add (sequence "F%u", 31, 20), RA, FP, |
| 222 | (sequence "S%u", 7, 0))>; |
| 223 | |
| 224 | def CSR_O32 : CalleeSavedRegs<(add (sequence "D%u", 15, 10), RA, FP, |
| 225 | (sequence "S%u", 7, 0))>; |
| 226 | |
| 227 | def CSR_N32 : CalleeSavedRegs<(add D31_64, D29_64, D27_64, D25_64, D24_64, |
| 228 | D23_64, D22_64, D21_64, RA_64, FP_64, GP_64, |
| 229 | (sequence "S%u_64", 7, 0))>; |
| 230 | |
| 231 | def CSR_N64 : CalleeSavedRegs<(add (sequence "D%u_64", 31, 24), RA_64, FP_64, |
| 232 | GP_64, (sequence "S%u_64", 7, 0))>; |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 233 | |
Jack Carter | d761004 | 2013-05-16 20:08:49 +0000 | [diff] [blame] | 234 | def CSR_Mips16RetHelper : |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 235 | CalleeSavedRegs<(add V0, V1, (sequence "A%u", 3, 0), S0, S1)>; |