ed6df5a76174ea949266ebada10a733387713ccb
[oota-llvm.git] / lib / Target / Mips / MCTargetDesc / MipsABIFlagsSection.h
1 //===-- MipsABIFlagsSection.h - Mips ELF ABI Flags Section -----*- C++ -*--===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef MIPSABIFLAGSSECTION_H
11 #define MIPSABIFLAGSSECTION_H
12
13 #include "llvm/MC/MCStreamer.h"
14
15 namespace llvm {
16
17 class MCStreamer;
18
19 struct MipsABIFlagsSection {
20   // Values for the xxx_size bytes of an ABI flags structure.
21   enum AFL_REG {
22     AFL_REG_NONE = 0x00, // No registers.
23     AFL_REG_32 = 0x01,   // 32-bit registers.
24     AFL_REG_64 = 0x02,   // 64-bit registers.
25     AFL_REG_128 = 0x03   // 128-bit registers.
26   };
27
28   // Masks for the ases word of an ABI flags structure.
29   enum AFL_ASE {
30     AFL_ASE_DSP = 0x00000001,       // DSP ASE.
31     AFL_ASE_DSPR2 = 0x00000002,     // DSP R2 ASE.
32     AFL_ASE_EVA = 0x00000004,       // Enhanced VA Scheme.
33     AFL_ASE_MCU = 0x00000008,       // MCU (MicroController) ASE.
34     AFL_ASE_MDMX = 0x00000010,      // MDMX ASE.
35     AFL_ASE_MIPS3D = 0x00000020,    // MIPS-3D ASE.
36     AFL_ASE_MT = 0x00000040,        // MT ASE.
37     AFL_ASE_SMARTMIPS = 0x00000080, // SmartMIPS ASE.
38     AFL_ASE_VIRT = 0x00000100,      // VZ ASE.
39     AFL_ASE_MSA = 0x00000200,       // MSA ASE.
40     AFL_ASE_MIPS16 = 0x00000400,    // MIPS16 ASE.
41     AFL_ASE_MICROMIPS = 0x00000800, // MICROMIPS ASE.
42     AFL_ASE_XPA = 0x00001000        // XPA ASE.
43   };
44
45   // Values for the isa_ext word of an ABI flags structure.
46   enum AFL_EXT {
47     AFL_EXT_XLR = 1,          // RMI Xlr instruction.
48     AFL_EXT_OCTEON2 = 2,      // Cavium Networks Octeon2.
49     AFL_EXT_OCTEONP = 3,      // Cavium Networks OcteonP.
50     AFL_EXT_LOONGSON_3A = 4,  // Loongson 3A.
51     AFL_EXT_OCTEON = 5,       // Cavium Networks Octeon.
52     AFL_EXT_5900 = 6,         // MIPS R5900 instruction.
53     AFL_EXT_4650 = 7,         // MIPS R4650 instruction.
54     AFL_EXT_4010 = 8,         // LSI R4010 instruction.
55     AFL_EXT_4100 = 9,         // NEC VR4100 instruction.
56     AFL_EXT_3900 = 10,        // Toshiba R3900 instruction.
57     AFL_EXT_10000 = 11,       // MIPS R10000 instruction.
58     AFL_EXT_SB1 = 12,         // Broadcom SB-1 instruction.
59     AFL_EXT_4111 = 13,        // NEC VR4111/VR4181 instruction.
60     AFL_EXT_4120 = 14,        // NEC VR4120 instruction.
61     AFL_EXT_5400 = 15,        // NEC VR5400 instruction.
62     AFL_EXT_5500 = 16,        // NEC VR5500 instruction.
63     AFL_EXT_LOONGSON_2E = 17, // ST Microelectronics Loongson 2E.
64     AFL_EXT_LOONGSON_2F = 18  // ST Microelectronics Loongson 2F.
65   };
66
67   // Values for the fp_abi word of an ABI flags structure.
68   enum Val_GNU_MIPS_ABI {
69     Val_GNU_MIPS_ABI_FP_ANY = 0,
70     Val_GNU_MIPS_ABI_FP_DOUBLE = 1,
71     Val_GNU_MIPS_ABI_FP_XX = 5,
72     Val_GNU_MIPS_ABI_FP_64 = 6
73   };
74
75   // Version of flags structure.
76   uint16_t Version;
77   // The level of the ISA: 1-5, 32, 64.
78   uint8_t ISALevel;
79   // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
80   uint8_t ISARevision;
81   // The size of general purpose registers.
82   AFL_REG GPRSize;
83   // The size of co-processor 1 registers.
84   AFL_REG CPR1Size;
85   // The size of co-processor 2 registers.
86   AFL_REG CPR2Size;
87   // The floating-point ABI.
88   Val_GNU_MIPS_ABI FpABI;
89   // Processor-specific extension.
90   uint32_t ISAExtensionSet;
91   // Mask of ASEs used.
92   uint32_t ASESet;
93
94   MipsABIFlagsSection()
95       : Version(0), ISALevel(0), ISARevision(0), GPRSize(AFL_REG_NONE),
96         CPR1Size(AFL_REG_NONE), CPR2Size(AFL_REG_NONE),
97         FpABI(Val_GNU_MIPS_ABI_FP_ANY), ISAExtensionSet(0), ASESet(0) {}
98
99   uint16_t getVersion() { return (uint16_t)Version; }
100   uint8_t getISALevel() { return (uint8_t)ISALevel; }
101   uint8_t getISARevision() { return (uint8_t)ISARevision; }
102   uint8_t getGPRSize() { return (uint8_t)GPRSize; }
103   uint8_t getCPR1Size() { return (uint8_t)CPR1Size; }
104   uint8_t getCPR2Size() { return (uint8_t)CPR2Size; }
105   uint8_t getFpABI() { return (uint8_t)FpABI; }
106   uint32_t getISAExtensionSet() { return (uint32_t)ISAExtensionSet; }
107   uint32_t getASESet() { return (uint32_t)ASESet; }
108   uint32_t getFlags1() { return 0; }
109   uint32_t getFlags2() { return 0; }
110
111   StringRef getFpABIString(Val_GNU_MIPS_ABI Value, bool Is32BitAbi);
112
113   template <class PredicateLibrary>
114   void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
115     if (P.hasMips64()) {
116       ISALevel = 64;
117       if (P.hasMips64r6())
118         ISARevision = 6;
119       else if (P.hasMips64r2())
120         ISARevision = 2;
121       else
122         ISARevision = 1;
123     } else if (P.hasMips32()) {
124       ISALevel = 32;
125       if (P.hasMips32r6())
126         ISARevision = 6;
127       else if (P.hasMips32r2())
128         ISARevision = 2;
129       else
130         ISARevision = 1;
131     } else {
132       ISARevision = 0;
133       if (P.hasMips5())
134         ISALevel = 5;
135       else if (P.hasMips4())
136         ISALevel = 4;
137       else if (P.hasMips3())
138         ISALevel = 3;
139       else if (P.hasMips2())
140         ISALevel = 2;
141       else if (P.hasMips1())
142         ISALevel = 1;
143       else
144         llvm_unreachable("Unknown ISA level!");
145     }
146   }
147
148   template <class PredicateLibrary>
149   void setGPRSizeFromPredicates(const PredicateLibrary &P) {
150     GPRSize = P.isGP64bit() ? AFL_REG_64 : AFL_REG_32;
151   }
152
153   template <class PredicateLibrary>
154   void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
155     if (P.mipsSEUsesSoftFloat())
156       CPR1Size = AFL_REG_NONE;
157     else if (P.hasMSA())
158       CPR1Size = AFL_REG_128;
159     else
160       CPR1Size = P.isFP64bit() ? AFL_REG_64 : AFL_REG_32;
161   }
162
163   template <class PredicateLibrary>
164   void setASESetFromPredicates(const PredicateLibrary &P) {
165     ASESet = 0;
166     if (P.hasDSP())
167       ASESet |= AFL_ASE_DSP;
168     if (P.hasDSPR2())
169       ASESet |= AFL_ASE_DSPR2;
170     if (P.hasMSA())
171       ASESet |= AFL_ASE_MSA;
172     if (P.inMicroMipsMode())
173       ASESet |= AFL_ASE_MICROMIPS;
174     if (P.inMips16Mode())
175       ASESet |= AFL_ASE_MIPS16;
176   }
177
178   template <class PredicateLibrary>
179   void setFpAbiFromPredicates(const PredicateLibrary &P) {
180     FpABI = Val_GNU_MIPS_ABI_FP_ANY;
181     if (P.isABI_N32() || P.isABI_N64())
182       FpABI = Val_GNU_MIPS_ABI_FP_DOUBLE;
183     else if (P.isABI_O32()) {
184       if (P.isFP64bit())
185         FpABI = Val_GNU_MIPS_ABI_FP_64;
186       else if (P.isABI_FPXX())
187         FpABI = Val_GNU_MIPS_ABI_FP_XX;
188       else
189         FpABI = Val_GNU_MIPS_ABI_FP_DOUBLE;
190     }
191   }
192
193   template <class PredicateLibrary>
194   void setAllFromPredicates(const PredicateLibrary &P) {
195     setISALevelAndRevisionFromPredicates(P);
196     setGPRSizeFromPredicates(P);
197     setCPR1SizeFromPredicates(P);
198     setASESetFromPredicates(P);
199     setFpAbiFromPredicates(P);
200   }
201 };
202
203 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
204 }
205
206 #endif