done
[oota-llvm.git] / lib / Target / X86 / X86CallingConv.td
index 110335b8c109a94ab6c8c585e89eefe0d392d3f1..f548af75fdc87238cd5d86e36793bbb456094011 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-class CCAction;
-class CallingConv;
-
-/// CCPredicateAction - Instances of this class check some predicate, then
-/// delegate to another action if the predicate is true.
-class CCPredicateAction<CCAction A> : CCAction {
-  CCAction SubAction = A;
-}
-
-/// CCMatchType - If the current argument is one of the specified types, apply
-/// Action A.
-class CCMatchType<list<ValueType> VTs, CCAction A> : CCPredicateAction<A> {
-}
-
-/// CCMatchIf - If the predicate matches, apply A.
-class CCMatchIf<string predicate, CCAction A> : CCPredicateAction<A> {
-  string Predicate = predicate;
-}
-
-/// CCMatchIfCC - Match of the current calling convention is 'CC'.
-class CCMatchIfCC<string CC, CCAction A> : CCPredicateAction<A> {
-  string CallingConv = CC;
-}
-
-/// CCAssignToReg - This action matches if there is a register in the specified
-/// list that is still available.  If so, it assigns the value to the first
-/// available register and succeeds.
-class CCAssignToReg<list<Register> regList> : CCAction {
-  list<Register> RegList = regList;
-}
-
-/// CCAssignToStack - This action always matches: it assigns the value to a
-/// stack slot of the specified size and alignment on the stack.
-class CCAssignToStack<int size, int align> : CCAction {
-  int Size = size;
-  int Align = align;
-}
-
-
-/// CCPromoteToType - If applied, this promotes the specified current value to
-/// the specified type.
-class CCPromoteToType<ValueType destTy> : CCAction {
-  ValueType DestTy = destTy;
-}
-
-/// CCDelegateTo - This action invokes the specified sub-calling-convention.  It
-/// is successful if the specified CC matches.
-class CCDelegateTo<CallingConv cc> : CCAction {
-  CallingConv CC = cc;
-}
-
-
-class CallingConv<list<CCAction> actions> {
-  list<CCAction> Actions = actions;
-}
+/// CCIfSubtarget - Match if the current subtarget has a feature F.
+class CCIfSubtarget<string F, CCAction A>
+ : CCIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().", F), A>;
 
 //===----------------------------------------------------------------------===//
 // Return Value Calling Conventions
