LLVM 24.0.0git
MipsSubtarget.cpp
Go to the documentation of this file.
1//===-- MipsSubtarget.cpp - Mips Subtarget Information --------------------===//
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 implements the Mips specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MipsSubtarget.h"
14#include "Mips.h"
15#include "MipsCallLowering.h"
16#include "MipsLegalizerInfo.h"
18#include "MipsRegisterInfo.h"
20#include "MipsTargetMachine.h"
22#include "llvm/IR/Attributes.h"
23#include "llvm/IR/Function.h"
26#include "llvm/Support/Debug.h"
28
29using namespace llvm;
30
31#define DEBUG_TYPE "mips-subtarget"
32
33#define GET_SUBTARGETINFO_TARGET_DESC
34#define GET_SUBTARGETINFO_CTOR
35#include "MipsGenSubtargetInfo.inc"
36
37#define OPTIONS_STRUCT_DEFS
38#include "MipsOptions.inc"
39
40bool MipsSubtarget::DspWarningPrinted = false;
41bool MipsSubtarget::MSAWarningPrinted = false;
42bool MipsSubtarget::VirtWarningPrinted = false;
43bool MipsSubtarget::CRCWarningPrinted = false;
44bool MipsSubtarget::GINVWarningPrinted = false;
45
46void MipsSubtarget::anchor() {}
47
49 StringRef ABIName, bool little,
50 const MipsTargetMachine &TM,
51 MaybeAlign StackAlignOverride)
52 : MipsGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
53 CLOpts(TM.getCLOpts()), MCCLOpts(TM.getMCCLOpts()),
54 MipsArchVersion(MipsDefault), IsLittle(little), IsSoftFloat(false),
55 IsSingleFloat(false), IsFPXX(false), NoABICalls(false), Abs2008(false),
56 IsFP64bit(false), UseOddSPReg(true), IsNaN2008bit(false),
57 IsGP64bit(false), HasVFPU(false), HasCnMips(false), HasCnMipsP(false),
58 IsR5900(false), FixR5900(false), HasMips3_32(false), HasMips3_32r2(false),
59 HasMips4_32(false), HasMips4_32r2(false), HasMips5_32r2(false),
60 InMips16Mode(false), InMips16HardFloat(CLOpts.mips16_hard_float),
61 InMicroMipsMode(false), HasDSP(false), HasDSPR2(false), HasDSPR3(false),
62 HasMSA(false), UseTCCInDIV(false), HasSym32(false), HasEVA(false),
63 DisableMadd4(false), HasMT(false), HasCRC(false), HasVirt(false),
64 HasGINV(false), UseIndirectJumpsHazard(false), StrictAlign(false),
65 UseCompactBranches(CLOpts.compact_branches != CompactBranchPolicy::Never),
66 StackAlignOverride(StackAlignOverride), TM(TM),
67 ABI(MipsABIInfo::computeTargetABI(TT, ABIName)),
68 InstrInfo(
70 FrameLowering(MipsFrameLowering::create(*this)),
71 TLInfo(MipsTargetLowering::create(TM, *this)) {
72
73 if (MipsArchVersion == MipsDefault)
74 MipsArchVersion = Mips32;
75
76 // Don't even attempt to generate code for MIPS-V. It has not
77 // been tested and currently exists for the integrated assembler only.
78 if (MipsArchVersion == Mips5)
79 report_fatal_error("Code generation for MIPS-V is not implemented", false);
80
81 // nanoMIPS is 32-bit architecture and always uses the P32 ABI.
82 // Other MIPS 32-bit architectures supports only O32 ABI.
83 // 64-bit MIPS architectures supports all ABIs except P32.
84 const bool IsValidArchABI =
85 (hasNanoMips() && isABI_P32()) ||
86 (!hasNanoMips() && ((!isGP64bit() && isABI_O32()) || isGP64bit()));
87
88 if (!IsValidArchABI)
89 report_fatal_error("Invalid Arch & ABI pair.", false);
90
91 if (hasMSA() && !isFP64bit())
92 report_fatal_error("MSA requires a 64-bit FPU register file (FR=1 mode). "
93 "See -mattr=+fp64.",
94 false);
95
96 if (isFP64bit() && !hasMips64() && hasMips32() && !hasMips32r2())
98 "FPU with 64-bit registers is not available on MIPS32 pre revision 2. "
99 "Use -mcpu=mips32r2 or greater.", false);
100
101 if (IsFPXX && (isABI_N32() || isABI_N64()))
102 report_fatal_error("FPXX is not permitted for the N32/N64 ABI's.", false);
103
104 if (hasMips64r6() && InMicroMipsMode)
105 report_fatal_error("microMIPS64R6 is not supported", false);
106
107 if (!hasNanoMips()) {
108 if (!isABI_O32() && !useOddSPReg())
109 report_fatal_error("-mattr=+nooddspreg requires the O32 ABI.", false);
110
111 if (!isABI_O32() && InMicroMipsMode)
112 report_fatal_error("microMIPS64 is not supported.", false);
113 }
114
115 if (UseIndirectJumpsHazard) {
116 if (InMicroMipsMode)
118 "cannot combine indirect jumps with hazard barriers and microMIPS");
119 if (!hasMips32r2())
121 "indirect jumps with hazard barriers requires MIPS32R2 or later");
122 }
123 if (inAbs2008Mode() && hasMips32() && !hasMips32r2()) {
124 report_fatal_error("IEEE 754-2008 abs.fmt is not supported for the given "
125 "architecture.",
126 false);
127 }
128
129 if (hasMips32r6()) {
130 StringRef ISA = hasMips64r6() ? "MIPS64r6" : "MIPS32r6";
131
132 assert(isFP64bit());
133 assert(isNaN2008());
135 if (hasDSP())
136 report_fatal_error(ISA + " is not compatible with the DSP ASE", false);
137 }
138
139 if (!NoABICalls && hasNanoMips())
140 report_fatal_error("nanoMIPS requires '-mno-abicalls'");
141
142 if (NoABICalls && TM.isPositionIndependent())
143 report_fatal_error("position-independent code requires '-mabicalls'");
144
145 if (isABI_N64() && !TM.isPositionIndependent() && !hasSym32())
146 NoABICalls = true;
147
148 // Set UseSmallSection.
149 UseSmallSection = CLOpts.mgpopt;
150 if (!NoABICalls && CLOpts.mgpopt) {
151 errs() << "warning: cannot use small-data accesses for '-mabicalls'"
152 << "\n";
153 UseSmallSection = false;
154 }
155
156 if (hasDSPR2() && !DspWarningPrinted) {
157 if (hasMips64() && !hasMips64r2()) {
158 errs() << "warning: the 'dspr2' ASE requires MIPS64 revision 2 or "
159 << "greater\n";
160 DspWarningPrinted = true;
161 } else if (hasMips32() && !hasMips32r2()) {
162 errs() << "warning: the 'dspr2' ASE requires MIPS32 revision 2 or "
163 << "greater\n";
164 DspWarningPrinted = true;
165 }
166 } else if (hasDSP() && !DspWarningPrinted) {
167 if (hasMips64() && !hasMips64r2()) {
168 errs() << "warning: the 'dsp' ASE requires MIPS64 revision 2 or "
169 << "greater\n";
170 DspWarningPrinted = true;
171 } else if (hasMips32() && !hasMips32r2()) {
172 errs() << "warning: the 'dsp' ASE requires MIPS32 revision 2 or "
173 << "greater\n";
174 DspWarningPrinted = true;
175 }
176 }
177
178 StringRef ArchName = hasMips64() ? "MIPS64" : "MIPS32";
179
180 if (!hasNanoMips()) {
181 if (!hasMips32r5() && hasMSA() && !MSAWarningPrinted) {
182 errs() << "warning: the 'msa' ASE requires " << ArchName
183 << " revision 5 or greater\n";
184 MSAWarningPrinted = true;
185 }
186 if (!hasMips32r5() && hasVirt() && !VirtWarningPrinted) {
187 errs() << "warning: the 'virt' ASE requires " << ArchName
188 << " revision 5 or greater\n";
189 VirtWarningPrinted = true;
190 }
191 if (!hasMips32r6() && hasCRC() && !CRCWarningPrinted) {
192 errs() << "warning: the 'crc' ASE requires " << ArchName
193 << " revision 6 or greater\n";
194 CRCWarningPrinted = true;
195 }
196 if (!hasMips32r6() && hasGINV() && !GINVWarningPrinted) {
197 errs() << "warning: the 'ginv' ASE requires " << ArchName
198 << " revision 6 or greater\n";
199 GINVWarningPrinted = true;
200 }
201 }
202
203 TSInfo = std::make_unique<MipsSelectionDAGInfo>();
204
206 Legalizer.reset(new MipsLegalizerInfo(*this));
207
208 auto *RBI = new MipsRegisterBankInfo(*getRegisterInfo());
209 RegBankInfo.reset(RBI);
210 InstSelector.reset(createMipsInstructionSelector(TM, *this, *RBI));
211}
212
214
216 return TM.isPositionIndependent();
217}
218
219/// This overrides the PostRAScheduler bit in the SchedModel for any CPU.
220bool MipsSubtarget::enablePostRAScheduler() const { return true; }
221
222void MipsSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
223 CriticalPathRCs.clear();
224 CriticalPathRCs.push_back(isGP64bit() ? &Mips::GPR64RegClass
225 : &Mips::GPR32RegClass);
226}
227
229 // We usually compute max call frame size after ISel. Do the computation now
230 // if the .mir file didn't specify it. Note that this will probably give you
231 // bogus values after PEI has eliminated the callframe setup/destroy pseudo
232 // instructions, specify explicitly if you need it to be correct.
233 MachineFrameInfo &MFI = MF.getFrameInfo();
236}
237
241
244 const TargetMachine &TM) {
245 StringRef CPUName = MIPS_MC::selectMipsCPU(TM.getTargetTriple(), CPU);
246
247 // Parse features string.
248 ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
249
250 // O32 uses 32-bit GPRs even when the selected CPU supports a 64-bit ISA.
251 if (isABI_O32())
252 IsGP64bit = false;
253
254 if (InMips16Mode && !IsSoftFloat)
255 InMips16HardFloat = true;
256
257 if (StackAlignOverride)
258 stackAlignment = *StackAlignOverride;
259 else if (isABI_N32() || isABI_N64() || isABI_P32())
260 stackAlignment = Align(16);
261 else {
262 assert(isABI_O32() && "Unknown ABI for stack alignment!");
263 stackAlignment = Align(8);
264 }
265
266 if ((isABI_N32() || isABI_N64()) && !isGP64bit())
267 reportFatalUsageError("64-bit code requested on a subtarget that doesn't "
268 "support it!");
269
270 return *this;
271}
272
274 LLVM_DEBUG(dbgs() << "use constant islands " << CLOpts.mips16_constant_islands
275 << "\n");
276 return CLOpts.mips16_constant_islands;
277}
278
280 return TM.getRelocationModel();
281}
282
283bool MipsSubtarget::isABI_N64() const { return getABI().IsN64(); }
284bool MipsSubtarget::isABI_N32() const { return getABI().IsN32(); }
285bool MipsSubtarget::isABI_O32() const { return getABI().IsO32(); }
286bool MipsSubtarget::isABI_P32() const { return getABI().IsP32(); }
287
289 return TSInfo.get();
290}
291
293 return CallLoweringInfo.get();
294}
295
297 return Legalizer.get();
298}
299
301 return RegBankInfo.get();
302}
303
307
308// Libcalls for which no helper is generated. Sorted by name for binary search.
309const RTLIB::LibcallImpl MipsSubtarget::HardFloatLibCalls[34] = {
310 RTLIB::impl___mips16_adddf3, RTLIB::impl___mips16_addsf3,
311 RTLIB::impl___mips16_divdf3, RTLIB::impl___mips16_divsf3,
312 RTLIB::impl___mips16_eqdf2, RTLIB::impl___mips16_eqsf2,
313 RTLIB::impl___mips16_extendsfdf2, RTLIB::impl___mips16_fix_truncdfsi,
314 RTLIB::impl___mips16_fix_truncsfsi, RTLIB::impl___mips16_floatsidf,
315 RTLIB::impl___mips16_floatsisf, RTLIB::impl___mips16_floatunsidf,
316 RTLIB::impl___mips16_floatunsisf, RTLIB::impl___mips16_gedf2,
317 RTLIB::impl___mips16_gesf2, RTLIB::impl___mips16_gtdf2,
318 RTLIB::impl___mips16_gtsf2, RTLIB::impl___mips16_ledf2,
319 RTLIB::impl___mips16_lesf2, RTLIB::impl___mips16_ltdf2,
320 RTLIB::impl___mips16_ltsf2, RTLIB::impl___mips16_muldf3,
321 RTLIB::impl___mips16_mulsf3, RTLIB::impl___mips16_nedf2,
322 RTLIB::impl___mips16_nesf2, RTLIB::impl___mips16_ret_dc,
323 RTLIB::impl___mips16_ret_df, RTLIB::impl___mips16_ret_sc,
324 RTLIB::impl___mips16_ret_sf, RTLIB::impl___mips16_subdf3,
325 RTLIB::impl___mips16_subsf3, RTLIB::impl___mips16_truncdfsf2,
326 RTLIB::impl___mips16_unorddf2, RTLIB::impl___mips16_unordsf2};
327
329 assert(is_sorted(HardFloatLibCalls) && "Array not sorted!");
330
331 static const struct {
332 RTLIB::Libcall LC;
333 RTLIB::LibcallImpl Mips16Impl;
334 RTLIB::LibcallImpl GenericImpl;
335 } HardFloatCalls[] = {
336 {RTLIB::ADD_F64, RTLIB::impl___mips16_adddf3, RTLIB::impl___adddf3},
337 {RTLIB::ADD_F32, RTLIB::impl___mips16_addsf3, RTLIB::impl___addsf3},
338 {RTLIB::DIV_F64, RTLIB::impl___mips16_divdf3, RTLIB::impl___divdf3},
339 {RTLIB::DIV_F32, RTLIB::impl___mips16_divsf3, RTLIB::impl___divsf3},
340 {RTLIB::FCMP3_PRED_OEQ_F64, RTLIB::impl___mips16_eqdf2,
341 RTLIB::impl___eqdf2},
342 {RTLIB::FCMP3_PRED_OEQ_F32, RTLIB::impl___mips16_eqsf2,
343 RTLIB::impl___eqsf2},
344 {RTLIB::FPEXT_F32_F64, RTLIB::impl___mips16_extendsfdf2,
345 RTLIB::impl___extendsfdf2},
346 {RTLIB::FPTOSINT_F64_I32, RTLIB::impl___mips16_fix_truncdfsi,
347 RTLIB::impl___fixdfsi},
348 {RTLIB::FPTOSINT_F32_I32, RTLIB::impl___mips16_fix_truncsfsi,
349 RTLIB::impl___fixsfsi},
350 {RTLIB::SINTTOFP_I32_F64, RTLIB::impl___mips16_floatsidf,
351 RTLIB::impl___floatsidf},
352 {RTLIB::SINTTOFP_I32_F32, RTLIB::impl___mips16_floatsisf,
353 RTLIB::impl___floatsisf},
354 {RTLIB::UINTTOFP_I32_F64, RTLIB::impl___mips16_floatunsidf,
355 RTLIB::impl___floatunsidf},
356 {RTLIB::UINTTOFP_I32_F32, RTLIB::impl___mips16_floatunsisf,
357 RTLIB::impl___floatunsisf},
358 {RTLIB::FCMP3_PRED_OGE_F64, RTLIB::impl___mips16_gedf2,
359 RTLIB::impl___gedf2},
360 {RTLIB::FCMP3_PRED_OGE_F32, RTLIB::impl___mips16_gesf2,
361 RTLIB::impl___gesf2},
362 {RTLIB::FCMP3_PRED_OGT_F64, RTLIB::impl___mips16_gtdf2,
363 RTLIB::impl___gtdf2},
364 {RTLIB::FCMP3_PRED_OGT_F32, RTLIB::impl___mips16_gtsf2,
365 RTLIB::impl___gtsf2},
366 {RTLIB::FCMP3_PRED_OLE_F64, RTLIB::impl___mips16_ledf2,
367 RTLIB::impl___ledf2},
368 {RTLIB::FCMP3_PRED_OLE_F32, RTLIB::impl___mips16_lesf2,
369 RTLIB::impl___lesf2},
370 {RTLIB::FCMP3_PRED_OLT_F64, RTLIB::impl___mips16_ltdf2,
371 RTLIB::impl___ltdf2},
372 {RTLIB::FCMP3_PRED_OLT_F32, RTLIB::impl___mips16_ltsf2,
373 RTLIB::impl___ltsf2},
374 {RTLIB::MUL_F64, RTLIB::impl___mips16_muldf3, RTLIB::impl___muldf3},
375 {RTLIB::MUL_F32, RTLIB::impl___mips16_mulsf3, RTLIB::impl___mulsf3},
376 {RTLIB::FCMP3_PRED_UNE_F64, RTLIB::impl___mips16_nedf2,
377 RTLIB::impl___nedf2},
378 {RTLIB::FCMP3_PRED_UNE_F32, RTLIB::impl___mips16_nesf2,
379 RTLIB::impl___nesf2},
380 {RTLIB::MIPS16_RET_DC, RTLIB::impl___mips16_ret_dc, RTLIB::Unsupported},
381 {RTLIB::MIPS16_RET_DF, RTLIB::impl___mips16_ret_df, RTLIB::Unsupported},
382 {RTLIB::MIPS16_RET_SC, RTLIB::impl___mips16_ret_sc, RTLIB::Unsupported},
383 {RTLIB::MIPS16_RET_SF, RTLIB::impl___mips16_ret_sf, RTLIB::Unsupported},
384 {RTLIB::SUB_F64, RTLIB::impl___mips16_subdf3, RTLIB::impl___subdf3},
385 {RTLIB::SUB_F32, RTLIB::impl___mips16_subsf3, RTLIB::impl___subsf3},
386 {RTLIB::FPROUND_F64_F32, RTLIB::impl___mips16_truncdfsf2,
387 RTLIB::impl___truncdfsf2},
388 {RTLIB::UO_F64, RTLIB::impl___mips16_unorddf2, RTLIB::impl___unorddf2},
389 {RTLIB::UO_F32, RTLIB::impl___mips16_unordsf2, RTLIB::impl___unordsf2},
390 };
391
392 bool UseMips16HardFloat = inMips16Mode() && !useSoftFloat();
393 for (const auto &E : HardFloatCalls) {
394 Info.setLibcallImpl(E.LC,
395 UseMips16HardFloat ? E.Mips16Impl : E.GenericImpl);
396 }
397}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the simple types necessary to represent the attributes associated with functions a...
This file describes how to lower LLVM calls to machine code calls.
This file declares the targeting of the Machinelegalizer class for Mips.
This file declares the targeting of the RegisterBankInfo class for Mips.
if(PassOpts->AAPipeline)
#define LLVM_DEBUG(...)
Definition Debug.h:119
Tracks which library functions to use for a particular subtarget or function.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI void computeMaxCallFrameSize(MachineFunction &MF, std::vector< MachineBasicBlock::iterator > *FrameSDOps=nullptr)
Computes the maximum size of a callframe.
bool isMaxCallFrameSizeComputed() const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool IsN64() const
Definition MipsABIInfo.h:42
bool IsN32() const
Definition MipsABIInfo.h:41
bool IsO32() const
Definition MipsABIInfo.h:40
bool IsP32() const
Definition MipsABIInfo.h:43
This class provides legalization strategies.
This class provides the information for the target register banks.
bool hasMips32r6() const
void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override
const LegalizerInfo * getLegalizerInfo() const override
bool hasMips64r2() const
bool isFP64bit() const
bool enablePostRAScheduler() const override
This overrides the PostRAScheduler bit in the SchedModel for each CPU.
bool hasMips32r5() const
bool hasNanoMips() 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 useSoftFloat() const
bool hasDSPR2() const
void mirFileLoaded(MachineFunction &MF) const override
bool hasMips64r6() const
bool isNaN2008() const
bool useOddSPReg() const
MipsSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS, const TargetMachine &TM)
const CallLowering * getCallLowering() const override
std::unique_ptr< RegisterBankInfo > RegBankInfo
bool inMips16Mode() const
bool hasMips64() const
~MipsSubtarget() override
bool hasMips32() const
bool hasSym32() const
bool inAbs2008Mode() const
const MipsOptions & getCLOpts() const
std::unique_ptr< CallLowering > CallLoweringInfo
const MipsRegisterInfo * getRegisterInfo() const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
const RegisterBankInfo * getRegBankInfo() const override
static const RTLIB::LibcallImpl HardFloatLibCalls[34]
bool isPositionIndependent() const
bool isGP64bit() const
bool hasMips32r2() const
InstructionSelector * getInstructionSelector() const override
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
std::unique_ptr< LegalizerInfo > Legalizer
const MipsTargetLowering * getTargetLowering() const override
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override
const MipsABIInfo & getABI() const
bool useConstantIslands() const
Reloc::Model getRelocationModel() const
const MipsMCOptions & getMCCLOpts() const
CodeGenOptLevel getOptLevelToEnablePostRAScheduler() 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
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
StringRef selectMipsCPU(const Triple &TT, StringRef CPU)
Select the Mips CPU for the given triple and cpu name.
This is an optimization pass for GlobalISel generic memory operations.
InstructionSelector * createMipsInstructionSelector(const MipsTargetMachine &, const MipsSubtarget &, const MipsRegisterBankInfo &)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition STLExtras.h:1986
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
CompactBranchPolicy
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
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