LLVM  9.0.0svn
MipsABIInfo.cpp
Go to the documentation of this file.
1 //===---- MipsABIInfo.cpp - Information about MIPS ABI's ------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "MipsABIInfo.h"
10 #include "MipsRegisterInfo.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/ADT/StringSwitch.h"
14 
15 using namespace llvm;
16 
17 // Note: this option is defined here to be visible from libLLVMMipsAsmParser
18 // and libLLVMMipsCodeGen
20 EmitJalrReloc("mips-jalr-reloc", cl::Hidden,
21  cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"),
22  cl::init(true));
23 
24 namespace {
25 static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
26 
27 static const MCPhysReg Mips64IntRegs[8] = {
28  Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64,
29  Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64};
30 }
31 
33  if (IsO32())
34  return makeArrayRef(O32IntRegs);
35  if (IsN32() || IsN64())
36  return makeArrayRef(Mips64IntRegs);
37  llvm_unreachable("Unhandled ABI");
38 }
39 
41  if (IsO32())
42  return makeArrayRef(O32IntRegs);
43  if (IsN32() || IsN64())
44  return makeArrayRef(Mips64IntRegs);
45  llvm_unreachable("Unhandled ABI");
46 }
47 
49  if (IsO32())
50  return CC != CallingConv::Fast ? 16 : 0;
51  if (IsN32() || IsN64())
52  return 0;
53  llvm_unreachable("Unhandled ABI");
54 }
55 
57  const MCTargetOptions &Options) {
58  if (Options.getABIName().startswith("o32"))
59  return MipsABIInfo::O32();
60  if (Options.getABIName().startswith("n32"))
61  return MipsABIInfo::N32();
62  if (Options.getABIName().startswith("n64"))
63  return MipsABIInfo::N64();
65  return MipsABIInfo::N32();
66  assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");
67 
68  if (TT.isMIPS64())
69  return MipsABIInfo::N64();
70  return MipsABIInfo::O32();
71 }
72 
73 unsigned MipsABIInfo::GetStackPtr() const {
74  return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
75 }
76 
77 unsigned MipsABIInfo::GetFramePtr() const {
78  return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
79 }
80 
81 unsigned MipsABIInfo::GetBasePtr() const {
82  return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
83 }
84 
85 unsigned MipsABIInfo::GetGlobalPtr() const {
86  return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
87 }
88 
89 unsigned MipsABIInfo::GetNullPtr() const {
90  return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
91 }
92 
93 unsigned MipsABIInfo::GetZeroReg() const {
94  return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
95 }
96 
97 unsigned MipsABIInfo::GetPtrAdduOp() const {
98  return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
99 }
100 
101 unsigned MipsABIInfo::GetPtrAddiuOp() const {
102  return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
103 }
104 
105 unsigned MipsABIInfo::GetPtrSubuOp() const {
106  return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
107 }
108 
109 unsigned MipsABIInfo::GetPtrAndOp() const {
110  return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
111 }
112 
113 unsigned MipsABIInfo::GetGPRMoveOp() const {
114  return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
115 }
116 
117 unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
118  static const unsigned EhDataReg[] = {
119  Mips::A0, Mips::A1, Mips::A2, Mips::A3
120  };
121  static const unsigned EhDataReg64[] = {
122  Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
123  };
124 
125  return IsN64() ? EhDataReg64[I] : EhDataReg[I];
126 }
127 
unsigned GetPtrAdduOp() const
Definition: MipsABIInfo.cpp:97
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition: Triple.h:700
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool ArePtrs64bit() const
Definition: MipsABIInfo.h:74
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
unsigned GetEhDataReg(unsigned I) const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:450
unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const
Obtain the size of the area allocated by the callee for arguments.
Definition: MipsABIInfo.cpp:48
bool IsN32() const
Definition: MipsABIInfo.h:42
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
unsigned GetGlobalPtr() const
Definition: MipsABIInfo.cpp:85
bool IsN64() const
Definition: MipsABIInfo.h:43
ArrayRef< MCPhysReg > GetByValArgRegs() const
The registers to use for byval arguments.
Definition: MipsABIInfo.cpp:32
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:427
unsigned GetPtrAddiuOp() const
static MipsABIInfo O32()
Definition: MipsABIInfo.h:34
static ManagedStatic< OptionRegistry > OR
Definition: Options.cpp:30
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:41
#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:43
bool AreGprs64bit() const
Definition: MipsABIInfo.h:75
EnvironmentType getEnvironment() const
getEnvironment - Get the parsed environment type of this triple.
Definition: Triple.h:309
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:42
unsigned GetPtrSubuOp() const
ArrayRef< MCPhysReg > GetVarArgRegs() const
The registers to use for the variable argument list.
Definition: MipsABIInfo.cpp:40
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:386
unsigned GetBasePtr() const
Definition: MipsABIInfo.cpp:81
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned GetZeroReg() const
Definition: MipsABIInfo.cpp:93
unsigned GetGPRMoveOp() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static MipsABIInfo computeTargetABI(const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
Definition: MipsABIInfo.cpp:56
static MipsABIInfo N32()
Definition: MipsABIInfo.h:35
unsigned GetStackPtr() const
Definition: MipsABIInfo.cpp:73
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
unsigned GetNullPtr() const
Definition: MipsABIInfo.cpp:89
static MipsABIInfo N64()
Definition: MipsABIInfo.h:36
unsigned GetFramePtr() const
Definition: MipsABIInfo.cpp:77