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"
21#include "llvm/IR/Attributes.h"
22#include "llvm/IR/Function.h"
25#include "llvm/Support/Debug.h"
27
28using namespace llvm;
29
31 "mips-compact-branches", cl::init(CB_Optimal),
32 cl::desc("MIPS Specific: Compact branch policy."),
34 "Do not use compact branches if possible."),
35 clEnumValN(CB_Optimal, "optimal",
36 "Use compact branches where appropriate (default)."),
37 clEnumValN(CB_Always, "always",
38 "Always use compact branches if possible.")));
39
40#define DEBUG_TYPE "mips-subtarget"
41
42#define GET_SUBTARGETINFO_TARGET_DESC
43#define GET_SUBTARGETINFO_CTOR
44#include "MipsGenSubtargetInfo.inc"
45
46static cl::opt<bool> Mips16HardFloat("mips16-hard-float", cl::NotHidden,
47 cl::desc("Enable mips16 hard float."),
48 cl::init(false));
49
50static cl::opt<bool>
51 Mips16ConstantIslands("mips16-constant-islands", cl::NotHidden,
52 cl::desc("Enable mips16 constant islands."),
53 cl::init(true));
54
55static cl::opt<bool>
56 GPOpt("mgpopt", cl::Hidden,
57 cl::desc("Enable gp-relative addressing of mips small data items"));
58
59bool MipsSubtarget::DspWarningPrinted = false;
60bool MipsSubtarget::MSAWarningPrinted = false;
61bool MipsSubtarget::VirtWarningPrinted = false;
62bool MipsSubtarget::CRCWarningPrinted = false;
63bool MipsSubtarget::GINVWarningPrinted = false;
64
65void MipsSubtarget::anchor() {}
66
68 bool little, const MipsTargetMachine &TM,
69 MaybeAlign StackAlignOverride)
70 : MipsGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
71 MipsArchVersion(MipsDefault), IsLittle(little), IsSoftFloat(false),
72 IsSingleFloat(false), IsFPXX(false), NoABICalls(false), Abs2008(false),
73 IsFP64bit(false), UseOddSPReg(true), IsNaN2008bit(false),
74 IsGP64bit(false), HasVFPU(false), HasCnMips(false), HasCnMipsP(false),
75 IsR5900(false), FixR5900(false), HasMips3_32(false), HasMips3_32r2(false),
76 HasMips4_32(false), HasMips4_32r2(false), HasMips5_32r2(false),
77 InMips16Mode(false), InMips16HardFloat(Mips16HardFloat),
78 InMicroMipsMode(false), HasDSP(false), HasDSPR2(false), HasDSPR3(false),
79 HasMSA(false), UseTCCInDIV(false), HasSym32(false), HasEVA(false),
80 DisableMadd4(false), HasMT(false), HasCRC(false), HasVirt(false),
81 HasGINV(false), UseIndirectJumpsHazard(false), StrictAlign(false),
82 UseCompactBranches(MipsCompactBranchPolicy != CB_Never),
83 StackAlignOverride(StackAlignOverride), TM(TM), TargetTriple(TT),
84 InstrInfo(
86 FrameLowering(MipsFrameLowering::create(*this)),
87 TLInfo(MipsTargetLowering::create(TM, *this)) {
88
89 if (MipsArchVersion == MipsDefault)
90 MipsArchVersion = Mips32;
91
92 // Don't even attempt to generate code for MIPS-V. It has not
93 // been tested and currently exists for the integrated assembler only.
94 if (MipsArchVersion == Mips5)
95 report_fatal_error("Code generation for MIPS-V is not implemented", false);
96
97 // Check if Architecture and ABI are compatible.
98 assert(((!isGP64bit() && isABI_O32()) || isGP64bit()) &&
99 "Invalid Arch & ABI pair.");
100
101 if (hasMSA() && !isFP64bit())
102 report_fatal_error("MSA requires a 64-bit FPU register file (FR=1 mode). "
103 "See -mattr=+fp64.",
104 false);
105
106 if (isFP64bit() && !hasMips64() && hasMips32() && !hasMips32r2())
108 "FPU with 64-bit registers is not available on MIPS32 pre revision 2. "
109 "Use -mcpu=mips32r2 or greater.", false);
110
111 if (!isABI_O32() && !useOddSPReg())
112 report_fatal_error("-mattr=+nooddspreg requires the O32 ABI.", false);
113
114 if (IsFPXX && (isABI_N32() || isABI_N64()))
115 report_fatal_error("FPXX is not permitted for the N32/N64 ABI's.", false);
116
117 if (hasMips64r6() && InMicroMipsMode)
118 report_fatal_error("microMIPS64R6 is not supported", false);
119
120 if (!isABI_O32() && InMicroMipsMode)
121 report_fatal_error("microMIPS64 is not supported.", false);
122
123 if (UseIndirectJumpsHazard) {
124 if (InMicroMipsMode)
126 "cannot combine indirect jumps with hazard barriers and microMIPS");
127 if (!hasMips32r2())
129 "indirect jumps with hazard barriers requires MIPS32R2 or later");
130 }
131 if (inAbs2008Mode() && hasMips32() && !hasMips32r2()) {
132 report_fatal_error("IEEE 754-2008 abs.fmt is not supported for the given "
133 "architecture.",
134 false);
135 }
136
137 if (hasMips32r6()) {
138 StringRef ISA = hasMips64r6() ? "MIPS64r6" : "MIPS32r6";
139
140 assert(isFP64bit());
141 assert(isNaN2008());
143 if (hasDSP())
144 report_fatal_error(ISA + " is not compatible with the DSP ASE", false);
145 }
146
147 if (NoABICalls && TM.isPositionIndependent())
148 report_fatal_error("position-independent code requires '-mabicalls'");
149
150 if (isABI_N64() && !TM.isPositionIndependent() && !hasSym32())
151 NoABICalls = true;
152
153 // Set UseSmallSection.
154 UseSmallSection = GPOpt;
155 if (!NoABICalls && GPOpt) {
156 errs() << "warning: cannot use small-data accesses for '-mabicalls'"
157 << "\n";
158 UseSmallSection = false;
159 }
160
161 if (hasDSPR2() && !DspWarningPrinted) {
162 if (hasMips64() && !hasMips64r2()) {
163 errs() << "warning: the 'dspr2' ASE requires MIPS64 revision 2 or "
164 << "greater\n";
165 DspWarningPrinted = true;
166 } else if (hasMips32() && !hasMips32r2()) {
167 errs() << "warning: the 'dspr2' ASE requires MIPS32 revision 2 or "
168 << "greater\n";
169 DspWarningPrinted = true;
170 }
171 } else if (hasDSP() && !DspWarningPrinted) {
172 if (hasMips64() && !hasMips64r2()) {
173 errs() << "warning: the 'dsp' ASE requires MIPS64 revision 2 or "
174 << "greater\n";
175 DspWarningPrinted = true;
176 } else if (hasMips32() && !hasMips32r2()) {
177 errs() << "warning: the 'dsp' ASE requires MIPS32 revision 2 or "
178 << "greater\n";
179 DspWarningPrinted = true;
180 }
181 }
182
183 StringRef ArchName = hasMips64() ? "MIPS64" : "MIPS32";
184
185 if (!hasMips32r5() && hasMSA() && !MSAWarningPrinted) {
186 errs() << "warning: the 'msa' ASE requires " << ArchName
187 << " revision 5 or greater\n";
188 MSAWarningPrinted = true;
189 }
190 if (!hasMips32r5() && hasVirt() && !VirtWarningPrinted) {
191 errs() << "warning: the 'virt' ASE requires " << ArchName
192 << " revision 5 or greater\n";
193 VirtWarningPrinted = true;
194 }
195 if (!hasMips32r6() && hasCRC() && !CRCWarningPrinted) {
196 errs() << "warning: the 'crc' ASE requires " << ArchName
197 << " revision 6 or greater\n";
198 CRCWarningPrinted = true;
199 }
200 if (!hasMips32r6() && hasGINV() && !GINVWarningPrinted) {
201 errs() << "warning: the 'ginv' ASE requires " << ArchName
202 << " revision 6 or greater\n";
203 GINVWarningPrinted = true;
204 }
205
206 TSInfo = std::make_unique<MipsSelectionDAGInfo>();
207
209 Legalizer.reset(new MipsLegalizerInfo(*this));
210
211 auto *RBI = new MipsRegisterBankInfo(*getRegisterInfo());
212 RegBankInfo.reset(RBI);
213 InstSelector.reset(createMipsInstructionSelector(TM, *this, *RBI));
214}
215
217
219 return TM.isPositionIndependent();
220}
221
222/// This overrides the PostRAScheduler bit in the SchedModel for any CPU.
223bool MipsSubtarget::enablePostRAScheduler() const { return true; }
224
225void MipsSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
226 CriticalPathRCs.clear();
227 CriticalPathRCs.push_back(isGP64bit() ? &Mips::GPR64RegClass
228 : &Mips::GPR32RegClass);
229}
230
234
237 const TargetMachine &TM) {
238 StringRef CPUName = MIPS_MC::selectMipsCPU(TM.getTargetTriple(), CPU);
239
240 // Parse features string.
241 ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
242
243 // O32 uses 32-bit GPRs even when the selected CPU supports a 64-bit ISA.
244 if (isABI_O32())
245 IsGP64bit = false;
246
247 if (InMips16Mode && !IsSoftFloat)
248 InMips16HardFloat = true;
249
250 if (StackAlignOverride)
251 stackAlignment = *StackAlignOverride;
252 else if (isABI_N32() || isABI_N64())
253 stackAlignment = Align(16);
254 else {
255 assert(isABI_O32() && "Unknown ABI for stack alignment!");
256 stackAlignment = Align(8);
257 }
258
259 if ((isABI_N32() || isABI_N64()) && !isGP64bit())
260 reportFatalUsageError("64-bit code requested on a subtarget that doesn't "
261 "support it!");
262
263 return *this;
264}
265
267 LLVM_DEBUG(dbgs() << "use constant islands " << Mips16ConstantIslands
268 << "\n");
270}
271
273 return TM.getRelocationModel();
274}
275
276bool MipsSubtarget::isABI_N64() const { return getABI().IsN64(); }
277bool MipsSubtarget::isABI_N32() const { return getABI().IsN32(); }
278bool MipsSubtarget::isABI_O32() const { return getABI().IsO32(); }
279const MipsABIInfo &MipsSubtarget::getABI() const { return TM.getABI(); }
280
282 return TSInfo.get();
283}
284
286 return CallLoweringInfo.get();
287}
288
290 return Legalizer.get();
291}
292
294 return RegBankInfo.get();
295}
296
300
301// Libcalls for which no helper is generated. Sorted by name for binary search.
302const RTLIB::LibcallImpl MipsSubtarget::HardFloatLibCalls[34] = {
303 RTLIB::impl___mips16_adddf3, RTLIB::impl___mips16_addsf3,
304 RTLIB::impl___mips16_divdf3, RTLIB::impl___mips16_divsf3,
305 RTLIB::impl___mips16_eqdf2, RTLIB::impl___mips16_eqsf2,
306 RTLIB::impl___mips16_extendsfdf2, RTLIB::impl___mips16_fix_truncdfsi,
307 RTLIB::impl___mips16_fix_truncsfsi, RTLIB::impl___mips16_floatsidf,
308 RTLIB::impl___mips16_floatsisf, RTLIB::impl___mips16_floatunsidf,
309 RTLIB::impl___mips16_floatunsisf, RTLIB::impl___mips16_gedf2,
310 RTLIB::impl___mips16_gesf2, RTLIB::impl___mips16_gtdf2,
311 RTLIB::impl___mips16_gtsf2, RTLIB::impl___mips16_ledf2,
312 RTLIB::impl___mips16_lesf2, RTLIB::impl___mips16_ltdf2,
313 RTLIB::impl___mips16_ltsf2, RTLIB::impl___mips16_muldf3,
314 RTLIB::impl___mips16_mulsf3, RTLIB::impl___mips16_nedf2,
315 RTLIB::impl___mips16_nesf2, RTLIB::impl___mips16_ret_dc,
316 RTLIB::impl___mips16_ret_df, RTLIB::impl___mips16_ret_sc,
317 RTLIB::impl___mips16_ret_sf, RTLIB::impl___mips16_subdf3,
318 RTLIB::impl___mips16_subsf3, RTLIB::impl___mips16_truncdfsf2,
319 RTLIB::impl___mips16_unorddf2, RTLIB::impl___mips16_unordsf2};
320
322 if (inMips16Mode() && !useSoftFloat()) {
323 for (unsigned I = 0; I != std::size(HardFloatLibCalls); ++I) {
324 assert((I == 0 || HardFloatLibCalls[I - 1] < HardFloatLibCalls[I]) &&
325 "Array not sorted!");
326 RTLIB::Libcall LC =
328 Info.setLibcallImpl(LC, HardFloatLibCalls[I]);
329 }
330 }
331}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the simple types necessary to represent the attributes associated with functions a...
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define I(x, y, z)
Definition MD5.cpp:57
This file describes how to lower LLVM calls to machine code calls.
cl::opt< CompactBranchPolicy > MipsCompactBranchPolicy
This file declares the targeting of the Machinelegalizer class for Mips.
This file declares the targeting of the RegisterBankInfo class for Mips.
static cl::opt< bool > Mips16ConstantIslands("mips16-constant-islands", cl::NotHidden, cl::desc("Enable mips16 constant islands."), cl::init(true))
static cl::opt< bool > Mips16HardFloat("mips16-hard-float", cl::NotHidden, cl::desc("Enable mips16 hard float."), cl::init(false))
static cl::opt< bool > GPOpt("mgpopt", cl::Hidden, cl::desc("Enable gp-relative addressing of mips small data items"))
cl::opt< CompactBranchPolicy > MipsCompactBranchPolicy("mips-compact-branches", cl::init(CB_Optimal), cl::desc("MIPS Specific: Compact branch policy."), cl::values(clEnumValN(CB_Never, "never", "Do not use compact branches if possible."), clEnumValN(CB_Optimal, "optimal", "Use compact branches where appropriate (default)."), clEnumValN(CB_Always, "always", "Always use compact branches if possible.")))
#define LLVM_DEBUG(...)
Definition Debug.h:119
Tracks which library functions to use for a particular subtarget or function.
bool IsN64() const
Definition MipsABIInfo.h:41
bool IsN32() const
Definition MipsABIInfo.h:40
bool IsO32() const
Definition MipsABIInfo.h:39
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
static bool useConstantIslands()
bool hasMips64r2() const
bool isFP64bit() const
bool enablePostRAScheduler() const override
This overrides the PostRAScheduler bit in the SchedModel for each CPU.
bool hasMips32r5() const
std::unique_ptr< InstructionSelector > InstSelector
bool useSoftFloat() const
bool hasDSPR2() const
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
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
MipsSubtarget(const Triple &TT, StringRef CPU, StringRef FS, bool little, const MipsTargetMachine &TM, MaybeAlign StackAlignOverride)
This constructor initializes the data members to match that of the specified triple.
Reloc::Model getRelocationModel() const
CodeGenOptLevel getOptLevelToEnablePostRAScheduler() const override
const MipsABIInfo & getABI() const
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.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
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
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:227
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ CB_Never
The policy 'never' may in some circumstances or for some ISAs not be absolutely adhered to.
@ CB_Always
'always' may in some circumstances may not be absolutely adhered to, there may not be a corresponding...
@ CB_Optimal
Optimal is the default and will produce compact branches when appropriate.
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:106
static RTLIB::Libcall getLibcallFromImpl(RTLIB::LibcallImpl Impl)
Return the libcall provided by Impl.