brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.2 KiB · d9c5048 Raw
151 lines · plain
1//===-- SparcCallingConv.td - Calling Conventions Sparc ----*- tablegen -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This describes the calling conventions for the Sparc architectures.10//11//===----------------------------------------------------------------------===//12 13//===----------------------------------------------------------------------===//14// SPARC v8 32-bit.15//===----------------------------------------------------------------------===//16 17def CC_Sparc32 : CallingConv<[18  // Custom assign SRet to [sp+64].19  CCIfSRet<CCCustom<"CC_Sparc_Assign_SRet">>,20  // f128 arguments are passed indirectly, using i32 pointers.21  // FIXME GCC in soft-float mode passes f128 as if 2xi64 values.22  CCIfType<[f128], CCPassIndirect<i32>>,23  // i32 f32 arguments get passed in integer registers if there is space.24  CCIfType<[i32, f32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>,25  // f64 arguments are split and passed through registers or through stack.26  CCIfType<[f64], CCCustom<"CC_Sparc_Assign_Split_64">>,27  // As are v2i32 arguments (this would be the default behavior for28  // v2i32 if it wasn't allocated to the IntPair register-class)29  CCIfType<[v2i32], CCCustom<"CC_Sparc_Assign_Split_64">>,30  // Alternatively, they are assigned to the stack in 4-byte aligned units.31  CCAssignToStack<4, 4>32]>;33 34 35def RetCC_Sparc32 : CallingConv<[36  CCIfType<[i32], CCAssignToReg<[I0, I1, I2, I3, I4, I5]>>,37  CCIfType<[f32], CCAssignToReg<[F0, F1, F2, F3]>>,38  CCIfType<[f64], CCAssignToReg<[D0, D1]>>,39  // FIXME GCC in soft-float mode passes f128 as if 2xi64 values.40  CCIfType<[f128], CCIfInReg<CCIfConsecutiveRegs<CCAssignToReg<[Q0, Q1]>>>>,41  CCIfType<[v2i32], CCCustom<"CC_Sparc_Assign_Ret_Split_64">>42]>;43 44//===----------------------------------------------------------------------===//45// SPARC v9 64-bit.46//===----------------------------------------------------------------------===//47//48// The 64-bit ABI conceptually assigns all function arguments to a parameter49// array starting at [%fp+BIAS+128] in the callee's stack frame. All arguments50// occupy a multiple of 8 bytes in the array. Integer arguments are extended to51// 64 bits by the caller. Floats are right-aligned in their 8-byte slot, the52// first 4 bytes in the slot are undefined.53//54// The integer registers %i0 to %i5 shadow the first 48 bytes of the parameter55// array at fixed offsets. Integer arguments are promoted to registers when56// possible.57//58// The floating point registers %f0 to %f31 shadow the first 128 bytes of the59// parameter array at fixed offsets. Float and double parameters are promoted60// to these registers when possible.61//62// Structs up to 16 bytes in size are passed by value. They are right-aligned63// in one or two 8-byte slots in the parameter array. Struct members are64// promoted to both floating point and integer registers when possible. A65// struct containing two floats would thus be passed in %f0 and %f1, while two66// float function arguments would occupy 8 bytes each, and be passed in %f1 and67// %f3.68//69// When a struct { int, float } is passed by value, the int goes in the high70// bits of an integer register while the float goes in a floating point71// register.72//73// The difference is encoded in LLVM IR using the inreg attribute on function74// arguments:75//76//   C:   void f(float, float);77//   IR:  declare void f(float %f1, float %f3)78//79//   C:   void f(struct { float f0, f1; });80//   IR:  declare void f(float inreg %f0, float inreg %f1)81//82//   C:   void f(int, float);83//   IR:  declare void f(int signext %i0, float %f3)84//85//   C:   void f(struct { int i0high; float f1; });86//   IR:  declare void f(i32 inreg %i0high, float inreg %f1)87//88// Two ints in a struct are simply coerced to i64:89//90//   C:   void f(struct { int i0high, i0low; });91//   IR:  declare void f(i64 %i0.coerced)92//93// The frontend and backend divide the task of producing ABI compliant code for94// C functions. The C frontend will:95//96//  - Annotate integer arguments with zeroext or signext attributes.97//98//  - Split structs into one or two 64-bit sized chunks, or 32-bit chunks with99//    inreg attributes.100//101//  - Pass structs larger than 16 bytes indirectly with an explicit pointer102//    argument. The byval attribute is not used.103//104// The backend will:105//106//  - Assign all arguments to 64-bit aligned stack slots, 32-bits for inreg.107//108//  - Promote to integer or floating point registers depending on type.109//110// Function return values are passed exactly like function arguments, except a111// struct up to 32 bytes in size can be returned in registers.112 113// Function arguments AND most return values.114def CC_Sparc64 : CallingConv<[115  // The frontend uses the inreg flag to indicate i32 and float arguments from116  // structs. These arguments are not promoted to 64 bits, but they can still117  // be assigned to integer and float registers.118  CCIfInReg<CCIfType<[i32, f32], CCCustom<"CC_Sparc64_Half">>>,119 120  // All integers are promoted to i64 by the caller.121  CCIfType<[i32], CCPromoteToType<i64>>,122 123  // Custom assignment is required because stack space is reserved for all124  // arguments whether they are passed in registers or not.125  CCCustom<"CC_Sparc64_Full">126]>;127 128def RetCC_Sparc64 : CallingConv<[129  // A single f32 return value always goes in %f0. The ABI doesn't specify what130  // happens to multiple f32 return values outside a struct.131  CCIfType<[f32], CCCustom<"RetCC_Sparc64_Half">>,132 133  // Otherwise, return values are passed exactly like arguments, except that134  // returns that are too big to fit into the registers is passed as an sret135  // instead.136  CCIfInReg<CCIfType<[i32, f32], CCCustom<"RetCC_Sparc64_Half">>>,137  CCIfType<[i32], CCPromoteToType<i64>>,138  CCCustom<"RetCC_Sparc64_Full">139]>;140 141// Callee-saved registers are handled by the register window mechanism.142def CSR : CalleeSavedRegs<(add)> {143  let OtherPreserved = (add (sequence "I%u", 0, 7),144                            (sequence "L%u", 0, 7), O6);145}146 147// Callee-saved registers for calls with ReturnsTwice attribute.148def RTCSR : CalleeSavedRegs<(add)> {149  let OtherPreserved = (add I6, I7);150}151