1 //===---- MipsABIInfo.cpp - Information about MIPS ABI's ------------------===// 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 10 #include "MipsABIInfo.h" 11 #include "MipsRegisterInfo.h" 12 #include "llvm/ADT/StringRef.h" 13 #include "llvm/ADT/StringSwitch.h" 14 #include "llvm/MC/MCTargetOptions.h" 15 16 using namespace llvm; 17 18 namespace { 19 static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3}; 20 21 static const MCPhysReg Mips64IntRegs[8] = { 22 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, 23 Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64}; 24 } 25 26 ArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const { 27 if (IsO32()) 28 return makeArrayRef(O32IntRegs); 29 if (IsN32() || IsN64()) 30 return makeArrayRef(Mips64IntRegs); 31 llvm_unreachable("Unhandled ABI"); 32 } 33 34 ArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const { 35 if (IsO32()) 36 return makeArrayRef(O32IntRegs); 37 if (IsN32() || IsN64()) 38 return makeArrayRef(Mips64IntRegs); 39 llvm_unreachable("Unhandled ABI"); 40 } 41 42 unsigned MipsABIInfo::GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const { 43 if (IsO32()) 44 return CC != CallingConv::Fast ? 16 : 0; 45 if (IsN32() || IsN64()) 46 return 0; 47 llvm_unreachable("Unhandled ABI"); 48 } 49 50 MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU, 51 const MCTargetOptions &Options) { 52 if (Options.getABIName().startswith("o32")) 53 return MipsABIInfo::O32(); 54 if (Options.getABIName().startswith("n32")) 55 return MipsABIInfo::N32(); 56 if (Options.getABIName().startswith("n64")) 57 return MipsABIInfo::N64(); 58 assert(Options.getABIName().empty() && "Unknown ABI option for MIPS"); 59 60 if (TT.getArch() == Triple::mips64 || TT.getArch() == Triple::mips64el) 61 return MipsABIInfo::N64(); 62 return MipsABIInfo::O32(); 63 } 64 65 unsigned MipsABIInfo::GetStackPtr() const { 66 return ArePtrs64bit() ? Mips::SP_64 : Mips::SP; 67 } 68 69 unsigned MipsABIInfo::GetFramePtr() const { 70 return ArePtrs64bit() ? Mips::FP_64 : Mips::FP; 71 } 72 73 unsigned MipsABIInfo::GetBasePtr() const { 74 return ArePtrs64bit() ? Mips::S7_64 : Mips::S7; 75 } 76 77 unsigned MipsABIInfo::GetGlobalPtr() const { 78 return ArePtrs64bit() ? Mips::GP_64 : Mips::GP; 79 } 80 81 unsigned MipsABIInfo::GetNullPtr() const { 82 return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO; 83 } 84 85 unsigned MipsABIInfo::GetZeroReg() const { 86 return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO; 87 } 88 89 unsigned MipsABIInfo::GetPtrAdduOp() const { 90 return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu; 91 } 92 93 unsigned MipsABIInfo::GetPtrAddiuOp() const { 94 return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu; 95 } 96 97 unsigned MipsABIInfo::GetPtrSubuOp() const { 98 return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu; 99 } 100 101 unsigned MipsABIInfo::GetPtrAndOp() const { 102 return ArePtrs64bit() ? Mips::AND64 : Mips::AND; 103 } 104 105 unsigned MipsABIInfo::GetGPRMoveOp() const { 106 return ArePtrs64bit() ? Mips::OR64 : Mips::OR; 107 } 108 109 unsigned MipsABIInfo::GetEhDataReg(unsigned I) const { 110 static const unsigned EhDataReg[] = { 111 Mips::A0, Mips::A1, Mips::A2, Mips::A3 112 }; 113 static const unsigned EhDataReg64[] = { 114 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64 115 }; 116 117 return IsN64() ? EhDataReg64[I] : EhDataReg[I]; 118 } 119 120