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));
24 NoZeroDivCheck("mno-check-zero-division", cl::Hidden,
25 cl::desc("MIPS: Don't trap on integer division by zero."),
26 cl::init(false));
27
28namespace {
29static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
30
31static const MCPhysReg Mips64IntRegs[8] = {
32 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64,
33 Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64};
34}
35
37 if (IsO32())
38 return ArrayRef(O32IntRegs);
39 if (IsN32() || IsN64())
40 return ArrayRef(Mips64IntRegs);
41 llvm_unreachable("Unhandled ABI");
42}
43
45 if (IsO32()) {
46 if (isGP64bit)
47 return ArrayRef(Mips64IntRegs);
48 else
49 return ArrayRef(O32IntRegs);
50 }
51 if (IsN32() || IsN64())
52 return ArrayRef(Mips64IntRegs);
53 llvm_unreachable("Unhandled ABI");
54}
55
57 if (IsO32())
58 return CC != CallingConv::Fast ? 16 : 0;
59 if (IsN32() || IsN64())
60 return 0;
61 llvm_unreachable("Unhandled ABI");
62}
63
65 if (ABIName.starts_with("o32"))
66 return MipsABIInfo::O32();
67 if (ABIName.starts_with("n32"))
68 return MipsABIInfo::N32();
69 if (ABIName.starts_with("n64"))
70 return MipsABIInfo::N64();
71 if (TT.isABIN32())
72 return MipsABIInfo::N32();
73 assert(ABIName.empty() && "Unknown ABI option for MIPS");
74
75 if (TT.isMIPS64())
76 return MipsABIInfo::N64();
77 return MipsABIInfo::O32();
78}
79
80unsigned MipsABIInfo::GetStackPtr() const {
81 return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
82}
83
84unsigned MipsABIInfo::GetFramePtr() const {
85 return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
86}
87
88unsigned MipsABIInfo::GetBasePtr() const {
89 return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
90}
91
92unsigned MipsABIInfo::GetGlobalPtr() const {
93 return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
94}
95
96unsigned MipsABIInfo::GetNullPtr() const {
97 return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
98}
99
100unsigned MipsABIInfo::GetZeroReg() const {
101 return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
102}
103
105 return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
106}
107
109 return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
110}
111
113 return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
114}
115
116unsigned MipsABIInfo::GetPtrAndOp() const {
117 return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
118}
119
121 return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
122}
123
124unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
125 static const unsigned EhDataReg[] = {
126 Mips::A0, Mips::A1, Mips::A2, Mips::A3
127 };
128 static const unsigned EhDataReg64[] = {
129 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
130 };
131
132 return IsN64() ? EhDataReg64[I] : EhDataReg[I];
133}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define I(x, y, z)
Definition MD5.cpp:57
cl::opt< bool > EmitJalrReloc("mips-jalr-reloc", cl::Hidden, cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"), cl::init(true))
cl::opt< bool > NoZeroDivCheck("mno-check-zero-division", cl::Hidden, cl::desc("MIPS: Don't trap on integer division by zero."), cl::init(false))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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 >