1//===-- X86CallingConv.td - Calling Conventions X86 32/64 --*- tablegen -*-===// 2// 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. 7// 8//===----------------------------------------------------------------------===// 9// 10// This describes the calling conventions for the X86-32 and X86-64 11// architectures. 12// 13//===----------------------------------------------------------------------===// 14 15/// CCIfSubtarget - Match if the current subtarget has a feature F. 16class CCIfSubtarget<string F, CCAction A> 17 : CCIf<!strconcat("static_cast<const X86Subtarget&>" 18 "(State.getMachineFunction().getSubtarget()).", F), 19 A>; 20 21/// CCIfNotSubtarget - Match if the current subtarget doesn't has a feature F. 22class CCIfNotSubtarget<string F, CCAction A> 23 : CCIf<!strconcat("!static_cast<const X86Subtarget&>" 24 "(State.getMachineFunction().getSubtarget()).", F), 25 A>; 26 27// Register classes for RegCall 28class RC_X86_RegCall { 29 list<Register> GPR_8 = []; 30 list<Register> GPR_16 = []; 31 list<Register> GPR_32 = []; 32 list<Register> GPR_64 = []; 33 list<Register> FP_CALL = [FP0]; 34 list<Register> FP_RET = [FP0, FP1]; 35 list<Register> XMM = []; 36 list<Register> YMM = []; 37 list<Register> ZMM = []; 38} 39 40// RegCall register classes for 32 bits 41def RC_X86_32_RegCall : RC_X86_RegCall { 42 let GPR_8 = [AL, CL, DL, DIL, SIL]; 43 let GPR_16 = [AX, CX, DX, DI, SI]; 44 let GPR_32 = [EAX, ECX, EDX, EDI, ESI]; 45 let GPR_64 = [RAX]; ///< Not actually used, but AssignToReg can't handle [] 46 ///< \todo Fix AssignToReg to enable empty lists 47 let XMM = [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]; 48 let YMM = [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7]; 49 let ZMM = [ZMM0, ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6, ZMM7]; 50} 51 52class RC_X86_64_RegCall : RC_X86_RegCall { 53 let XMM = [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, 54 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15]; 55 let YMM = [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7, 56 YMM8, YMM9, YMM10, YMM11, YMM12, YMM13, YMM14, YMM15]; 57 let ZMM = [ZMM0, ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6, ZMM7, 58 ZMM8, ZMM9, ZMM10, ZMM11, ZMM12, ZMM13, ZMM14, ZMM15]; 59} 60 61def RC_X86_64_RegCall_Win : RC_X86_64_RegCall { 62 let GPR_8 = [AL, CL, DL, DIL, SIL, R8B, R9B, R10B, R11B, R12B, R14B, R15B]; 63 let GPR_16 = [AX, CX, DX, DI, SI, R8W, R9W, R10W, R11W, R12W, R14W, R15W]; 64 let GPR_32 = [EAX, ECX, EDX, EDI, ESI, R8D, R9D, R10D, R11D, R12D, R14D, R15D]; 65 let GPR_64 = [RAX, RCX, RDX, RDI, RSI, R8, R9, R10, R11, R12, R14, R15]; 66} 67 68def RC_X86_64_RegCall_SysV : RC_X86_64_RegCall { 69 let GPR_8 = [AL, CL, DL, DIL, SIL, R8B, R9B, R12B, R13B, R14B, R15B]; 70 let GPR_16 = [AX, CX, DX, DI, SI, R8W, R9W, R12W, R13W, R14W, R15W]; 71 let GPR_32 = [EAX, ECX, EDX, EDI, ESI, R8D, R9D, R12D, R13D, R14D, R15D]; 72 let GPR_64 = [RAX, RCX, RDX, RDI, RSI, R8, R9, R12, R13, R14, R15]; 73} 74 75// X86-64 Intel regcall calling convention. 76multiclass X86_RegCall_base<RC_X86_RegCall RC> { 77def CC_#NAME : CallingConv<[ 78 // Handles byval parameters. 79 CCIfSubtarget<"is64Bit()", CCIfByVal<CCPassByVal<8, 8>>>, 80 CCIfByVal<CCPassByVal<4, 4>>, 81 82 // Promote i1/i8/i16/v1i1 arguments to i32. 83 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>, 84 85 // Promote v8i1/v16i1/v32i1 arguments to i32. 86 CCIfType<[v8i1, v16i1, v32i1], CCPromoteToType<i32>>, 87 88 // bool, char, int, enum, long, pointer --> GPR 89 CCIfType<[i32], CCAssignToReg<RC.GPR_32>>, 90 91 // long long, __int64 --> GPR 92 CCIfType<[i64], CCAssignToReg<RC.GPR_64>>, 93 94 // __mmask64 (v64i1) --> GPR64 (for x64) or 2 x GPR32 (for IA32) 95 CCIfType<[v64i1], CCPromoteToType<i64>>, 96 CCIfSubtarget<"is64Bit()", CCIfType<[i64], 97 CCAssignToReg<RC.GPR_64>>>, 98 CCIfSubtarget<"is32Bit()", CCIfType<[i64], 99 CCCustom<"CC_X86_32_RegCall_Assign2Regs">>>, 100 101 // float, double, float128 --> XMM 102 // In the case of SSE disabled --> save to stack 103 CCIfType<[f32, f64, f128], 104 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>, 105 106 // long double --> FP 107 CCIfType<[f80], CCAssignToReg<RC.FP_CALL>>, 108 109 // __m128, __m128i, __m128d --> XMM 110 // In the case of SSE disabled --> save to stack 111 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 112 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>, 113 114 // __m256, __m256i, __m256d --> YMM 115 // In the case of SSE disabled --> save to stack 116 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 117 CCIfSubtarget<"hasAVX()", CCAssignToReg<RC.YMM>>>, 118 119 // __m512, __m512i, __m512d --> ZMM 120 // In the case of SSE disabled --> save to stack 121 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 122 CCIfSubtarget<"hasAVX512()",CCAssignToReg<RC.ZMM>>>, 123 124 // If no register was found -> assign to stack 125 126 // In 64 bit, assign 64/32 bit values to 8 byte stack 127 CCIfSubtarget<"is64Bit()", CCIfType<[i32, i64, f32, f64], 128 CCAssignToStack<8, 8>>>, 129 130 // In 32 bit, assign 64/32 bit values to 8/4 byte stack 131 CCIfType<[i32, f32], CCAssignToStack<4, 4>>, 132 CCIfType<[i64, f64], CCAssignToStack<8, 4>>, 133 134 // MMX type gets 8 byte slot in stack , while alignment depends on target 135 CCIfSubtarget<"is64Bit()", CCIfType<[x86mmx], CCAssignToStack<8, 8>>>, 136 CCIfType<[x86mmx], CCAssignToStack<8, 4>>, 137 138 // float 128 get stack slots whose size and alignment depends 139 // on the subtarget. 140 CCIfType<[f80, f128], CCAssignToStack<0, 0>>, 141 142 // Vectors get 16-byte stack slots that are 16-byte aligned. 143 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 144 CCAssignToStack<16, 16>>, 145 146 // 256-bit vectors get 32-byte stack slots that are 32-byte aligned. 147 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 148 CCAssignToStack<32, 32>>, 149 150 // 512-bit vectors get 64-byte stack slots that are 64-byte aligned. 151 CCIfType<[v16i32, v8i64, v16f32, v8f64], CCAssignToStack<64, 64>> 152]>; 153 154def RetCC_#NAME : CallingConv<[ 155 // Promote i1, v1i1, v8i1 arguments to i8. 156 CCIfType<[i1, v1i1, v8i1], CCPromoteToType<i8>>, 157 158 // Promote v16i1 arguments to i16. 159 CCIfType<[v16i1], CCPromoteToType<i16>>, 160 161 // Promote v32i1 arguments to i32. 162 CCIfType<[v32i1], CCPromoteToType<i32>>, 163 164 // bool, char, int, enum, long, pointer --> GPR 165 CCIfType<[i8], CCAssignToReg<RC.GPR_8>>, 166 CCIfType<[i16], CCAssignToReg<RC.GPR_16>>, 167 CCIfType<[i32], CCAssignToReg<RC.GPR_32>>, 168 169 // long long, __int64 --> GPR 170 CCIfType<[i64], CCAssignToReg<RC.GPR_64>>, 171 172 // __mmask64 (v64i1) --> GPR64 (for x64) or 2 x GPR32 (for IA32) 173 CCIfType<[v64i1], CCPromoteToType<i64>>, 174 CCIfSubtarget<"is64Bit()", CCIfType<[i64], 175 CCAssignToReg<RC.GPR_64>>>, 176 CCIfSubtarget<"is32Bit()", CCIfType<[i64], 177 CCCustom<"CC_X86_32_RegCall_Assign2Regs">>>, 178 179 // long double --> FP 180 CCIfType<[f80], CCAssignToReg<RC.FP_RET>>, 181 182 // float, double, float128 --> XMM 183 CCIfType<[f32, f64, f128], 184 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>, 185 186 // __m128, __m128i, __m128d --> XMM 187 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 188 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>, 189 190 // __m256, __m256i, __m256d --> YMM 191 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 192 CCIfSubtarget<"hasAVX()", CCAssignToReg<RC.YMM>>>, 193 194 // __m512, __m512i, __m512d --> ZMM 195 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 196 CCIfSubtarget<"hasAVX512()", CCAssignToReg<RC.ZMM>>> 197]>; 198} 199 200//===----------------------------------------------------------------------===// 201// Return Value Calling Conventions 202//===----------------------------------------------------------------------===// 203 204// Return-value conventions common to all X86 CC's. 205def RetCC_X86Common : CallingConv<[ 206 // Scalar values are returned in AX first, then DX. For i8, the ABI 207 // requires the values to be in AL and AH, however this code uses AL and DL 208 // instead. This is because using AH for the second register conflicts with 209 // the way LLVM does multiple return values -- a return of {i16,i8} would end 210 // up in AX and AH, which overlap. Front-ends wishing to conform to the ABI 211 // for functions that return two i8 values are currently expected to pack the 212 // values into an i16 (which uses AX, and thus AL:AH). 213 // 214 // For code that doesn't care about the ABI, we allow returning more than two 215 // integer values in registers. 216 CCIfType<[v1i1], CCPromoteToType<i8>>, 217 CCIfType<[i1], CCPromoteToType<i8>>, 218 CCIfType<[i8] , CCAssignToReg<[AL, DL, CL]>>, 219 CCIfType<[i16], CCAssignToReg<[AX, DX, CX]>>, 220 CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>, 221 CCIfType<[i64], CCAssignToReg<[RAX, RDX, RCX]>>, 222 223 // Boolean vectors of AVX-512 are returned in SIMD registers. 224 // The call from AVX to AVX-512 function should work, 225 // since the boolean types in AVX/AVX2 are promoted by default. 226 CCIfType<[v2i1], CCPromoteToType<v2i64>>, 227 CCIfType<[v4i1], CCPromoteToType<v4i32>>, 228 CCIfType<[v8i1], CCPromoteToType<v8i16>>, 229 CCIfType<[v16i1], CCPromoteToType<v16i8>>, 230 CCIfType<[v32i1], CCPromoteToType<v32i8>>, 231 CCIfType<[v64i1], CCPromoteToType<v64i8>>, 232 233 // Vector types are returned in XMM0 and XMM1, when they fit. XMM2 and XMM3 234 // can only be used by ABI non-compliant code. If the target doesn't have XMM 235 // registers, it won't have vector types. 236 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 237 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>, 238 239 // 256-bit vectors are returned in YMM0 and XMM1, when they fit. YMM2 and YMM3 240 // can only be used by ABI non-compliant code. This vector type is only 241 // supported while using the AVX target feature. 242 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 243 CCAssignToReg<[YMM0,YMM1,YMM2,YMM3]>>, 244 245 // 512-bit vectors are returned in ZMM0 and ZMM1, when they fit. ZMM2 and ZMM3 246 // can only be used by ABI non-compliant code. This vector type is only 247 // supported while using the AVX-512 target feature. 248 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 249 CCAssignToReg<[ZMM0,ZMM1,ZMM2,ZMM3]>>, 250 251 // MMX vector types are always returned in MM0. If the target doesn't have 252 // MM0, it doesn't support these vector types. 253 CCIfType<[x86mmx], CCAssignToReg<[MM0]>>, 254 255 // Long double types are always returned in FP0 (even with SSE), 256 // except on Win64. 257 CCIfNotSubtarget<"isTargetWin64()", CCIfType<[f80], CCAssignToReg<[FP0, FP1]>>> 258]>; 259 260// X86-32 C return-value convention. 261def RetCC_X86_32_C : CallingConv<[ 262 // The X86-32 calling convention returns FP values in FP0, unless marked 263 // with "inreg" (used here to distinguish one kind of reg from another, 264 // weirdly; this is really the sse-regparm calling convention) in which 265 // case they use XMM0, otherwise it is the same as the common X86 calling 266 // conv. 267 CCIfInReg<CCIfSubtarget<"hasSSE2()", 268 CCIfType<[f32, f64], CCAssignToReg<[XMM0,XMM1,XMM2]>>>>, 269 CCIfType<[f32,f64], CCAssignToReg<[FP0, FP1]>>, 270 CCDelegateTo<RetCC_X86Common> 271]>; 272 273// X86-32 FastCC return-value convention. 274def RetCC_X86_32_Fast : CallingConv<[ 275 // The X86-32 fastcc returns 1, 2, or 3 FP values in XMM0-2 if the target has 276 // SSE2. 277 // This can happen when a float, 2 x float, or 3 x float vector is split by 278 // target lowering, and is returned in 1-3 sse regs. 279 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>, 280 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>, 281 282 // For integers, ECX can be used as an extra return register 283 CCIfType<[i8], CCAssignToReg<[AL, DL, CL]>>, 284 CCIfType<[i16], CCAssignToReg<[AX, DX, CX]>>, 285 CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>, 286 287 // Otherwise, it is the same as the common X86 calling convention. 288 CCDelegateTo<RetCC_X86Common> 289]>; 290 291// Intel_OCL_BI return-value convention. 292def RetCC_Intel_OCL_BI : CallingConv<[ 293 // Vector types are returned in XMM0,XMM1,XMMM2 and XMM3. 294 CCIfType<[f32, f64, v4i32, v2i64, v4f32, v2f64], 295 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>, 296 297 // 256-bit FP vectors 298 // No more than 4 registers 299 CCIfType<[v8f32, v4f64, v8i32, v4i64], 300 CCAssignToReg<[YMM0,YMM1,YMM2,YMM3]>>, 301 302 // 512-bit FP vectors 303 CCIfType<[v16f32, v8f64, v16i32, v8i64], 304 CCAssignToReg<[ZMM0,ZMM1,ZMM2,ZMM3]>>, 305 306 // i32, i64 in the standard way 307 CCDelegateTo<RetCC_X86Common> 308]>; 309 310// X86-32 HiPE return-value convention. 311def RetCC_X86_32_HiPE : CallingConv<[ 312 // Promote all types to i32 313 CCIfType<[i8, i16], CCPromoteToType<i32>>, 314 315 // Return: HP, P, VAL1, VAL2 316 CCIfType<[i32], CCAssignToReg<[ESI, EBP, EAX, EDX]>> 317]>; 318 319// X86-32 Vectorcall return-value convention. 320def RetCC_X86_32_VectorCall : CallingConv<[ 321 // Floating Point types are returned in XMM0,XMM1,XMMM2 and XMM3. 322 CCIfType<[f32, f64, f128], 323 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>, 324 325 // Return integers in the standard way. 326 CCDelegateTo<RetCC_X86Common> 327]>; 328 329// X86-64 C return-value convention. 330def RetCC_X86_64_C : CallingConv<[ 331 // The X86-64 calling convention always returns FP values in XMM0. 332 CCIfType<[f32], CCAssignToReg<[XMM0, XMM1]>>, 333 CCIfType<[f64], CCAssignToReg<[XMM0, XMM1]>>, 334 CCIfType<[f128], CCAssignToReg<[XMM0, XMM1]>>, 335 336 // MMX vector types are always returned in XMM0. 337 CCIfType<[x86mmx], CCAssignToReg<[XMM0, XMM1]>>, 338 339 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>, 340 341 CCDelegateTo<RetCC_X86Common> 342]>; 343 344// X86-Win64 C return-value convention. 345def RetCC_X86_Win64_C : CallingConv<[ 346 // The X86-Win64 calling convention always returns __m64 values in RAX. 347 CCIfType<[x86mmx], CCBitConvertToType<i64>>, 348 349 // Otherwise, everything is the same as 'normal' X86-64 C CC. 350 CCDelegateTo<RetCC_X86_64_C> 351]>; 352 353// X86-64 vectorcall return-value convention. 354def RetCC_X86_64_Vectorcall : CallingConv<[ 355 // Vectorcall calling convention always returns FP values in XMMs. 356 CCIfType<[f32, f64, f128], 357 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>, 358 359 // Otherwise, everything is the same as Windows X86-64 C CC. 360 CCDelegateTo<RetCC_X86_Win64_C> 361]>; 362 363// X86-64 HiPE return-value convention. 364def RetCC_X86_64_HiPE : CallingConv<[ 365 // Promote all types to i64 366 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>, 367 368 // Return: HP, P, VAL1, VAL2 369 CCIfType<[i64], CCAssignToReg<[R15, RBP, RAX, RDX]>> 370]>; 371 372// X86-64 WebKit_JS return-value convention. 373def RetCC_X86_64_WebKit_JS : CallingConv<[ 374 // Promote all types to i64 375 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>, 376 377 // Return: RAX 378 CCIfType<[i64], CCAssignToReg<[RAX]>> 379]>; 380 381def RetCC_X86_64_Swift : CallingConv<[ 382 383 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>, 384 385 // For integers, ECX, R8D can be used as extra return registers. 386 CCIfType<[v1i1], CCPromoteToType<i8>>, 387 CCIfType<[i1], CCPromoteToType<i8>>, 388 CCIfType<[i8] , CCAssignToReg<[AL, DL, CL, R8B]>>, 389 CCIfType<[i16], CCAssignToReg<[AX, DX, CX, R8W]>>, 390 CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX, R8D]>>, 391 CCIfType<[i64], CCAssignToReg<[RAX, RDX, RCX, R8]>>, 392 393 // XMM0, XMM1, XMM2 and XMM3 can be used to return FP values. 394 CCIfType<[f32], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>, 395 CCIfType<[f64], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>, 396 CCIfType<[f128], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>, 397 398 // MMX vector types are returned in XMM0, XMM1, XMM2 and XMM3. 399 CCIfType<[x86mmx], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>, 400 CCDelegateTo<RetCC_X86Common> 401]>; 402 403// X86-64 AnyReg return-value convention. No explicit register is specified for 404// the return-value. The register allocator is allowed and expected to choose 405// any free register. 406// 407// This calling convention is currently only supported by the stackmap and 408// patchpoint intrinsics. All other uses will result in an assert on Debug 409// builds. On Release builds we fallback to the X86 C calling convention. 410def RetCC_X86_64_AnyReg : CallingConv<[ 411 CCCustom<"CC_X86_AnyReg_Error"> 412]>; 413 414// X86-64 HHVM return-value convention. 415def RetCC_X86_64_HHVM: CallingConv<[ 416 // Promote all types to i64 417 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>, 418 419 // Return: could return in any GP register save RSP and R12. 420 CCIfType<[i64], CCAssignToReg<[RBX, RBP, RDI, RSI, RDX, RCX, R8, R9, 421 RAX, R10, R11, R13, R14, R15]>> 422]>; 423 424 425defm X86_32_RegCall : 426 X86_RegCall_base<RC_X86_32_RegCall>; 427defm X86_Win64_RegCall : 428 X86_RegCall_base<RC_X86_64_RegCall_Win>; 429defm X86_SysV64_RegCall : 430 X86_RegCall_base<RC_X86_64_RegCall_SysV>; 431 432// This is the root return-value convention for the X86-32 backend. 433def RetCC_X86_32 : CallingConv<[ 434 // If FastCC, use RetCC_X86_32_Fast. 435 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>, 436 // If HiPE, use RetCC_X86_32_HiPE. 437 CCIfCC<"CallingConv::HiPE", CCDelegateTo<RetCC_X86_32_HiPE>>, 438 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<RetCC_X86_32_VectorCall>>, 439 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<RetCC_X86_32_RegCall>>, 440 441 // Otherwise, use RetCC_X86_32_C. 442 CCDelegateTo<RetCC_X86_32_C> 443]>; 444 445// This is the root return-value convention for the X86-64 backend. 446def RetCC_X86_64 : CallingConv<[ 447 // HiPE uses RetCC_X86_64_HiPE 448 CCIfCC<"CallingConv::HiPE", CCDelegateTo<RetCC_X86_64_HiPE>>, 449 450 // Handle JavaScript calls. 451 CCIfCC<"CallingConv::WebKit_JS", CCDelegateTo<RetCC_X86_64_WebKit_JS>>, 452 CCIfCC<"CallingConv::AnyReg", CCDelegateTo<RetCC_X86_64_AnyReg>>, 453 454 // Handle Swift calls. 455 CCIfCC<"CallingConv::Swift", CCDelegateTo<RetCC_X86_64_Swift>>, 456 457 // Handle explicit CC selection 458 CCIfCC<"CallingConv::Win64", CCDelegateTo<RetCC_X86_Win64_C>>, 459 CCIfCC<"CallingConv::X86_64_SysV", CCDelegateTo<RetCC_X86_64_C>>, 460 461 // Handle Vectorcall CC 462 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<RetCC_X86_64_Vectorcall>>, 463 464 // Handle HHVM calls. 465 CCIfCC<"CallingConv::HHVM", CCDelegateTo<RetCC_X86_64_HHVM>>, 466 467 CCIfCC<"CallingConv::X86_RegCall", 468 CCIfSubtarget<"isTargetWin64()", 469 CCDelegateTo<RetCC_X86_Win64_RegCall>>>, 470 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<RetCC_X86_SysV64_RegCall>>, 471 472 // Mingw64 and native Win64 use Win64 CC 473 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<RetCC_X86_Win64_C>>, 474 475 // Otherwise, drop to normal X86-64 CC 476 CCDelegateTo<RetCC_X86_64_C> 477]>; 478 479// This is the return-value convention used for the entire X86 backend. 480def RetCC_X86 : CallingConv<[ 481 482 // Check if this is the Intel OpenCL built-ins calling convention 483 CCIfCC<"CallingConv::Intel_OCL_BI", CCDelegateTo<RetCC_Intel_OCL_BI>>, 484 485 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>, 486 CCDelegateTo<RetCC_X86_32> 487]>; 488 489//===----------------------------------------------------------------------===// 490// X86-64 Argument Calling Conventions 491//===----------------------------------------------------------------------===// 492 493def CC_X86_64_C : CallingConv<[ 494 // Handles byval parameters. 495 CCIfByVal<CCPassByVal<8, 8>>, 496 497 // Promote i1/i8/i16/v1i1 arguments to i32. 498 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>, 499 500 // The 'nest' parameter, if any, is passed in R10. 501 CCIfNest<CCIfSubtarget<"isTarget64BitILP32()", CCAssignToReg<[R10D]>>>, 502 CCIfNest<CCAssignToReg<[R10]>>, 503 504 // Pass SwiftSelf in a callee saved register. 505 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R13]>>>, 506 507 // A SwiftError is passed in R12. 508 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>, 509 510 // For Swift Calling Convention, pass sret in %rax. 511 CCIfCC<"CallingConv::Swift", 512 CCIfSRet<CCIfType<[i64], CCAssignToReg<[RAX]>>>>, 513 514 // The first 6 integer arguments are passed in integer registers. 515 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>, 516 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>, 517 518 // The first 8 MMX vector arguments are passed in XMM registers on Darwin. 519 CCIfType<[x86mmx], 520 CCIfSubtarget<"isTargetDarwin()", 521 CCIfSubtarget<"hasSSE2()", 522 CCPromoteToType<v2i64>>>>, 523 524 // Boolean vectors of AVX-512 are passed in SIMD registers. 525 // The call from AVX to AVX-512 function should work, 526 // since the boolean types in AVX/AVX2 are promoted by default. 527 CCIfType<[v2i1], CCPromoteToType<v2i64>>, 528 CCIfType<[v4i1], CCPromoteToType<v4i32>>, 529 CCIfType<[v8i1], CCPromoteToType<v8i16>>, 530 CCIfType<[v16i1], CCPromoteToType<v16i8>>, 531 CCIfType<[v32i1], CCPromoteToType<v32i8>>, 532 CCIfType<[v64i1], CCPromoteToType<v64i8>>, 533 534 // The first 8 FP/Vector arguments are passed in XMM registers. 535 CCIfType<[f32, f64, f128, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 536 CCIfSubtarget<"hasSSE1()", 537 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>, 538 539 // The first 8 256-bit vector arguments are passed in YMM registers, unless 540 // this is a vararg function. 541 // FIXME: This isn't precisely correct; the x86-64 ABI document says that 542 // fixed arguments to vararg functions are supposed to be passed in 543 // registers. Actually modeling that would be a lot of work, though. 544 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 545 CCIfSubtarget<"hasAVX()", 546 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3, 547 YMM4, YMM5, YMM6, YMM7]>>>>, 548 549 // The first 8 512-bit vector arguments are passed in ZMM registers. 550 CCIfNotVarArg<CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 551 CCIfSubtarget<"hasAVX512()", 552 CCAssignToReg<[ZMM0, ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6, ZMM7]>>>>, 553 554 // Integer/FP values get stored in stack slots that are 8 bytes in size and 555 // 8-byte aligned if there are no more registers to hold them. 556 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>, 557 558 // Long doubles get stack slots whose size and alignment depends on the 559 // subtarget. 560 CCIfType<[f80, f128], CCAssignToStack<0, 0>>, 561 562 // Vectors get 16-byte stack slots that are 16-byte aligned. 563 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>, 564 565 // 256-bit vectors get 32-byte stack slots that are 32-byte aligned. 566 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 567 CCAssignToStack<32, 32>>, 568 569 // 512-bit vectors get 64-byte stack slots that are 64-byte aligned. 570 CCIfType<[v16i32, v8i64, v16f32, v8f64], 571 CCAssignToStack<64, 64>> 572]>; 573 574// Calling convention for X86-64 HHVM. 575def CC_X86_64_HHVM : CallingConv<[ 576 // Use all/any GP registers for args, except RSP. 577 CCIfType<[i64], CCAssignToReg<[RBX, R12, RBP, R15, 578 RDI, RSI, RDX, RCX, R8, R9, 579 RAX, R10, R11, R13, R14]>> 580]>; 581 582// Calling convention for helper functions in HHVM. 583def CC_X86_64_HHVM_C : CallingConv<[ 584 // Pass the first argument in RBP. 585 CCIfType<[i64], CCAssignToReg<[RBP]>>, 586 587 // Otherwise it's the same as the regular C calling convention. 588 CCDelegateTo<CC_X86_64_C> 589]>; 590 591// Calling convention used on Win64 592def CC_X86_Win64_C : CallingConv<[ 593 // FIXME: Handle byval stuff. 594 // FIXME: Handle varargs. 595 596 // Promote i1/v1i1 arguments to i8. 597 CCIfType<[i1, v1i1], CCPromoteToType<i8>>, 598 599 // The 'nest' parameter, if any, is passed in R10. 600 CCIfNest<CCAssignToReg<[R10]>>, 601 602 // A SwiftError is passed in R12. 603 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>, 604 605 // 128 bit vectors are passed by pointer 606 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCPassIndirect<i64>>, 607 608 609 // 256 bit vectors are passed by pointer 610 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], CCPassIndirect<i64>>, 611 612 // 512 bit vectors are passed by pointer 613 CCIfType<[v16i32, v16f32, v8f64, v8i64], CCPassIndirect<i64>>, 614 615 // Long doubles are passed by pointer 616 CCIfType<[f80], CCPassIndirect<i64>>, 617 618 // The first 4 MMX vector arguments are passed in GPRs. 619 CCIfType<[x86mmx], CCBitConvertToType<i64>>, 620 621 // The first 4 integer arguments are passed in integer registers. 622 CCIfType<[i8 ], CCAssignToRegWithShadow<[CL , DL , R8B , R9B ], 623 [XMM0, XMM1, XMM2, XMM3]>>, 624 CCIfType<[i16], CCAssignToRegWithShadow<[CX , DX , R8W , R9W ], 625 [XMM0, XMM1, XMM2, XMM3]>>, 626 CCIfType<[i32], CCAssignToRegWithShadow<[ECX , EDX , R8D , R9D ], 627 [XMM0, XMM1, XMM2, XMM3]>>, 628 629 // Do not pass the sret argument in RCX, the Win64 thiscall calling 630 // convention requires "this" to be passed in RCX. 631 CCIfCC<"CallingConv::X86_ThisCall", 632 CCIfSRet<CCIfType<[i64], CCAssignToRegWithShadow<[RDX , R8 , R9 ], 633 [XMM1, XMM2, XMM3]>>>>, 634 635 CCIfType<[i64], CCAssignToRegWithShadow<[RCX , RDX , R8 , R9 ], 636 [XMM0, XMM1, XMM2, XMM3]>>, 637 638 // The first 4 FP/Vector arguments are passed in XMM registers. 639 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 640 CCAssignToRegWithShadow<[XMM0, XMM1, XMM2, XMM3], 641 [RCX , RDX , R8 , R9 ]>>, 642 643 // Integer/FP values get stored in stack slots that are 8 bytes in size and 644 // 8-byte aligned if there are no more registers to hold them. 645 CCIfType<[i8, i16, i32, i64, f32, f64], CCAssignToStack<8, 8>> 646]>; 647 648def CC_X86_Win64_VectorCall : CallingConv<[ 649 CCCustom<"CC_X86_64_VectorCall">, 650 651 // Delegate to fastcall to handle integer types. 652 CCDelegateTo<CC_X86_Win64_C> 653]>; 654 655 656def CC_X86_64_GHC : CallingConv<[ 657 // Promote i8/i16/i32 arguments to i64. 658 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>, 659 660 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, R5, R6, SpLim 661 CCIfType<[i64], 662 CCAssignToReg<[R13, RBP, R12, RBX, R14, RSI, RDI, R8, R9, R15]>>, 663 664 // Pass in STG registers: F1, F2, F3, F4, D1, D2 665 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 666 CCIfSubtarget<"hasSSE1()", 667 CCAssignToReg<[XMM1, XMM2, XMM3, XMM4, XMM5, XMM6]>>>, 668 // AVX 669 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 670 CCIfSubtarget<"hasAVX()", 671 CCAssignToReg<[YMM1, YMM2, YMM3, YMM4, YMM5, YMM6]>>>, 672 // AVX-512 673 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 674 CCIfSubtarget<"hasAVX512()", 675 CCAssignToReg<[ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6]>>> 676]>; 677 678def CC_X86_64_HiPE : CallingConv<[ 679 // Promote i8/i16/i32 arguments to i64. 680 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>, 681 682 // Pass in VM's registers: HP, P, ARG0, ARG1, ARG2, ARG3 683 CCIfType<[i64], CCAssignToReg<[R15, RBP, RSI, RDX, RCX, R8]>>, 684 685 // Integer/FP values get stored in stack slots that are 8 bytes in size and 686 // 8-byte aligned if there are no more registers to hold them. 687 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>> 688]>; 689 690def CC_X86_64_WebKit_JS : CallingConv<[ 691 // Promote i8/i16 arguments to i32. 692 CCIfType<[i8, i16], CCPromoteToType<i32>>, 693 694 // Only the first integer argument is passed in register. 695 CCIfType<[i32], CCAssignToReg<[EAX]>>, 696 CCIfType<[i64], CCAssignToReg<[RAX]>>, 697 698 // The remaining integer arguments are passed on the stack. 32bit integer and 699 // floating-point arguments are aligned to 4 byte and stored in 4 byte slots. 700 // 64bit integer and floating-point arguments are aligned to 8 byte and stored 701 // in 8 byte stack slots. 702 CCIfType<[i32, f32], CCAssignToStack<4, 4>>, 703 CCIfType<[i64, f64], CCAssignToStack<8, 8>> 704]>; 705 706// No explicit register is specified for the AnyReg calling convention. The 707// register allocator may assign the arguments to any free register. 708// 709// This calling convention is currently only supported by the stackmap and 710// patchpoint intrinsics. All other uses will result in an assert on Debug 711// builds. On Release builds we fallback to the X86 C calling convention. 712def CC_X86_64_AnyReg : CallingConv<[ 713 CCCustom<"CC_X86_AnyReg_Error"> 714]>; 715 716//===----------------------------------------------------------------------===// 717// X86 C Calling Convention 718//===----------------------------------------------------------------------===// 719 720/// CC_X86_32_Vector_Common - In all X86-32 calling conventions, extra vector 721/// values are spilled on the stack. 722def CC_X86_32_Vector_Common : CallingConv<[ 723 // Other SSE vectors get 16-byte stack slots that are 16-byte aligned. 724 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>, 725 726 // 256-bit AVX vectors get 32-byte stack slots that are 32-byte aligned. 727 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 728 CCAssignToStack<32, 32>>, 729 730 // 512-bit AVX 512-bit vectors get 64-byte stack slots that are 64-byte aligned. 731 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 732 CCAssignToStack<64, 64>> 733]>; 734 735// CC_X86_32_Vector_Standard - The first 3 vector arguments are passed in 736// vector registers 737def CC_X86_32_Vector_Standard : CallingConv<[ 738 // SSE vector arguments are passed in XMM registers. 739 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 740 CCAssignToReg<[XMM0, XMM1, XMM2]>>>, 741 742 // AVX 256-bit vector arguments are passed in YMM registers. 743 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 744 CCIfSubtarget<"hasAVX()", 745 CCAssignToReg<[YMM0, YMM1, YMM2]>>>>, 746 747 // AVX 512-bit vector arguments are passed in ZMM registers. 748 CCIfNotVarArg<CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 749 CCAssignToReg<[ZMM0, ZMM1, ZMM2]>>>, 750 751 CCDelegateTo<CC_X86_32_Vector_Common> 752]>; 753 754// CC_X86_32_Vector_Darwin - The first 4 vector arguments are passed in 755// vector registers. 756def CC_X86_32_Vector_Darwin : CallingConv<[ 757 // SSE vector arguments are passed in XMM registers. 758 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 759 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>>, 760 761 // AVX 256-bit vector arguments are passed in YMM registers. 762 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], 763 CCIfSubtarget<"hasAVX()", 764 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3]>>>>, 765 766 // AVX 512-bit vector arguments are passed in ZMM registers. 767 CCIfNotVarArg<CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64], 768 CCAssignToReg<[ZMM0, ZMM1, ZMM2, ZMM3]>>>, 769 770 CCDelegateTo<CC_X86_32_Vector_Common> 771]>; 772 773/// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP 774/// values are spilled on the stack. 775def CC_X86_32_Common : CallingConv<[ 776 // Handles byval parameters. 777 CCIfByVal<CCPassByVal<4, 4>>, 778 779 // The first 3 float or double arguments, if marked 'inreg' and if the call 780 // is not a vararg call and if SSE2 is available, are passed in SSE registers. 781 CCIfNotVarArg<CCIfInReg<CCIfType<[f32,f64], 782 CCIfSubtarget<"hasSSE2()", 783 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>>, 784 785 // The first 3 __m64 vector arguments are passed in mmx registers if the 786 // call is not a vararg call. 787 CCIfNotVarArg<CCIfType<[x86mmx], 788 CCAssignToReg<[MM0, MM1, MM2]>>>, 789 790 // Integer/Float values get stored in stack slots that are 4 bytes in 791 // size and 4-byte aligned. 792 CCIfType<[i32, f32], CCAssignToStack<4, 4>>, 793 794 // Doubles get 8-byte slots that are 4-byte aligned. 795 CCIfType<[f64], CCAssignToStack<8, 4>>, 796 797 // Long doubles get slots whose size depends on the subtarget. 798 CCIfType<[f80], CCAssignToStack<0, 4>>, 799 800 // Boolean vectors of AVX-512 are passed in SIMD registers. 801 // The call from AVX to AVX-512 function should work, 802 // since the boolean types in AVX/AVX2 are promoted by default. 803 CCIfType<[v2i1], CCPromoteToType<v2i64>>, 804 CCIfType<[v4i1], CCPromoteToType<v4i32>>, 805 CCIfType<[v8i1], CCPromoteToType<v8i16>>, 806 CCIfType<[v16i1], CCPromoteToType<v16i8>>, 807 CCIfType<[v32i1], CCPromoteToType<v32i8>>, 808 CCIfType<[v64i1], CCPromoteToType<v64i8>>, 809 810 // __m64 vectors get 8-byte stack slots that are 4-byte aligned. They are 811 // passed in the parameter area. 812 CCIfType<[x86mmx], CCAssignToStack<8, 4>>, 813 814 // Darwin passes vectors in a form that differs from the i386 psABI 815 CCIfSubtarget<"isTargetDarwin()", CCDelegateTo<CC_X86_32_Vector_Darwin>>, 816 817 // Otherwise, drop to 'normal' X86-32 CC 818 CCDelegateTo<CC_X86_32_Vector_Standard> 819]>; 820 821def CC_X86_32_C : CallingConv<[ 822 // Promote i1/i8/i16/v1i1 arguments to i32. 823 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>, 824 825 // The 'nest' parameter, if any, is passed in ECX. 826 CCIfNest<CCAssignToReg<[ECX]>>, 827 828 // The first 3 integer arguments, if marked 'inreg' and if the call is not 829 // a vararg call, are passed in integer registers. 830 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>, 831 832 // Otherwise, same as everything else. 833 CCDelegateTo<CC_X86_32_Common> 834]>; 835 836def CC_X86_32_MCU : CallingConv<[ 837 // Handles byval parameters. Note that, like FastCC, we can't rely on 838 // the delegation to CC_X86_32_Common because that happens after code that 839 // puts arguments in registers. 840 CCIfByVal<CCPassByVal<4, 4>>, 841 842 // Promote i1/i8/i16/v1i1 arguments to i32. 843 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>, 844 845 // If the call is not a vararg call, some arguments may be passed 846 // in integer registers. 847 CCIfNotVarArg<CCIfType<[i32], CCCustom<"CC_X86_32_MCUInReg">>>, 848 849 // Otherwise, same as everything else. 850 CCDelegateTo<CC_X86_32_Common> 851]>; 852 853def CC_X86_32_FastCall : CallingConv<[ 854 // Promote i1 to i8. 855 CCIfType<[i1], CCPromoteToType<i8>>, 856 857 // The 'nest' parameter, if any, is passed in EAX. 858 CCIfNest<CCAssignToReg<[EAX]>>, 859 860 // The first 2 integer arguments are passed in ECX/EDX 861 CCIfInReg<CCIfType<[ i8], CCAssignToReg<[ CL, DL]>>>, 862 CCIfInReg<CCIfType<[i16], CCAssignToReg<[ CX, DX]>>>, 863 CCIfInReg<CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>>, 864 865 // Otherwise, same as everything else. 866 CCDelegateTo<CC_X86_32_Common> 867]>; 868 869def CC_X86_Win32_VectorCall : CallingConv<[ 870 // Pass floating point in XMMs 871 CCCustom<"CC_X86_32_VectorCall">, 872 873 // Delegate to fastcall to handle integer types. 874 CCDelegateTo<CC_X86_32_FastCall> 875]>; 876 877def CC_X86_32_ThisCall_Common : CallingConv<[ 878 // The first integer argument is passed in ECX 879 CCIfType<[i32], CCAssignToReg<[ECX]>>, 880 881 // Otherwise, same as everything else. 882 CCDelegateTo<CC_X86_32_Common> 883]>; 884 885def CC_X86_32_ThisCall_Mingw : CallingConv<[ 886 // Promote i1/i8/i16/v1i1 arguments to i32. 887 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>, 888 889 CCDelegateTo<CC_X86_32_ThisCall_Common> 890]>; 891 892def CC_X86_32_ThisCall_Win : CallingConv<[ 893 // Promote i1/i8/i16/v1i1 arguments to i32. 894 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>, 895 896 // Pass sret arguments indirectly through stack. 897 CCIfSRet<CCAssignToStack<4, 4>>, 898 899 CCDelegateTo<CC_X86_32_ThisCall_Common> 900]>; 901 902def CC_X86_32_ThisCall : CallingConv<[ 903 CCIfSubtarget<"isTargetCygMing()", CCDelegateTo<CC_X86_32_ThisCall_Mingw>>, 904 CCDelegateTo<CC_X86_32_ThisCall_Win> 905]>; 906 907def CC_X86_32_FastCC : CallingConv<[ 908 // Handles byval parameters. Note that we can't rely on the delegation 909 // to CC_X86_32_Common for this because that happens after code that 910 // puts arguments in registers. 911 CCIfByVal<CCPassByVal<4, 4>>, 912 913 // Promote i1/i8/i16/v1i1 arguments to i32. 914 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>, 915 916 // The 'nest' parameter, if any, is passed in EAX. 917 CCIfNest<CCAssignToReg<[EAX]>>, 918 919 // The first 2 integer arguments are passed in ECX/EDX 920 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>, 921 922 // The first 3 float or double arguments, if the call is not a vararg 923 // call and if SSE2 is available, are passed in SSE registers. 924 CCIfNotVarArg<CCIfType<[f32,f64], 925 CCIfSubtarget<"hasSSE2()", 926 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>, 927 928 // Doubles get 8-byte slots that are 8-byte aligned. 929 CCIfType<[f64], CCAssignToStack<8, 8>>, 930 931 // Otherwise, same as everything else. 932 CCDelegateTo<CC_X86_32_Common> 933]>; 934 935def CC_X86_32_GHC : CallingConv<[ 936 // Promote i8/i16 arguments to i32. 937 CCIfType<[i8, i16], CCPromoteToType<i32>>, 938 939 // Pass in STG registers: Base, Sp, Hp, R1 940 CCIfType<[i32], CCAssignToReg<[EBX, EBP, EDI, ESI]>> 941]>; 942 943def CC_X86_32_HiPE : CallingConv<[ 944 // Promote i8/i16 arguments to i32. 945 CCIfType<[i8, i16], CCPromoteToType<i32>>, 946 947 // Pass in VM's registers: HP, P, ARG0, ARG1, ARG2 948 CCIfType<[i32], CCAssignToReg<[ESI, EBP, EAX, EDX, ECX]>>, 949 950 // Integer/Float values get stored in stack slots that are 4 bytes in 951 // size and 4-byte aligned. 952 CCIfType<[i32, f32], CCAssignToStack<4, 4>> 953]>; 954 955// X86-64 Intel OpenCL built-ins calling convention. 956def CC_Intel_OCL_BI : CallingConv<[ 957 958 CCIfType<[i32], CCIfSubtarget<"isTargetWin64()", CCAssignToReg<[ECX, EDX, R8D, R9D]>>>, 959 CCIfType<[i64], CCIfSubtarget<"isTargetWin64()", CCAssignToReg<[RCX, RDX, R8, R9 ]>>>, 960 961 CCIfType<[i32], CCIfSubtarget<"is64Bit()", CCAssignToReg<[EDI, ESI, EDX, ECX]>>>, 962 CCIfType<[i64], CCIfSubtarget<"is64Bit()", CCAssignToReg<[RDI, RSI, RDX, RCX]>>>, 963 964 CCIfType<[i32], CCAssignToStack<4, 4>>, 965 966 // The SSE vector arguments are passed in XMM registers. 967 CCIfType<[f32, f64, v4i32, v2i64, v4f32, v2f64], 968 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>, 969 970 // The 256-bit vector arguments are passed in YMM registers. 971 CCIfType<[v8f32, v4f64, v8i32, v4i64], 972 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3]>>, 973 974 // The 512-bit vector arguments are passed in ZMM registers. 975 CCIfType<[v16f32, v8f64, v16i32, v8i64], 976 CCAssignToReg<[ZMM0, ZMM1, ZMM2, ZMM3]>>, 977 978 // Pass masks in mask registers 979 CCIfType<[v16i1, v8i1], CCAssignToReg<[K1]>>, 980 981 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>, 982 CCIfSubtarget<"is64Bit()", CCDelegateTo<CC_X86_64_C>>, 983 CCDelegateTo<CC_X86_32_C> 984]>; 985 986def CC_X86_32_Intr : CallingConv<[ 987 CCAssignToStack<4, 4> 988]>; 989 990def CC_X86_64_Intr : CallingConv<[ 991 CCAssignToStack<8, 8> 992]>; 993 994//===----------------------------------------------------------------------===// 995// X86 Root Argument Calling Conventions 996//===----------------------------------------------------------------------===// 997 998// This is the root argument convention for the X86-32 backend. 999def CC_X86_32 : CallingConv<[ 1000 // X86_INTR calling convention is valid in MCU target and should override the 1001 // MCU calling convention. Thus, this should be checked before isTargetMCU(). 1002 CCIfCC<"CallingConv::X86_INTR", CCDelegateTo<CC_X86_32_Intr>>, 1003 CCIfSubtarget<"isTargetMCU()", CCDelegateTo<CC_X86_32_MCU>>, 1004 CCIfCC<"CallingConv::X86_FastCall", CCDelegateTo<CC_X86_32_FastCall>>, 1005 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<CC_X86_Win32_VectorCall>>, 1006 CCIfCC<"CallingConv::X86_ThisCall", CCDelegateTo<CC_X86_32_ThisCall>>, 1007 CCIfCC<"CallingConv::Fast", CCDelegateTo<CC_X86_32_FastCC>>, 1008 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_X86_32_GHC>>, 1009 CCIfCC<"CallingConv::HiPE", CCDelegateTo<CC_X86_32_HiPE>>, 1010 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<CC_X86_32_RegCall>>, 1011 1012 // Otherwise, drop to normal X86-32 CC 1013 CCDelegateTo<CC_X86_32_C> 1014]>; 1015 1016// This is the root argument convention for the X86-64 backend. 1017def CC_X86_64 : CallingConv<[ 1018 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_X86_64_GHC>>, 1019 CCIfCC<"CallingConv::HiPE", CCDelegateTo<CC_X86_64_HiPE>>, 1020 CCIfCC<"CallingConv::WebKit_JS", CCDelegateTo<CC_X86_64_WebKit_JS>>, 1021 CCIfCC<"CallingConv::AnyReg", CCDelegateTo<CC_X86_64_AnyReg>>, 1022 CCIfCC<"CallingConv::Win64", CCDelegateTo<CC_X86_Win64_C>>, 1023 CCIfCC<"CallingConv::X86_64_SysV", CCDelegateTo<CC_X86_64_C>>, 1024 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<CC_X86_Win64_VectorCall>>, 1025 CCIfCC<"CallingConv::HHVM", CCDelegateTo<CC_X86_64_HHVM>>, 1026 CCIfCC<"CallingConv::HHVM_C", CCDelegateTo<CC_X86_64_HHVM_C>>, 1027 CCIfCC<"CallingConv::X86_RegCall", 1028 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_RegCall>>>, 1029 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<CC_X86_SysV64_RegCall>>, 1030 CCIfCC<"CallingConv::X86_INTR", CCDelegateTo<CC_X86_64_Intr>>, 1031 1032 // Mingw64 and native Win64 use Win64 CC 1033 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>, 1034 1035 // Otherwise, drop to normal X86-64 CC 1036 CCDelegateTo<CC_X86_64_C> 1037]>; 1038 1039// This is the argument convention used for the entire X86 backend. 1040def CC_X86 : CallingConv<[ 1041 CCIfCC<"CallingConv::Intel_OCL_BI", CCDelegateTo<CC_Intel_OCL_BI>>, 1042 CCIfSubtarget<"is64Bit()", CCDelegateTo<CC_X86_64>>, 1043 CCDelegateTo<CC_X86_32> 1044]>; 1045 1046//===----------------------------------------------------------------------===// 1047// Callee-saved Registers. 1048//===----------------------------------------------------------------------===// 1049 1050def CSR_NoRegs : CalleeSavedRegs<(add)>; 1051 1052def CSR_32 : CalleeSavedRegs<(add ESI, EDI, EBX, EBP)>; 1053def CSR_64 : CalleeSavedRegs<(add RBX, R12, R13, R14, R15, RBP)>; 1054 1055def CSR_64_SwiftError : CalleeSavedRegs<(sub CSR_64, R12)>; 1056 1057def CSR_32EHRet : CalleeSavedRegs<(add EAX, EDX, CSR_32)>; 1058def CSR_64EHRet : CalleeSavedRegs<(add RAX, RDX, CSR_64)>; 1059 1060def CSR_Win64_NoSSE : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, R13, R14, R15)>; 1061 1062def CSR_Win64 : CalleeSavedRegs<(add CSR_Win64_NoSSE, 1063 (sequence "XMM%u", 6, 15))>; 1064 1065def CSR_Win64_SwiftError : CalleeSavedRegs<(sub CSR_Win64, R12)>; 1066 1067// The function used by Darwin to obtain the address of a thread-local variable 1068// uses rdi to pass a single parameter and rax for the return value. All other 1069// GPRs are preserved. 1070def CSR_64_TLS_Darwin : CalleeSavedRegs<(add CSR_64, RCX, RDX, RSI, 1071 R8, R9, R10, R11)>; 1072 1073// CSRs that are handled by prologue, epilogue. 1074def CSR_64_CXX_TLS_Darwin_PE : CalleeSavedRegs<(add RBP)>; 1075 1076// CSRs that are handled explicitly via copies. 1077def CSR_64_CXX_TLS_Darwin_ViaCopy : CalleeSavedRegs<(sub CSR_64_TLS_Darwin, RBP)>; 1078 1079// All GPRs - except r11 1080def CSR_64_RT_MostRegs : CalleeSavedRegs<(add CSR_64, RAX, RCX, RDX, RSI, RDI, 1081 R8, R9, R10, RSP)>; 1082 1083// All registers - except r11 1084def CSR_64_RT_AllRegs : CalleeSavedRegs<(add CSR_64_RT_MostRegs, 1085 (sequence "XMM%u", 0, 15))>; 1086def CSR_64_RT_AllRegs_AVX : CalleeSavedRegs<(add CSR_64_RT_MostRegs, 1087 (sequence "YMM%u", 0, 15))>; 1088 1089def CSR_64_MostRegs : CalleeSavedRegs<(add RBX, RCX, RDX, RSI, RDI, R8, R9, R10, 1090 R11, R12, R13, R14, R15, RBP, 1091 (sequence "XMM%u", 0, 15))>; 1092 1093def CSR_32_AllRegs : CalleeSavedRegs<(add EAX, EBX, ECX, EDX, EBP, ESI, 1094 EDI)>; 1095def CSR_32_AllRegs_SSE : CalleeSavedRegs<(add CSR_32_AllRegs, 1096 (sequence "XMM%u", 0, 7))>; 1097def CSR_32_AllRegs_AVX : CalleeSavedRegs<(add CSR_32_AllRegs, 1098 (sequence "YMM%u", 0, 7))>; 1099def CSR_32_AllRegs_AVX512 : CalleeSavedRegs<(add CSR_32_AllRegs, 1100 (sequence "ZMM%u", 0, 7), 1101 (sequence "K%u", 0, 7))>; 1102 1103def CSR_64_AllRegs : CalleeSavedRegs<(add CSR_64_MostRegs, RAX)>; 1104def CSR_64_AllRegs_NoSSE : CalleeSavedRegs<(add RAX, RBX, RCX, RDX, RSI, RDI, R8, R9, 1105 R10, R11, R12, R13, R14, R15, RBP)>; 1106def CSR_64_AllRegs_AVX : CalleeSavedRegs<(sub (add CSR_64_MostRegs, RAX, 1107 (sequence "YMM%u", 0, 15)), 1108 (sequence "XMM%u", 0, 15))>; 1109def CSR_64_AllRegs_AVX512 : CalleeSavedRegs<(sub (add CSR_64_MostRegs, RAX, 1110 (sequence "ZMM%u", 0, 31), 1111 (sequence "K%u", 0, 7)), 1112 (sequence "XMM%u", 0, 15))>; 1113 1114// Standard C + YMM6-15 1115def CSR_Win64_Intel_OCL_BI_AVX : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, 1116 R13, R14, R15, 1117 (sequence "YMM%u", 6, 15))>; 1118 1119def CSR_Win64_Intel_OCL_BI_AVX512 : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, 1120 R12, R13, R14, R15, 1121 (sequence "ZMM%u", 6, 21), 1122 K4, K5, K6, K7)>; 1123//Standard C + XMM 8-15 1124def CSR_64_Intel_OCL_BI : CalleeSavedRegs<(add CSR_64, 1125 (sequence "XMM%u", 8, 15))>; 1126 1127//Standard C + YMM 8-15 1128def CSR_64_Intel_OCL_BI_AVX : CalleeSavedRegs<(add CSR_64, 1129 (sequence "YMM%u", 8, 15))>; 1130 1131def CSR_64_Intel_OCL_BI_AVX512 : CalleeSavedRegs<(add RBX, RDI, RSI, R14, R15, 1132 (sequence "ZMM%u", 16, 31), 1133 K4, K5, K6, K7)>; 1134 1135// Only R12 is preserved for PHP calls in HHVM. 1136def CSR_64_HHVM : CalleeSavedRegs<(add R12)>; 1137 1138// Register calling convention preserves few GPR and XMM8-15 1139def CSR_32_RegCall_NoSSE : CalleeSavedRegs<(add ESI, EDI, EBX, EBP, ESP)>; 1140def CSR_32_RegCall : CalleeSavedRegs<(add CSR_32_RegCall_NoSSE, 1141 (sequence "XMM%u", 4, 7))>; 1142def CSR_Win64_RegCall_NoSSE : CalleeSavedRegs<(add RBX, RBP, RSP, 1143 (sequence "R%u", 10, 15))>; 1144def CSR_Win64_RegCall : CalleeSavedRegs<(add CSR_Win64_RegCall_NoSSE, 1145 (sequence "XMM%u", 8, 15))>; 1146def CSR_SysV64_RegCall_NoSSE : CalleeSavedRegs<(add RBX, RBP, RSP, 1147 (sequence "R%u", 12, 15))>; 1148def CSR_SysV64_RegCall : CalleeSavedRegs<(add CSR_SysV64_RegCall_NoSSE, 1149 (sequence "XMM%u", 8, 15))>; 1150 1151