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   if (TT.getEnvironment() == llvm::Triple::GNUABIN32)
59     return MipsABIInfo::N32();
60   assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");
61 
62   if (TT.isMIPS64())
63     return MipsABIInfo::N64();
64   return MipsABIInfo::O32();
65 }
66 
67 unsigned MipsABIInfo::GetStackPtr() const {
68   return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
69 }
70 
71 unsigned MipsABIInfo::GetFramePtr() const {
72   return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
73 }
74 
75 unsigned MipsABIInfo::GetBasePtr() const {
76   return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
77 }
78 
79 unsigned MipsABIInfo::GetGlobalPtr() const {
80   return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
81 }
82 
83 unsigned MipsABIInfo::GetNullPtr() const {
84   return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
85 }
86 
87 unsigned MipsABIInfo::GetZeroReg() const {
88   return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
89 }
90 
91 unsigned MipsABIInfo::GetPtrAdduOp() const {
92   return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
93 }
94 
95 unsigned MipsABIInfo::GetPtrAddiuOp() const {
96   return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
97 }
98 
99 unsigned MipsABIInfo::GetPtrSubuOp() const {
100   return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
101 }
102 
103 unsigned MipsABIInfo::GetPtrAndOp() const {
104   return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
105 }
106 
107 unsigned MipsABIInfo::GetGPRMoveOp() const {
108   return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
109 }
110 
111 unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
112   static const unsigned EhDataReg[] = {
113     Mips::A0, Mips::A1, Mips::A2, Mips::A3
114   };
115   static const unsigned EhDataReg64[] = {
116     Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
117   };
118 
119   return IsN64() ? EhDataReg64[I] : EhDataReg[I];
120 }
121 
122