1251607Sdim//=- SystemZCallingConv.td - Calling conventions for SystemZ -*- tablegen -*-=//
2251607Sdim//
3251607Sdim//                     The LLVM Compiler Infrastructure
4251607Sdim//
5251607Sdim// This file is distributed under the University of Illinois Open Source
6251607Sdim// License. See LICENSE.TXT for details.
7251607Sdim//
8251607Sdim//===----------------------------------------------------------------------===//
9251607Sdim// This describes the calling conventions for the SystemZ ABI.
10251607Sdim//===----------------------------------------------------------------------===//
11251607Sdim
12251607Sdimclass CCIfExtend<CCAction A>
13251607Sdim  : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>;
14251607Sdim
15251607Sdim//===----------------------------------------------------------------------===//
16251607Sdim// SVR4 return value calling convention
17251607Sdim//===----------------------------------------------------------------------===//
18251607Sdimdef RetCC_SystemZ : CallingConv<[
19251607Sdim  // Promote i32 to i64 if it has an explicit extension type.
20251607Sdim  CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
21251607Sdim
22251607Sdim  // ABI-compliant code returns 64-bit integers in R2.  Make the other
23251607Sdim  // call-clobbered argument registers available for code that doesn't
24251607Sdim  // care about the ABI.  (R6 is an argument register too, but is
25251607Sdim  // call-saved and therefore not suitable for return values.)
26263509Sdim  CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L]>>,
27251607Sdim  CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D]>>,
28251607Sdim
29251607Sdim  // ABI-complaint code returns float and double in F0.  Make the
30251607Sdim  // other floating-point argument registers available for code that
31251607Sdim  // doesn't care about the ABI.  All floating-point argument registers
32251607Sdim  // are call-clobbered, so we can use all of them here.
33251607Sdim  CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
34251607Sdim  CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>
35251607Sdim
36251607Sdim  // ABI-compliant code returns long double by reference, but that conversion
37251607Sdim  // is left to higher-level code.  Perhaps we could add an f128 definition
38251607Sdim  // here for code that doesn't care about the ABI?
39251607Sdim]>;
40251607Sdim
41251607Sdim//===----------------------------------------------------------------------===//
42251607Sdim// SVR4 argument calling conventions
43251607Sdim//===----------------------------------------------------------------------===//
44251607Sdimdef CC_SystemZ : CallingConv<[
45251607Sdim  // Promote i32 to i64 if it has an explicit extension type.
46251607Sdim  // The convention is that true integer arguments that are smaller
47251607Sdim  // than 64 bits should be marked as extended, but structures that
48251607Sdim  // are smaller than 64 bits shouldn't.
49251607Sdim  CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
50251607Sdim
51251607Sdim  // Force long double values to the stack and pass i64 pointers to them.
52251607Sdim  CCIfType<[f128], CCPassIndirect<i64>>,
53251607Sdim
54251607Sdim  // The first 5 integer arguments are passed in R2-R6.  Note that R6
55251607Sdim  // is call-saved.
56263509Sdim  CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
57251607Sdim  CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
58251607Sdim
59251607Sdim  // The first 4 float and double arguments are passed in even registers F0-F6.
60251607Sdim  CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
61251607Sdim  CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
62251607Sdim
63251607Sdim  // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
64251607Sdim  CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
65251607Sdim]>;
66