1235633Sdim//===-- SparcCallingConv.td - Calling Conventions Sparc ----*- tablegen -*-===// 2235633Sdim// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7235633Sdim// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This describes the calling conventions for the Sparc architectures. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed//===----------------------------------------------------------------------===// 15252723Sdim// SPARC v8 32-bit. 16193323Sed//===----------------------------------------------------------------------===// 17193323Sed 18193323Seddef CC_Sparc32 : CallingConv<[ 19263509Sdim // Custom assign SRet to [sp+64]. 20218893Sdim CCIfSRet<CCCustom<"CC_Sparc_Assign_SRet">>, 21218893Sdim // i32 f32 arguments get passed in integer registers if there is space. 22218893Sdim CCIfType<[i32, f32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>, 23218893Sdim // f64 arguments are split and passed through registers or through stack. 24218893Sdim CCIfType<[f64], CCCustom<"CC_Sparc_Assign_f64">>, 25218893Sdim 26193323Sed // Alternatively, they are assigned to the stack in 4-byte aligned units. 27193323Sed CCAssignToStack<4, 4> 28193323Sed]>; 29252723Sdim 30252723Sdimdef RetCC_Sparc32 : CallingConv<[ 31252723Sdim CCIfType<[i32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>, 32252723Sdim CCIfType<[f32], CCAssignToReg<[F0, F1, F2, F3]>>, 33252723Sdim CCIfType<[f64], CCAssignToReg<[D0, D1]>> 34252723Sdim]>; 35252723Sdim 36252723Sdim 37252723Sdim//===----------------------------------------------------------------------===// 38252723Sdim// SPARC v9 64-bit. 39252723Sdim//===----------------------------------------------------------------------===// 40252723Sdim// 41252723Sdim// The 64-bit ABI conceptually assigns all function arguments to a parameter 42252723Sdim// array starting at [%fp+BIAS+128] in the callee's stack frame. All arguments 43252723Sdim// occupy a multiple of 8 bytes in the array. Integer arguments are extended to 44252723Sdim// 64 bits by the caller. Floats are right-aligned in their 8-byte slot, the 45252723Sdim// first 4 bytes in the slot are undefined. 46252723Sdim// 47252723Sdim// The integer registers %i0 to %i5 shadow the first 48 bytes of the parameter 48252723Sdim// array at fixed offsets. Integer arguments are promoted to registers when 49252723Sdim// possible. 50252723Sdim// 51252723Sdim// The floating point registers %f0 to %f31 shadow the first 128 bytes of the 52252723Sdim// parameter array at fixed offsets. Float and double parameters are promoted 53252723Sdim// to these registers when possible. 54252723Sdim// 55252723Sdim// Structs up to 16 bytes in size are passed by value. They are right-aligned 56252723Sdim// in one or two 8-byte slots in the parameter array. Struct members are 57252723Sdim// promoted to both floating point and integer registers when possible. A 58252723Sdim// struct containing two floats would thus be passed in %f0 and %f1, while two 59252723Sdim// float function arguments would occupy 8 bytes each, and be passed in %f1 and 60252723Sdim// %f3. 61252723Sdim// 62252723Sdim// When a struct { int, float } is passed by value, the int goes in the high 63252723Sdim// bits of an integer register while the float goes in a floating point 64252723Sdim// register. 65252723Sdim// 66252723Sdim// The difference is encoded in LLVM IR using the inreg atttribute on function 67252723Sdim// arguments: 68252723Sdim// 69252723Sdim// C: void f(float, float); 70252723Sdim// IR: declare void f(float %f1, float %f3) 71252723Sdim// 72252723Sdim// C: void f(struct { float f0, f1; }); 73252723Sdim// IR: declare void f(float inreg %f0, float inreg %f1) 74252723Sdim// 75252723Sdim// C: void f(int, float); 76252723Sdim// IR: declare void f(int signext %i0, float %f3) 77252723Sdim// 78252723Sdim// C: void f(struct { int i0high; float f1; }); 79252723Sdim// IR: declare void f(i32 inreg %i0high, float inreg %f1) 80252723Sdim// 81252723Sdim// Two ints in a struct are simply coerced to i64: 82252723Sdim// 83252723Sdim// C: void f(struct { int i0high, i0low; }); 84252723Sdim// IR: declare void f(i64 %i0.coerced) 85252723Sdim// 86252723Sdim// The frontend and backend divide the task of producing ABI compliant code for 87252723Sdim// C functions. The C frontend will: 88252723Sdim// 89252723Sdim// - Annotate integer arguments with zeroext or signext attributes. 90252723Sdim// 91252723Sdim// - Split structs into one or two 64-bit sized chunks, or 32-bit chunks with 92252723Sdim// inreg attributes. 93252723Sdim// 94252723Sdim// - Pass structs larger than 16 bytes indirectly with an explicit pointer 95252723Sdim// argument. The byval attribute is not used. 96252723Sdim// 97252723Sdim// The backend will: 98252723Sdim// 99252723Sdim// - Assign all arguments to 64-bit aligned stack slots, 32-bits for inreg. 100252723Sdim// 101252723Sdim// - Promote to integer or floating point registers depending on type. 102252723Sdim// 103252723Sdim// Function return values are passed exactly like function arguments, except a 104252723Sdim// struct up to 32 bytes in size can be returned in registers. 105252723Sdim 106263764Sdim// Function arguments AND most return values. 107252723Sdimdef CC_Sparc64 : CallingConv<[ 108252723Sdim // The frontend uses the inreg flag to indicate i32 and float arguments from 109252723Sdim // structs. These arguments are not promoted to 64 bits, but they can still 110252723Sdim // be assigned to integer and float registers. 111252723Sdim CCIfInReg<CCIfType<[i32, f32], CCCustom<"CC_Sparc64_Half">>>, 112252723Sdim 113252723Sdim // All integers are promoted to i64 by the caller. 114252723Sdim CCIfType<[i32], CCPromoteToType<i64>>, 115252723Sdim 116252723Sdim // Custom assignment is required because stack space is reserved for all 117252723Sdim // arguments whether they are passed in registers or not. 118252723Sdim CCCustom<"CC_Sparc64_Full"> 119252723Sdim]>; 120263509Sdim 121263764Sdimdef RetCC_Sparc64 : CallingConv<[ 122263764Sdim // A single f32 return value always goes in %f0. The ABI doesn't specify what 123263764Sdim // happens to multiple f32 return values outside a struct. 124263764Sdim CCIfType<[f32], CCCustom<"CC_Sparc64_Half">>, 125263764Sdim 126263764Sdim // Otherwise, return values are passed exactly like arguments. 127263764Sdim CCDelegateTo<CC_Sparc64> 128263764Sdim]>; 129263764Sdim 130263509Sdim// Callee-saved registers are handled by the register window mechanism. 131263509Sdimdef CSR : CalleeSavedRegs<(add)> { 132263509Sdim let OtherPreserved = (add (sequence "I%u", 0, 7), 133263509Sdim (sequence "L%u", 0, 7)); 134263509Sdim} 135263509Sdim 136263509Sdim// Callee-saved registers for calls with ReturnsTwice attribute. 137263509Sdimdef RTCSR : CalleeSavedRegs<(add)> { 138263509Sdim let OtherPreserved = (add I6, I7); 139263509Sdim} 140