LLVM  3.7.0
MipsABIInfo.cpp
Go to the documentation of this file.
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"
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 
27  if (IsO32())
28  return makeArrayRef(O32IntRegs);
29  if (IsN32() || IsN64())
30  return makeArrayRef(Mips64IntRegs);
31  llvm_unreachable("Unhandled ABI");
32 }
33 
35  if (IsO32())
36  return makeArrayRef(O32IntRegs);
37  if (IsN32() || IsN64())
38  return makeArrayRef(Mips64IntRegs);
39  llvm_unreachable("Unhandled ABI");
40 }
41 
43  if (IsO32())
44  return CC != CallingConv::Fast ? 16 : 0;
45  if (IsN32() || IsN64() || IsEABI())
46  return 0;
47  llvm_unreachable("Unhandled ABI");
48 }
49 
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().startswith("eabi"))
59  return MipsABIInfo::EABI();
60  else if (!Options.getABIName().empty())
61  llvm_unreachable("Unknown ABI option for MIPS");
62 
63  // FIXME: This shares code with the selectMipsCPU routine that's
64  // used and not shared in a couple of other places. This needs unifying
65  // at some level.
66  if (CPU.empty() || CPU == "generic") {
67  if (TT.getArch() == Triple::mips || TT.getArch() == Triple::mipsel)
68  CPU = "mips32";
69  else
70  CPU = "mips64";
71  }
72 
73  return StringSwitch<MipsABIInfo>(CPU)
74  .Case("mips1", MipsABIInfo::O32())
75  .Case("mips2", MipsABIInfo::O32())
76  .Case("mips32", MipsABIInfo::O32())
77  .Case("mips32r2", MipsABIInfo::O32())
78  .Case("mips32r3", MipsABIInfo::O32())
79  .Case("mips32r5", MipsABIInfo::O32())
80  .Case("mips32r6", MipsABIInfo::O32())
81  .Case("mips16", MipsABIInfo::O32())
82  .Case("mips3", MipsABIInfo::N64())
83  .Case("mips4", MipsABIInfo::N64())
84  .Case("mips5", MipsABIInfo::N64())
85  .Case("mips64", MipsABIInfo::N64())
86  .Case("mips64r2", MipsABIInfo::N64())
87  .Case("mips64r3", MipsABIInfo::N64())
88  .Case("mips64r5", MipsABIInfo::N64())
89  .Case("mips64r6", MipsABIInfo::N64())
90  .Case("octeon", MipsABIInfo::N64())
92 }
93 
94 unsigned MipsABIInfo::GetStackPtr() const {
95  return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
96 }
97 
98 unsigned MipsABIInfo::GetFramePtr() const {
99  return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
100 }
101 
102 unsigned MipsABIInfo::GetBasePtr() const {
103  return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
104 }
105 
106 unsigned MipsABIInfo::GetNullPtr() const {
107  return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
108 }
109 
110 unsigned MipsABIInfo::GetPtrAdduOp() const {
111  return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
112 }
113 
114 unsigned MipsABIInfo::GetPtrAddiuOp() const {
115  return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
116 }
117 
118 unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
119  static const unsigned EhDataReg[] = {
120  Mips::A0, Mips::A1, Mips::A2, Mips::A3
121  };
122  static const unsigned EhDataReg64[] = {
123  Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
124  };
125 
126  return IsN64() ? EhDataReg64[I] : EhDataReg[I];
127 }
128 
bool ArePtrs64bit() const
Definition: MipsABIInfo.h:72
unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const
Obtain the size of the area allocated by the callee for arguments.
Definition: MipsABIInfo.cpp:42
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
static MipsABIInfo EABI()
Definition: MipsABIInfo.h:38
static MipsABIInfo Unknown()
Definition: MipsABIInfo.h:34
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:308
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:242
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
static MipsABIInfo O32()
Definition: MipsABIInfo.h:35
bool IsN32() const
Definition: MipsABIInfo.h:44
const ArrayRef< MCPhysReg > GetByValArgRegs() const
The registers to use for byval arguments.
Definition: MipsABIInfo.cpp:26
bool IsN64() const
Definition: MipsABIInfo.h:45
unsigned GetBasePtr() const
bool IsEABI() const
Definition: MipsABIInfo.h:46
unsigned GetEhDataReg(unsigned I) const
unsigned GetStackPtr() const
Definition: MipsABIInfo.cpp:94
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
unsigned GetNullPtr() const
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:215
bool IsO32() const
Definition: MipsABIInfo.h:43
const ArrayRef< MCPhysReg > GetVarArgRegs() const
The registers to use for the variable argument list.
Definition: MipsABIInfo.cpp:34
StringRef getABIName() const
getABIName - If this returns a non-empty string this represents the textual name of the ABI that we w...
#define I(x, y, z)
Definition: MD5.cpp:54
unsigned GetFramePtr() const
Definition: MipsABIInfo.cpp:98
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:42
static MipsABIInfo computeTargetABI(const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
Definition: MipsABIInfo.cpp:50
static MipsABIInfo N32()
Definition: MipsABIInfo.h:36
unsigned GetPtrAdduOp() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
unsigned GetPtrAddiuOp() const
static MipsABIInfo N64()
Definition: MipsABIInfo.h:37
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110