LLVM  14.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 
12 #include "llvm/ADT/StringRef.h"
15 #include <cstdint>
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.
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 
46 protected:
47  // The floating-point ABI.
49 
50 public:
51  MipsABIFlagsSection() = default;
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
137  CPR1Size = P.isFP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
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 
204 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
205 
206 } // end namespace llvm
207 
208 #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::Mips::AFL_EXT_OCTEONP
@ AFL_EXT_OCTEONP
Definition: MipsABIFlags.h:54
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::MipsABIFlagsSection::getISAExtensionValue
uint32_t getISAExtensionValue()
Definition: MipsABIFlagsSection.h:60
llvm::MipsABIFlagsSection::getFpABIString
StringRef getFpABIString(FpABIKind Value)
Definition: MipsABIFlagsSection.cpp:37
llvm::Mips::AFL_ASE_VIRT
@ AFL_ASE_VIRT
Definition: MipsABIFlags.h:40
llvm::MipsABIFlagsSection::OddSPReg
bool OddSPReg
Definition: MipsABIFlagsSection.h:42
llvm::MipsABIFlagsSection::getCPR2SizeValue
uint8_t getCPR2SizeValue()
Definition: MipsABIFlagsSection.h:58
ErrorHandling.h
llvm::Mips::AFL_EXT_NONE
@ AFL_EXT_NONE
Definition: MipsABIFlags.h:51
llvm::MipsABIFlagsSection::getFpABI
FpABIKind getFpABI()
Definition: MipsABIFlagsSection.h:74
llvm::MipsABIFlagsSection::setAllFromPredicates
void setAllFromPredicates(const PredicateLibrary &P)
Definition: MipsABIFlagsSection.h:193
llvm::Mips::AFL_ASE_MIPS16
@ AFL_ASE_MIPS16
Definition: MipsABIFlags.h:42
llvm::Mips::AFL_REG_32
@ AFL_REG_32
Definition: MipsABIFlags.h:25
llvm::MipsABIFlagsSection::getASESetValue
uint32_t getASESetValue()
Definition: MipsABIFlagsSection.h:61
llvm::MipsABIFlagsSection::FpABIKind::S32
@ S32
llvm::MipsABIFlagsSection::FpABIKind::SOFT
@ SOFT
llvm::MipsABIFlagsSection::getISARevisionValue
uint8_t getISARevisionValue()
Definition: MipsABIFlagsSection.h:55
llvm::Mips::AFL_FLAGS1_ODDSPREG
@ AFL_FLAGS1_ODDSPREG
Definition: MipsABIFlags.h:74
llvm::MipsABIFlagsSection::GPRSize
Mips::AFL_REG GPRSize
Definition: MipsABIFlagsSection.h:32
llvm::MipsABIFlagsSection::ISALevel
uint8_t ISALevel
Definition: MipsABIFlagsSection.h:28
llvm::MipsABIFlagsSection::getFlags2Value
uint32_t getFlags2Value()
Definition: MipsABIFlagsSection.h:72
llvm::MipsABIFlagsSection::setASESetFromPredicates
void setASESetFromPredicates(const PredicateLibrary &P)
Definition: MipsABIFlagsSection.h:151
MipsABIFlags.h
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::MipsABIFlagsSection::getCPR1SizeValue
uint8_t getCPR1SizeValue()
Definition: MipsABIFlagsSection.cpp:50
llvm::Mips::AFL_EXT_OCTEON
@ AFL_EXT_OCTEON
Definition: MipsABIFlags.h:56
llvm::MipsABIFlagsSection::MipsABIFlagsSection
MipsABIFlagsSection()=default
llvm::Mips::AFL_REG_128
@ AFL_REG_128
Definition: MipsABIFlags.h:27
llvm::MipsABIFlagsSection::FpABIKind::ANY
@ ANY
llvm::MipsABIFlagsSection::FpABI
FpABIKind FpABI
Definition: MipsABIFlagsSection.h:48
llvm::MipsABIFlagsSection::CPR1Size
Mips::AFL_REG CPR1Size
Definition: MipsABIFlagsSection.h:34
llvm::MipsABIFlagsSection::ISARevision
uint8_t ISARevision
Definition: MipsABIFlagsSection.h:30
llvm::MipsABIFlagsSection::FpABIKind::XX
@ XX
llvm::MipsABIFlagsSection::ISAExtension
Mips::AFL_EXT ISAExtension
Definition: MipsABIFlagsSection.h:38
llvm::MipsABIFlagsSection::setISAExtensionFromPredicates
void setISAExtensionFromPredicates(const PredicateLibrary &P)
Definition: MipsABIFlagsSection.h:141
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
uint32_t
llvm::Mips::AFL_ASE_MSA
@ AFL_ASE_MSA
Definition: MipsABIFlags.h:41
llvm::MipsABIFlagsSection::setFpABI
void setFpABI(FpABIKind Value, bool IsABI32Bit)
Definition: MipsABIFlagsSection.h:75
llvm::MipsABIFlagsSection::getISALevelValue
uint8_t getISALevelValue()
Definition: MipsABIFlagsSection.h:54
llvm::MipsABIFlagsSection::Is32BitABI
bool Is32BitABI
Definition: MipsABIFlagsSection.h:44
llvm::MipsABIFlagsSection::FpABIKind::S64
@ S64
llvm::MipsABIFlagsSection::getGPRSizeValue
uint8_t getGPRSizeValue()
Definition: MipsABIFlagsSection.h:56
llvm::Mips::AFL_REG
AFL_REG
Definition: MipsABIFlags.h:23
llvm::MipsABIFlagsSection
Definition: MipsABIFlagsSection.h:21
llvm::Mips::AFL_REG_64
@ AFL_REG_64
Definition: MipsABIFlags.h:26
llvm::Mips::AFL_ASE_DSP
@ AFL_ASE_DSP
Definition: MipsABIFlags.h:32
uint16_t
llvm::Mips::AFL_ASE_CRC
@ AFL_ASE_CRC
Definition: MipsABIFlags.h:45
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::MipsABIFlagsSection::FpABIKind
FpABIKind
Definition: MipsABIFlagsSection.h:23
llvm::MipsABIFlagsSection::setFpAbiFromPredicates
void setFpAbiFromPredicates(const PredicateLibrary &P)
Definition: MipsABIFlagsSection.h:174
llvm::MipsABIFlagsSection::ASESet
uint32_t ASESet
Definition: MipsABIFlagsSection.h:40
llvm::Mips::AFL_ASE_DSPR2
@ AFL_ASE_DSPR2
Definition: MipsABIFlags.h:33
llvm::Mips::AFL_ASE_MT
@ AFL_ASE_MT
Definition: MipsABIFlags.h:38
llvm::MipsABIFlagsSection::Version
uint16_t Version
Definition: MipsABIFlagsSection.h:26
llvm::MipsABIFlagsSection::setISALevelAndRevisionFromPredicates
void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P)
Definition: MipsABIFlagsSection.h:83
llvm::MipsABIFlagsSection::getFlags1Value
uint32_t getFlags1Value()
Definition: MipsABIFlagsSection.h:63
llvm::MipsABIFlagsSection::setGPRSizeFromPredicates
void setGPRSizeFromPredicates(const PredicateLibrary &P)
Definition: MipsABIFlagsSection.h:126
llvm::Mips::AFL_ASE_GINV
@ AFL_ASE_GINV
Definition: MipsABIFlags.h:46
llvm::MipsABIFlagsSection::getFpABIValue
uint8_t getFpABIValue()
Definition: MipsABIFlagsSection.cpp:17
llvm::MipsABIFlagsSection::getVersionValue
uint16_t getVersionValue()
Definition: MipsABIFlagsSection.h:53
llvm::Mips::AFL_ASE_MICROMIPS
@ AFL_ASE_MICROMIPS
Definition: MipsABIFlags.h:43
llvm::MipsABIFlagsSection::setCPR1SizeFromPredicates
void setCPR1SizeFromPredicates(const PredicateLibrary &P)
Definition: MipsABIFlagsSection.h:131
llvm::Mips::AFL_REG_NONE
@ AFL_REG_NONE
Definition: MipsABIFlags.h:24
llvm::Mips::AFL_EXT
AFL_EXT
Definition: MipsABIFlags.h:50
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MipsABIFlagsSection::CPR2Size
Mips::AFL_REG CPR2Size
Definition: MipsABIFlagsSection.h:36