1 //===---- MipsABIInfo.cpp - Information about MIPS ABI's ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
19 static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
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};
26 ArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const {
28 return makeArrayRef(O32IntRegs);
29 if (IsN32() || IsN64())
30 return makeArrayRef(Mips64IntRegs);
31 llvm_unreachable("Unhandled ABI");
34 ArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const {
36 return makeArrayRef(O32IntRegs);
37 if (IsN32() || IsN64())
38 return makeArrayRef(Mips64IntRegs);
39 llvm_unreachable("Unhandled ABI");
42 unsigned MipsABIInfo::GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const {
44 return CC != CallingConv::Fast ? 16 : 0;
45 if (IsN32() || IsN64())
47 llvm_unreachable("Unhandled ABI");
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");
61 return MipsABIInfo::N64();
62 return MipsABIInfo::O32();
65 unsigned MipsABIInfo::GetStackPtr() const {
66 return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
69 unsigned MipsABIInfo::GetFramePtr() const {
70 return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
73 unsigned MipsABIInfo::GetBasePtr() const {
74 return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
77 unsigned MipsABIInfo::GetGlobalPtr() const {
78 return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
81 unsigned MipsABIInfo::GetNullPtr() const {
82 return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
85 unsigned MipsABIInfo::GetZeroReg() const {
86 return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
89 unsigned MipsABIInfo::GetPtrAdduOp() const {
90 return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
93 unsigned MipsABIInfo::GetPtrAddiuOp() const {
94 return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
97 unsigned MipsABIInfo::GetPtrSubuOp() const {
98 return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
101 unsigned MipsABIInfo::GetPtrAndOp() const {
102 return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
105 unsigned MipsABIInfo::GetGPRMoveOp() const {
106 return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
109 unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
110 static const unsigned EhDataReg[] = {
111 Mips::A0, Mips::A1, Mips::A2, Mips::A3
113 static const unsigned EhDataReg64[] = {
114 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
117 return IsN64() ? EhDataReg64[I] : EhDataReg[I];