• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetByValArgRegs() const26 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 
GetVarArgRegs() const34 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 
GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const42 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 
computeTargetABI(const Triple & TT,StringRef CPU,const MCTargetOptions & Options)50 MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU,
51                                           const MCTargetOptions &Options) {
52   if (Options.getABIName().startswith("o32"))
53     return MipsABIInfo::O32();
54   else if (Options.getABIName().startswith("n32"))
55     return MipsABIInfo::N32();
56   else if (Options.getABIName().startswith("n64"))
57     return MipsABIInfo::N64();
58   else if (!Options.getABIName().empty())
59     llvm_unreachable("Unknown ABI option for MIPS");
60 
61   if (TT.getArch() == Triple::mips64 || TT.getArch() == Triple::mips64el)
62     return MipsABIInfo::N64();
63   return MipsABIInfo::O32();
64 }
65 
GetStackPtr() const66 unsigned MipsABIInfo::GetStackPtr() const {
67   return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
68 }
69 
GetFramePtr() const70 unsigned MipsABIInfo::GetFramePtr() const {
71   return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
72 }
73 
GetBasePtr() const74 unsigned MipsABIInfo::GetBasePtr() const {
75   return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
76 }
77 
GetGlobalPtr() const78 unsigned MipsABIInfo::GetGlobalPtr() const {
79   return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
80 }
81 
GetNullPtr() const82 unsigned MipsABIInfo::GetNullPtr() const {
83   return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
84 }
85 
GetZeroReg() const86 unsigned MipsABIInfo::GetZeroReg() const {
87   return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
88 }
89 
GetPtrAdduOp() const90 unsigned MipsABIInfo::GetPtrAdduOp() const {
91   return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
92 }
93 
GetPtrAddiuOp() const94 unsigned MipsABIInfo::GetPtrAddiuOp() const {
95   return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
96 }
97 
GetPtrSubuOp() const98 unsigned MipsABIInfo::GetPtrSubuOp() const {
99   return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
100 }
101 
GetPtrAndOp() const102 unsigned MipsABIInfo::GetPtrAndOp() const {
103   return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
104 }
105 
GetGPRMoveOp() const106 unsigned MipsABIInfo::GetGPRMoveOp() const {
107   return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
108 }
109 
GetEhDataReg(unsigned I) const110 unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
111   static const unsigned EhDataReg[] = {
112     Mips::A0, Mips::A1, Mips::A2, Mips::A3
113   };
114   static const unsigned EhDataReg64[] = {
115     Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
116   };
117 
118   return IsN64() ? EhDataReg64[I] : EhDataReg[I];
119 }
120 
121