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 //===----------------------------------------------------------------------===//
25 // z/Linux return value calling convention
26 //===----------------------------------------------------------------------===//
27 def RetCC_SystemZ : CallingConv<[
28 // Promote i32 to i64 if it has an explicit extension type.
29 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
31 // ABI-compliant code returns 64-bit integers in R2. Make the other
32 // call-clobbered argument registers available for code that doesn't
33 // care about the ABI. (R6 is an argument register too, but is
34 // call-saved and therefore not suitable for return values.)
35 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L]>>,
36 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D]>>,
38 // ABI-complaint code returns float and double in F0. Make the
39 // other floating-point argument registers available for code that
40 // doesn't care about the ABI. All floating-point argument registers
41 // are call-clobbered, so we can use all of them here.
42 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
43 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
45 // Similarly for vectors, with V24 being the ABI-compliant choice.
46 CCIfSubtarget<"hasVector()",
47 CCIfType<[v16i8, v8i16, v4i32, v2i64, v2f64],
48 CCAssignToReg<[V24, V26, V28, V30, V25, V27, V29, V31]>>>
50 // ABI-compliant code returns long double by reference, but that conversion
51 // is left to higher-level code. Perhaps we could add an f128 definition
52 // here for code that doesn't care about the ABI?
55 //===----------------------------------------------------------------------===//
56 // z/Linux argument calling conventions
57 //===----------------------------------------------------------------------===//
58 def CC_SystemZ : CallingConv<[
59 // Promote i32 to i64 if it has an explicit extension type.
60 // The convention is that true integer arguments that are smaller
61 // than 64 bits should be marked as extended, but structures that
62 // are smaller than 64 bits shouldn't.
63 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
65 // Force long double values to the stack and pass i64 pointers to them.
66 CCIfType<[f128], CCPassIndirect<i64>>,
68 // The first 5 integer arguments are passed in R2-R6. Note that R6
70 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
71 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
73 // The first 4 float and double arguments are passed in even registers F0-F6.
74 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
75 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
77 // The first 8 named vector arguments are passed in V24-V31.
78 CCIfSubtarget<"hasVector()",
79 CCIfType<[v16i8, v8i16, v4i32, v2i64, v2f64],
80 CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
81 V25, V27, V29, V31]>>>>,
83 // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
84 CCIfSubtarget<"hasVector()",
85 CCIfType<[v16i8, v8i16, v4i32, v2i64, v2f64],
86 CCAssignToStack<16, 8>>>,
88 // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
89 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
92 //===----------------------------------------------------------------------===//
93 // z/Linux callee-saved registers
94 //===----------------------------------------------------------------------===//
95 def CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
96 (sequence "F%dD", 8, 15))>;