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/MC/MCStreamer.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/MipsABIFlags.h"
21 struct MipsABIFlagsSection {
22 // Internal representation of the fp_abi related values used in .module.
23 enum class FpABIKind { ANY, XX, S32, S64, SOFT };
25 // Version of flags structure.
27 // The level of the ISA: 1-5, 32, 64.
29 // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
31 // The size of general purpose registers.
32 Mips::AFL_REG GPRSize;
33 // The size of co-processor 1 registers.
34 Mips::AFL_REG CPR1Size;
35 // The size of co-processor 2 registers.
36 Mips::AFL_REG CPR2Size;
37 // Processor-specific extension.
38 Mips::AFL_EXT ISAExtension;
47 // The floating-point ABI.
52 : Version(0), ISALevel(0), ISARevision(0), GPRSize(Mips::AFL_REG_NONE),
53 CPR1Size(Mips::AFL_REG_NONE), CPR2Size(Mips::AFL_REG_NONE),
54 ISAExtension(Mips::AFL_EXT_NONE), ASESet(0), OddSPReg(false),
55 Is32BitABI(false), FpABI(FpABIKind::ANY) {}
57 uint16_t getVersionValue() { return (uint16_t)Version; }
58 uint8_t getISALevelValue() { return (uint8_t)ISALevel; }
59 uint8_t getISARevisionValue() { return (uint8_t)ISARevision; }
60 uint8_t getGPRSizeValue() { return (uint8_t)GPRSize; }
61 uint8_t getCPR1SizeValue();
62 uint8_t getCPR2SizeValue() { return (uint8_t)CPR2Size; }
63 uint8_t getFpABIValue();
64 uint32_t getISAExtensionValue() { return (uint32_t)ISAExtension; }
65 uint32_t getASESetValue() { return (uint32_t)ASESet; }
67 uint32_t getFlags1Value() {
71 Value |= (uint32_t)Mips::AFL_FLAGS1_ODDSPREG;
76 uint32_t getFlags2Value() { return 0; }
78 FpABIKind getFpABI() { return FpABI; }
79 void setFpABI(FpABIKind Value, bool IsABI32Bit) {
81 Is32BitABI = IsABI32Bit;
83 StringRef getFpABIString(FpABIKind Value);
85 template <class PredicateLibrary>
86 void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
91 else if (P.hasMips64r5())
93 else if (P.hasMips64r3())
95 else if (P.hasMips64r2())
99 } else if (P.hasMips32()) {
103 else if (P.hasMips32r5())
105 else if (P.hasMips32r3())
107 else if (P.hasMips32r2())
115 else if (P.hasMips4())
117 else if (P.hasMips3())
119 else if (P.hasMips2())
121 else if (P.hasMips1())
124 llvm_unreachable("Unknown ISA level!");
128 template <class PredicateLibrary>
129 void setGPRSizeFromPredicates(const PredicateLibrary &P) {
130 GPRSize = P.isGP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
133 template <class PredicateLibrary>
134 void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
135 if (P.useSoftFloat())
136 CPR1Size = Mips::AFL_REG_NONE;
138 CPR1Size = Mips::AFL_REG_128;
140 CPR1Size = P.isFP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
143 template <class PredicateLibrary>
144 void setISAExtensionFromPredicates(const PredicateLibrary &P) {
146 ISAExtension = Mips::AFL_EXT_OCTEON;
148 ISAExtension = Mips::AFL_EXT_NONE;
151 template <class PredicateLibrary>
152 void setASESetFromPredicates(const PredicateLibrary &P) {
155 ASESet |= Mips::AFL_ASE_DSP;
157 ASESet |= Mips::AFL_ASE_DSPR2;
159 ASESet |= Mips::AFL_ASE_MSA;
160 if (P.inMicroMipsMode())
161 ASESet |= Mips::AFL_ASE_MICROMIPS;
162 if (P.inMips16Mode())
163 ASESet |= Mips::AFL_ASE_MIPS16;
166 template <class PredicateLibrary>
167 void setFpAbiFromPredicates(const PredicateLibrary &P) {
168 Is32BitABI = P.isABI_O32();
170 FpABI = FpABIKind::ANY;
171 if (P.useSoftFloat())
172 FpABI = FpABIKind::SOFT;
173 else if (P.isABI_N32() || P.isABI_N64())
174 FpABI = FpABIKind::S64;
175 else if (P.isABI_O32()) {
177 FpABI = FpABIKind::XX;
178 else if (P.isFP64bit())
179 FpABI = FpABIKind::S64;
181 FpABI = FpABIKind::S32;
185 template <class PredicateLibrary>
186 void setAllFromPredicates(const PredicateLibrary &P) {
187 setISALevelAndRevisionFromPredicates(P);
188 setGPRSizeFromPredicates(P);
189 setCPR1SizeFromPredicates(P);
190 setISAExtensionFromPredicates(P);
191 setASESetFromPredicates(P);
192 setFpAbiFromPredicates(P);
193 OddSPReg = P.useOddSPReg();
197 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);