LLVM  9.0.0svn
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 // Note: this option is defined here to be visible from libLLVMMipsAsmParser
19 // and libLLVMMipsCodeGen
21 EmitJalrReloc("mips-jalr-reloc", cl::Hidden,
22  cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"),
23  cl::init(true));
24 
25 namespace {
26 static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
27 
28 static const MCPhysReg Mips64IntRegs[8] = {
29  Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64,
30  Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64};
31 }
32 
34  if (IsO32())
35  return makeArrayRef(O32IntRegs);
36  if (IsN32() || IsN64())
37  return makeArrayRef(Mips64IntRegs);
38  llvm_unreachable("Unhandled ABI");
39 }
40 
42  if (IsO32())
43  return makeArrayRef(O32IntRegs);
44  if (IsN32() || IsN64())
45  return makeArrayRef(Mips64IntRegs);
46  llvm_unreachable("Unhandled ABI");
47 }
48 
50  if (IsO32())
51  return CC != CallingConv::Fast ? 16 : 0;
52  if (IsN32() || IsN64())
53  return 0;
54  llvm_unreachable("Unhandled ABI");
55 }
56 
58  const MCTargetOptions &Options) {
59  if (Options.getABIName().startswith("o32"))
60  return MipsABIInfo::O32();
61  if (Options.getABIName().startswith("n32"))
62  return MipsABIInfo::N32();
63  if (Options.getABIName().startswith("n64"))
64  return MipsABIInfo::N64();
66  return MipsABIInfo::N32();
67  assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");
68 
69  if (TT.isMIPS64())
70  return MipsABIInfo::N64();
71  return MipsABIInfo::O32();
72 }
73 
74 unsigned MipsABIInfo::GetStackPtr() const {
75  return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
76 }
77 
78 unsigned MipsABIInfo::GetFramePtr() const {
79  return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
80 }
81 
82 unsigned MipsABIInfo::GetBasePtr() const {
83  return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
84 }
85 
86 unsigned MipsABIInfo::GetGlobalPtr() const {
87  return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
88 }
89 
90 unsigned MipsABIInfo::GetNullPtr() const {
91  return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
92 }
93 
94 unsigned MipsABIInfo::GetZeroReg() const {
95  return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
96 }
97 
98 unsigned MipsABIInfo::GetPtrAdduOp() const {
99  return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
100 }
101 
102 unsigned MipsABIInfo::GetPtrAddiuOp() const {
103  return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
104 }
105 
106 unsigned MipsABIInfo::GetPtrSubuOp() const {
107  return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
108 }
109 
110 unsigned MipsABIInfo::GetPtrAndOp() const {
111  return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
112 }
113 
114 unsigned MipsABIInfo::GetGPRMoveOp() const {
115  return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
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 
unsigned GetPtrAdduOp() const
Definition: MipsABIInfo.cpp:98
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition: Triple.h:685
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool ArePtrs64bit() const
Definition: MipsABIInfo.h:75
unsigned GetEhDataReg(unsigned I) const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const
Obtain the size of the area allocated by the callee for arguments.
Definition: MipsABIInfo.cpp:49
bool IsN32() const
Definition: MipsABIInfo.h:43
unsigned GetGlobalPtr() const
Definition: MipsABIInfo.cpp:86
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:43
bool IsN64() const
Definition: MipsABIInfo.h:44
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
ArrayRef< MCPhysReg > GetByValArgRegs() const
The registers to use for byval arguments.
Definition: MipsABIInfo.cpp:33
unsigned GetPtrAndOp() const
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:423
unsigned GetPtrAddiuOp() const
static MipsABIInfo O32()
Definition: MipsABIInfo.h:35
static ManagedStatic< OptionRegistry > OR
Definition: Options.cpp:31
cl::opt< bool > EmitJalrReloc("mips-jalr-reloc", cl::Hidden, cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"), cl::init(true))
bool IsO32() const
Definition: MipsABIInfo.h:42
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool AreGprs64bit() const
Definition: MipsABIInfo.h:76
EnvironmentType getEnvironment() const
getEnvironment - Get the parsed environment type of this triple.
Definition: Triple.h:308
unsigned GetPtrSubuOp() const
ArrayRef< MCPhysReg > GetVarArgRegs() const
The registers to use for the variable argument list.
Definition: MipsABIInfo.cpp:41
StringRef getABIName() const
getABIName - If this returns a non-empty string this represents the textual name of the ABI that we w...
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:387
unsigned GetBasePtr() const
Definition: MipsABIInfo.cpp:82
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned GetZeroReg() const
Definition: MipsABIInfo.cpp:94
unsigned GetGPRMoveOp() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static MipsABIInfo computeTargetABI(const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
Definition: MipsABIInfo.cpp:57
static MipsABIInfo N32()
Definition: MipsABIInfo.h:36
unsigned GetStackPtr() const
Definition: MipsABIInfo.cpp:74
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
unsigned GetNullPtr() const
Definition: MipsABIInfo.cpp:90
static MipsABIInfo N64()
Definition: MipsABIInfo.h:37
unsigned GetFramePtr() const
Definition: MipsABIInfo.cpp:78