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