LLVM  4.0.0
MipsABIFlagsSection.h
Go to the documentation of this file.
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 LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
11 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
12 
13 #include "llvm/MC/MCStreamer.h"
16 
17 namespace llvm {
18 
19 class MCStreamer;
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.
26  uint16_t Version;
27  // The level of the ISA: 1-5, 32, 64.
28  uint8_t ISALevel;
29  // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
30  uint8_t ISARevision;
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;
43 
44  bool Is32BitABI;
45 
46 protected:
47  // The floating-point ABI.
49 
50 public:
52  : Version(0), ISALevel(0), ISARevision(0), GPRSize(Mips::AFL_REG_NONE),
55  Is32BitABI(false), FpABI(FpABIKind::ANY) {}
56 
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();
66 
68  uint32_t Value = 0;
69 
70  if (OddSPReg)
72 
73  return Value;
74  }
75 
76  uint32_t getFlags2Value() { return 0; }
77 
78  FpABIKind getFpABI() { return FpABI; }
79  void setFpABI(FpABIKind Value, bool IsABI32Bit) {
80  FpABI = Value;
81  Is32BitABI = IsABI32Bit;
82  }
84 
85  template <class PredicateLibrary>
86  void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
87  if (P.hasMips64()) {
88  ISALevel = 64;
89  if (P.hasMips64r6())
90  ISARevision = 6;
91  else if (P.hasMips64r5())
92  ISARevision = 5;
93  else if (P.hasMips64r3())
94  ISARevision = 3;
95  else if (P.hasMips64r2())
96  ISARevision = 2;
97  else
98  ISARevision = 1;
99  } else if (P.hasMips32()) {
100  ISALevel = 32;
101  if (P.hasMips32r6())
102  ISARevision = 6;
103  else if (P.hasMips32r5())
104  ISARevision = 5;
105  else if (P.hasMips32r3())
106  ISARevision = 3;
107  else if (P.hasMips32r2())
108  ISARevision = 2;
109  else
110  ISARevision = 1;
111  } else {
112  ISARevision = 0;
113  if (P.hasMips5())
114  ISALevel = 5;
115  else if (P.hasMips4())
116  ISALevel = 4;
117  else if (P.hasMips3())
118  ISALevel = 3;
119  else if (P.hasMips2())
120  ISALevel = 2;
121  else if (P.hasMips1())
122  ISALevel = 1;
123  else
124  llvm_unreachable("Unknown ISA level!");
125  }
126  }
127 
128  template <class PredicateLibrary>
129  void setGPRSizeFromPredicates(const PredicateLibrary &P) {
130  GPRSize = P.isGP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
131  }
132 
133  template <class PredicateLibrary>
134  void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
135  if (P.useSoftFloat())
137  else if (P.hasMSA())
139  else
140  CPR1Size = P.isFP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
141  }
142 
143  template <class PredicateLibrary>
144  void setISAExtensionFromPredicates(const PredicateLibrary &P) {
145  if (P.hasCnMips())
147  else
149  }
150 
151  template <class PredicateLibrary>
152  void setASESetFromPredicates(const PredicateLibrary &P) {
153  ASESet = 0;
154  if (P.hasDSP())
156  if (P.hasDSPR2())
158  if (P.hasMSA())
160  if (P.inMicroMipsMode())
162  if (P.inMips16Mode())
164  }
165 
166  template <class PredicateLibrary>
167  void setFpAbiFromPredicates(const PredicateLibrary &P) {
168  Is32BitABI = P.isABI_O32();
169 
171  if (P.useSoftFloat())
173  else if (P.isABI_N32() || P.isABI_N64())
175  else if (P.isABI_O32()) {
176  if (P.isABI_FPXX())
178  else if (P.isFP64bit())
180  else
182  }
183  }
184 
185  template <class PredicateLibrary>
186  void setAllFromPredicates(const PredicateLibrary &P) {
193  OddSPReg = P.useOddSPReg();
194  }
195 };
196 
197 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
198 }
199 
200 #endif
void setFpABI(FpABIKind Value, bool IsABI32Bit)
void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P)
void setCPR1SizeFromPredicates(const PredicateLibrary &P)
void setISAExtensionFromPredicates(const PredicateLibrary &P)
void setGPRSizeFromPredicates(const PredicateLibrary &P)
Function Alias Analysis false
#define P(N)
void setFpAbiFromPredicates(const PredicateLibrary &P)
StringRef getFpABIString(FpABIKind Value)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setAllFromPredicates(const PredicateLibrary &P)
void setASESetFromPredicates(const PredicateLibrary &P)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1726
LLVM Value Representation.
Definition: Value.h:71
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47