clang 22.0.0git
Mips.h
Go to the documentation of this file.
1//===--- Mips.h - Declare Mips target feature support -----------*- 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 Mips TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H
15
16#include "OSTargets.h"
19#include "llvm/Support/Compiler.h"
20#include "llvm/TargetParser/Triple.h"
21
22namespace clang {
23namespace targets {
24
25class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
26 std::string CPU;
27 bool IsMips16;
28 bool IsMicromips;
29 bool IsNan2008;
30 bool IsAbs2008;
31 bool IsSingleFloat;
32 bool IsNoABICalls;
33 bool CanUseBSDABICalls;
34 enum MipsFloatABI { HardFloat, SoftFloat } FloatABI;
35 enum DspRevEnum { NoDSP, DSP1, DSP2 } DspRev;
36 bool HasMSA;
37 bool DisableMadd4;
38 bool UseIndirectJumpHazard;
39 bool NoOddSpreg;
40
41protected:
42 enum FPModeEnum { FPXX, FP32, FP64 } FPMode;
43 std::string ABI;
44
45public:
46 MipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
47 : TargetInfo(Triple), IsMips16(false), IsMicromips(false),
48 IsNan2008(false), IsAbs2008(false), IsSingleFloat(false),
49 IsNoABICalls(false), CanUseBSDABICalls(false), FloatABI(HardFloat),
50 DspRev(NoDSP), HasMSA(false), DisableMadd4(false),
51 UseIndirectJumpHazard(false), FPMode(FPXX) {
52 TheCXXABI.set(TargetCXXABI::GenericMIPS);
53
54 if (Triple.isMIPS32())
55 setABI("o32");
56 else if (Triple.isABIN32())
57 setABI("n32");
58 else
59 setABI("n64");
60
61 CPU = ABI == "o32" ? "mips32r2" : "mips64r2";
62
63 CanUseBSDABICalls = Triple.isOSFreeBSD() ||
64 Triple.isOSOpenBSD();
65 }
66
67 bool isIEEE754_2008Default() const {
68 return CPU == "mips32r6" || CPU == "mips64r6" || CPU == "i6400" ||
69 CPU == "i6500";
70 }
71
73 if (CPU == "mips32r6" || ABI == "n32" || ABI == "n64" || ABI == "64")
74 return FP64;
75 else if (CPU == "mips1")
76 return FP32;
77 else
78 return FPXX;
79 }
80
81 bool isNan2008() const override { return IsNan2008; }
82
83 bool processorSupportsGPR64() const;
84
85 StringRef getABI() const override { return ABI; }
86
87 bool setABI(const std::string &Name) override {
88 if (Name == "o32") {
90 ABI = Name;
91 return true;
92 }
93
94 if (Name == "n32") {
96 ABI = Name;
97 return true;
98 }
99 if (Name == "n64") {
101 ABI = Name;
102 return true;
103 }
104 return false;
105 }
106
119
122 LongDoubleFormat = &llvm::APFloat::IEEEquad();
123 if (getTriple().isOSFreeBSD()) {
125 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
126 }
128 SuitableAlign = 128;
129 }
130
133 if (getTriple().isOSOpenBSD()) {
135 } else {
137 }
139 LongWidth = LongAlign = 64;
143 }
144
154
155 bool isValidCPUName(StringRef Name) const override;
156 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
157
158 bool setCPU(const std::string &Name) override {
159 CPU = Name;
160 return isValidCPUName(Name);
161 }
162
163 const std::string &getCPU() const { return CPU; }
164 bool
165 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
166 StringRef CPU,
167 const std::vector<std::string> &FeaturesVec) const override {
168 if (CPU.empty())
169 CPU = getCPU();
170 if (CPU == "octeon")
171 Features["mips64r2"] = Features["cnmips"] = true;
172 else if (CPU == "octeon+")
173 Features["mips64r2"] = Features["cnmips"] = Features["cnmipsp"] = true;
174 else
175 Features[CPU] = true;
176 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
177 }
178
179 unsigned getISARev() const;
180
181 void getTargetDefines(const LangOptions &Opts,
182 MacroBuilder &Builder) const override;
183
184 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
185
186 bool hasFeature(StringRef Feature) const override;
187
191
193 static const char *const GCCRegNames[] = {
194 // CPU register names
195 // Must match second column of GCCRegAliases
196 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$10",
197 "$11", "$12", "$13", "$14", "$15", "$16", "$17", "$18", "$19", "$20",
198 "$21", "$22", "$23", "$24", "$25", "$26", "$27", "$28", "$29", "$30",
199 "$31",
200 // Floating point register names
201 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", "$f8", "$f9",
202 "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", "$f16", "$f17", "$f18",
203 "$f19", "$f20", "$f21", "$f22", "$f23", "$f24", "$f25", "$f26", "$f27",
204 "$f28", "$f29", "$f30", "$f31",
205 // Hi/lo and condition register names
206 "hi", "lo", "", "$fcc0", "$fcc1", "$fcc2", "$fcc3", "$fcc4", "$fcc5",
207 "$fcc6", "$fcc7", "$ac1hi", "$ac1lo", "$ac2hi", "$ac2lo", "$ac3hi",
208 "$ac3lo",
209 // MSA register names
210 "$w0", "$w1", "$w2", "$w3", "$w4", "$w5", "$w6", "$w7", "$w8", "$w9",
211 "$w10", "$w11", "$w12", "$w13", "$w14", "$w15", "$w16", "$w17", "$w18",
212 "$w19", "$w20", "$w21", "$w22", "$w23", "$w24", "$w25", "$w26", "$w27",
213 "$w28", "$w29", "$w30", "$w31",
214 // MSA control register names
215 "$msair", "$msacsr", "$msaaccess", "$msasave", "$msamodify",
216 "$msarequest", "$msamap", "$msaunmap"
217 };
219 }
220
221 bool validateAsmConstraint(const char *&Name,
222 TargetInfo::ConstraintInfo &Info) const override {
223 switch (*Name) {
224 default:
225 return false;
226 case 'r': // CPU registers.
227 case 'd': // Equivalent to "r" unless generating MIPS16 code.
228 case 'y': // Equivalent to "r", backward compatibility only.
229 case 'c': // $25 for indirect jumps
230 case 'l': // lo register
231 case 'x': // hilo register pair
232 Info.setAllowsRegister();
233 return true;
234 case 'f': // floating-point registers.
235 Info.setAllowsRegister();
236 return FloatABI != SoftFloat;
237 case 'I': // Signed 16-bit constant
238 case 'J': // Integer 0
239 case 'K': // Unsigned 16-bit constant
240 case 'L': // Signed 32-bit constant, lower 16-bit zeros (for lui)
241 case 'M': // Constants not loadable via lui, addiu, or ori
242 case 'N': // Constant -1 to -65535
243 case 'O': // A signed 15-bit constant
244 case 'P': // A constant between 1 go 65535
245 return true;
246 case 'R': // An address that can be used in a non-macro load or store
247 Info.setAllowsMemory();
248 return true;
249 case 'Z':
250 if (Name[1] == 'C') { // An address usable by ll, and sc.
251 Info.setAllowsMemory();
252 Name++; // Skip over 'Z'.
253 return true;
254 }
255 return false;
256 }
257 }
258
259 std::string convertConstraint(const char *&Constraint) const override {
260 std::string R;
261 switch (*Constraint) {
262 case 'Z': // Two-character constraint; add "^" hint for later parsing.
263 if (Constraint[1] == 'C') {
264 R = std::string("^") + std::string(Constraint, 2);
265 Constraint++;
266 return R;
267 }
268 break;
269 }
270 return TargetInfo::convertConstraint(Constraint);
271 }
272
273 std::string_view getClobbers() const override {
274 // In GCC, $1 is not widely used in generated code (it's used only in a few
275 // specific situations), so there is no real need for users to add it to
276 // the clobbers list if they want to use it in their inline assembly code.
277 //
278 // In LLVM, $1 is treated as a normal GPR and is always allocatable during
279 // code generation, so using it in inline assembly without adding it to the
280 // clobbers list can cause conflicts between the inline assembly code and
281 // the surrounding generated code.
282 //
283 // Another problem is that LLVM is allowed to choose $1 for inline assembly
284 // operands, which will conflict with the ".set at" assembler option (which
285 // we use only for inline assembly, in order to maintain compatibility with
286 // GCC) and will also conflict with the user's usage of $1.
287 //
288 // The easiest way to avoid these conflicts and keep $1 as an allocatable
289 // register for generated code is to automatically clobber $1 for all inline
290 // assembly code.
291 //
292 // FIXME: We should automatically clobber $1 only for inline assembly code
293 // which actually uses it. This would allow LLVM to use $1 for inline
294 // assembly operands if the user's assembly code doesn't use it.
295 return "~{$1}";
296 }
297
298 bool handleTargetFeatures(std::vector<std::string> &Features,
299 DiagnosticsEngine &Diags) override {
300 IsMips16 = false;
301 IsMicromips = false;
302 IsNan2008 = isIEEE754_2008Default();
303 IsAbs2008 = isIEEE754_2008Default();
304 IsSingleFloat = false;
305 FloatABI = HardFloat;
306 DspRev = NoDSP;
307 NoOddSpreg = false;
309 bool OddSpregGiven = false;
310 bool StrictAlign = false;
311 bool FpGiven = false;
312
313 for (const auto &Feature : Features) {
314 if (Feature == "+single-float")
315 IsSingleFloat = true;
316 else if (Feature == "+soft-float")
317 FloatABI = SoftFloat;
318 else if (Feature == "+mips16")
319 IsMips16 = true;
320 else if (Feature == "+micromips")
321 IsMicromips = true;
322 else if (Feature == "+mips32r6" || Feature == "+mips64r6")
323 HasUnalignedAccess = true;
324 // We cannot be sure that the order of strict-align vs mips32r6.
325 // Thus we need an extra variable here.
326 else if (Feature == "+strict-align")
327 StrictAlign = true;
328 else if (Feature == "+dsp")
329 DspRev = std::max(DspRev, DSP1);
330 else if (Feature == "+dspr2")
331 DspRev = std::max(DspRev, DSP2);
332 else if (Feature == "+msa")
333 HasMSA = true;
334 else if (Feature == "+nomadd4")
335 DisableMadd4 = true;
336 else if (Feature == "+fp64") {
337 FPMode = FP64;
338 FpGiven = true;
339 } else if (Feature == "-fp64") {
340 FPMode = FP32;
341 FpGiven = true;
342 } else if (Feature == "+fpxx") {
343 FPMode = FPXX;
344 FpGiven = true;
345 } else if (Feature == "+nan2008")
346 IsNan2008 = true;
347 else if (Feature == "-nan2008")
348 IsNan2008 = false;
349 else if (Feature == "+abs2008")
350 IsAbs2008 = true;
351 else if (Feature == "-abs2008")
352 IsAbs2008 = false;
353 else if (Feature == "+noabicalls")
354 IsNoABICalls = true;
355 else if (Feature == "+use-indirect-jump-hazard")
356 UseIndirectJumpHazard = true;
357 else if (Feature == "+nooddspreg") {
358 NoOddSpreg = true;
359 OddSpregGiven = false;
360 } else if (Feature == "-nooddspreg") {
361 NoOddSpreg = false;
362 OddSpregGiven = true;
363 }
364 }
365
366 if (FPMode == FPXX && !OddSpregGiven)
367 NoOddSpreg = true;
368
369 if (StrictAlign)
370 HasUnalignedAccess = false;
371
372 if (HasMSA && !FpGiven) {
373 FPMode = FP64;
374 Features.push_back("+fp64");
375 }
376
378
379 return true;
380 }
381
382 int getEHDataRegisterNumber(unsigned RegNo) const override {
383 if (RegNo == 0)
384 return 4;
385 if (RegNo == 1)
386 return 5;
387 return -1;
388 }
389
390 bool isCLZForZeroUndef() const override { return false; }
391
393 static const TargetInfo::GCCRegAlias O32RegAliases[] = {
394 {{"at"}, "$1"}, {{"v0"}, "$2"}, {{"v1"}, "$3"},
395 {{"a0"}, "$4"}, {{"a1"}, "$5"}, {{"a2"}, "$6"},
396 {{"a3"}, "$7"}, {{"t0"}, "$8"}, {{"t1"}, "$9"},
397 {{"t2"}, "$10"}, {{"t3"}, "$11"}, {{"t4"}, "$12"},
398 {{"t5"}, "$13"}, {{"t6"}, "$14"}, {{"t7"}, "$15"},
399 {{"s0"}, "$16"}, {{"s1"}, "$17"}, {{"s2"}, "$18"},
400 {{"s3"}, "$19"}, {{"s4"}, "$20"}, {{"s5"}, "$21"},
401 {{"s6"}, "$22"}, {{"s7"}, "$23"}, {{"t8"}, "$24"},
402 {{"t9"}, "$25"}, {{"k0"}, "$26"}, {{"k1"}, "$27"},
403 {{"gp"}, "$28"}, {{"sp", "$sp"}, "$29"}, {{"fp", "$fp"}, "$30"},
404 {{"ra"}, "$31"}
405 };
406 static const TargetInfo::GCCRegAlias NewABIRegAliases[] = {
407 {{"at"}, "$1"}, {{"v0"}, "$2"}, {{"v1"}, "$3"},
408 {{"a0"}, "$4"}, {{"a1"}, "$5"}, {{"a2"}, "$6"},
409 {{"a3"}, "$7"}, {{"a4"}, "$8"}, {{"a5"}, "$9"},
410 {{"a6"}, "$10"}, {{"a7"}, "$11"}, {{"t0"}, "$12"},
411 {{"t1"}, "$13"}, {{"t2"}, "$14"}, {{"t3"}, "$15"},
412 {{"s0"}, "$16"}, {{"s1"}, "$17"}, {{"s2"}, "$18"},
413 {{"s3"}, "$19"}, {{"s4"}, "$20"}, {{"s5"}, "$21"},
414 {{"s6"}, "$22"}, {{"s7"}, "$23"}, {{"t8"}, "$24"},
415 {{"t9"}, "$25"}, {{"k0"}, "$26"}, {{"k1"}, "$27"},
416 {{"gp"}, "$28"}, {{"sp", "$sp"}, "$29"}, {{"fp", "$fp"}, "$30"},
417 {{"ra"}, "$31"}
418 };
419 if (ABI == "o32")
420 return llvm::ArrayRef(O32RegAliases);
421 return llvm::ArrayRef(NewABIRegAliases);
422 }
423
424 bool hasInt128Type() const override {
425 return (ABI == "n32" || ABI == "n64") || getTargetOpts().ForceEnableInt128;
426 }
427
428 unsigned getUnwindWordWidth() const override;
429
430 bool validateTarget(DiagnosticsEngine &Diags) const override;
431 bool hasBitIntType() const override { return true; }
432
433 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
434 return std::make_pair(32, 32);
435 }
436};
437
438class LLVM_LIBRARY_VISIBILITY WindowsMipsTargetInfo
439 : public WindowsTargetInfo<MipsTargetInfo> {
440 const llvm::Triple Triple;
441
442public:
443 WindowsMipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
444
445 void getVisualStudioDefines(const LangOptions &Opts,
446 MacroBuilder &Builder) const;
447
449
451};
452
453// Windows MIPS, MS (C++) ABI
454class LLVM_LIBRARY_VISIBILITY MicrosoftMipsTargetInfo
455 : public WindowsMipsTargetInfo {
456public:
457 MicrosoftMipsTargetInfo(const llvm::Triple &Triple,
458 const TargetOptions &Opts);
459
460 void getTargetDefines(const LangOptions &Opts,
461 MacroBuilder &Builder) const override;
462};
463
464// MIPS MinGW target
465class LLVM_LIBRARY_VISIBILITY MinGWMipsTargetInfo
466 : public WindowsMipsTargetInfo {
467public:
468 MinGWMipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
469
470 void getTargetDefines(const LangOptions &Opts,
471 MacroBuilder &Builder) const override;
472};
473} // namespace targets
474} // namespace clang
475
476#endif // LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition Module.cpp:95
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetOptions & getTargetOpts() const
Retrieve the target options.
Definition TargetInfo.h:326
TargetInfo(const llvm::Triple &T)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:333
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:338
unsigned HasUnalignedAccess
Definition TargetInfo.h:284
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:252
void resetDataLayout(StringRef DL)
Set the data layout to the given string.
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
virtual std::string convertConstraint(const char *&Constraint) const
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:252
TargetCXXABI TheCXXABI
Definition TargetInfo.h:257
Options for controlling the target.
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition Mips.cpp:358
MicrosoftMipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Mips.cpp:352
MinGWMipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Mips.cpp:364
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition Mips.cpp:370
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition Mips.h:431
enum clang::targets::MipsTargetInfo::FPModeEnum FPMode
MipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition Mips.h:46
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition Mips.h:382
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition Mips.h:188
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition Mips.h:165
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition Mips.h:158
StringRef getABI() const override
Get the ABI currently in use.
Definition Mips.h:85
ArrayRef< const char * > getGCCRegNames() const override
Definition Mips.h:192
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition Mips.cpp:60
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition Mips.h:298
bool hasInt128Type() const override
Determine whether the __int128 type is supported on this target.
Definition Mips.h:424
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition Mips.h:221
bool isIEEE754_2008Default() const
Definition Mips.h:67
enum FPModeEnum getDefaultFPMode() const
Definition Mips.h:72
std::pair< unsigned, unsigned > hardwareInterferenceSizes() const override
The first value in the pair is the minimum offset between two objects to avoid false sharing (destruc...
Definition Mips.h:433
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition Mips.h:87
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition Mips.h:273
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition Mips.h:392
std::string convertConstraint(const char *&Constraint) const override
Definition Mips.h:259
bool isCLZForZeroUndef() const override
The __builtin_clz* and __builtin_ctz* built-in functions are specified to have undefined results for ...
Definition Mips.h:390
bool isNan2008() const override
Returns true if NaN encoding is IEEE 754-2008.
Definition Mips.h:81
const std::string & getCPU() const
Definition Mips.h:163
void getVisualStudioDefines(const LangOptions &Opts, MacroBuilder &Builder) const
Definition Mips.cpp:321
WindowsMipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Mips.cpp:317
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition Mips.cpp:332
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition Mips.cpp:327
WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition OSTargets.h:882
Defines the clang::TargetInfo interface.
static const char *const GCCRegNames[]
Definition X86.cpp:73
The JSON file list parser is used to communicate input to InstallAPI.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:278
#define false
Definition stdbool.h:26
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:143