Home | History | Annotate | Download | only in SystemZ
      1 //=- SystemZCallingConv.td - Calling conventions for SystemZ -*- 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 // This describes the calling conventions for the SystemZ ABI.
     10 //===----------------------------------------------------------------------===//
     11 
     12 class CCIfExtend<CCAction A>
     13   : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>;
     14 
     15 class CCIfSubtarget<string F, CCAction A>
     16   : CCIf<!strconcat("static_cast<const SystemZSubtarget&>"
     17                     "(State.getMachineFunction().getSubtarget()).", F),
     18          A>;
     19 
     20 // Match if this specific argument is a fixed (i.e. named) argument.
     21 class CCIfFixed<CCAction A>
     22     : CCIf<"static_cast<SystemZCCState *>(&State)->IsFixed(ValNo)", A>;
     23 
     24 // Match if this specific argument was widened from a short vector type.
     25 class CCIfShortVector<CCAction A>
     26     : CCIf<"static_cast<SystemZCCState *>(&State)->IsShortVector(ValNo)", A>;
     27 
     28 
     29 //===----------------------------------------------------------------------===//
     30 // z/Linux return value calling convention
     31 //===----------------------------------------------------------------------===//
     32 def RetCC_SystemZ : CallingConv<[
     33   // Promote i32 to i64 if it has an explicit extension type.
     34   CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
     35 
     36   // A SwiftError is returned in R9.
     37   CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
     38 
     39   // ABI-compliant code returns 64-bit integers in R2.  Make the other
     40   // call-clobbered argument registers available for code that doesn't
     41   // care about the ABI.  (R6 is an argument register too, but is
     42   // call-saved and therefore not suitable for return values.)
     43   CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L]>>,
     44   CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D]>>,
     45 
     46   // ABI-complaint code returns float and double in F0.  Make the
     47   // other floating-point argument registers available for code that
     48   // doesn't care about the ABI.  All floating-point argument registers
     49   // are call-clobbered, so we can use all of them here.
     50   CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
     51   CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
     52 
     53   // Similarly for vectors, with V24 being the ABI-compliant choice.
     54   // Sub-128 vectors are returned in the same way, but they're widened
     55   // to one of these types during type legalization.
     56   CCIfSubtarget<"hasVector()",
     57     CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
     58              CCAssignToReg<[V24, V26, V28, V30, V25, V27, V29, V31]>>>
     59 ]>;
     60 
     61 //===----------------------------------------------------------------------===//
     62 // z/Linux argument calling conventions
     63 //===----------------------------------------------------------------------===//
     64 def CC_SystemZ : CallingConv<[
     65   // Promote i32 to i64 if it has an explicit extension type.
     66   // The convention is that true integer arguments that are smaller
     67   // than 64 bits should be marked as extended, but structures that
     68   // are smaller than 64 bits shouldn't.
     69   CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
     70 
     71   // A SwiftSelf is passed in callee-saved R10.
     72   CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R10D]>>>,
     73 
     74   // A SwiftError is passed in callee-saved R9.
     75   CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
     76 
     77   // Force long double values to the stack and pass i64 pointers to them.
     78   CCIfType<[f128], CCPassIndirect<i64>>,
     79   // Same for i128 values.  These are already split into two i64 here,
     80   // so we have to use a custom handler.
     81   CCIfType<[i64], CCCustom<"CC_SystemZ_I128Indirect">>,
     82 
     83   // The first 5 integer arguments are passed in R2-R6.  Note that R6
     84   // is call-saved.
     85   CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
     86   CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
     87 
     88   // The first 4 float and double arguments are passed in even registers F0-F6.
     89   CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
     90   CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
     91 
     92   // The first 8 named vector arguments are passed in V24-V31.  Sub-128 vectors
     93   // are passed in the same way, but they're widened to one of these types
     94   // during type legalization.
     95   CCIfSubtarget<"hasVector()",
     96     CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
     97              CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
     98                                       V25, V27, V29, V31]>>>>,
     99 
    100   // However, sub-128 vectors which need to go on the stack occupy just a
    101   // single 8-byte-aligned 8-byte stack slot.  Pass as i64.
    102   CCIfSubtarget<"hasVector()",
    103     CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
    104              CCIfShortVector<CCBitConvertToType<i64>>>>,
    105 
    106   // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
    107   CCIfSubtarget<"hasVector()",
    108     CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
    109              CCAssignToStack<16, 8>>>,
    110 
    111   // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
    112   CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
    113 ]>;
    114 
    115 //===----------------------------------------------------------------------===//
    116 // z/Linux callee-saved registers
    117 //===----------------------------------------------------------------------===//
    118 def CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
    119                                        (sequence "F%dD", 8, 15))>;
    120 
    121 // R9 is used to return SwiftError; remove it from CSR.
    122 def CSR_SystemZ_SwiftError : CalleeSavedRegs<(sub CSR_SystemZ, R9D)>;
    123