@@ -75,22 +23,26 @@ class CallingConv<list<CCAction> actions> {
 // Return-value conventions common to all X86 CC's.
 def RetCC_X86Common : CallingConv<[
   // Scalar values are returned in AX first, then DX.
-  CCMatchType<[i8] , CCAssignToReg<[AL]>>,
-  CCMatchType<[i16], CCAssignToReg<[AX]>>,
-  CCMatchType<[i32], CCAssignToReg<[EAX, EDX]>>,
-  CCMatchType<[i64], CCAssignToReg<[RAX, RDX]>>,
+  CCIfType<[i8] , CCAssignToReg<[AL]>>,
+  CCIfType<[i16], CCAssignToReg<[AX]>>,
+  CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>,
+  CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>,
   
   // Vector types are always returned in XMM0.  If the target doesn't have XMM0,
   // it won't have vector types.
-  CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>
+  CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>,
+
+  // MMX vector types are always returned in MM0. If the target doesn't have
+  // MM0, it doesn't support these vector types.
+  CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[MM0]>>
 ]>;
 
 // X86-32 C return-value convention.
 def RetCC_X86_32_C : CallingConv<[
   // The X86-32 calling convention returns FP values in ST0, otherwise it is the
   // same as the common X86 calling conv.
-  CCMatchType<[f32], CCAssignToReg<[ST0]>>,
-  CCMatchType<[f64], CCAssignToReg<[ST0]>>,
+  CCIfType<[f32], CCAssignToReg<[ST0]>>,
+  CCIfType<[f64], CCAssignToReg<[ST0]>>,
   CCDelegateTo<RetCC_X86Common>
 ]>;
 
@@ -98,16 +50,16 @@ def RetCC_X86_32_C : CallingConv<[
 def RetCC_X86_32_Fast : CallingConv<[
   // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2,
   // otherwise it is the the C calling conventions.
-  CCMatchType<[f32], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>,
-  CCMatchType<[f64], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>,
+  CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
+  CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
   CCDelegateTo<RetCC_X86Common>
 ]>;
 
 // X86-64 C return-value convention.
 def RetCC_X86_64_C : CallingConv<[
   // The X86-64 calling convention always returns FP values in XMM0.
-  CCMatchType<[f32], CCAssignToReg<[XMM0]>>,
-  CCMatchType<[f64], CCAssignToReg<[XMM0]>>,
+  CCIfType<[f32], CCAssignToReg<[XMM0]>>,
+  CCIfType<[f64], CCAssignToReg<[XMM0]>>,
   CCDelegateTo<RetCC_X86Common>
 ]>;
 
@@ -116,7 +68,7 @@ def RetCC_X86_64_C : CallingConv<[
 // This is the root return-value convention for the X86-32 backend.
 def RetCC_X86_32 : CallingConv<[
   // If FastCC, use RetCC_X86_32_Fast.
-  CCMatchIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
+  CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
   // Otherwise, use RetCC_X86_32_C.
   CCDelegateTo<RetCC_X86_32_C>
 ]>;
@@ -127,32 +79,93 @@ def RetCC_X86_64 : CallingConv<[
   CCDelegateTo<RetCC_X86_64_C>
 ]>;
 
-
+// This is the return-value convention used for the entire X86 backend.
+def RetCC_X86 : CallingConv<[
+  CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
+  CCDelegateTo<RetCC_X86_32>
+]>;
 
 //===----------------------------------------------------------------------===//
-// Argument Calling Conventions
+// X86-64 Argument Calling Conventions
 //===----------------------------------------------------------------------===//
 
-
 def CC_X86_64_C : CallingConv<[
   // Promote i8/i16 arguments to i32.
-  CCMatchType<[i8, i16], CCPromoteToType<i32>>,
+  CCIfType<[i8, i16], CCPromoteToType<i32>>,
   
   // The first 6 integer arguments are passed in integer registers.
-  CCMatchType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
-  CCMatchType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
+  CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
+  CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
   
   // The first 8 FP/Vector arguments are passed in XMM registers.
-  CCMatchType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
+  CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
               CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
 
+  // The first 8 MMX vector arguments are passed in GPRs.
+  CCIfType<[v8i8, v4i16, v2i32, v1i64],
+              CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
+
   // Integer/FP values get stored in stack slots that are 8 bytes in size and
   // 8-byte aligned if there are no more registers to hold them.
-  CCMatchType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
+  CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
   
   // Vectors get 16-byte stack slots that are 16-byte aligned.
-  CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
-              CCAssignToStack<16, 16>>
+  CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
+
+  // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
+  CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
+]>;
+
+
+//===----------------------------------------------------------------------===//
+// X86 C Calling Convention
+//===----------------------------------------------------------------------===//
+
+/// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
+/// values are spilled on the stack, and the first 4 vector values go in XMM
+/// regs.
+def CC_X86_32_Common : CallingConv<[
+  // Integer/Float values get stored in stack slots that are 4 bytes in
+  // size and 4-byte aligned.
+  CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
+  
+  // Doubles get 8-byte slots that are 4-byte aligned.
+  CCIfType<[f64], CCAssignToStack<8, 4>>,
+  
+  // The first 4 vector arguments are passed in XMM registers.
+  CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
+              CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
+
+  // Other vectors get 16-byte stack slots that are 16-byte aligned.
+  CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
+
+  // __m64 vectors get 8-byte stack slots that are 8-byte aligned. They are
+  // passed in the parameter area.
+  CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
+]>;
+
+def CC_X86_32_C : CallingConv<[
+  // Promote i8/i16 arguments to i32.
+  CCIfType<[i8, i16], CCPromoteToType<i32>>,
+  
+  // The first 3 integer arguments, if marked 'inreg', are passed in integer
+  // registers.
+  CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>,
+  
+  // Otherwise, same as everything else.
+  CCDelegateTo<CC_X86_32_Common>
+]>;
+
+
+def CC_X86_32_FastCall : CallingConv<[
+  // Promote i8/i16 arguments to i32.
+  CCIfType<[i8, i16], CCPromoteToType<i32>>,
+  
+  // The first 2 integer arguments are passed in ECX/EDX
+  CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
+  
+  // Otherwise, same as everything else.
+  CCDelegateTo<CC_X86_32_Common>
 ]>;