[Sparc] Implement i64 load/store support for 32-bit sparc.
[oota-llvm.git] / lib / Target / Sparc / SparcCallingConv.td
1 //===-- SparcCallingConv.td - Calling Conventions Sparc ----*- 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 //
10 // This describes the calling conventions for the Sparc architectures.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // SPARC v8 32-bit.
16 //===----------------------------------------------------------------------===//
17
18 def CC_Sparc32 : CallingConv<[
19   // Custom assign SRet to [sp+64].
20   CCIfSRet<CCCustom<"CC_Sparc_Assign_SRet">>,
21   // 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_Split_64">>,
25   // As are v2i32 arguments (this would be the default behavior for
26   // v2i32 if it wasn't allocated to the IntPair register-class)
27   CCIfType<[v2i32], CCCustom<"CC_Sparc_Assign_Split_64">>,
28
29
30   // Alternatively, they are assigned to the stack in 4-byte aligned units.
31   CCAssignToStack<4, 4>
32 ]>;
33
34 def RetCC_Sparc32 : CallingConv<[
35   CCIfType<[i32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>,
36   CCIfType<[f32], CCAssignToReg<[F0, F1, F2, F3]>>,
37   CCIfType<[f64], CCAssignToReg<[D0, D1]>>,
38   CCIfType<[v2i32], CCCustom<"CC_Sparc_Assign_Ret_Split_64">>
39 ]>;
40
41
42 //===----------------------------------------------------------------------===//
43 // SPARC v9 64-bit.
44 //===----------------------------------------------------------------------===//
45 //
46 // The 64-bit ABI conceptually assigns all function arguments to a parameter
47 // array starting at [%fp+BIAS+128] in the callee's stack frame. All arguments
48 // occupy a multiple of 8 bytes in the array. Integer arguments are extended to
49 // 64 bits by the caller. Floats are right-aligned in their 8-byte slot, the
50 // first 4 bytes in the slot are undefined.
51 //
52 // The integer registers %i0 to %i5 shadow the first 48 bytes of the parameter
53 // array at fixed offsets. Integer arguments are promoted to registers when
54 // possible.
55 //
56 // The floating point registers %f0 to %f31 shadow the first 128 bytes of the
57 // parameter array at fixed offsets. Float and double parameters are promoted
58 // to these registers when possible.
59 //
60 // Structs up to 16 bytes in size are passed by value. They are right-aligned
61 // in one or two 8-byte slots in the parameter array. Struct members are
62 // promoted to both floating point and integer registers when possible. A
63 // struct containing two floats would thus be passed in %f0 and %f1, while two
64 // float function arguments would occupy 8 bytes each, and be passed in %f1 and
65 // %f3.
66 //
67 // When a struct { int, float } is passed by value, the int goes in the high
68 // bits of an integer register while the float goes in a floating point
69 // register.
70 //
71 // The difference is encoded in LLVM IR using the inreg atttribute on function
72 // arguments:
73 //
74 //   C:   void f(float, float);
75 //   IR:  declare void f(float %f1, float %f3)
76 //
77 //   C:   void f(struct { float f0, f1; });
78 //   IR:  declare void f(float inreg %f0, float inreg %f1)
79 //
80 //   C:   void f(int, float);
81 //   IR:  declare void f(int signext %i0, float %f3)
82 //
83 //   C:   void f(struct { int i0high; float f1; });
84 //   IR:  declare void f(i32 inreg %i0high, float inreg %f1)
85 //
86 // Two ints in a struct are simply coerced to i64:
87 //
88 //   C:   void f(struct { int i0high, i0low; });
89 //   IR:  declare void f(i64 %i0.coerced)
90 //
91 // The frontend and backend divide the task of producing ABI compliant code for
92 // C functions. The C frontend will:
93 //
94 //  - Annotate integer arguments with zeroext or signext attributes.
95 //
96 //  - Split structs into one or two 64-bit sized chunks, or 32-bit chunks with
97 //    inreg attributes.
98 //
99 //  - Pass structs larger than 16 bytes indirectly with an explicit pointer
100 //    argument. The byval attribute is not used.
101 //
102 // The backend will:
103 //
104 //  - Assign all arguments to 64-bit aligned stack slots, 32-bits for inreg.
105 //
106 //  - Promote to integer or floating point registers depending on type.
107 //
108 // Function return values are passed exactly like function arguments, except a
109 // struct up to 32 bytes in size can be returned in registers.
110
111 // Function arguments AND most return values.
112 def CC_Sparc64 : CallingConv<[
113   // The frontend uses the inreg flag to indicate i32 and float arguments from
114   // structs. These arguments are not promoted to 64 bits, but they can still
115   // be assigned to integer and float registers.
116   CCIfInReg<CCIfType<[i32, f32], CCCustom<"CC_Sparc64_Half">>>,
117
118   // All integers are promoted to i64 by the caller.
119   CCIfType<[i32], CCPromoteToType<i64>>,
120
121   // Custom assignment is required because stack space is reserved for all
122   // arguments whether they are passed in registers or not.
123   CCCustom<"CC_Sparc64_Full">
124 ]>;
125
126 def RetCC_Sparc64 : CallingConv<[
127   // A single f32 return value always goes in %f0. The ABI doesn't specify what
128   // happens to multiple f32 return values outside a struct.
129   CCIfType<[f32], CCCustom<"CC_Sparc64_Half">>,
130
131   // Otherwise, return values are passed exactly like arguments.
132   CCDelegateTo<CC_Sparc64>
133 ]>;
134
135 // Callee-saved registers are handled by the register window mechanism.
136 def CSR : CalleeSavedRegs<(add)> {
137   let OtherPreserved = (add (sequence "I%u", 0, 7),
138                             (sequence "L%u", 0, 7));
139 }
140
141 // Callee-saved registers for calls with ReturnsTwice attribute.
142 def RTCSR : CalleeSavedRegs<(add)> {
143   let OtherPreserved = (add I6, I7);
144 }