blob: dfaaabf344a3ad692d71967d7a1d5982bdea287d [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- SparcCallingConv.td - Calling Conventions Sparc ----*- tablegen -*-===//
2//
Chris Lattner49b269d2008-03-17 05:41:48 +00003// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jia Liub22310f2012-02-18 12:03:15 +00007//
Chris Lattner49b269d2008-03-17 05:41:48 +00008//===----------------------------------------------------------------------===//
9//
10// This describes the calling conventions for the Sparc architectures.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
Jakob Stoklund Olesen1c9a95a2013-04-06 18:32:12 +000015// SPARC v8 32-bit.
Chris Lattner49b269d2008-03-17 05:41:48 +000016//===----------------------------------------------------------------------===//
17
Chris Lattner7d4152b2008-03-17 06:58:37 +000018def CC_Sparc32 : CallingConv<[
Venkatraman Govindarajua54533ed2013-06-04 18:33:25 +000019 // Custom assign SRet to [sp+64].
Venkatraman Govindarajucc91b7a2011-01-22 13:05:16 +000020 CCIfSRet<CCCustom<"CC_Sparc_Assign_SRet">>,
Venkatraman Govindarajuc386f8a2011-01-18 06:09:55 +000021 // i32 f32 arguments get passed in integer registers if there is space.
22 CCIfType<[i32, f32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>,
23 // f64 arguments are split and passed through registers or through stack.
24 CCIfType<[f64], CCCustom<"CC_Sparc_Assign_f64">>,
25
Chris Lattner7d4152b2008-03-17 06:58:37 +000026 // Alternatively, they are assigned to the stack in 4-byte aligned units.
27 CCAssignToStack<4, 4>
28]>;
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +000029
Jakob Stoklund Olesen1c9a95a2013-04-06 18:32:12 +000030def RetCC_Sparc32 : CallingConv<[
31 CCIfType<[i32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>,
32 CCIfType<[f32], CCAssignToReg<[F0, F1, F2, F3]>>,
33 CCIfType<[f64], CCAssignToReg<[D0, D1]>>
34]>;
35
36
37//===----------------------------------------------------------------------===//
38// SPARC v9 64-bit.
39//===----------------------------------------------------------------------===//
40//
41// The 64-bit ABI conceptually assigns all function arguments to a parameter
42// array starting at [%fp+BIAS+128] in the callee's stack frame. All arguments
43// occupy a multiple of 8 bytes in the array. Integer arguments are extended to
44// 64 bits by the caller. Floats are right-aligned in their 8-byte slot, the
45// first 4 bytes in the slot are undefined.
46//
47// The integer registers %i0 to %i5 shadow the first 48 bytes of the parameter
48// array at fixed offsets. Integer arguments are promoted to registers when
49// possible.
50//
51// The floating point registers %f0 to %f31 shadow the first 128 bytes of the
52// parameter array at fixed offsets. Float and double parameters are promoted
53// to these registers when possible.
54//
55// Structs up to 16 bytes in size are passed by value. They are right-aligned
56// in one or two 8-byte slots in the parameter array. Struct members are
57// promoted to both floating point and integer registers when possible. A
58// struct containing two floats would thus be passed in %f0 and %f1, while two
59// float function arguments would occupy 8 bytes each, and be passed in %f1 and
60// %f3.
61//
62// When a struct { int, float } is passed by value, the int goes in the high
63// bits of an integer register while the float goes in a floating point
64// register.
65//
66// The difference is encoded in LLVM IR using the inreg atttribute on function
67// arguments:
68//
69// C: void f(float, float);
70// IR: declare void f(float %f1, float %f3)
71//
72// C: void f(struct { float f0, f1; });
73// IR: declare void f(float inreg %f0, float inreg %f1)
74//
75// C: void f(int, float);
76// IR: declare void f(int signext %i0, float %f3)
77//
78// C: void f(struct { int i0high; float f1; });
79// IR: declare void f(i32 inreg %i0high, float inreg %f1)
80//
81// Two ints in a struct are simply coerced to i64:
82//
83// C: void f(struct { int i0high, i0low; });
84// IR: declare void f(i64 %i0.coerced)
85//
86// The frontend and backend divide the task of producing ABI compliant code for
87// C functions. The C frontend will:
88//
89// - Annotate integer arguments with zeroext or signext attributes.
90//
91// - Split structs into one or two 64-bit sized chunks, or 32-bit chunks with
92// inreg attributes.
93//
94// - Pass structs larger than 16 bytes indirectly with an explicit pointer
95// argument. The byval attribute is not used.
96//
97// The backend will:
98//
99// - Assign all arguments to 64-bit aligned stack slots, 32-bits for inreg.
100//
101// - Promote to integer or floating point registers depending on type.
102//
103// Function return values are passed exactly like function arguments, except a
104// struct up to 32 bytes in size can be returned in registers.
105
Jakob Stoklund Olesene7084a12014-01-12 04:13:17 +0000106// Function arguments AND most return values.
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000107def CC_Sparc64 : CallingConv<[
Jakob Stoklund Olesen1c9a95a2013-04-06 18:32:12 +0000108 // The frontend uses the inreg flag to indicate i32 and float arguments from
109 // structs. These arguments are not promoted to 64 bits, but they can still
110 // be assigned to integer and float registers.
111 CCIfInReg<CCIfType<[i32, f32], CCCustom<"CC_Sparc64_Half">>>,
112
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000113 // All integers are promoted to i64 by the caller.
114 CCIfType<[i32], CCPromoteToType<i64>>,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000115
Jakob Stoklund Olesen1c9a95a2013-04-06 18:32:12 +0000116 // Custom assignment is required because stack space is reserved for all
117 // arguments whether they are passed in registers or not.
118 CCCustom<"CC_Sparc64_Full">
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000119]>;
Jakob Stoklund Olesena8960a12013-08-23 02:25:47 +0000120
Jakob Stoklund Olesene7084a12014-01-12 04:13:17 +0000121def RetCC_Sparc64 : CallingConv<[
122 // A single f32 return value always goes in %f0. The ABI doesn't specify what
123 // happens to multiple f32 return values outside a struct.
124 CCIfType<[f32], CCCustom<"CC_Sparc64_Half">>,
125
126 // Otherwise, return values are passed exactly like arguments.
127 CCDelegateTo<CC_Sparc64>
128]>;
129
Jakob Stoklund Olesena8960a12013-08-23 02:25:47 +0000130// Callee-saved registers are handled by the register window mechanism.
131def CSR : CalleeSavedRegs<(add)> {
132 let OtherPreserved = (add (sequence "I%u", 0, 7),
133 (sequence "L%u", 0, 7));
134}
Venkatraman Govindaraju55ecb102013-09-05 05:32:16 +0000135
136// Callee-saved registers for calls with ReturnsTwice attribute.
137def RTCSR : CalleeSavedRegs<(add)> {
138 let OtherPreserved = (add I6, I7);
139}