LLVM API Documentation

HexagonVarargsCallingConvention.h
Go to the documentation of this file.
00001 //===-- HexagonVarargsCallingConvention.h - Calling Conventions -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the functions that assign locations to outgoing function
00011 // arguments. Adapted from the target independent version but this handles
00012 // calls to varargs functions
00013 //
00014 //===----------------------------------------------------------------------===//
00015 //
00016 
00017 
00018 
00019 
00020 static bool RetCC_Hexagon32_VarArgs(unsigned ValNo, EVT ValVT,
00021                                     EVT LocVT, CCValAssign::LocInfo LocInfo,
00022                                     ISD::ArgFlagsTy ArgFlags,
00023                                     Hexagon_CCState &State,
00024                                     int NonVarArgsParams,
00025                                     int CurrentParam,
00026                                     bool ForceMem);
00027 
00028 
00029 static bool CC_Hexagon32_VarArgs(unsigned ValNo, EVT ValVT,
00030                                  EVT LocVT, CCValAssign::LocInfo LocInfo,
00031                                  ISD::ArgFlagsTy ArgFlags,
00032                                  Hexagon_CCState &State,
00033                                  int NonVarArgsParams,
00034                                  int CurrentParam,
00035                                  bool ForceMem) {
00036   unsigned ByValSize = 0;
00037   if (ArgFlags.isByVal() &&
00038       ((ByValSize = ArgFlags.getByValSize()) >
00039        (MVT(MVT::i64).getSizeInBits() / 8))) {
00040     ForceMem = true;
00041   }
00042 
00043 
00044   // Only assign registers for named (non-varargs) arguments
00045   if ( !ForceMem && ((NonVarArgsParams == -1) || (CurrentParam <=
00046                                                   NonVarArgsParams))) {
00047 
00048     if (LocVT == MVT::i32 ||
00049         LocVT == MVT::i16 ||
00050         LocVT == MVT::i8 ||
00051         LocVT == MVT::f32) {
00052       static const unsigned RegList1[] = {
00053         Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4,
00054         Hexagon::R5
00055       };
00056       if (unsigned Reg = State.AllocateReg(RegList1, 6)) {
00057         State.addLoc(CCValAssign::getReg(ValNo, ValVT.getSimpleVT(), Reg,
00058                                          LocVT.getSimpleVT(), LocInfo));
00059         return false;
00060       }
00061     }
00062 
00063     if (LocVT == MVT::i64 ||
00064         LocVT == MVT::f64) {
00065       static const unsigned RegList2[] = {
00066         Hexagon::D0, Hexagon::D1, Hexagon::D2
00067       };
00068       if (unsigned Reg = State.AllocateReg(RegList2, 3)) {
00069         State.addLoc(CCValAssign::getReg(ValNo, ValVT.getSimpleVT(), Reg,
00070                                          LocVT.getSimpleVT(), LocInfo));
00071         return false;
00072       }
00073     }
00074   }
00075 
00076   const Type* ArgTy = LocVT.getTypeForEVT(State.getContext());
00077   unsigned Alignment = State.getTarget()
00078                            .getSubtargetImpl()
00079                            ->getDataLayout()
00080                            ->getABITypeAlignment(ArgTy);
00081   unsigned Size =
00082       State.getTarget().getSubtargetImpl()->getDataLayout()->getTypeSizeInBits(
00083           ArgTy) /
00084       8;
00085 
00086   // If it's passed by value, then we need the size of the aggregate not of
00087   // the pointer.
00088   if (ArgFlags.isByVal()) {
00089     Size = ByValSize;
00090 
00091     // Hexagon_TODO: Get the alignment of the contained type here.
00092     Alignment = 8;
00093   }
00094 
00095   unsigned Offset3 = State.AllocateStack(Size, Alignment);
00096   State.addLoc(CCValAssign::getMem(ValNo, ValVT.getSimpleVT(), Offset3,
00097                                    LocVT.getSimpleVT(), LocInfo));
00098   return false;
00099 }
00100 
00101 
00102 static bool RetCC_Hexagon32_VarArgs(unsigned ValNo, EVT ValVT,
00103                                     EVT LocVT, CCValAssign::LocInfo LocInfo,
00104                                     ISD::ArgFlagsTy ArgFlags,
00105                                     Hexagon_CCState &State,
00106                                     int NonVarArgsParams,
00107                                     int CurrentParam,
00108                                     bool ForceMem) {
00109 
00110   if (LocVT == MVT::i32 ||
00111       LocVT == MVT::f32) {
00112     static const unsigned RegList1[] = {
00113       Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4,
00114       Hexagon::R5
00115     };
00116     if (unsigned Reg = State.AllocateReg(RegList1, 6)) {
00117       State.addLoc(CCValAssign::getReg(ValNo, ValVT.getSimpleVT(), Reg,
00118                                        LocVT.getSimpleVT(), LocInfo));
00119       return false;
00120     }
00121   }
00122 
00123   if (LocVT == MVT::i64 ||
00124       LocVT == MVT::f64) {
00125     static const unsigned RegList2[] = {
00126       Hexagon::D0, Hexagon::D1, Hexagon::D2
00127     };
00128     if (unsigned Reg = State.AllocateReg(RegList2, 3)) {
00129       State.addLoc(CCValAssign::getReg(ValNo, ValVT.getSimpleVT(), Reg,
00130                                        LocVT.getSimpleVT(), LocInfo));
00131       return false;
00132     }
00133   }
00134 
00135   const Type* ArgTy = LocVT.getTypeForEVT(State.getContext());
00136   unsigned Alignment = State.getTarget()
00137                            .getSubtargetImpl()
00138                            ->getDataLayout()
00139                            ->getABITypeAlignment(ArgTy);
00140   unsigned Size =
00141       State.getTarget().getSubtargetImpl()->getDataLayout()->getTypeSizeInBits(
00142           ArgTy) /
00143       8;
00144 
00145   unsigned Offset3 = State.AllocateStack(Size, Alignment);
00146   State.addLoc(CCValAssign::getMem(ValNo, ValVT.getSimpleVT(), Offset3,
00147                                    LocVT.getSimpleVT(), LocInfo));
00148   return false;
00149 }