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