LLVM 24.0.0git
MipsSubtarget.h
Go to the documentation of this file.
1//===-- MipsSubtarget.h - Define Subtarget for the Mips ---------*- 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// This file declares the Mips specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_MIPS_MIPSSUBTARGET_H
14#define LLVM_LIB_TARGET_MIPS_MIPSSUBTARGET_H
15
18#include "MipsFrameLowering.h"
19#include "MipsISelLowering.h"
20#include "MipsInstrInfo.h"
26#include "llvm/IR/DataLayout.h"
28#include <bitset>
29
30#define GET_SUBTARGETINFO_HEADER
31#include "MipsGenSubtargetInfo.inc"
32
33namespace llvm {
34class StringRef;
35
37 Never, ///< The policy 'never' may in some circumstances or for some
38 ///< ISAs not be absolutely adhered to.
39 Optimal, ///< Optimal is the default and will produce compact branches
40 ///< when appropriate.
41 Always ///< 'always' may in some circumstances may not be
42 ///< absolutely adhered to, there may not be a corresponding
43 ///< compact form of a branch.
44};
45} // namespace llvm
46
47#define OPTIONS_STRUCT_DECL
48#include "MipsOptions.inc"
49
50namespace llvm {
51class MipsTargetMachine;
52
54 const MipsOptions &CLOpts;
55 const MipsMCOptions &MCCLOpts;
56
57 virtual void anchor();
58
59 enum MipsArchEnum {
60 MipsDefault,
61 NanoMips,
62 Mips1,
63 Mips2,
64 Mips32,
65 Mips32r2,
66 Mips32r3,
67 Mips32r5,
68 Mips32r6,
69 Mips32Max,
70 Mips3,
71 Mips4,
72 Mips5,
73 Mips64,
74 Mips64r2,
75 Mips64r3,
76 Mips64r5,
77 Mips64r6
78 };
79
80 enum class CPU { Others, P5600, I6400, I6500 };
81
82 // Used to avoid printing dsp warnings multiple times.
83 static bool DspWarningPrinted;
84
85 // Used to avoid printing msa warnings multiple times.
86 static bool MSAWarningPrinted;
87
88 // Used to avoid printing crc warnings multiple times.
89 static bool CRCWarningPrinted;
90
91 // Used to avoid printing ginv warnings multiple times.
92 static bool GINVWarningPrinted;
93
94 // Used to avoid printing virt warnings multiple times.
95 static bool VirtWarningPrinted;
96
97 // Mips architecture version
98 MipsArchEnum MipsArchVersion;
99
100 // Processor implementation
101 CPU ProcImpl = CPU::Others;
102
103 // IsLittle - The target is Little Endian
104 bool IsLittle;
105
106 // IsSoftFloat - The target does not support any floating point instructions.
107 bool IsSoftFloat;
108
109 // IsSingleFloat - The target only supports single precision float
110 // point operations. This enable the target to use all 32 32-bit
111 // floating point registers instead of only using even ones.
112 bool IsSingleFloat;
113
114 // IsFPXX - MIPS O32 modeless ABI.
115 bool IsFPXX;
116
117 // NoABICalls - Disable SVR4-style position-independent code.
118 bool NoABICalls;
119
120 // Abs2008 - Use IEEE 754-2008 abs.fmt instruction.
121 bool Abs2008;
122
123 // IsFP64bit - The target processor has 64-bit floating point registers.
124 bool IsFP64bit;
125
126 /// Are odd single-precision registers permitted?
127 /// This corresponds to -modd-spreg and -mno-odd-spreg
128 bool UseOddSPReg;
129
130 // IsNan2008 - IEEE 754-2008 NaN encoding.
131 bool IsNaN2008bit;
132
133 // IsGP64bit - General-purpose registers are 64 bits wide
134 bool IsGP64bit;
135
136 // MIPS GPRs explicitly reserved through -ffixed-REG.
137 std::bitset<32> UserReservedGPR;
138
139 // IsPTR64bit - Pointers are 64 bit wide
140 bool IsPTR64bit;
141
142 // HasVFPU - Processor has a vector floating point unit.
143 bool HasVFPU;
144
145 // CPU supports cnMIPS (Cavium Networks Octeon CPU).
146 bool HasCnMips;
147
148 // CPU supports cnMIPSP (Cavium Networks Octeon+ CPU).
149 bool HasCnMipsP;
150
151 // IsR5900 - CPU is R5900 (PlayStation 2 Emotion Engine).
152 bool IsR5900;
153
154 // FixR5900 - Enable R5900 short loop erratum fix.
155 bool FixR5900;
156
157 // UseSmallSection - Small section is used.
158 bool UseSmallSection;
159
160 /// Features related to the presence of specific instructions.
161
162 // HasMips3_32 - The subset of MIPS-III instructions added to MIPS32
163 bool HasMips3_32;
164
165 // HasMips3_32r2 - The subset of MIPS-III instructions added to MIPS32r2
166 bool HasMips3_32r2;
167
168 // HasMips4_32 - Has the subset of MIPS-IV present in MIPS32
169 bool HasMips4_32;
170
171 // HasMips4_32r2 - Has the subset of MIPS-IV present in MIPS32r2
172 bool HasMips4_32r2;
173
174 // HasMips5_32r2 - Has the subset of MIPS-V present in MIPS32r2
175 bool HasMips5_32r2;
176
177 // InMips16 -- can process Mips16 instructions
178 bool InMips16Mode;
179
180 // Mips16 hard float
181 bool InMips16HardFloat;
182
183 // InMicroMips -- can process MicroMips instructions
184 bool InMicroMipsMode;
185
186 // HasDSP, HasDSPR2, HasDSPR3 -- supports DSP ASE.
187 bool HasDSP, HasDSPR2, HasDSPR3;
188
189 // Has3D -- Supports Mips3D ASE.
190 bool Has3D;
191
192 // HasMSA -- supports MSA ASE.
193 bool HasMSA;
194
195 // UseTCCInDIV -- Enables the use of trapping in the assembler.
196 bool UseTCCInDIV;
197
198 // Sym32 -- On Mips64 symbols are 32 bits.
199 bool HasSym32;
200
201 // HasEVA -- supports EVA ASE.
202 bool HasEVA;
203
204 // nomadd4 - disables generation of 4-operand madd.s, madd.d and
205 // related instructions.
206 bool DisableMadd4;
207
208 // HasMT -- support MT ASE.
209 bool HasMT;
210
211 // HasCRC -- supports R6 CRC ASE
212 bool HasCRC;
213
214 // HasVirt -- supports Virtualization ASE
215 bool HasVirt;
216
217 // HasGINV -- supports R6 Global INValidate ASE
218 bool HasGINV;
219
220 // Use hazard variants of the jump register instructions for indirect
221 // function calls and jump tables.
222 bool UseIndirectJumpsHazard;
223
224 // Disable use of the `jal` instruction.
225 bool UseLongCalls = false;
226
227 // Assume 32-bit GOT.
228 bool UseXGOT = false;
229
230 // Disable unaligned load store for r6.
231 bool StrictAlign;
232
233 // Use compact branch instructions for R6.
234 bool UseCompactBranches = true;
235
236 /// The minimum alignment known to hold of the stack frame on
237 /// entry to the function and which must be maintained by every function.
238 Align stackAlignment;
239
240 /// The overridden stack alignment.
241 MaybeAlign StackAlignOverride;
242
243 const MipsTargetMachine &TM;
244
245 MipsABIInfo ABI;
246
247 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
248 std::unique_ptr<const MipsInstrInfo> InstrInfo;
249 std::unique_ptr<const MipsFrameLowering> FrameLowering;
250 std::unique_ptr<const MipsTargetLowering> TLInfo;
251
252public:
253 bool isPositionIndependent() const;
254 /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
255 bool enablePostRAScheduler() const override;
256 void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
258 void mirFileLoaded(MachineFunction &MF) const override;
259
260 bool isABI_N64() const;
261 bool isABI_N32() const;
262 bool isABI_O32() const;
263 bool isABI_P32() const;
264 const MipsABIInfo &getABI() const { return ABI; }
265 bool isABI_FPXX() const { return isABI_O32() && IsFPXX; }
266
267 bool isGPRReservedByUser(unsigned GPR) const {
268 assert(GPR < UserReservedGPR.size() && "GPR number out of range");
269 return UserReservedGPR[GPR];
270 }
271
272 /// This constructor initializes the data members to match that
273 /// of the specified triple.
274 MipsSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
275 StringRef ABIName, bool little, const MipsTargetMachine &TM,
276 MaybeAlign StackAlignOverride);
277
278 ~MipsSubtarget() override;
279
280 /// ParseSubtargetFeatures - Parses features string setting specified
281 /// subtarget options. Definition of function is auto generated by tblgen.
283
284 static const RTLIB::LibcallImpl HardFloatLibCalls[34];
285
286 bool hasMips1() const { return MipsArchVersion >= Mips1; }
287 bool hasMips2() const { return MipsArchVersion >= Mips2; }
288 bool hasMips3() const { return MipsArchVersion >= Mips3; }
289 bool hasMips4() const { return MipsArchVersion >= Mips4; }
290 bool hasMips5() const { return MipsArchVersion >= Mips5; }
291 bool hasMips4_32() const { return HasMips4_32; }
292 bool hasMips4_32r2() const { return HasMips4_32r2; }
293 bool hasMips32() const {
294 return (MipsArchVersion >= Mips32 && MipsArchVersion < Mips32Max) ||
295 hasMips64();
296 }
297 bool hasMips32r2() const {
298 return (MipsArchVersion >= Mips32r2 && MipsArchVersion < Mips32Max) ||
299 hasMips64r2();
300 }
301 bool hasMips32r3() const {
302 return (MipsArchVersion >= Mips32r3 && MipsArchVersion < Mips32Max) ||
303 hasMips64r2();
304 }
305 bool hasMips32r5() const {
306 return (MipsArchVersion >= Mips32r5 && MipsArchVersion < Mips32Max) ||
307 hasMips64r5();
308 }
309 bool hasMips32r6() const {
310 return (MipsArchVersion >= Mips32r6 && MipsArchVersion < Mips32Max) ||
311 hasMips64r6();
312 }
313 bool hasMips64() const { return MipsArchVersion >= Mips64; }
314 bool hasMips64r2() const { return MipsArchVersion >= Mips64r2; }
315 bool hasMips64r3() const { return MipsArchVersion >= Mips64r3; }
316 bool hasMips64r5() const { return MipsArchVersion >= Mips64r5; }
317 bool hasMips64r6() const { return MipsArchVersion >= Mips64r6; }
318 bool hasNanoMips() const { return MipsArchVersion == NanoMips; }
319
320 bool hasCnMips() const { return HasCnMips; }
321 bool hasCnMipsP() const { return HasCnMipsP; }
322 bool isR5900() const { return IsR5900; }
323 bool fixR5900() const { return FixR5900; }
324
325 bool isLittle() const { return IsLittle; }
326 bool isABICalls() const { return !NoABICalls; }
327 bool isFPXX() const { return IsFPXX; }
328 bool isFP64bit() const { return IsFP64bit; }
329 bool useOddSPReg() const { return UseOddSPReg; }
330 bool noOddSPReg() const { return !UseOddSPReg; }
331 bool isNaN2008() const { return IsNaN2008bit; }
332 bool inAbs2008Mode() const { return Abs2008; }
333 bool isGP64bit() const { return IsGP64bit; }
334 bool isGP32bit() const { return !IsGP64bit; }
335 unsigned getGPRSizeInBytes() const { return isGP64bit() ? 8 : 4; }
336 bool isPTR64bit() const { return IsPTR64bit; }
337 bool isPTR32bit() const { return !IsPTR64bit; }
338 bool hasSym32() const {
339 return (HasSym32 && isABI_N64()) || isABI_N32() || isABI_O32();
340 }
341 bool isSingleFloat() const { return IsSingleFloat; }
342 bool isTargetCOFF() const { return getTargetTriple().isOSBinFormatCOFF(); }
343 bool isTargetELF() const { return getTargetTriple().isOSBinFormatELF(); }
344 bool hasVFPU() const { return HasVFPU; }
345 bool inMips16Mode() const { return InMips16Mode; }
346 // Hard float for mips16 means essentially to compile as soft float
347 // but to use a runtime library for soft float that is written with
348 // native mips32 floating point instructions (those runtime routines
349 // run in mips32 hard float mode).
350 bool inMips16HardFloat() const {
351 return inMips16Mode() && InMips16HardFloat;
352 }
353 bool inMicroMipsMode() const { return InMicroMipsMode && !InMips16Mode; }
354 bool inMicroMips32r6Mode() const {
355 return inMicroMipsMode() && hasMips32r6();
356 }
357 bool hasDSP() const { return HasDSP; }
358 bool hasDSPR2() const { return HasDSPR2; }
359 bool hasDSPR3() const { return HasDSPR3; }
360 bool has3D() const { return Has3D; }
361 bool hasMSA() const { return HasMSA; }
362 bool disableMadd4() const { return DisableMadd4; }
363 bool hasEVA() const { return HasEVA; }
364 bool hasMT() const { return HasMT; }
365 bool hasCRC() const { return HasCRC; }
366 bool hasVirt() const { return HasVirt; }
367 bool hasGINV() const { return HasGINV; }
369 return UseIndirectJumpsHazard && hasMips32r2();
370 }
371 bool useSmallSection() const { return UseSmallSection; }
372
373 bool useCompactBranches() const {
374 return UseCompactBranches && hasMips32r6();
375 }
376
377 bool hasStandardEncoding() const {
378 return !InMips16Mode && !InMicroMipsMode && !hasNanoMips();
379 }
380
381 bool useSoftFloat() const { return IsSoftFloat; }
382
383 bool useLongCalls() const { return UseLongCalls; }
384
385 bool useXGOT() const { return UseXGOT; }
386
387 /// Features related to the presence of specific instructions.
388 bool hasExtractInsert() const { return !inMips16Mode() && hasMips32r2(); }
389 bool hasMTHC1() const { return hasMips32r2(); }
390
391 bool isTargetWindows() const { return getTargetTriple().isOSWindows(); }
392
393 bool isXRaySupported() const override { return true; }
394
395 // for now constant islands are on for the whole compilation unit but we only
396 // really use them if in addition we are in mips16 mode
397 bool useConstantIslands() const;
398
399 Align getStackAlignment() const { return stackAlignment; }
400
401 // Grab relocation model
403
405 const TargetMachine &TM);
406
407 /// Does the system support unaligned memory access.
408 ///
409 /// MIPS32r6/MIPS64r6 require full unaligned access support but does not
410 /// specify which component of the system provides it. Hardware, software, and
411 /// hybrid implementations are all valid.
413 return hasMips32r6() && !StrictAlign;
414 }
415
416 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
417
418 const MipsOptions &getCLOpts() const { return CLOpts; }
419 const MipsMCOptions &getMCCLOpts() const { return MCCLOpts; }
420 const MipsInstrInfo *getInstrInfo() const override { return InstrInfo.get(); }
421 const TargetFrameLowering *getFrameLowering() const override {
422 return FrameLowering.get();
423 }
424 const MipsRegisterInfo *getRegisterInfo() const override {
425 return &InstrInfo->getRegisterInfo();
426 }
427 const MipsTargetLowering *getTargetLowering() const override {
428 return TLInfo.get();
429 }
430 void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override;
431
432protected:
433 // GlobalISel related APIs.
434 std::unique_ptr<CallLowering> CallLoweringInfo;
435 std::unique_ptr<LegalizerInfo> Legalizer;
436 std::unique_ptr<RegisterBankInfo> RegBankInfo;
437 std::unique_ptr<InstructionSelector> InstSelector;
438
439public:
440 const CallLowering *getCallLowering() const override;
441 const LegalizerInfo *getLegalizerInfo() const override;
442 const RegisterBankInfo *getRegBankInfo() const override;
444};
445} // namespace llvm
446
447#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file describes how to lower LLVM calls to machine code calls.
Interface for Targets to specify which operations they can successfully select and how the others sho...
Tracks which library functions to use for a particular subtarget or function.
bool hasMips32r6() const
void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override
bool isXRaySupported() const override
const LegalizerInfo * getLegalizerInfo() const override
bool hasMips4() const
bool hasMips64r2() const
bool isFP64bit() const
bool isTargetELF() const
bool enablePostRAScheduler() const override
This overrides the PostRAScheduler bit in the SchedModel for each CPU.
bool isLittle() const
bool inMicroMipsMode() const
bool hasMips32r5() const
bool hasNanoMips() const
bool hasMips4_32() const
bool isGP32bit() const
MipsSubtarget(const Triple &TT, StringRef CPU, StringRef FS, StringRef ABIName, bool little, const MipsTargetMachine &TM, MaybeAlign StackAlignOverride)
This constructor initializes the data members to match that of the specified triple.
std::unique_ptr< InstructionSelector > InstSelector
bool hasMips32r3() const
bool useSoftFloat() const
bool hasDSPR2() const
const MipsInstrInfo * getInstrInfo() const override
void mirFileLoaded(MachineFunction &MF) const override
bool useIndirectJumpsHazard() const
bool hasMips64r6() const
bool isNaN2008() const
bool useOddSPReg() const
bool fixR5900() const
MipsSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS, const TargetMachine &TM)
const CallLowering * getCallLowering() const override
std::unique_ptr< RegisterBankInfo > RegBankInfo
bool inMips16Mode() const
bool hasMips5() const
bool hasMips64() const
~MipsSubtarget() override
bool hasMips32() const
bool useCompactBranches() const
bool isPTR32bit() const
bool hasSym32() const
bool isABI_FPXX() const
bool inAbs2008Mode() const
const MipsOptions & getCLOpts() const
std::unique_ptr< CallLowering > CallLoweringInfo
bool noOddSPReg() const
const MipsRegisterInfo * getRegisterInfo() const override
bool isABICalls() const
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
bool disableMadd4() const
const RegisterBankInfo * getRegBankInfo() const override
bool hasCnMips() const
static const RTLIB::LibcallImpl HardFloatLibCalls[34]
bool systemSupportsUnalignedAccess() const
Does the system support unaligned memory access.
bool isPositionIndependent() const
bool isGP64bit() const
bool hasExtractInsert() const
Features related to the presence of specific instructions.
bool inMicroMips32r6Mode() const
bool hasMips32r2() const
bool isTargetCOFF() const
bool hasMips4_32r2() const
Align getStackAlignment() const
bool isTargetWindows() const
InstructionSelector * getInstructionSelector() const override
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool isSingleFloat() const
std::unique_ptr< LegalizerInfo > Legalizer
bool useLongCalls() const
unsigned getGPRSizeInBytes() const
bool useSmallSection() const
const MipsTargetLowering * getTargetLowering() const override
bool inMips16HardFloat() const
bool hasCnMipsP() const
bool hasMTHC1() const
bool hasStandardEncoding() const
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override
bool hasMips64r5() const
const MipsABIInfo & getABI() const
bool useConstantIslands() const
bool hasMips3() const
bool hasMips1() const
Reloc::Model getRelocationModel() const
const MipsMCOptions & getMCCLOpts() const
bool isPTR64bit() const
bool hasMips2() const
bool hasMips64r3() const
bool hasDSPR3() const
bool isGPRReservedByUser(unsigned GPR) const
CodeGenOptLevel getOptLevelToEnablePostRAScheduler() const override
const TargetFrameLowering * getFrameLowering() const override
Holds all the information related to register banks.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Information about stack frame layout on the target.
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
This is an optimization pass for GlobalISel generic memory operations.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
CompactBranchPolicy
@ Optimal
Optimal is the default and will produce compact branches when appropriate.
@ Always
Always emit .debug_str_offsets talbes as DWARF64 for testing.
Definition DWP.h:32
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111