1 //=- SystemZCallingConv.td - Calling conventions for SystemZ -*- tablegen -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // This describes the calling conventions for the SystemZ ABI.
10 //===----------------------------------------------------------------------===//
12 class CCIfExtend<CCAction A>
13 : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>;
15 class CCIfSubtarget<string F, CCAction A>
16 : CCIf<!strconcat("static_cast<const SystemZSubtarget&>"
17 "(State.getMachineFunction().getSubtarget()).", F),
20 // Match if this specific argument is a fixed (i.e. named) argument.
21 class CCIfFixed<CCAction A>
22 : CCIf<"static_cast<SystemZCCState *>(&State)->IsFixed(ValNo)", A>;
24 // Match if this specific argument was widened from a short vector type.
25 class CCIfShortVector<CCAction A>
26 : CCIf<"static_cast<SystemZCCState *>(&State)->IsShortVector(ValNo)", A>;
29 //===----------------------------------------------------------------------===//
30 // z/Linux return value calling convention
31 //===----------------------------------------------------------------------===//
32 def RetCC_SystemZ : CallingConv<[
33 // Promote i32 to i64 if it has an explicit extension type.
34 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
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]>>,
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]>>,
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]>>>
58 //===----------------------------------------------------------------------===//
59 // z/Linux argument calling conventions
60 //===----------------------------------------------------------------------===//
61 def CC_SystemZ : CallingConv<[
62 // Promote i32 to i64 if it has an explicit extension type.
63 // The convention is that true integer arguments that are smaller
64 // than 64 bits should be marked as extended, but structures that
65 // are smaller than 64 bits shouldn't.
66 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
68 // Force long double values to the stack and pass i64 pointers to them.
69 CCIfType<[f128], CCPassIndirect<i64>>,
71 // The first 5 integer arguments are passed in R2-R6. Note that R6
73 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
74 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
76 // The first 4 float and double arguments are passed in even registers F0-F6.
77 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
78 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
80 // The first 8 named vector arguments are passed in V24-V31. Sub-128 vectors
81 // are passed in the same way, but they're widened to one of these types
82 // during type legalization.
83 CCIfSubtarget<"hasVector()",
84 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
85 CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
86 V25, V27, V29, V31]>>>>,
88 // However, sub-128 vectors which need to go on the stack occupy just a
89 // single 8-byte-aligned 8-byte stack slot. Pass as i64.
90 CCIfSubtarget<"hasVector()",
91 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
92 CCIfShortVector<CCBitConvertToType<i64>>>>,
94 // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
95 CCIfSubtarget<"hasVector()",
96 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
97 CCAssignToStack<16, 8>>>,
99 // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
100 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
103 //===----------------------------------------------------------------------===//
104 // z/Linux callee-saved registers
105 //===----------------------------------------------------------------------===//
106 def CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
107 (sequence "F%dD", 8, 15))>;