1//===---- MipsABIInfo.h - 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#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIINFO_H
10#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIINFO_H
11
12#include "llvm/IR/CallingConv.h"
13#include "llvm/MC/MCRegisterInfo.h"
14#include "llvm/TargetParser/Triple.h"
15
16namespace llvm {
17
18template <typename T> class ArrayRef;
19class MCTargetOptions;
20class StringRef;
21
22class MipsABIInfo {
23public:
24 enum class ABI { Unknown, O32, N32, N64, P32 };
25
26protected:
27 ABI ThisABI;
28
29public:
30 MipsABIInfo(ABI ThisABI) : ThisABI(ThisABI) {}
31
32 static MipsABIInfo Unknown() { return MipsABIInfo(ABI::Unknown); }
33 static MipsABIInfo O32() { return MipsABIInfo(ABI::O32); }
34 static MipsABIInfo N32() { return MipsABIInfo(ABI::N32); }
35 static MipsABIInfo N64() { return MipsABIInfo(ABI::N64); }
36 static MipsABIInfo P32() { return MipsABIInfo(ABI::P32); }
37 static MipsABIInfo computeTargetABI(const Triple &TT, StringRef ABIName);
38
39 bool IsKnown() const { return ThisABI != ABI::Unknown; }
40 bool IsO32() const { return ThisABI == ABI::O32; }
41 bool IsN32() const { return ThisABI == ABI::N32; }
42 bool IsN64() const { return ThisABI == ABI::N64; }
43 bool IsP32() const { return ThisABI == ABI::P32; }
44 ABI GetEnumValue() const { return ThisABI; }
45
46 /// Register naming convention for this ABI.
47 unsigned getRegAltNameIndex() const;
48
49 /// Integer argument registers in calling-convention order.
50 ArrayRef<MCPhysReg> getArgRegs(bool Is64Bit) const;
51
52 /// ABI register accessors default to the ABI's GPR width. Use the *RegPtr
53 /// variants for pointer-sized values; N32 has 32-bit pointers and 64-bit
54 /// GPRs.
55 MCRegister getArgReg(unsigned I, bool Is64Bit) const;
56 MCRegister getArgReg(unsigned I) const {
57 return getArgReg(I, Is64Bit: AreGprs64bit());
58 }
59 MCRegister getArgRegPtr(unsigned I) const {
60 return getArgReg(I, Is64Bit: ArePtrs64bit());
61 }
62 /// I is the suffix in tI (NABI has t0-t3 and t8-t9).
63 MCRegister getTempReg(unsigned I, bool Is64Bit) const;
64 MCRegister getTempReg(unsigned I) const {
65 return getTempReg(I, Is64Bit: AreGprs64bit());
66 }
67 MCRegister getTempRegPtr(unsigned I) const {
68 return getTempReg(I, Is64Bit: ArePtrs64bit());
69 }
70 MCRegister getSavedReg(unsigned I, bool Is64Bit) const;
71 MCRegister getSavedReg(unsigned I) const {
72 return getSavedReg(I, Is64Bit: AreGprs64bit());
73 }
74 MCRegister getSavedRegPtr(unsigned I) const {
75 return getSavedReg(I, Is64Bit: ArePtrs64bit());
76 }
77 /// Integer return-value registers.
78 MCRegister getReturnReg(unsigned I, bool Is64Bit) const;
79 MCRegister getReturnReg(unsigned I) const {
80 return getReturnReg(I, Is64Bit: AreGprs64bit());
81 }
82 MCRegister getReturnRegPtr(unsigned I) const {
83 return getReturnReg(I, Is64Bit: ArePtrs64bit());
84 }
85
86 /// The registers to use for byval arguments.
87 ArrayRef<MCPhysReg> GetByValArgRegs() const;
88
89 /// The registers to use for the variable argument list.
90 ArrayRef<MCPhysReg> getVarArgRegs(bool isGP64bit) const;
91
92 /// Obtain the size of the area allocated by the callee for arguments.
93 /// CallingConv::FastCall affects the value for O32.
94 unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const;
95
96 /// Ordering of ABI's
97 /// MipsGenSubtargetInfo.inc will use this to resolve conflicts when given
98 /// multiple ABI options.
99 bool operator<(const MipsABIInfo Other) const {
100 return ThisABI < Other.GetEnumValue();
101 }
102
103 unsigned GetStackPtr() const;
104 unsigned GetFramePtr() const;
105 unsigned GetBasePtr() const;
106 unsigned GetGlobalPtr() const;
107 unsigned GetNullPtr() const;
108 unsigned GetZeroReg() const;
109 unsigned GetPtrAdduOp() const;
110 unsigned GetPtrAddiuOp() const;
111 unsigned GetPtrSubuOp() const;
112 unsigned GetPtrAndOp() const;
113 unsigned GetGPRMoveOp() const;
114 inline bool ArePtrs64bit() const { return IsN64(); }
115 inline bool AreGprs64bit() const { return IsN32() || IsN64(); }
116
117 unsigned GetEhDataReg(unsigned I) const;
118};
119}
120
121#endif
122