2007-02-26 19:17:14 +01:00
|
|
|
//===- X86CallingConv.td - Calling Conventions for X86 32/64 ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-02-26 19:56:07 +01:00
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
2007-02-26 19:17:14 +01:00
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This describes the calling conventions for the X86-32 and X86-64
|
|
|
|
// architectures.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-02-28 06:30:29 +01:00
|
|
|
/// CCIfSubtarget - Match if the current subtarget has a feature F.
|
|
|
|
class CCIfSubtarget<string F, CCAction A>
|
|
|
|
: CCIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().", F), A>;
|
2007-02-28 05:51:41 +01:00
|
|
|
|
2007-02-26 19:17:14 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Return Value Calling Conventions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-02-27 06:51:05 +01:00
|
|
|
// Return-value conventions common to all X86 CC's.
|
2007-02-26 19:17:14 +01:00
|
|
|
def RetCC_X86Common : CallingConv<[
|
|
|
|
// Scalar values are returned in AX first, then DX.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[i8] , CCAssignToReg<[AL]>>,
|
|
|
|
CCIfType<[i16], CCAssignToReg<[AX]>>,
|
|
|
|
CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>,
|
|
|
|
CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>,
|
2007-02-26 19:17:14 +01:00
|
|
|
|
2007-07-02 18:21:53 +02:00
|
|
|
// Vector types are returned in XMM0 and XMM1, when they fit. If the target
|
|
|
|
// doesn't have XMM registers, it won't have vector types.
|
|
|
|
CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
|
|
|
|
CCAssignToReg<[XMM0,XMM1]>>,
|
2007-03-30 02:35:22 +02:00
|
|
|
|
|
|
|
// 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]>>
|
2007-02-26 19:17:14 +01:00
|
|
|
]>;
|
|
|
|
|
2007-02-27 06:51:05 +01:00
|
|
|
// X86-32 C return-value convention.
|
2007-02-26 19:17:14 +01:00
|
|
|
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.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[f32], CCAssignToReg<[ST0]>>,
|
|
|
|
CCIfType<[f64], CCAssignToReg<[ST0]>>,
|
2007-02-26 19:17:14 +01:00
|
|
|
CCDelegateTo<RetCC_X86Common>
|
|
|
|
]>;
|
|
|
|
|
2007-02-27 06:51:05 +01:00
|
|
|
// X86-32 FastCC return-value convention.
|
2007-02-26 19:17:14 +01:00
|
|
|
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.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
|
|
|
|
CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
|
2007-02-26 19:17:14 +01:00
|
|
|
CCDelegateTo<RetCC_X86Common>
|
|
|
|
]>;
|
|
|
|
|
2007-02-27 06:51:05 +01:00
|
|
|
// X86-64 C return-value convention.
|
2007-02-26 19:17:14 +01:00
|
|
|
def RetCC_X86_64_C : CallingConv<[
|
|
|
|
// The X86-64 calling convention always returns FP values in XMM0.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[f32], CCAssignToReg<[XMM0]>>,
|
|
|
|
CCIfType<[f64], CCAssignToReg<[XMM0]>>,
|
2007-02-26 19:17:14 +01:00
|
|
|
CCDelegateTo<RetCC_X86Common>
|
|
|
|
]>;
|
|
|
|
|
|
|
|
|
2007-02-27 06:51:05 +01:00
|
|
|
|
|
|
|
// This is the root return-value convention for the X86-32 backend.
|
|
|
|
def RetCC_X86_32 : CallingConv<[
|
|
|
|
// If FastCC, use RetCC_X86_32_Fast.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
|
2007-02-27 06:51:05 +01:00
|
|
|
// Otherwise, use RetCC_X86_32_C.
|
|
|
|
CCDelegateTo<RetCC_X86_32_C>
|
|
|
|
]>;
|
|
|
|
|
|
|
|
// This is the root return-value convention for the X86-64 backend.
|
|
|
|
def RetCC_X86_64 : CallingConv<[
|
|
|
|
// Always just the same as C calling conv for X86-64.
|
|
|
|
CCDelegateTo<RetCC_X86_64_C>
|
|
|
|
]>;
|
|
|
|
|
2007-02-27 07:59:52 +01:00
|
|
|
// This is the return-value convention used for the entire X86 backend.
|
|
|
|
def RetCC_X86 : CallingConv<[
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
|
2007-02-27 07:59:52 +01:00
|
|
|
CCDelegateTo<RetCC_X86_32>
|
|
|
|
]>;
|
2007-02-27 06:51:05 +01:00
|
|
|
|
2007-02-26 19:17:14 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-02-28 06:30:29 +01:00
|
|
|
// X86-64 Argument Calling Conventions
|
2007-02-26 19:17:14 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
def CC_X86_64_C : CallingConv<[
|
|
|
|
// Promote i8/i16 arguments to i32.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[i8, i16], CCPromoteToType<i32>>,
|
2007-02-26 19:17:14 +01:00
|
|
|
|
2007-07-06 12:57:03 +02:00
|
|
|
CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8, R9 ]>>,
|
|
|
|
|
2007-02-26 19:17:14 +01:00
|
|
|
// The first 6 integer arguments are passed in integer registers.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
|
|
|
|
CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
|
2007-02-26 19:17:14 +01:00
|
|
|
|
|
|
|
// The first 8 FP/Vector arguments are passed in XMM registers.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
|
2007-02-26 19:17:14 +01:00
|
|
|
CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
|
|
|
|
|
2007-03-31 11:36:12 +02:00
|
|
|
// The first 8 MMX vector arguments are passed in GPRs.
|
2007-03-31 03:03:53 +02:00
|
|
|
CCIfType<[v8i8, v4i16, v2i32, v1i64],
|
|
|
|
CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
|
|
|
|
|
2007-02-26 19:17:14 +01:00
|
|
|
// 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.
|
2007-02-28 06:30:29 +01:00
|
|
|
CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
|
2007-02-26 19:17:14 +01:00
|
|
|
|
|
|
|
// Vectors get 16-byte stack slots that are 16-byte aligned.
|
2007-03-30 02:35:22 +02:00
|
|
|
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>>
|
2007-02-26 19:17:14 +01:00
|
|
|
]>;
|
|
|
|
|
|
|
|
|
2007-02-28 06:31:48 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// X86 C Calling Convention
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-02-28 07:20:01 +01:00
|
|
|
/// 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
|
2007-02-28 06:31:48 +01:00
|
|
|
// 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>>,
|
|
|
|
|
2007-02-28 07:20:01 +01:00
|
|
|
// The first 4 vector arguments are passed in XMM registers.
|
2007-02-28 06:31:48 +01:00
|
|
|
CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
|
|
|
|
CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
|
|
|
|
|
|
|
|
// Other vectors get 16-byte stack slots that are 16-byte aligned.
|
2007-03-30 02:35:22 +02:00
|
|
|
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>>
|
2007-02-28 06:31:48 +01:00
|
|
|
]>;
|
|
|
|
|
2007-02-28 07:20:01 +01:00
|
|
|
def CC_X86_32_C : CallingConv<[
|
|
|
|
// Promote i8/i16 arguments to i32.
|
|
|
|
CCIfType<[i8, i16], CCPromoteToType<i32>>,
|
|
|
|
|
2007-06-19 02:13:10 +02:00
|
|
|
// The first 3 integer arguments, if marked 'inreg' and if the call is not
|
|
|
|
// a vararg call, are passed in integer registers.
|
|
|
|
CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
|
2007-02-28 07:20:01 +01:00
|
|
|
|
|
|
|
// 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
|
2007-02-28 19:35:11 +01:00
|
|
|
CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
|
2007-02-28 07:20:01 +01:00
|
|
|
|
|
|
|
// Otherwise, same as everything else.
|
|
|
|
CCDelegateTo<CC_X86_32_Common>
|
|
|
|
]>;
|