Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 1 | //===- X86CallingConv.td - Calling Conventions for X86 32/64 ----*- C++ -*-===// |
| 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 | 3d55910 | 2007-02-28 04:51:41 +0000 | [diff] [blame^] | 15 | /// CCMatchIfSubtarget - Match if the current subtarget has a feature F. |
| 16 | class CCMatchIfSubtarget<string F, CCAction A> |
| 17 | : CCMatchIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().",F),A>; |
| 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. |
| 26 | CCMatchType<[i8] , CCAssignToReg<[AL]>>, |
| 27 | CCMatchType<[i16], CCAssignToReg<[AX]>>, |
| 28 | CCMatchType<[i32], CCAssignToReg<[EAX, EDX]>>, |
| 29 | CCMatchType<[i64], CCAssignToReg<[RAX, RDX]>>, |
| 30 | |
| 31 | // Vector types are always returned in XMM0. If the target doesn't have XMM0, |
| 32 | // it won't have vector types. |
| 33 | CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>> |
| 34 | ]>; |
| 35 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 36 | // X86-32 C return-value convention. |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 37 | def RetCC_X86_32_C : CallingConv<[ |
| 38 | // The X86-32 calling convention returns FP values in ST0, otherwise it is the |
| 39 | // same as the common X86 calling conv. |
| 40 | CCMatchType<[f32], CCAssignToReg<[ST0]>>, |
| 41 | CCMatchType<[f64], CCAssignToReg<[ST0]>>, |
| 42 | CCDelegateTo<RetCC_X86Common> |
| 43 | ]>; |
| 44 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 45 | // X86-32 FastCC return-value convention. |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 46 | def RetCC_X86_32_Fast : CallingConv<[ |
| 47 | // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2, |
| 48 | // otherwise it is the the C calling conventions. |
Chris Lattner | 3d55910 | 2007-02-28 04:51:41 +0000 | [diff] [blame^] | 49 | CCMatchType<[f32], CCMatchIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>, |
| 50 | CCMatchType<[f64], CCMatchIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>, |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 51 | CCDelegateTo<RetCC_X86Common> |
| 52 | ]>; |
| 53 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 54 | // X86-64 C return-value convention. |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 55 | def RetCC_X86_64_C : CallingConv<[ |
| 56 | // The X86-64 calling convention always returns FP values in XMM0. |
| 57 | CCMatchType<[f32], CCAssignToReg<[XMM0]>>, |
| 58 | CCMatchType<[f64], CCAssignToReg<[XMM0]>>, |
| 59 | CCDelegateTo<RetCC_X86Common> |
| 60 | ]>; |
| 61 | |
| 62 | |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 63 | |
| 64 | // This is the root return-value convention for the X86-32 backend. |
| 65 | def RetCC_X86_32 : CallingConv<[ |
| 66 | // If FastCC, use RetCC_X86_32_Fast. |
| 67 | CCMatchIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>, |
| 68 | // Otherwise, use RetCC_X86_32_C. |
| 69 | CCDelegateTo<RetCC_X86_32_C> |
| 70 | ]>; |
| 71 | |
| 72 | // This is the root return-value convention for the X86-64 backend. |
| 73 | def RetCC_X86_64 : CallingConv<[ |
| 74 | // Always just the same as C calling conv for X86-64. |
| 75 | CCDelegateTo<RetCC_X86_64_C> |
| 76 | ]>; |
| 77 | |
Chris Lattner | d637a8b | 2007-02-27 06:59:52 +0000 | [diff] [blame] | 78 | // This is the return-value convention used for the entire X86 backend. |
| 79 | def RetCC_X86 : CallingConv<[ |
Chris Lattner | 3d55910 | 2007-02-28 04:51:41 +0000 | [diff] [blame^] | 80 | CCMatchIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>, |
Chris Lattner | d637a8b | 2007-02-27 06:59:52 +0000 | [diff] [blame] | 81 | CCDelegateTo<RetCC_X86_32> |
| 82 | ]>; |
Chris Lattner | d50110d | 2007-02-27 05:51:05 +0000 | [diff] [blame] | 83 | |
Chris Lattner | 31c8a6d | 2007-02-26 18:17:14 +0000 | [diff] [blame] | 84 | //===----------------------------------------------------------------------===// |
| 85 | // Argument Calling Conventions |
| 86 | //===----------------------------------------------------------------------===// |
| 87 | |
| 88 | |
| 89 | def CC_X86_64_C : CallingConv<[ |
| 90 | // Promote i8/i16 arguments to i32. |
| 91 | CCMatchType<[i8, i16], CCPromoteToType<i32>>, |
| 92 | |
| 93 | // The first 6 integer arguments are passed in integer registers. |
| 94 | CCMatchType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>, |
| 95 | CCMatchType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>, |
| 96 | |
| 97 | // The first 8 FP/Vector arguments are passed in XMM registers. |
| 98 | CCMatchType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
| 99 | CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>, |
| 100 | |
| 101 | // Integer/FP values get stored in stack slots that are 8 bytes in size and |
| 102 | // 8-byte aligned if there are no more registers to hold them. |
| 103 | CCMatchType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>, |
| 104 | |
| 105 | // Vectors get 16-byte stack slots that are 16-byte aligned. |
| 106 | CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
| 107 | CCAssignToStack<16, 16>> |
| 108 | ]>; |
| 109 | |
| 110 | |