1ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines//===---- MipsABIInfo.cpp - Information about MIPS ABI's ------------------===// 2ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines// 3ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines// The LLVM Compiler Infrastructure 4ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines// 5ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines// This file is distributed under the University of Illinois Open Source 6ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines// License. See LICENSE.TXT for details. 7ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines// 8ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines//===----------------------------------------------------------------------===// 9ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 10ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "MipsABIInfo.h" 11ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "MipsRegisterInfo.h" 12ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/ADT/StringRef.h" 13ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/ADT/StringSwitch.h" 14ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/MC/MCTargetOptions.h" 15ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 16ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesusing namespace llvm; 17ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 18ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesnamespace { 19ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesstatic const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3}; 20ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 21ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesstatic const MCPhysReg Mips64IntRegs[8] = { 22ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, 23ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64}; 24ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines} 25ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 26cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga NainarArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const { 27ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (IsO32()) 28ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return makeArrayRef(O32IntRegs); 29ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (IsN32() || IsN64()) 30ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return makeArrayRef(Mips64IntRegs); 31ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines llvm_unreachable("Unhandled ABI"); 32ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines} 33ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 34cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga NainarArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const { 35ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (IsO32()) 36ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return makeArrayRef(O32IntRegs); 37ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (IsN32() || IsN64()) 38ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return makeArrayRef(Mips64IntRegs); 39ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines llvm_unreachable("Unhandled ABI"); 40ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines} 41ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 42ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesunsigned MipsABIInfo::GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const { 43ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (IsO32()) 44ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return CC != CallingConv::Fast ? 16 : 0; 45ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (IsN32() || IsN64() || IsEABI()) 46ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return 0; 47ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines llvm_unreachable("Unhandled ABI"); 48ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines} 49ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 50cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga NainarMipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU, 51ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines const MCTargetOptions &Options) { 52ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (Options.getABIName().startswith("o32")) 53ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return MipsABIInfo::O32(); 54ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines else if (Options.getABIName().startswith("n32")) 55ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return MipsABIInfo::N32(); 56ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines else if (Options.getABIName().startswith("n64")) 57ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return MipsABIInfo::N64(); 58ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines else if (Options.getABIName().startswith("eabi")) 59ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return MipsABIInfo::EABI(); 60ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines else if (!Options.getABIName().empty()) 61ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines llvm_unreachable("Unknown ABI option for MIPS"); 62ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 63ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // FIXME: This shares code with the selectMipsCPU routine that's 64ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // used and not shared in a couple of other places. This needs unifying 65ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // at some level. 66ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (CPU.empty() || CPU == "generic") { 67ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines if (TT.getArch() == Triple::mips || TT.getArch() == Triple::mipsel) 68ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines CPU = "mips32"; 69ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines else 70ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines CPU = "mips64"; 71ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines } 72ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 73ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return StringSwitch<MipsABIInfo>(CPU) 74ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips1", MipsABIInfo::O32()) 75ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips2", MipsABIInfo::O32()) 76ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips32", MipsABIInfo::O32()) 77ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips32r2", MipsABIInfo::O32()) 78ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips32r3", MipsABIInfo::O32()) 79ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips32r5", MipsABIInfo::O32()) 80ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips32r6", MipsABIInfo::O32()) 81ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips3", MipsABIInfo::N64()) 82ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips4", MipsABIInfo::N64()) 83ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips5", MipsABIInfo::N64()) 84ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips64", MipsABIInfo::N64()) 85ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips64r2", MipsABIInfo::N64()) 86ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips64r3", MipsABIInfo::N64()) 87ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips64r5", MipsABIInfo::N64()) 88ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("mips64r6", MipsABIInfo::N64()) 89ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Case("octeon", MipsABIInfo::N64()) 90ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines .Default(MipsABIInfo::Unknown()); 91ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines} 926948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 936948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarunsigned MipsABIInfo::GetStackPtr() const { 946948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return ArePtrs64bit() ? Mips::SP_64 : Mips::SP; 956948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar} 966948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 976948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarunsigned MipsABIInfo::GetFramePtr() const { 986948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return ArePtrs64bit() ? Mips::FP_64 : Mips::FP; 996948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar} 1006948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 1016948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarunsigned MipsABIInfo::GetBasePtr() const { 1026948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return ArePtrs64bit() ? Mips::S7_64 : Mips::S7; 1036948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar} 1046948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 1056948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarunsigned MipsABIInfo::GetNullPtr() const { 1066948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO; 1076948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar} 1086948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 109cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainarunsigned MipsABIInfo::GetZeroReg() const { 110cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO; 111cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar} 112cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar 1136948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarunsigned MipsABIInfo::GetPtrAdduOp() const { 1146948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu; 1156948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar} 1166948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 1176948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarunsigned MipsABIInfo::GetPtrAddiuOp() const { 1186948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu; 1196948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar} 1206948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 121cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainarunsigned MipsABIInfo::GetGPRMoveOp() const { 122cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar return ArePtrs64bit() ? Mips::OR64 : Mips::OR; 123cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar} 124cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar 1256948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarunsigned MipsABIInfo::GetEhDataReg(unsigned I) const { 1266948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar static const unsigned EhDataReg[] = { 1276948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar Mips::A0, Mips::A1, Mips::A2, Mips::A3 1286948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar }; 1296948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar static const unsigned EhDataReg64[] = { 1306948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64 1316948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar }; 1326948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 1336948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return IsN64() ? EhDataReg64[I] : EhDataReg[I]; 1346948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar} 1356948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 136