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 | |
| 15 | |
| 16 | class CCAction; |
| 17 | class CallingConv; |
| 18 | |
| 19 | |
| 20 | /// CCMatchType - If the current argument is one of the specified types, apply |
| 21 | /// Action A. |
| 22 | class CCMatchType<list<ValueType> VTs, CCAction A> : CCAction { |
| 23 | } |
| 24 | |
| 25 | /// CCMatchIf - If the predicate matches, apply A. |
| 26 | class CCMatchIf<string predicate, CCAction A> : CCAction { |
| 27 | string Predicate = predicate; |
| 28 | } |
| 29 | |
| 30 | /// CCAssignToReg - This action matches if there is a register in the specified |
| 31 | /// list that is still available. If so, it assigns the value to the first |
| 32 | /// available register and succeeds. |
| 33 | class CCAssignToReg<list<Register> regList> : CCAction { |
| 34 | list<Register> RegList = regList; |
| 35 | } |
| 36 | |
| 37 | /// CCAssignToStack - This action always matches: it assigns the value to a |
| 38 | /// stack slot of the specified size and alignment on the stack. |
| 39 | class CCAssignToStack<int size, int align> : CCAction { |
| 40 | int Size = size; |
| 41 | int Align = align; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | |
| 46 | /// CCPromoteToType - If applied, this promotes the specified current value to |
| 47 | /// the specified type. |
| 48 | class CCPromoteToType<ValueType destTy> : CCAction { |
| 49 | ValueType DestTy = destTy; |
| 50 | } |
| 51 | |
| 52 | /// CCDelegateTo - This action invokes the specified sub-calling-convention. It |
| 53 | /// is successful if the specified CC matches. |
| 54 | class CCDelegateTo<CallingConv cc> : CCAction { |
| 55 | CallingConv CC = cc; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | class CallingConv<list<CCAction> actions> { |
| 60 | list<CCAction> Actions = actions; |
| 61 | } |
| 62 | |
| 63 | //===----------------------------------------------------------------------===// |
| 64 | // Return Value Calling Conventions |
| 65 | //===----------------------------------------------------------------------===// |
| 66 | |
| 67 | def RetCC_X86Common : CallingConv<[ |
| 68 | // Scalar values are returned in AX first, then DX. |
| 69 | CCMatchType<[i8] , CCAssignToReg<[AL]>>, |
| 70 | CCMatchType<[i16], CCAssignToReg<[AX]>>, |
| 71 | CCMatchType<[i32], CCAssignToReg<[EAX, EDX]>>, |
| 72 | CCMatchType<[i64], CCAssignToReg<[RAX, RDX]>>, |
| 73 | |
| 74 | // Vector types are always returned in XMM0. If the target doesn't have XMM0, |
| 75 | // it won't have vector types. |
| 76 | CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>> |
| 77 | ]>; |
| 78 | |
| 79 | // Return conventions for the X86-32 C calling convention. |
| 80 | def RetCC_X86_32_C : CallingConv<[ |
| 81 | // The X86-32 calling convention returns FP values in ST0, otherwise it is the |
| 82 | // same as the common X86 calling conv. |
| 83 | CCMatchType<[f32], CCAssignToReg<[ST0]>>, |
| 84 | CCMatchType<[f64], CCAssignToReg<[ST0]>>, |
| 85 | CCDelegateTo<RetCC_X86Common> |
| 86 | ]>; |
| 87 | |
| 88 | // Return conventions for the X86-32 Fast calling convention. |
| 89 | def RetCC_X86_32_Fast : CallingConv<[ |
| 90 | // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2, |
| 91 | // otherwise it is the the C calling conventions. |
| 92 | CCMatchType<[f32], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>, |
| 93 | CCMatchType<[f64], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>, |
| 94 | CCDelegateTo<RetCC_X86Common> |
| 95 | ]>; |
| 96 | |
| 97 | // Return conventions for the X86-64 C calling convention. |
| 98 | def RetCC_X86_64_C : CallingConv<[ |
| 99 | // The X86-64 calling convention always returns FP values in XMM0. |
| 100 | CCMatchType<[f32], CCAssignToReg<[XMM0]>>, |
| 101 | CCMatchType<[f64], CCAssignToReg<[XMM0]>>, |
| 102 | CCDelegateTo<RetCC_X86Common> |
| 103 | ]>; |
| 104 | |
| 105 | |
| 106 | //===----------------------------------------------------------------------===// |
| 107 | // Argument Calling Conventions |
| 108 | //===----------------------------------------------------------------------===// |
| 109 | |
| 110 | |
| 111 | def CC_X86_64_C : CallingConv<[ |
| 112 | // Promote i8/i16 arguments to i32. |
| 113 | CCMatchType<[i8, i16], CCPromoteToType<i32>>, |
| 114 | |
| 115 | // The first 6 integer arguments are passed in integer registers. |
| 116 | CCMatchType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>, |
| 117 | CCMatchType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>, |
| 118 | |
| 119 | // The first 8 FP/Vector arguments are passed in XMM registers. |
| 120 | CCMatchType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
| 121 | CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>, |
| 122 | |
| 123 | // Integer/FP values get stored in stack slots that are 8 bytes in size and |
| 124 | // 8-byte aligned if there are no more registers to hold them. |
| 125 | CCMatchType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>, |
| 126 | |
| 127 | // Vectors get 16-byte stack slots that are 16-byte aligned. |
| 128 | CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], |
| 129 | CCAssignToStack<16, 16>> |
| 130 | ]>; |
| 131 | |
| 132 | |