LLVM 17.0.0git
MipsABIFlagsSection.h
Go to the documentation of this file.
1//===- MipsABIFlagsSection.h - Mips ELF ABI Flags Section -------*- C++ -*-===//
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_MIPSABIFLAGSSECTION_H
10#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
11
14#include <cstdint>
15
16namespace llvm {
17
18class MCStreamer;
19class StringRef;
20
22 // Internal representation of the fp_abi related values used in .module.
23 enum class FpABIKind { ANY, XX, S32, S64, SOFT };
24
25 // Version of flags structure.
27 // The level of the ISA: 1-5, 32, 64.
28 uint8_t ISALevel = 0;
29 // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
30 uint8_t ISARevision = 0;
31 // The size of general purpose registers.
33 // The size of co-processor 1 registers.
35 // The size of co-processor 2 registers.
37 // Processor-specific extension.
39 // Mask of ASEs used.
41
42 bool OddSPReg = false;
43
44 bool Is32BitABI = false;
45
46protected:
47 // The floating-point ABI.
49
50public:
52
54 uint8_t getISALevelValue() { return (uint8_t)ISALevel; }
55 uint8_t getISARevisionValue() { return (uint8_t)ISARevision; }
56 uint8_t getGPRSizeValue() { return (uint8_t)GPRSize; }
57 uint8_t getCPR1SizeValue();
58 uint8_t getCPR2SizeValue() { return (uint8_t)CPR2Size; }
59 uint8_t getFpABIValue();
62
64 uint32_t Value = 0;
65
66 if (OddSPReg)
68
69 return Value;
70 }
71
72 uint32_t getFlags2Value() { return 0; }
73
74 FpABIKind getFpABI() { return FpABI; }
75 void setFpABI(FpABIKind Value, bool IsABI32Bit) {
76 FpABI = Value;
77 Is32BitABI = IsABI32Bit;
78 }
79
81
82 template <class PredicateLibrary>
83 void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
84 if (P.hasMips64()) {
85 ISALevel = 64;
86 if (P.hasMips64r6())
87 ISARevision = 6;
88 else if (P.hasMips64r5())
89 ISARevision = 5;
90 else if (P.hasMips64r3())
91 ISARevision = 3;
92 else if (P.hasMips64r2())
93 ISARevision = 2;
94 else
95 ISARevision = 1;
96 } else if (P.hasMips32()) {
97 ISALevel = 32;
98 if (P.hasMips32r6())
99 ISARevision = 6;
100 else if (P.hasMips32r5())
101 ISARevision = 5;
102 else if (P.hasMips32r3())
103 ISARevision = 3;
104 else if (P.hasMips32r2())
105 ISARevision = 2;
106 else
107 ISARevision = 1;
108 } else {
109 ISARevision = 0;
110 if (P.hasMips5())
111 ISALevel = 5;
112 else if (P.hasMips4())
113 ISALevel = 4;
114 else if (P.hasMips3())
115 ISALevel = 3;
116 else if (P.hasMips2())
117 ISALevel = 2;
118 else if (P.hasMips1())
119 ISALevel = 1;
120 else
121 llvm_unreachable("Unknown ISA level!");
122 }
123 }
124
125 template <class PredicateLibrary>
126 void setGPRSizeFromPredicates(const PredicateLibrary &P) {
127 GPRSize = P.isGP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
128 }
129
130 template <class PredicateLibrary>
131 void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
132 if (P.useSoftFloat())
134 else if (P.hasMSA())
136 else
138 }
139
140 template <class PredicateLibrary>
141 void setISAExtensionFromPredicates(const PredicateLibrary &P) {
142 if (P.hasCnMipsP())
144 else if (P.hasCnMips())
146 else
148 }
149
150 template <class PredicateLibrary>
151 void setASESetFromPredicates(const PredicateLibrary &P) {
152 ASESet = 0;
153 if (P.hasDSP())
155 if (P.hasDSPR2())
157 if (P.hasMSA())
159 if (P.inMicroMipsMode())
161 if (P.inMips16Mode())
163 if (P.hasMT())
165 if (P.hasCRC())
167 if (P.hasVirt())
169 if (P.hasGINV())
171 }
172
173 template <class PredicateLibrary>
174 void setFpAbiFromPredicates(const PredicateLibrary &P) {
175 Is32BitABI = P.isABI_O32();
176
178 if (P.useSoftFloat())
180 else if (P.isABI_N32() || P.isABI_N64())
182 else if (P.isABI_O32()) {
183 if (P.isABI_FPXX())
185 else if (P.isFP64bit())
187 else
189 }
190 }
191
192 template <class PredicateLibrary>
193 void setAllFromPredicates(const PredicateLibrary &P) {
200 OddSPReg = P.useOddSPReg();
201 }
202};
203
204MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
205
206} // end namespace llvm
207
208#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
#define P(N)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ AFL_ASE_MICROMIPS
Definition: MipsABIFlags.h:43
@ AFL_FLAGS1_ODDSPREG
Definition: MipsABIFlags.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:292
StringRef getFpABIString(FpABIKind Value)
void setFpAbiFromPredicates(const PredicateLibrary &P)
void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P)
void setCPR1SizeFromPredicates(const PredicateLibrary &P)
void setGPRSizeFromPredicates(const PredicateLibrary &P)
void setASESetFromPredicates(const PredicateLibrary &P)
void setISAExtensionFromPredicates(const PredicateLibrary &P)
void setAllFromPredicates(const PredicateLibrary &P)
void setFpABI(FpABIKind Value, bool IsABI32Bit)