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