Arnold Schwaighofer | 48abc5c | 2007-10-12 21:30:57 +0000 | [diff] [blame] | 1 | //===- X86CallingConv.td - Calling Conventions X86 32/64 ---*- tablegen -*-===// |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | bffc1b3 | 2007-02-26 18:56:07 +0000 | [diff] [blame] | 5 | // This file was developed by Chris Lattner and is distributed under |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This describes the calling conventions for the X86-32 and X86-64 |
| 11 | // architectures. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 15 | /// CCIfSubtarget - Match if the current subtarget has a feature F. |
| 16 | class CCIfSubtarget<string F, CCAction A> |
| 17 | : CCIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().", F), A>; |
Chris Lattner | 3d55910 | 2007-02-28 04:51:41 +0000 | [diff] [blame] | 18 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 19 | //===----------------------------------------------------------------------===// |
| 20 | // Return Value Calling Conventions |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 23 | // Return-value conventions common to all X86 CC's. |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 24 | def RetCC_X86Common : CallingConv<[ |
| 25 | // Scalar values are returned in AX first, then DX. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 26 | CCIfType<[i8] , CCAssignToReg<[AL]>>, |
| 27 | CCIfType<[i16], CCAssignToReg<[AX]>>, |
| 28 | CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>, |
| 29 | CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 30 | |
Dan Gohman | 1866f6e | 2007-07-02 16:21:53 +0000 | [diff] [blame] | 31 | // Vector types are returned in XMM0 and XMM1, when they fit. If the target |
| 32 | // doesn't have XMM registers, it won't have vector types. |
| 33 | CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
| 34 | CCAssignToReg<[XMM0,XMM1]>>, |
Bill Wendling | e2501b3 | 2007-03-30 00:35:22 +0000 | [diff] [blame] | 35 | |
| 36 | // MMX vector types are always returned in MM0. If the target doesn't have |
| 37 | // MM0, it doesn't support these vector types. |
Dale Johannesen | 6a30811 | 2007-08-06 21:31:06 +0000 | [diff] [blame] | 38 | CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[MM0]>>, |
| 39 | |
| 40 | // Long double types are always returned in ST0 (even with SSE). |
| 41 | CCIfType<[f80], CCAssignToReg<[ST0]>> |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 42 | ]>; |
| 43 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 44 | // X86-32 C return-value convention. |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 45 | def RetCC_X86_32_C : CallingConv<[ |
| 46 | // The X86-32 calling convention returns FP values in ST0, otherwise it is the |
| 47 | // same as the common X86 calling conv. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 48 | CCIfType<[f32], CCAssignToReg<[ST0]>>, |
| 49 | CCIfType<[f64], CCAssignToReg<[ST0]>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 50 | CCDelegateTo<RetCC_X86Common> |
| 51 | ]>; |
| 52 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 53 | // X86-32 FastCC return-value convention. |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 54 | def RetCC_X86_32_Fast : CallingConv<[ |
Nate Begeman | d73ab88 | 2007-11-27 19:28:48 +0000 | [diff] [blame] | 55 | // The X86-32 fastcc returns 1, 2, or 3 FP values in XMM0-2 if the target has |
| 56 | // SSE2, otherwise it is the the C calling conventions. |
| 57 | // This can happen when a float, 2 x float, or 3 x float vector is split by |
| 58 | // target lowering, and is returned in 1-3 sse regs. |
| 59 | CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>, |
| 60 | CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 61 | CCDelegateTo<RetCC_X86Common> |
| 62 | ]>; |
| 63 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 64 | // X86-64 C return-value convention. |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 65 | def RetCC_X86_64_C : CallingConv<[ |
| 66 | // The X86-64 calling convention always returns FP values in XMM0. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 67 | CCIfType<[f32], CCAssignToReg<[XMM0]>>, |
| 68 | CCIfType<[f64], CCAssignToReg<[XMM0]>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 69 | CCDelegateTo<RetCC_X86Common> |
| 70 | ]>; |
| 71 | |
| 72 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 73 | |
| 74 | // This is the root return-value convention for the X86-32 backend. |
| 75 | def RetCC_X86_32 : CallingConv<[ |
| 76 | // If FastCC, use RetCC_X86_32_Fast. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 77 | CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>, |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 78 | // Otherwise, use RetCC_X86_32_C. |
| 79 | CCDelegateTo<RetCC_X86_32_C> |
| 80 | ]>; |
| 81 | |
| 82 | // This is the root return-value convention for the X86-64 backend. |
| 83 | def RetCC_X86_64 : CallingConv<[ |
| 84 | // Always just the same as C calling conv for X86-64. |
| 85 | CCDelegateTo<RetCC_X86_64_C> |
| 86 | ]>; |
| 87 | |
Chris Lattner | d637a8b | 2007-02-27 06:59:52 +0000 | [diff] [blame] | 88 | // This is the return-value convention used for the entire X86 backend. |
| 89 | def RetCC_X86 : CallingConv<[ |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 90 | CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>, |
Chris Lattner | d637a8b | 2007-02-27 06:59:52 +0000 | [diff] [blame] | 91 | CCDelegateTo<RetCC_X86_32> |
| 92 | ]>; |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 94 | //===----------------------------------------------------------------------===// |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 95 | // X86-64 Argument Calling Conventions |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 96 | //===----------------------------------------------------------------------===// |
| 97 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 98 | def CC_X86_64_C : CallingConv<[ |
| 99 | // Promote i8/i16 arguments to i32. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 100 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 101 | |
Rafael Espindola | 1aa7efb | 2007-07-06 10:57:03 +0000 | [diff] [blame] | 102 | CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8, R9 ]>>, |
| 103 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 104 | // The first 6 integer arguments are passed in integer registers. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 105 | CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>, |
| 106 | CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 107 | |
| 108 | // The first 8 FP/Vector arguments are passed in XMM registers. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 109 | CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 110 | CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>, |
| 111 | |
Bill Wendling | 577c7d9 | 2007-03-31 09:36:12 +0000 | [diff] [blame] | 112 | // The first 8 MMX vector arguments are passed in GPRs. |
Bill Wendling | db5c993 | 2007-03-31 01:03:53 +0000 | [diff] [blame] | 113 | CCIfType<[v8i8, v4i16, v2i32, v1i64], |
| 114 | CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>, |
| 115 | |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 116 | // The 'nest' parameter, if any, is passed in R10. |
| 117 | CCIfNest<CCAssignToReg<[R10]>>, |
| 118 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 119 | // Integer/FP values get stored in stack slots that are 8 bytes in size and |
| 120 | // 8-byte aligned if there are no more registers to hold them. |
Chris Lattner | 370bdda | 2007-02-28 05:30:29 +0000 | [diff] [blame] | 121 | CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 122 | |
Dale Johannesen | e3ef744 | 2007-11-10 22:07:15 +0000 | [diff] [blame] | 123 | // Long doubles get stack slots whose size and alignment depends on the |
| 124 | // subtarget. |
Duncan Sands | 87b665d | 2007-11-14 08:29:13 +0000 | [diff] [blame] | 125 | CCIfType<[f80], CCAssignToStack<0, 0>>, |
Dale Johannesen | e3ef744 | 2007-11-10 22:07:15 +0000 | [diff] [blame] | 126 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 127 | // Vectors get 16-byte stack slots that are 16-byte aligned. |
Dale Johannesen | e3ef744 | 2007-11-10 22:07:15 +0000 | [diff] [blame] | 128 | CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>, |
Bill Wendling | e2501b3 | 2007-03-30 00:35:22 +0000 | [diff] [blame] | 129 | |
| 130 | // __m64 vectors get 8-byte stack slots that are 8-byte aligned. |
| 131 | CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>> |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 132 | ]>; |
| 133 | |
Arnold Schwaighofer | 48abc5c | 2007-10-12 21:30:57 +0000 | [diff] [blame] | 134 | // Tail call convention (fast): One register is reserved for target address, |
Arnold Schwaighofer | c85e171 | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 135 | // namely R9 |
| 136 | def CC_X86_64_TailCall : CallingConv<[ |
| 137 | // Promote i8/i16 arguments to i32. |
| 138 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
| 139 | |
| 140 | CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8]>>, |
| 141 | |
| 142 | // The first 6 integer arguments are passed in integer registers. |
| 143 | CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D]>>, |
| 144 | CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>, |
| 145 | |
| 146 | // The first 8 FP/Vector arguments are passed in XMM registers. |
| 147 | CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
| 148 | CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>, |
| 149 | |
| 150 | // The first 8 MMX vector arguments are passed in GPRs. |
| 151 | CCIfType<[v8i8, v4i16, v2i32, v1i64], |
| 152 | CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>, |
| 153 | |
| 154 | // The 'nest' parameter, if any, is passed in R10. |
| 155 | CCIfNest<CCAssignToReg<[R10]>>, |
| 156 | |
| 157 | // Integer/FP values get stored in stack slots that are 8 bytes in size and |
| 158 | // 8-byte aligned if there are no more registers to hold them. |
| 159 | CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>, |
| 160 | |
| 161 | // Vectors get 16-byte stack slots that are 16-byte aligned. |
| 162 | CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>, |
| 163 | |
| 164 | // __m64 vectors get 8-byte stack slots that are 8-byte aligned. |
| 165 | CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>> |
| 166 | ]>; |
| 167 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 168 | |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 169 | //===----------------------------------------------------------------------===// |
| 170 | // X86 C Calling Convention |
| 171 | //===----------------------------------------------------------------------===// |
| 172 | |
Chris Lattner | 011bcc8 | 2007-02-28 06:20:01 +0000 | [diff] [blame] | 173 | /// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP |
| 174 | /// values are spilled on the stack, and the first 4 vector values go in XMM |
| 175 | /// regs. |
| 176 | def CC_X86_32_Common : CallingConv<[ |
| 177 | // Integer/Float values get stored in stack slots that are 4 bytes in |
| 178 | // size and 4-byte aligned. |
| 179 | CCIfType<[i32, f32], CCAssignToStack<4, 4>>, |
| 180 | |
| 181 | // Doubles get 8-byte slots that are 4-byte aligned. |
| 182 | CCIfType<[f64], CCAssignToStack<8, 4>>, |
Dale Johannesen | 6a30811 | 2007-08-06 21:31:06 +0000 | [diff] [blame] | 183 | |
Dale Johannesen | e3ef744 | 2007-11-10 22:07:15 +0000 | [diff] [blame] | 184 | // Long doubles get slots whose size and alignment depends on the |
| 185 | // subtarget. |
Dale Johannesen | 6e959b9 | 2007-12-14 19:25:34 +0000 | [diff] [blame^] | 186 | CCIfType<[f80], CCAssignToStack<16, 4>>, |
Dale Johannesen | 6a30811 | 2007-08-06 21:31:06 +0000 | [diff] [blame] | 187 | |
Chris Lattner | 011bcc8 | 2007-02-28 06:20:01 +0000 | [diff] [blame] | 188 | // The first 4 vector arguments are passed in XMM registers. |
| 189 | CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
| 190 | CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>, |
| 191 | |
| 192 | // Other vectors get 16-byte stack slots that are 16-byte aligned. |
Bill Wendling | e2501b3 | 2007-03-30 00:35:22 +0000 | [diff] [blame] | 193 | CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>, |
| 194 | |
| 195 | // __m64 vectors get 8-byte stack slots that are 8-byte aligned. They are |
| 196 | // passed in the parameter area. |
| 197 | CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>> |
Chris Lattner | 011bcc8 | 2007-02-28 06:20:01 +0000 | [diff] [blame] | 198 | ]>; |
| 199 | |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 200 | def CC_X86_32_C : CallingConv<[ |
| 201 | // Promote i8/i16 arguments to i32. |
| 202 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 203 | |
| 204 | // The 'nest' parameter, if any, is passed in ECX. |
| 205 | CCIfNest<CCAssignToReg<[ECX]>>, |
| 206 | |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 207 | // The first 3 integer arguments, if marked 'inreg' and if the call is not |
| 208 | // a vararg call, are passed in integer registers. |
| 209 | CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>, |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 210 | |
Chris Lattner | 011bcc8 | 2007-02-28 06:20:01 +0000 | [diff] [blame] | 211 | // Otherwise, same as everything else. |
| 212 | CCDelegateTo<CC_X86_32_Common> |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 213 | ]>; |
| 214 | |
Arnold Schwaighofer | 48abc5c | 2007-10-12 21:30:57 +0000 | [diff] [blame] | 215 | /// Same as C calling convention except for non-free ECX which is used for storing |
| 216 | /// a potential pointer to the tail called function. |
Arnold Schwaighofer | c85e171 | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 217 | def CC_X86_32_TailCall : CallingConv<[ |
| 218 | // Promote i8/i16 arguments to i32. |
| 219 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
| 220 | |
Duncan Sands | 7fef59f | 2007-10-13 07:38:37 +0000 | [diff] [blame] | 221 | // Nested function trampolines are currently not supported by fastcc. |
Arnold Schwaighofer | 48abc5c | 2007-10-12 21:30:57 +0000 | [diff] [blame] | 222 | |
Arnold Schwaighofer | c85e171 | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 223 | // The first 3 integer arguments, if marked 'inreg' and if the call is not |
| 224 | // a vararg call, are passed in integer registers. |
| 225 | CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>>>, |
| 226 | |
| 227 | // Otherwise, same as everything else. |
| 228 | CCDelegateTo<CC_X86_32_Common> |
| 229 | ]>; |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 230 | |
Chris Lattner | 011bcc8 | 2007-02-28 06:20:01 +0000 | [diff] [blame] | 231 | def CC_X86_32_FastCall : CallingConv<[ |
| 232 | // Promote i8/i16 arguments to i32. |
| 233 | CCIfType<[i8, i16], CCPromoteToType<i32>>, |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 234 | |
| 235 | // The 'nest' parameter, if any, is passed in EAX. |
| 236 | CCIfNest<CCAssignToReg<[EAX]>>, |
| 237 | |
Chris Lattner | 011bcc8 | 2007-02-28 06:20:01 +0000 | [diff] [blame] | 238 | // The first 2 integer arguments are passed in ECX/EDX |
Chris Lattner | 7050080 | 2007-02-28 18:35:11 +0000 | [diff] [blame] | 239 | CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>, |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 240 | |
Chris Lattner | 011bcc8 | 2007-02-28 06:20:01 +0000 | [diff] [blame] | 241 | // Otherwise, same as everything else. |
| 242 | CCDelegateTo<CC_X86_32_Common> |
| 243 | ]>; |