1//=- SystemZCallingConv.td - Calling conventions for SystemZ -*- tablegen -*-=//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9// This describes the calling conventions for the SystemZ ABI.
10//===----------------------------------------------------------------------===//
11
12class CCIfExtend<CCAction A>
13  : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>;
14
15class CCIfSubtarget<string F, CCAction A>
16  : CCIf<!strconcat("static_cast<const SystemZSubtarget&>"
17                    "(State.getMachineFunction().getSubtarget()).", F),
18         A>;
19
20// Match if this specific argument is a fixed (i.e. named) argument.
21class CCIfFixed<CCAction A>
22    : CCIf<"static_cast<SystemZCCState *>(&State)->IsFixed(ValNo)", A>;
23
24// Match if this specific argument was widened from a short vector type.
25class CCIfShortVector<CCAction A>
26    : CCIf<"static_cast<SystemZCCState *>(&State)->IsShortVector(ValNo)", A>;
27
28
29//===----------------------------------------------------------------------===//
30// z/Linux return value calling convention
31//===----------------------------------------------------------------------===//
32def RetCC_SystemZ : CallingConv<[
33  // Promote i32 to i64 if it has an explicit extension type.
34  CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
35
36  // ABI-compliant code returns 64-bit integers in R2.  Make the other
37  // call-clobbered argument registers available for code that doesn't
38  // care about the ABI.  (R6 is an argument register too, but is
39  // call-saved and therefore not suitable for return values.)
40  CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L]>>,
41  CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D]>>,
42
43  // ABI-complaint code returns float and double in F0.  Make the
44  // other floating-point argument registers available for code that
45  // doesn't care about the ABI.  All floating-point argument registers
46  // are call-clobbered, so we can use all of them here.
47  CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
48  CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
49
50  // Similarly for vectors, with V24 being the ABI-compliant choice.
51  // Sub-128 vectors are returned in the same way, but they're widened
52  // to one of these types during type legalization.
53  CCIfSubtarget<"hasVector()",
54    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
55             CCAssignToReg<[V24, V26, V28, V30, V25, V27, V29, V31]>>>
56
57  // ABI-compliant code returns long double by reference, but that conversion
58  // is left to higher-level code.  Perhaps we could add an f128 definition
59  // here for code that doesn't care about the ABI?
60]>;
61
62//===----------------------------------------------------------------------===//
63// z/Linux argument calling conventions
64//===----------------------------------------------------------------------===//
65def CC_SystemZ : CallingConv<[
66  // Promote i32 to i64 if it has an explicit extension type.
67  // The convention is that true integer arguments that are smaller
68  // than 64 bits should be marked as extended, but structures that
69  // are smaller than 64 bits shouldn't.
70  CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
71
72  // Force long double values to the stack and pass i64 pointers to them.
73  CCIfType<[f128], CCPassIndirect<i64>>,
74
75  // The first 5 integer arguments are passed in R2-R6.  Note that R6
76  // is call-saved.
77  CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
78  CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
79
80  // The first 4 float and double arguments are passed in even registers F0-F6.
81  CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
82  CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
83
84  // The first 8 named vector arguments are passed in V24-V31.  Sub-128 vectors
85  // are passed in the same way, but they're widened to one of these types
86  // during type legalization.
87  CCIfSubtarget<"hasVector()",
88    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
89             CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
90                                      V25, V27, V29, V31]>>>>,
91
92  // However, sub-128 vectors which need to go on the stack occupy just a
93  // single 8-byte-aligned 8-byte stack slot.  Pass as i64.
94  CCIfSubtarget<"hasVector()",
95    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
96             CCIfShortVector<CCBitConvertToType<i64>>>>,
97
98  // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
99  CCIfSubtarget<"hasVector()",
100    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
101             CCAssignToStack<16, 8>>>,
102
103  // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
104  CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
105]>;
106
107//===----------------------------------------------------------------------===//
108// z/Linux callee-saved registers
109//===----------------------------------------------------------------------===//
110def CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
111                                       (sequence "F%dD", 8, 15))>;
112