1 //===- MipsABIFlagsSection.h - Mips ELF ABI Flags Section -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
11 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/MipsABIFlags.h"
22 struct MipsABIFlagsSection {
23 // Internal representation of the fp_abi related values used in .module.
24 enum class FpABIKind { ANY, XX, S32, S64, SOFT };
26 // Version of flags structure.
28 // The level of the ISA: 1-5, 32, 64.
30 // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
31 uint8_t ISARevision = 0;
32 // The size of general purpose registers.
33 Mips::AFL_REG GPRSize = Mips::AFL_REG_NONE;
34 // The size of co-processor 1 registers.
35 Mips::AFL_REG CPR1Size = Mips::AFL_REG_NONE;
36 // The size of co-processor 2 registers.
37 Mips::AFL_REG CPR2Size = Mips::AFL_REG_NONE;
38 // Processor-specific extension.
39 Mips::AFL_EXT ISAExtension = Mips::AFL_EXT_NONE;
43 bool OddSPReg = false;
45 bool Is32BitABI = false;
48 // The floating-point ABI.
49 FpABIKind FpABI = FpABIKind::ANY;
52 MipsABIFlagsSection() = default;
54 uint16_t getVersionValue() { return (uint16_t)Version; }
55 uint8_t getISALevelValue() { return (uint8_t)ISALevel; }
56 uint8_t getISARevisionValue() { return (uint8_t)ISARevision; }
57 uint8_t getGPRSizeValue() { return (uint8_t)GPRSize; }
58 uint8_t getCPR1SizeValue();
59 uint8_t getCPR2SizeValue() { return (uint8_t)CPR2Size; }
60 uint8_t getFpABIValue();
61 uint32_t getISAExtensionValue() { return (uint32_t)ISAExtension; }
62 uint32_t getASESetValue() { return (uint32_t)ASESet; }
64 uint32_t getFlags1Value() {
68 Value |= (uint32_t)Mips::AFL_FLAGS1_ODDSPREG;
73 uint32_t getFlags2Value() { return 0; }
75 FpABIKind getFpABI() { return FpABI; }
76 void setFpABI(FpABIKind Value, bool IsABI32Bit) {
78 Is32BitABI = IsABI32Bit;
81 StringRef getFpABIString(FpABIKind Value);
83 template <class PredicateLibrary>
84 void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
89 else if (P.hasMips64r5())
91 else if (P.hasMips64r3())
93 else if (P.hasMips64r2())
97 } else if (P.hasMips32()) {
101 else if (P.hasMips32r5())
103 else if (P.hasMips32r3())
105 else if (P.hasMips32r2())
113 else if (P.hasMips4())
115 else if (P.hasMips3())
117 else if (P.hasMips2())
119 else if (P.hasMips1())
122 llvm_unreachable("Unknown ISA level!");
126 template <class PredicateLibrary>
127 void setGPRSizeFromPredicates(const PredicateLibrary &P) {
128 GPRSize = P.isGP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
131 template <class PredicateLibrary>
132 void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
133 if (P.useSoftFloat())
134 CPR1Size = Mips::AFL_REG_NONE;
136 CPR1Size = Mips::AFL_REG_128;
138 CPR1Size = P.isFP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
141 template <class PredicateLibrary>
142 void setISAExtensionFromPredicates(const PredicateLibrary &P) {
144 ISAExtension = Mips::AFL_EXT_OCTEON;
146 ISAExtension = Mips::AFL_EXT_NONE;
149 template <class PredicateLibrary>
150 void setASESetFromPredicates(const PredicateLibrary &P) {
153 ASESet |= Mips::AFL_ASE_DSP;
155 ASESet |= Mips::AFL_ASE_DSPR2;
157 ASESet |= Mips::AFL_ASE_MSA;
158 if (P.inMicroMipsMode())
159 ASESet |= Mips::AFL_ASE_MICROMIPS;
160 if (P.inMips16Mode())
161 ASESet |= Mips::AFL_ASE_MIPS16;
163 ASESet |= Mips::AFL_ASE_MT;
165 ASESet |= Mips::AFL_ASE_CRC;
167 ASESet |= Mips::AFL_ASE_VIRT;
169 ASESet |= Mips::AFL_ASE_GINV;
172 template <class PredicateLibrary>
173 void setFpAbiFromPredicates(const PredicateLibrary &P) {
174 Is32BitABI = P.isABI_O32();
176 FpABI = FpABIKind::ANY;
177 if (P.useSoftFloat())
178 FpABI = FpABIKind::SOFT;
179 else if (P.isABI_N32() || P.isABI_N64())
180 FpABI = FpABIKind::S64;
181 else if (P.isABI_O32()) {
183 FpABI = FpABIKind::XX;
184 else if (P.isFP64bit())
185 FpABI = FpABIKind::S64;
187 FpABI = FpABIKind::S32;
191 template <class PredicateLibrary>
192 void setAllFromPredicates(const PredicateLibrary &P) {
193 setISALevelAndRevisionFromPredicates(P);
194 setGPRSizeFromPredicates(P);
195 setCPR1SizeFromPredicates(P);
196 setISAExtensionFromPredicates(P);
197 setASESetFromPredicates(P);
198 setFpAbiFromPredicates(P);
199 OddSPReg = P.useOddSPReg();
203 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
205 } // end namespace llvm
207 #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H