LLVM 22.0.0git
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 "Mips.h"
11#include "llvm/ADT/StringRef.h"
14
15using namespace llvm;
16
17// Note: this option is defined here to be visible from libLLVMMipsAsmParser
18// and libLLVMMipsCodeGen
20EmitJalrReloc("mips-jalr-reloc", cl::Hidden,
21 cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"),
22 cl::init(true));
23
24namespace {
25static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
26
27static 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 ArrayRef(O32IntRegs);
35 if (IsN32() || IsN64())
36 return ArrayRef(Mips64IntRegs);
37 llvm_unreachable("Unhandled ABI");
38}
39
41 if (IsO32()) {
42 if (isGP64bit)
43 return ArrayRef(Mips64IntRegs);
44 else
45 return ArrayRef(O32IntRegs);
46 }
47 if (IsN32() || IsN64())
48 return ArrayRef(Mips64IntRegs);
49 llvm_unreachable("Unhandled ABI");
50}
51
53 if (IsO32())
54 return CC != CallingConv::Fast ? 16 : 0;
55 if (IsN32() || IsN64())
56 return 0;
57 llvm_unreachable("Unhandled ABI");
58}
59
61 if (ABIName.starts_with("o32"))
62 return MipsABIInfo::O32();
63 if (ABIName.starts_with("n32"))
64 return MipsABIInfo::N32();
65 if (ABIName.starts_with("n64"))
66 return MipsABIInfo::N64();
67 if (TT.isABIN32())
68 return MipsABIInfo::N32();
69 assert(ABIName.empty() && "Unknown ABI option for MIPS");
70
71 if (TT.isMIPS64())
72 return MipsABIInfo::N64();
73 return MipsABIInfo::O32();
74}
75
76unsigned MipsABIInfo::GetStackPtr() const {
77 return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
78}
79
80unsigned MipsABIInfo::GetFramePtr() const {
81 return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
82}
83
84unsigned MipsABIInfo::GetBasePtr() const {
85 return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
86}
87
88unsigned MipsABIInfo::GetGlobalPtr() const {
89 return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
90}
91
92unsigned MipsABIInfo::GetNullPtr() const {
93 return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
94}
95
96unsigned MipsABIInfo::GetZeroReg() const {
97 return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
98}
99
101 return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
102}
103
105 return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
106}
107
109 return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
110}
111
112unsigned MipsABIInfo::GetPtrAndOp() const {
113 return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
114}
115
117 return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
118}
119
120unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
121 static const unsigned EhDataReg[] = {
122 Mips::A0, Mips::A1, Mips::A2, Mips::A3
123 };
124 static const unsigned EhDataReg64[] = {
125 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
126 };
127
128 return IsN64() ? EhDataReg64[I] : EhDataReg[I];
129}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define I(x, y, z)
Definition MD5.cpp:58
cl::opt< bool > EmitJalrReloc("mips-jalr-reloc", cl::Hidden, cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"), cl::init(true))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
bool AreGprs64bit() const
Definition MipsABIInfo.h:73
bool IsN64() const
Definition MipsABIInfo.h:41
unsigned GetGlobalPtr() const
static MipsABIInfo O32()
Definition MipsABIInfo.h:33
MipsABIInfo(ABI ThisABI)
Definition MipsABIInfo.h:30
unsigned GetEhDataReg(unsigned I) const
bool ArePtrs64bit() const
Definition MipsABIInfo.h:72
unsigned GetGPRMoveOp() const
unsigned GetStackPtr() const
static MipsABIInfo N32()
Definition MipsABIInfo.h:34
unsigned GetZeroReg() const
unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const
Obtain the size of the area allocated by the callee for arguments.
static MipsABIInfo N64()
Definition MipsABIInfo.h:35
unsigned GetPtrAddiuOp() const
unsigned GetPtrAndOp() const
unsigned GetFramePtr() const
static MipsABIInfo computeTargetABI(const Triple &TT, StringRef ABIName)
ArrayRef< MCPhysReg > GetByValArgRegs() const
The registers to use for byval arguments.
unsigned GetNullPtr() const
ArrayRef< MCPhysReg > getVarArgRegs(bool isGP64bit) const
The registers to use for the variable argument list.
unsigned GetPtrAdduOp() const
bool IsN32() const
Definition MipsABIInfo.h:40
unsigned GetBasePtr() const
unsigned GetPtrSubuOp() const
bool IsO32() const
Definition MipsABIInfo.h:39
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:261
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
ArrayRef(const T &OneElt) -> ArrayRef< T >