1 | //===--- TargetInfo.h - Expose information about the target -----*- 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 | /// \file |
10 | /// Defines the clang::TargetInfo interface. |
11 | /// |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_BASIC_TARGETINFO_H |
15 | #define LLVM_CLANG_BASIC_TARGETINFO_H |
16 | |
17 | #include "clang/Basic/AddressSpaces.h" |
18 | #include "clang/Basic/BitmaskEnum.h" |
19 | #include "clang/Basic/CodeGenOptions.h" |
20 | #include "clang/Basic/LLVM.h" |
21 | #include "clang/Basic/LangOptions.h" |
22 | #include "clang/Basic/Specifiers.h" |
23 | #include "clang/Basic/TargetCXXABI.h" |
24 | #include "clang/Basic/TargetOptions.h" |
25 | #include "llvm/ADT/APFloat.h" |
26 | #include "llvm/ADT/APInt.h" |
27 | #include "llvm/ADT/APSInt.h" |
28 | #include "llvm/ADT/ArrayRef.h" |
29 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
30 | #include "llvm/ADT/SmallSet.h" |
31 | #include "llvm/ADT/StringMap.h" |
32 | #include "llvm/ADT/StringRef.h" |
33 | #include "llvm/ADT/StringSet.h" |
34 | #include "llvm/Frontend/OpenMP/OMPGridValues.h" |
35 | #include "llvm/IR/DerivedTypes.h" |
36 | #include "llvm/Support/DataTypes.h" |
37 | #include "llvm/Support/Error.h" |
38 | #include "llvm/Support/VersionTuple.h" |
39 | #include "llvm/TargetParser/Triple.h" |
40 | #include <cassert> |
41 | #include <optional> |
42 | #include <string> |
43 | #include <vector> |
44 | |
45 | namespace llvm { |
46 | struct fltSemantics; |
47 | } |
48 | |
49 | namespace clang { |
50 | class DiagnosticsEngine; |
51 | class LangOptions; |
52 | class CodeGenOptions; |
53 | class MacroBuilder; |
54 | |
55 | /// Contains information gathered from parsing the contents of TargetAttr. |
56 | struct ParsedTargetAttr { |
57 | std::vector<std::string> Features; |
58 | StringRef CPU; |
59 | StringRef Tune; |
60 | StringRef BranchProtection; |
61 | StringRef Duplicate; |
62 | bool operator ==(const ParsedTargetAttr &Other) const { |
63 | return Duplicate == Other.Duplicate && CPU == Other.CPU && |
64 | Tune == Other.Tune && BranchProtection == Other.BranchProtection && |
65 | Features == Other.Features; |
66 | } |
67 | }; |
68 | |
69 | namespace Builtin { struct Info; } |
70 | |
71 | enum class FloatModeKind { |
72 | NoFloat = 0, |
73 | Half = 1 << 0, |
74 | Float = 1 << 1, |
75 | Double = 1 << 2, |
76 | LongDouble = 1 << 3, |
77 | Float128 = 1 << 4, |
78 | Ibm128 = 1 << 5, |
79 | LLVM_MARK_AS_BITMASK_ENUM(Ibm128) |
80 | }; |
81 | |
82 | /// Fields controlling how types are laid out in memory; these may need to |
83 | /// be copied for targets like AMDGPU that base their ABIs on an auxiliary |
84 | /// CPU target. |
85 | struct TransferrableTargetInfo { |
86 | unsigned char PointerWidth, PointerAlign; |
87 | unsigned char BoolWidth, BoolAlign; |
88 | unsigned char IntWidth, IntAlign; |
89 | unsigned char HalfWidth, HalfAlign; |
90 | unsigned char BFloat16Width, BFloat16Align; |
91 | unsigned char FloatWidth, FloatAlign; |
92 | unsigned char DoubleWidth, DoubleAlign; |
93 | unsigned char LongDoubleWidth, LongDoubleAlign, Float128Align, Ibm128Align; |
94 | unsigned char LargeArrayMinWidth, LargeArrayAlign; |
95 | unsigned char LongWidth, LongAlign; |
96 | unsigned char LongLongWidth, LongLongAlign; |
97 | unsigned char Int128Align; |
98 | |
99 | // Fixed point bit widths |
100 | unsigned char ShortAccumWidth, ShortAccumAlign; |
101 | unsigned char AccumWidth, AccumAlign; |
102 | unsigned char LongAccumWidth, LongAccumAlign; |
103 | unsigned char ShortFractWidth, ShortFractAlign; |
104 | unsigned char FractWidth, FractAlign; |
105 | unsigned char LongFractWidth, LongFractAlign; |
106 | |
107 | // If true, unsigned fixed point types have the same number of fractional bits |
108 | // as their signed counterparts, forcing the unsigned types to have one extra |
109 | // bit of padding. Otherwise, unsigned fixed point types have |
110 | // one more fractional bit than its corresponding signed type. This is false |
111 | // by default. |
112 | bool PaddingOnUnsignedFixedPoint; |
113 | |
114 | // Fixed point integral and fractional bit sizes |
115 | // Saturated types share the same integral/fractional bits as their |
116 | // corresponding unsaturated types. |
117 | // For simplicity, the fractional bits in a _Fract type will be one less the |
118 | // width of that _Fract type. This leaves all signed _Fract types having no |
119 | // padding and unsigned _Fract types will only have 1 bit of padding after the |
120 | // sign if PaddingOnUnsignedFixedPoint is set. |
121 | unsigned char ShortAccumScale; |
122 | unsigned char AccumScale; |
123 | unsigned char LongAccumScale; |
124 | |
125 | unsigned char DefaultAlignForAttributeAligned; |
126 | unsigned char MinGlobalAlign; |
127 | |
128 | unsigned short SuitableAlign; |
129 | unsigned short NewAlign; |
130 | unsigned MaxVectorAlign; |
131 | unsigned MaxTLSAlign; |
132 | |
133 | const llvm::fltSemantics *HalfFormat, *BFloat16Format, *FloatFormat, |
134 | *DoubleFormat, *LongDoubleFormat, *Float128Format, *Ibm128Format; |
135 | |
136 | ///===---- Target Data Type Query Methods -------------------------------===// |
137 | enum IntType { |
138 | NoInt = 0, |
139 | SignedChar, |
140 | UnsignedChar, |
141 | SignedShort, |
142 | UnsignedShort, |
143 | SignedInt, |
144 | UnsignedInt, |
145 | SignedLong, |
146 | UnsignedLong, |
147 | SignedLongLong, |
148 | UnsignedLongLong |
149 | }; |
150 | |
151 | protected: |
152 | IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType, WIntType, |
153 | Char16Type, Char32Type, Int64Type, Int16Type, SigAtomicType, |
154 | ProcessIDType; |
155 | |
156 | /// Whether Objective-C's built-in boolean type should be signed char. |
157 | /// |
158 | /// Otherwise, when this flag is not set, the normal built-in boolean type is |
159 | /// used. |
160 | LLVM_PREFERRED_TYPE(bool) |
161 | unsigned UseSignedCharForObjCBool : 1; |
162 | |
163 | /// Control whether the alignment of bit-field types is respected when laying |
164 | /// out structures. If true, then the alignment of the bit-field type will be |
165 | /// used to (a) impact the alignment of the containing structure, and (b) |
166 | /// ensure that the individual bit-field will not straddle an alignment |
167 | /// boundary. |
168 | LLVM_PREFERRED_TYPE(bool) |
169 | unsigned UseBitFieldTypeAlignment : 1; |
170 | |
171 | /// Whether zero length bitfields (e.g., int : 0;) force alignment of |
172 | /// the next bitfield. |
173 | /// |
174 | /// If the alignment of the zero length bitfield is greater than the member |
175 | /// that follows it, `bar', `bar' will be aligned as the type of the |
176 | /// zero-length bitfield. |
177 | LLVM_PREFERRED_TYPE(bool) |
178 | unsigned UseZeroLengthBitfieldAlignment : 1; |
179 | |
180 | /// Whether zero length bitfield alignment is respected if they are the |
181 | /// leading members. |
182 | LLVM_PREFERRED_TYPE(bool) |
183 | unsigned UseLeadingZeroLengthBitfield : 1; |
184 | |
185 | /// Whether explicit bit field alignment attributes are honored. |
186 | LLVM_PREFERRED_TYPE(bool) |
187 | unsigned UseExplicitBitFieldAlignment : 1; |
188 | |
189 | /// If non-zero, specifies a fixed alignment value for bitfields that follow |
190 | /// zero length bitfield, regardless of the zero length bitfield type. |
191 | unsigned ZeroLengthBitfieldBoundary; |
192 | |
193 | /// If non-zero, specifies a maximum alignment to truncate alignment |
194 | /// specified in the aligned attribute of a static variable to this value. |
195 | unsigned MaxAlignedAttribute; |
196 | }; |
197 | |
198 | /// OpenCL type kinds. |
199 | enum OpenCLTypeKind : uint8_t { |
200 | OCLTK_Default, |
201 | OCLTK_ClkEvent, |
202 | OCLTK_Event, |
203 | OCLTK_Image, |
204 | OCLTK_Pipe, |
205 | OCLTK_Queue, |
206 | OCLTK_ReserveID, |
207 | OCLTK_Sampler, |
208 | }; |
209 | |
210 | /// Exposes information about the current target. |
211 | /// |
212 | class TargetInfo : public TransferrableTargetInfo, |
213 | public RefCountedBase<TargetInfo> { |
214 | std::shared_ptr<TargetOptions> TargetOpts; |
215 | llvm::Triple Triple; |
216 | protected: |
217 | // Target values set by the ctor of the actual target implementation. Default |
218 | // values are specified by the TargetInfo constructor. |
219 | bool BigEndian; |
220 | bool TLSSupported; |
221 | bool VLASupported; |
222 | bool NoAsmVariants; // True if {|} are normal characters. |
223 | bool HasLegalHalfType; // True if the backend supports operations on the half |
224 | // LLVM IR type. |
225 | bool HalfArgsAndReturns; |
226 | bool HasFloat128; |
227 | bool HasFloat16; |
228 | bool HasBFloat16; |
229 | bool HasFullBFloat16; // True if the backend supports native bfloat16 |
230 | // arithmetic. Used to determine excess precision |
231 | // support in the frontend. |
232 | bool HasIbm128; |
233 | bool HasLongDouble; |
234 | bool HasFPReturn; |
235 | bool HasStrictFP; |
236 | |
237 | unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; |
238 | std::string DataLayoutString; |
239 | const char *UserLabelPrefix; |
240 | const char *MCountName; |
241 | unsigned char RegParmMax, SSERegParmMax; |
242 | TargetCXXABI TheCXXABI; |
243 | const LangASMap *AddrSpaceMap; |
244 | |
245 | mutable StringRef PlatformName; |
246 | mutable VersionTuple PlatformMinVersion; |
247 | |
248 | LLVM_PREFERRED_TYPE(bool) |
249 | unsigned HasAlignMac68kSupport : 1; |
250 | LLVM_PREFERRED_TYPE(FloatModeKind) |
251 | unsigned RealTypeUsesObjCFPRetMask : llvm::BitWidth<FloatModeKind>; |
252 | LLVM_PREFERRED_TYPE(bool) |
253 | unsigned ComplexLongDoubleUsesFP2Ret : 1; |
254 | |
255 | LLVM_PREFERRED_TYPE(bool) |
256 | unsigned HasBuiltinMSVaList : 1; |
257 | |
258 | LLVM_PREFERRED_TYPE(bool) |
259 | unsigned IsRenderScriptTarget : 1; |
260 | |
261 | LLVM_PREFERRED_TYPE(bool) |
262 | unsigned HasAArch64SVETypes : 1; |
263 | |
264 | LLVM_PREFERRED_TYPE(bool) |
265 | unsigned HasRISCVVTypes : 1; |
266 | |
267 | LLVM_PREFERRED_TYPE(bool) |
268 | unsigned AllowAMDGPUUnsafeFPAtomics : 1; |
269 | |
270 | LLVM_PREFERRED_TYPE(bool) |
271 | unsigned HasUnalignedAccess : 1; |
272 | |
273 | unsigned ARMCDECoprocMask : 8; |
274 | |
275 | unsigned MaxOpenCLWorkGroupSize; |
276 | |
277 | std::optional<unsigned> MaxBitIntWidth; |
278 | |
279 | std::optional<llvm::Triple> DarwinTargetVariantTriple; |
280 | |
281 | // TargetInfo Constructor. Default initializes all fields. |
282 | TargetInfo(const llvm::Triple &T); |
283 | |
284 | // UserLabelPrefix must match DL's getGlobalPrefix() when interpreted |
285 | // as a DataLayout object. |
286 | void resetDataLayout(StringRef DL, const char *UserLabelPrefix = "" ); |
287 | |
288 | // Target features that are read-only and should not be disabled/enabled |
289 | // by command line options. Such features are for emitting predefined |
290 | // macros or checking availability of builtin functions and can be omitted |
291 | // in function attributes in IR. |
292 | llvm::StringSet<> ReadOnlyFeatures; |
293 | |
294 | public: |
295 | /// Construct a target for the given options. |
296 | /// |
297 | /// \param Opts - The options to use to initialize the target. The target may |
298 | /// modify the options to canonicalize the target feature information to match |
299 | /// what the backend expects. |
300 | static TargetInfo * |
301 | CreateTargetInfo(DiagnosticsEngine &Diags, |
302 | const std::shared_ptr<TargetOptions> &Opts); |
303 | |
304 | virtual ~TargetInfo(); |
305 | |
306 | /// Retrieve the target options. |
307 | TargetOptions &getTargetOpts() const { |
308 | assert(TargetOpts && "Missing target options" ); |
309 | return *TargetOpts; |
310 | } |
311 | |
312 | /// The different kinds of __builtin_va_list types defined by |
313 | /// the target implementation. |
314 | enum BuiltinVaListKind { |
315 | /// typedef char* __builtin_va_list; |
316 | CharPtrBuiltinVaList = 0, |
317 | |
318 | /// typedef void* __builtin_va_list; |
319 | VoidPtrBuiltinVaList, |
320 | |
321 | /// __builtin_va_list as defined by the AArch64 ABI |
322 | /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf |
323 | AArch64ABIBuiltinVaList, |
324 | |
325 | /// __builtin_va_list as defined by the PNaCl ABI: |
326 | /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types |
327 | PNaClABIBuiltinVaList, |
328 | |
329 | /// __builtin_va_list as defined by the Power ABI: |
330 | /// https://www.power.org |
331 | /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf |
332 | PowerABIBuiltinVaList, |
333 | |
334 | /// __builtin_va_list as defined by the x86-64 ABI: |
335 | /// http://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf |
336 | X86_64ABIBuiltinVaList, |
337 | |
338 | /// __builtin_va_list as defined by ARM AAPCS ABI |
339 | /// http://infocenter.arm.com |
340 | // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf |
341 | AAPCSABIBuiltinVaList, |
342 | |
343 | // typedef struct __va_list_tag |
344 | // { |
345 | // long __gpr; |
346 | // long __fpr; |
347 | // void *__overflow_arg_area; |
348 | // void *__reg_save_area; |
349 | // } va_list[1]; |
350 | SystemZBuiltinVaList, |
351 | |
352 | // typedef struct __va_list_tag { |
353 | // void *__current_saved_reg_area_pointer; |
354 | // void *__saved_reg_area_end_pointer; |
355 | // void *__overflow_area_pointer; |
356 | //} va_list; |
357 | HexagonBuiltinVaList |
358 | }; |
359 | |
360 | protected: |
361 | /// Specify if mangling based on address space map should be used or |
362 | /// not for language specific address spaces |
363 | bool UseAddrSpaceMapMangling; |
364 | |
365 | public: |
366 | IntType getSizeType() const { return SizeType; } |
367 | IntType getSignedSizeType() const { |
368 | switch (SizeType) { |
369 | case UnsignedShort: |
370 | return SignedShort; |
371 | case UnsignedInt: |
372 | return SignedInt; |
373 | case UnsignedLong: |
374 | return SignedLong; |
375 | case UnsignedLongLong: |
376 | return SignedLongLong; |
377 | default: |
378 | llvm_unreachable("Invalid SizeType" ); |
379 | } |
380 | } |
381 | IntType getIntMaxType() const { return IntMaxType; } |
382 | IntType getUIntMaxType() const { |
383 | return getCorrespondingUnsignedType(T: IntMaxType); |
384 | } |
385 | IntType getPtrDiffType(LangAS AddrSpace) const { |
386 | return AddrSpace == LangAS::Default ? PtrDiffType |
387 | : getPtrDiffTypeV(AddrSpace); |
388 | } |
389 | IntType getUnsignedPtrDiffType(LangAS AddrSpace) const { |
390 | return getCorrespondingUnsignedType(T: getPtrDiffType(AddrSpace)); |
391 | } |
392 | IntType getIntPtrType() const { return IntPtrType; } |
393 | IntType getUIntPtrType() const { |
394 | return getCorrespondingUnsignedType(T: IntPtrType); |
395 | } |
396 | IntType getWCharType() const { return WCharType; } |
397 | IntType getWIntType() const { return WIntType; } |
398 | IntType getChar16Type() const { return Char16Type; } |
399 | IntType getChar32Type() const { return Char32Type; } |
400 | IntType getInt64Type() const { return Int64Type; } |
401 | IntType getUInt64Type() const { |
402 | return getCorrespondingUnsignedType(T: Int64Type); |
403 | } |
404 | IntType getInt16Type() const { return Int16Type; } |
405 | IntType getUInt16Type() const { |
406 | return getCorrespondingUnsignedType(T: Int16Type); |
407 | } |
408 | IntType getSigAtomicType() const { return SigAtomicType; } |
409 | IntType getProcessIDType() const { return ProcessIDType; } |
410 | |
411 | static IntType getCorrespondingUnsignedType(IntType T) { |
412 | switch (T) { |
413 | case SignedChar: |
414 | return UnsignedChar; |
415 | case SignedShort: |
416 | return UnsignedShort; |
417 | case SignedInt: |
418 | return UnsignedInt; |
419 | case SignedLong: |
420 | return UnsignedLong; |
421 | case SignedLongLong: |
422 | return UnsignedLongLong; |
423 | default: |
424 | llvm_unreachable("Unexpected signed integer type" ); |
425 | } |
426 | } |
427 | |
428 | /// In the event this target uses the same number of fractional bits for its |
429 | /// unsigned types as it does with its signed counterparts, there will be |
430 | /// exactly one bit of padding. |
431 | /// Return true if unsigned fixed point types have padding for this target. |
432 | bool doUnsignedFixedPointTypesHavePadding() const { |
433 | return PaddingOnUnsignedFixedPoint; |
434 | } |
435 | |
436 | /// Return the width (in bits) of the specified integer type enum. |
437 | /// |
438 | /// For example, SignedInt -> getIntWidth(). |
439 | unsigned getTypeWidth(IntType T) const; |
440 | |
441 | /// Return integer type with specified width. |
442 | virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const; |
443 | |
444 | /// Return the smallest integer type with at least the specified width. |
445 | virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, |
446 | bool IsSigned) const; |
447 | |
448 | /// Return floating point type with specified width. On PPC, there are |
449 | /// three possible types for 128-bit floating point: "PPC double-double", |
450 | /// IEEE 754R quad precision, and "long double" (which under the covers |
451 | /// is represented as one of those two). At this time, there is no support |
452 | /// for an explicit "PPC double-double" type (i.e. __ibm128) so we only |
453 | /// need to differentiate between "long double" and IEEE quad precision. |
454 | FloatModeKind getRealTypeByWidth(unsigned BitWidth, |
455 | FloatModeKind ExplicitType) const; |
456 | |
457 | /// Return the alignment (in bits) of the specified integer type enum. |
458 | /// |
459 | /// For example, SignedInt -> getIntAlign(). |
460 | unsigned getTypeAlign(IntType T) const; |
461 | |
462 | /// Returns true if the type is signed; false otherwise. |
463 | static bool isTypeSigned(IntType T); |
464 | |
465 | /// Return the width of pointers on this target, for the |
466 | /// specified address space. |
467 | uint64_t getPointerWidth(LangAS AddrSpace) const { |
468 | return AddrSpace == LangAS::Default ? PointerWidth |
469 | : getPointerWidthV(AddrSpace); |
470 | } |
471 | uint64_t getPointerAlign(LangAS AddrSpace) const { |
472 | return AddrSpace == LangAS::Default ? PointerAlign |
473 | : getPointerAlignV(AddrSpace); |
474 | } |
475 | |
476 | /// Return the maximum width of pointers on this target. |
477 | virtual uint64_t getMaxPointerWidth() const { |
478 | return PointerWidth; |
479 | } |
480 | |
481 | /// Get integer value for null pointer. |
482 | /// \param AddrSpace address space of pointee in source language. |
483 | virtual uint64_t getNullPointerValue(LangAS AddrSpace) const { return 0; } |
484 | |
485 | /// Return the size of '_Bool' and C++ 'bool' for this target, in bits. |
486 | unsigned getBoolWidth() const { return BoolWidth; } |
487 | |
488 | /// Return the alignment of '_Bool' and C++ 'bool' for this target. |
489 | unsigned getBoolAlign() const { return BoolAlign; } |
490 | |
491 | unsigned getCharWidth() const { return 8; } // FIXME |
492 | unsigned getCharAlign() const { return 8; } // FIXME |
493 | |
494 | /// Return the size of 'signed short' and 'unsigned short' for this |
495 | /// target, in bits. |
496 | unsigned getShortWidth() const { return 16; } // FIXME |
497 | |
498 | /// Return the alignment of 'signed short' and 'unsigned short' for |
499 | /// this target. |
500 | unsigned getShortAlign() const { return 16; } // FIXME |
501 | |
502 | /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for |
503 | /// this target, in bits. |
504 | unsigned getIntWidth() const { return IntWidth; } |
505 | unsigned getIntAlign() const { return IntAlign; } |
506 | |
507 | /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' |
508 | /// for this target, in bits. |
509 | unsigned getLongWidth() const { return LongWidth; } |
510 | unsigned getLongAlign() const { return LongAlign; } |
511 | |
512 | /// getLongLongWidth/Align - Return the size of 'signed long long' and |
513 | /// 'unsigned long long' for this target, in bits. |
514 | unsigned getLongLongWidth() const { return LongLongWidth; } |
515 | unsigned getLongLongAlign() const { return LongLongAlign; } |
516 | |
517 | /// getInt128Align() - Returns the alignment of Int128. |
518 | unsigned getInt128Align() const { return Int128Align; } |
519 | |
520 | /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and |
521 | /// 'unsigned short _Accum' for this target, in bits. |
522 | unsigned getShortAccumWidth() const { return ShortAccumWidth; } |
523 | unsigned getShortAccumAlign() const { return ShortAccumAlign; } |
524 | |
525 | /// getAccumWidth/Align - Return the size of 'signed _Accum' and |
526 | /// 'unsigned _Accum' for this target, in bits. |
527 | unsigned getAccumWidth() const { return AccumWidth; } |
528 | unsigned getAccumAlign() const { return AccumAlign; } |
529 | |
530 | /// getLongAccumWidth/Align - Return the size of 'signed long _Accum' and |
531 | /// 'unsigned long _Accum' for this target, in bits. |
532 | unsigned getLongAccumWidth() const { return LongAccumWidth; } |
533 | unsigned getLongAccumAlign() const { return LongAccumAlign; } |
534 | |
535 | /// getShortFractWidth/Align - Return the size of 'signed short _Fract' and |
536 | /// 'unsigned short _Fract' for this target, in bits. |
537 | unsigned getShortFractWidth() const { return ShortFractWidth; } |
538 | unsigned getShortFractAlign() const { return ShortFractAlign; } |
539 | |
540 | /// getFractWidth/Align - Return the size of 'signed _Fract' and |
541 | /// 'unsigned _Fract' for this target, in bits. |
542 | unsigned getFractWidth() const { return FractWidth; } |
543 | unsigned getFractAlign() const { return FractAlign; } |
544 | |
545 | /// getLongFractWidth/Align - Return the size of 'signed long _Fract' and |
546 | /// 'unsigned long _Fract' for this target, in bits. |
547 | unsigned getLongFractWidth() const { return LongFractWidth; } |
548 | unsigned getLongFractAlign() const { return LongFractAlign; } |
549 | |
550 | /// getShortAccumScale/IBits - Return the number of fractional/integral bits |
551 | /// in a 'signed short _Accum' type. |
552 | unsigned getShortAccumScale() const { return ShortAccumScale; } |
553 | unsigned getShortAccumIBits() const { |
554 | return ShortAccumWidth - ShortAccumScale - 1; |
555 | } |
556 | |
557 | /// getAccumScale/IBits - Return the number of fractional/integral bits |
558 | /// in a 'signed _Accum' type. |
559 | unsigned getAccumScale() const { return AccumScale; } |
560 | unsigned getAccumIBits() const { return AccumWidth - AccumScale - 1; } |
561 | |
562 | /// getLongAccumScale/IBits - Return the number of fractional/integral bits |
563 | /// in a 'signed long _Accum' type. |
564 | unsigned getLongAccumScale() const { return LongAccumScale; } |
565 | unsigned getLongAccumIBits() const { |
566 | return LongAccumWidth - LongAccumScale - 1; |
567 | } |
568 | |
569 | /// getUnsignedShortAccumScale/IBits - Return the number of |
570 | /// fractional/integral bits in a 'unsigned short _Accum' type. |
571 | unsigned getUnsignedShortAccumScale() const { |
572 | return PaddingOnUnsignedFixedPoint ? ShortAccumScale : ShortAccumScale + 1; |
573 | } |
574 | unsigned getUnsignedShortAccumIBits() const { |
575 | return PaddingOnUnsignedFixedPoint |
576 | ? getShortAccumIBits() |
577 | : ShortAccumWidth - getUnsignedShortAccumScale(); |
578 | } |
579 | |
580 | /// getUnsignedAccumScale/IBits - Return the number of fractional/integral |
581 | /// bits in a 'unsigned _Accum' type. |
582 | unsigned getUnsignedAccumScale() const { |
583 | return PaddingOnUnsignedFixedPoint ? AccumScale : AccumScale + 1; |
584 | } |
585 | unsigned getUnsignedAccumIBits() const { |
586 | return PaddingOnUnsignedFixedPoint ? getAccumIBits() |
587 | : AccumWidth - getUnsignedAccumScale(); |
588 | } |
589 | |
590 | /// getUnsignedLongAccumScale/IBits - Return the number of fractional/integral |
591 | /// bits in a 'unsigned long _Accum' type. |
592 | unsigned getUnsignedLongAccumScale() const { |
593 | return PaddingOnUnsignedFixedPoint ? LongAccumScale : LongAccumScale + 1; |
594 | } |
595 | unsigned getUnsignedLongAccumIBits() const { |
596 | return PaddingOnUnsignedFixedPoint |
597 | ? getLongAccumIBits() |
598 | : LongAccumWidth - getUnsignedLongAccumScale(); |
599 | } |
600 | |
601 | /// getShortFractScale - Return the number of fractional bits |
602 | /// in a 'signed short _Fract' type. |
603 | unsigned getShortFractScale() const { return ShortFractWidth - 1; } |
604 | |
605 | /// getFractScale - Return the number of fractional bits |
606 | /// in a 'signed _Fract' type. |
607 | unsigned getFractScale() const { return FractWidth - 1; } |
608 | |
609 | /// getLongFractScale - Return the number of fractional bits |
610 | /// in a 'signed long _Fract' type. |
611 | unsigned getLongFractScale() const { return LongFractWidth - 1; } |
612 | |
613 | /// getUnsignedShortFractScale - Return the number of fractional bits |
614 | /// in a 'unsigned short _Fract' type. |
615 | unsigned getUnsignedShortFractScale() const { |
616 | return PaddingOnUnsignedFixedPoint ? getShortFractScale() |
617 | : getShortFractScale() + 1; |
618 | } |
619 | |
620 | /// getUnsignedFractScale - Return the number of fractional bits |
621 | /// in a 'unsigned _Fract' type. |
622 | unsigned getUnsignedFractScale() const { |
623 | return PaddingOnUnsignedFixedPoint ? getFractScale() : getFractScale() + 1; |
624 | } |
625 | |
626 | /// getUnsignedLongFractScale - Return the number of fractional bits |
627 | /// in a 'unsigned long _Fract' type. |
628 | unsigned getUnsignedLongFractScale() const { |
629 | return PaddingOnUnsignedFixedPoint ? getLongFractScale() |
630 | : getLongFractScale() + 1; |
631 | } |
632 | |
633 | /// Determine whether the __int128 type is supported on this target. |
634 | virtual bool hasInt128Type() const { |
635 | return (getPointerWidth(AddrSpace: LangAS::Default) >= 64) || |
636 | getTargetOpts().ForceEnableInt128; |
637 | } // FIXME |
638 | |
639 | /// Determine whether the _BitInt type is supported on this target. This |
640 | /// limitation is put into place for ABI reasons. |
641 | /// FIXME: _BitInt is a required type in C23, so there's not much utility in |
642 | /// asking whether the target supported it or not; I think this should be |
643 | /// removed once backends have been alerted to the type and have had the |
644 | /// chance to do implementation work if needed. |
645 | virtual bool hasBitIntType() const { |
646 | return false; |
647 | } |
648 | |
649 | // Different targets may support a different maximum width for the _BitInt |
650 | // type, depending on what operations are supported. |
651 | virtual size_t getMaxBitIntWidth() const { |
652 | // Consider -fexperimental-max-bitint-width= first. |
653 | if (MaxBitIntWidth) |
654 | return std::min<size_t>(a: *MaxBitIntWidth, b: llvm::IntegerType::MAX_INT_BITS); |
655 | |
656 | // FIXME: this value should be llvm::IntegerType::MAX_INT_BITS, which is |
657 | // maximum bit width that LLVM claims its IR can support. However, most |
658 | // backends currently have a bug where they only support float to int |
659 | // conversion (and vice versa) on types that are <= 128 bits and crash |
660 | // otherwise. We're setting the max supported value to 128 to be |
661 | // conservative. |
662 | return 128; |
663 | } |
664 | |
665 | /// Determine whether _Float16 is supported on this target. |
666 | virtual bool hasLegalHalfType() const { return HasLegalHalfType; } |
667 | |
668 | /// Whether half args and returns are supported. |
669 | virtual bool allowHalfArgsAndReturns() const { return HalfArgsAndReturns; } |
670 | |
671 | /// Determine whether the __float128 type is supported on this target. |
672 | virtual bool hasFloat128Type() const { return HasFloat128; } |
673 | |
674 | /// Determine whether the _Float16 type is supported on this target. |
675 | virtual bool hasFloat16Type() const { return HasFloat16; } |
676 | |
677 | /// Determine whether the _BFloat16 type is supported on this target. |
678 | virtual bool hasBFloat16Type() const { |
679 | return HasBFloat16 || HasFullBFloat16; |
680 | } |
681 | |
682 | /// Determine whether the BFloat type is fully supported on this target, i.e |
683 | /// arithemtic operations. |
684 | virtual bool hasFullBFloat16Type() const { return HasFullBFloat16; } |
685 | |
686 | /// Determine whether the __ibm128 type is supported on this target. |
687 | virtual bool hasIbm128Type() const { return HasIbm128; } |
688 | |
689 | /// Determine whether the long double type is supported on this target. |
690 | virtual bool hasLongDoubleType() const { return HasLongDouble; } |
691 | |
692 | /// Determine whether return of a floating point value is supported |
693 | /// on this target. |
694 | virtual bool hasFPReturn() const { return HasFPReturn; } |
695 | |
696 | /// Determine whether constrained floating point is supported on this target. |
697 | virtual bool hasStrictFP() const { return HasStrictFP; } |
698 | |
699 | /// Return the alignment that is the largest alignment ever used for any |
700 | /// scalar/SIMD data type on the target machine you are compiling for |
701 | /// (including types with an extended alignment requirement). |
702 | unsigned getSuitableAlign() const { return SuitableAlign; } |
703 | |
704 | /// Return the default alignment for __attribute__((aligned)) on |
705 | /// this target, to be used if no alignment value is specified. |
706 | unsigned getDefaultAlignForAttributeAligned() const { |
707 | return DefaultAlignForAttributeAligned; |
708 | } |
709 | |
710 | /// getMinGlobalAlign - Return the minimum alignment of a global variable, |
711 | /// unless its alignment is explicitly reduced via attributes. If \param |
712 | /// HasNonWeakDef is true, this concerns a VarDecl which has a definition |
713 | /// in current translation unit and that is not weak. |
714 | virtual unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const { |
715 | return MinGlobalAlign; |
716 | } |
717 | |
718 | /// Return the largest alignment for which a suitably-sized allocation with |
719 | /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned |
720 | /// pointer. |
721 | unsigned getNewAlign() const { |
722 | return NewAlign ? NewAlign : std::max(a: LongDoubleAlign, b: LongLongAlign); |
723 | } |
724 | |
725 | /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in |
726 | /// bits. |
727 | unsigned getWCharWidth() const { return getTypeWidth(T: WCharType); } |
728 | unsigned getWCharAlign() const { return getTypeAlign(T: WCharType); } |
729 | |
730 | /// getChar16Width/Align - Return the size of 'char16_t' for this target, in |
731 | /// bits. |
732 | unsigned getChar16Width() const { return getTypeWidth(T: Char16Type); } |
733 | unsigned getChar16Align() const { return getTypeAlign(T: Char16Type); } |
734 | |
735 | /// getChar32Width/Align - Return the size of 'char32_t' for this target, in |
736 | /// bits. |
737 | unsigned getChar32Width() const { return getTypeWidth(T: Char32Type); } |
738 | unsigned getChar32Align() const { return getTypeAlign(T: Char32Type); } |
739 | |
740 | /// getHalfWidth/Align/Format - Return the size/align/format of 'half'. |
741 | unsigned getHalfWidth() const { return HalfWidth; } |
742 | unsigned getHalfAlign() const { return HalfAlign; } |
743 | const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; } |
744 | |
745 | /// getFloatWidth/Align/Format - Return the size/align/format of 'float'. |
746 | unsigned getFloatWidth() const { return FloatWidth; } |
747 | unsigned getFloatAlign() const { return FloatAlign; } |
748 | const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; } |
749 | |
750 | /// getBFloat16Width/Align/Format - Return the size/align/format of '__bf16'. |
751 | unsigned getBFloat16Width() const { return BFloat16Width; } |
752 | unsigned getBFloat16Align() const { return BFloat16Align; } |
753 | const llvm::fltSemantics &getBFloat16Format() const { return *BFloat16Format; } |
754 | |
755 | /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. |
756 | unsigned getDoubleWidth() const { return DoubleWidth; } |
757 | unsigned getDoubleAlign() const { return DoubleAlign; } |
758 | const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; } |
759 | |
760 | /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long |
761 | /// double'. |
762 | unsigned getLongDoubleWidth() const { return LongDoubleWidth; } |
763 | unsigned getLongDoubleAlign() const { return LongDoubleAlign; } |
764 | const llvm::fltSemantics &getLongDoubleFormat() const { |
765 | return *LongDoubleFormat; |
766 | } |
767 | |
768 | /// getFloat128Width/Align/Format - Return the size/align/format of |
769 | /// '__float128'. |
770 | unsigned getFloat128Width() const { return 128; } |
771 | unsigned getFloat128Align() const { return Float128Align; } |
772 | const llvm::fltSemantics &getFloat128Format() const { |
773 | return *Float128Format; |
774 | } |
775 | |
776 | /// getIbm128Width/Align/Format - Return the size/align/format of |
777 | /// '__ibm128'. |
778 | unsigned getIbm128Width() const { return 128; } |
779 | unsigned getIbm128Align() const { return Ibm128Align; } |
780 | const llvm::fltSemantics &getIbm128Format() const { return *Ibm128Format; } |
781 | |
782 | /// Return the mangled code of long double. |
783 | virtual const char *getLongDoubleMangling() const { return "e" ; } |
784 | |
785 | /// Return the mangled code of __float128. |
786 | virtual const char *getFloat128Mangling() const { return "g" ; } |
787 | |
788 | /// Return the mangled code of __ibm128. |
789 | virtual const char *getIbm128Mangling() const { |
790 | llvm_unreachable("ibm128 not implemented on this target" ); |
791 | } |
792 | |
793 | /// Return the mangled code of bfloat. |
794 | virtual const char *getBFloat16Mangling() const { return "DF16b" ; } |
795 | |
796 | /// Return the value for the C99 FLT_EVAL_METHOD macro. |
797 | virtual LangOptions::FPEvalMethodKind getFPEvalMethod() const { |
798 | return LangOptions::FPEvalMethodKind::FEM_Source; |
799 | } |
800 | |
801 | virtual bool supportSourceEvalMethod() const { return true; } |
802 | |
803 | // getLargeArrayMinWidth/Align - Return the minimum array size that is |
804 | // 'large' and its alignment. |
805 | unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; } |
806 | unsigned getLargeArrayAlign() const { return LargeArrayAlign; } |
807 | |
808 | /// Return the maximum width lock-free atomic operation which will |
809 | /// ever be supported for the given target |
810 | unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; } |
811 | /// Return the maximum width lock-free atomic operation which can be |
812 | /// inlined given the supported features of the given target. |
813 | unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; } |
814 | /// Set the maximum inline or promote width lock-free atomic operation |
815 | /// for the given target. |
816 | virtual void setMaxAtomicWidth() {} |
817 | /// Returns true if the given target supports lock-free atomic |
818 | /// operations at the specified width and alignment. |
819 | virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits, |
820 | uint64_t AlignmentInBits) const { |
821 | return AtomicSizeInBits <= AlignmentInBits && |
822 | AtomicSizeInBits <= getMaxAtomicInlineWidth() && |
823 | (AtomicSizeInBits <= getCharWidth() || |
824 | llvm::isPowerOf2_64(Value: AtomicSizeInBits / getCharWidth())); |
825 | } |
826 | |
827 | /// Return the maximum vector alignment supported for the given target. |
828 | unsigned getMaxVectorAlign() const { return MaxVectorAlign; } |
829 | |
830 | unsigned getMaxOpenCLWorkGroupSize() const { return MaxOpenCLWorkGroupSize; } |
831 | |
832 | /// Return the alignment (in bits) of the thrown exception object. This is |
833 | /// only meaningful for targets that allocate C++ exceptions in a system |
834 | /// runtime, such as those using the Itanium C++ ABI. |
835 | virtual unsigned getExnObjectAlignment() const { |
836 | // Itanium says that an _Unwind_Exception has to be "double-word" |
837 | // aligned (and thus the end of it is also so-aligned), meaning 16 |
838 | // bytes. Of course, that was written for the actual Itanium, |
839 | // which is a 64-bit platform. Classically, the ABI doesn't really |
840 | // specify the alignment on other platforms, but in practice |
841 | // libUnwind declares the struct with __attribute__((aligned)), so |
842 | // we assume that alignment here. (It's generally 16 bytes, but |
843 | // some targets overwrite it.) |
844 | return getDefaultAlignForAttributeAligned(); |
845 | } |
846 | |
847 | /// Return the size of intmax_t and uintmax_t for this target, in bits. |
848 | unsigned getIntMaxTWidth() const { |
849 | return getTypeWidth(T: IntMaxType); |
850 | } |
851 | |
852 | // Return the size of unwind_word for this target. |
853 | virtual unsigned getUnwindWordWidth() const { |
854 | return getPointerWidth(AddrSpace: LangAS::Default); |
855 | } |
856 | |
857 | /// Return the "preferred" register width on this target. |
858 | virtual unsigned getRegisterWidth() const { |
859 | // Currently we assume the register width on the target matches the pointer |
860 | // width, we can introduce a new variable for this if/when some target wants |
861 | // it. |
862 | return PointerWidth; |
863 | } |
864 | |
865 | /// Return true iff unaligned accesses are a single instruction (rather than |
866 | /// a synthesized sequence). |
867 | bool hasUnalignedAccess() const { return HasUnalignedAccess; } |
868 | |
869 | /// Return true iff unaligned accesses are cheap. This affects placement and |
870 | /// size of bitfield loads/stores. (Not the ABI-mandated placement of |
871 | /// the bitfields themselves.) |
872 | bool hasCheapUnalignedBitFieldAccess() const { |
873 | // Simply forward to the unaligned access getter. |
874 | return hasUnalignedAccess(); |
875 | } |
876 | |
877 | /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro, |
878 | /// which is the prefix given to user symbols by default. |
879 | /// |
880 | /// On most platforms this is "", but it is "_" on some. |
881 | const char *getUserLabelPrefix() const { return UserLabelPrefix; } |
882 | |
883 | /// Returns the name of the mcount instrumentation function. |
884 | const char *getMCountName() const { |
885 | return MCountName; |
886 | } |
887 | |
888 | /// Check if the Objective-C built-in boolean type should be signed |
889 | /// char. |
890 | /// |
891 | /// Otherwise, if this returns false, the normal built-in boolean type |
892 | /// should also be used for Objective-C. |
893 | bool useSignedCharForObjCBool() const { |
894 | return UseSignedCharForObjCBool; |
895 | } |
896 | void noSignedCharForObjCBool() { |
897 | UseSignedCharForObjCBool = false; |
898 | } |
899 | |
900 | /// Check whether the alignment of bit-field types is respected |
901 | /// when laying out structures. |
902 | bool useBitFieldTypeAlignment() const { |
903 | return UseBitFieldTypeAlignment; |
904 | } |
905 | |
906 | /// Check whether zero length bitfields should force alignment of |
907 | /// the next member. |
908 | bool useZeroLengthBitfieldAlignment() const { |
909 | return UseZeroLengthBitfieldAlignment; |
910 | } |
911 | |
912 | /// Check whether zero length bitfield alignment is respected if they are |
913 | /// leading members. |
914 | bool useLeadingZeroLengthBitfield() const { |
915 | return UseLeadingZeroLengthBitfield; |
916 | } |
917 | |
918 | /// Get the fixed alignment value in bits for a member that follows |
919 | /// a zero length bitfield. |
920 | unsigned getZeroLengthBitfieldBoundary() const { |
921 | return ZeroLengthBitfieldBoundary; |
922 | } |
923 | |
924 | /// Get the maximum alignment in bits for a static variable with |
925 | /// aligned attribute. |
926 | unsigned getMaxAlignedAttribute() const { return MaxAlignedAttribute; } |
927 | |
928 | /// Check whether explicit bitfield alignment attributes should be |
929 | // honored, as in "__attribute__((aligned(2))) int b : 1;". |
930 | bool useExplicitBitFieldAlignment() const { |
931 | return UseExplicitBitFieldAlignment; |
932 | } |
933 | |
934 | /// Check whether this target support '\#pragma options align=mac68k'. |
935 | bool hasAlignMac68kSupport() const { |
936 | return HasAlignMac68kSupport; |
937 | } |
938 | |
939 | /// Return the user string for the specified integer type enum. |
940 | /// |
941 | /// For example, SignedShort -> "short". |
942 | static const char *getTypeName(IntType T); |
943 | |
944 | /// Return the constant suffix for the specified integer type enum. |
945 | /// |
946 | /// For example, SignedLong -> "L". |
947 | const char *getTypeConstantSuffix(IntType T) const; |
948 | |
949 | /// Return the printf format modifier for the specified |
950 | /// integer type enum. |
951 | /// |
952 | /// For example, SignedLong -> "l". |
953 | static const char *getTypeFormatModifier(IntType T); |
954 | |
955 | /// Check whether the given real type should use the "fpret" flavor of |
956 | /// Objective-C message passing on this target. |
957 | bool useObjCFPRetForRealType(FloatModeKind T) const { |
958 | return (int)((FloatModeKind)RealTypeUsesObjCFPRetMask & T); |
959 | } |
960 | |
961 | /// Check whether _Complex long double should use the "fp2ret" flavor |
962 | /// of Objective-C message passing on this target. |
963 | bool useObjCFP2RetForComplexLongDouble() const { |
964 | return ComplexLongDoubleUsesFP2Ret; |
965 | } |
966 | |
967 | /// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used |
968 | /// to convert to and from __fp16. |
969 | /// FIXME: This function should be removed once all targets stop using the |
970 | /// conversion intrinsics. |
971 | virtual bool useFP16ConversionIntrinsics() const { |
972 | return true; |
973 | } |
974 | |
975 | /// Specify if mangling based on address space map should be used or |
976 | /// not for language specific address spaces |
977 | bool useAddressSpaceMapMangling() const { |
978 | return UseAddrSpaceMapMangling; |
979 | } |
980 | |
981 | ///===---- Other target property query methods --------------------------===// |
982 | |
983 | /// Appends the target-specific \#define values for this |
984 | /// target set to the specified buffer. |
985 | virtual void getTargetDefines(const LangOptions &Opts, |
986 | MacroBuilder &Builder) const = 0; |
987 | |
988 | |
989 | /// Return information about target-specific builtins for |
990 | /// the current primary target, and info about which builtins are non-portable |
991 | /// across the current set of primary and secondary targets. |
992 | virtual ArrayRef<Builtin::Info> getTargetBuiltins() const = 0; |
993 | |
994 | /// Returns target-specific min and max values VScale_Range. |
995 | virtual std::optional<std::pair<unsigned, unsigned>> |
996 | getVScaleRange(const LangOptions &LangOpts) const { |
997 | return std::nullopt; |
998 | } |
999 | /// The __builtin_clz* and __builtin_ctz* built-in |
1000 | /// functions are specified to have undefined results for zero inputs, but |
1001 | /// on targets that support these operations in a way that provides |
1002 | /// well-defined results for zero without loss of performance, it is a good |
1003 | /// idea to avoid optimizing based on that undef behavior. |
1004 | virtual bool isCLZForZeroUndef() const { return true; } |
1005 | |
1006 | /// Returns the kind of __builtin_va_list type that should be used |
1007 | /// with this target. |
1008 | virtual BuiltinVaListKind getBuiltinVaListKind() const = 0; |
1009 | |
1010 | /// Returns whether or not type \c __builtin_ms_va_list type is |
1011 | /// available on this target. |
1012 | bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; } |
1013 | |
1014 | /// Returns true for RenderScript. |
1015 | bool isRenderScriptTarget() const { return IsRenderScriptTarget; } |
1016 | |
1017 | /// Returns whether or not the AArch64 SVE built-in types are |
1018 | /// available on this target. |
1019 | bool hasAArch64SVETypes() const { return HasAArch64SVETypes; } |
1020 | |
1021 | /// Returns whether or not the RISC-V V built-in types are |
1022 | /// available on this target. |
1023 | bool hasRISCVVTypes() const { return HasRISCVVTypes; } |
1024 | |
1025 | /// Returns whether or not the AMDGPU unsafe floating point atomics are |
1026 | /// allowed. |
1027 | bool allowAMDGPUUnsafeFPAtomics() const { return AllowAMDGPUUnsafeFPAtomics; } |
1028 | |
1029 | /// For ARM targets returns a mask defining which coprocessors are configured |
1030 | /// as Custom Datapath. |
1031 | uint32_t getARMCDECoprocMask() const { return ARMCDECoprocMask; } |
1032 | |
1033 | /// Returns whether the passed in string is a valid clobber in an |
1034 | /// inline asm statement. |
1035 | /// |
1036 | /// This is used by Sema. |
1037 | bool isValidClobber(StringRef Name) const; |
1038 | |
1039 | /// Returns whether the passed in string is a valid register name |
1040 | /// according to GCC. |
1041 | /// |
1042 | /// This is used by Sema for inline asm statements. |
1043 | virtual bool isValidGCCRegisterName(StringRef Name) const; |
1044 | |
1045 | /// Returns the "normalized" GCC register name. |
1046 | /// |
1047 | /// ReturnCannonical true will return the register name without any additions |
1048 | /// such as "{}" or "%" in it's canonical form, for example: |
1049 | /// ReturnCanonical = true and Name = "rax", will return "ax". |
1050 | StringRef getNormalizedGCCRegisterName(StringRef Name, |
1051 | bool ReturnCanonical = false) const; |
1052 | |
1053 | virtual bool isSPRegName(StringRef) const { return false; } |
1054 | |
1055 | /// Extracts a register from the passed constraint (if it is a |
1056 | /// single-register constraint) and the asm label expression related to a |
1057 | /// variable in the input or output list of an inline asm statement. |
1058 | /// |
1059 | /// This function is used by Sema in order to diagnose conflicts between |
1060 | /// the clobber list and the input/output lists. |
1061 | virtual StringRef getConstraintRegister(StringRef Constraint, |
1062 | StringRef Expression) const { |
1063 | return "" ; |
1064 | } |
1065 | |
1066 | struct ConstraintInfo { |
1067 | enum { |
1068 | CI_None = 0x00, |
1069 | CI_AllowsMemory = 0x01, |
1070 | CI_AllowsRegister = 0x02, |
1071 | CI_ReadWrite = 0x04, // "+r" output constraint (read and write). |
1072 | CI_HasMatchingInput = 0x08, // This output operand has a matching input. |
1073 | CI_ImmediateConstant = 0x10, // This operand must be an immediate constant |
1074 | CI_EarlyClobber = 0x20, // "&" output constraint (early clobber). |
1075 | }; |
1076 | unsigned Flags; |
1077 | int TiedOperand; |
1078 | struct { |
1079 | int Min; |
1080 | int Max; |
1081 | bool isConstrained; |
1082 | } ImmRange; |
1083 | llvm::SmallSet<int, 4> ImmSet; |
1084 | |
1085 | std::string ConstraintStr; // constraint: "=rm" |
1086 | std::string Name; // Operand name: [foo] with no []'s. |
1087 | public: |
1088 | ConstraintInfo(StringRef ConstraintStr, StringRef Name) |
1089 | : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()), |
1090 | Name(Name.str()) { |
1091 | ImmRange.Min = ImmRange.Max = 0; |
1092 | ImmRange.isConstrained = false; |
1093 | } |
1094 | |
1095 | const std::string &getConstraintStr() const { return ConstraintStr; } |
1096 | const std::string &getName() const { return Name; } |
1097 | bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; } |
1098 | bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; } |
1099 | bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; } |
1100 | bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; } |
1101 | |
1102 | /// Return true if this output operand has a matching |
1103 | /// (tied) input operand. |
1104 | bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; } |
1105 | |
1106 | /// Return true if this input operand is a matching |
1107 | /// constraint that ties it to an output operand. |
1108 | /// |
1109 | /// If this returns true then getTiedOperand will indicate which output |
1110 | /// operand this is tied to. |
1111 | bool hasTiedOperand() const { return TiedOperand != -1; } |
1112 | unsigned getTiedOperand() const { |
1113 | assert(hasTiedOperand() && "Has no tied operand!" ); |
1114 | return (unsigned)TiedOperand; |
1115 | } |
1116 | |
1117 | bool requiresImmediateConstant() const { |
1118 | return (Flags & CI_ImmediateConstant) != 0; |
1119 | } |
1120 | bool isValidAsmImmediate(const llvm::APInt &Value) const { |
1121 | if (!ImmSet.empty()) |
1122 | return Value.isSignedIntN(N: 32) && ImmSet.contains(V: Value.getZExtValue()); |
1123 | return !ImmRange.isConstrained || |
1124 | (Value.sge(RHS: ImmRange.Min) && Value.sle(RHS: ImmRange.Max)); |
1125 | } |
1126 | |
1127 | void setIsReadWrite() { Flags |= CI_ReadWrite; } |
1128 | void setEarlyClobber() { Flags |= CI_EarlyClobber; } |
1129 | void setAllowsMemory() { Flags |= CI_AllowsMemory; } |
1130 | void setAllowsRegister() { Flags |= CI_AllowsRegister; } |
1131 | void setHasMatchingInput() { Flags |= CI_HasMatchingInput; } |
1132 | void setRequiresImmediate(int Min, int Max) { |
1133 | Flags |= CI_ImmediateConstant; |
1134 | ImmRange.Min = Min; |
1135 | ImmRange.Max = Max; |
1136 | ImmRange.isConstrained = true; |
1137 | } |
1138 | void setRequiresImmediate(llvm::ArrayRef<int> Exacts) { |
1139 | Flags |= CI_ImmediateConstant; |
1140 | for (int Exact : Exacts) |
1141 | ImmSet.insert(V: Exact); |
1142 | } |
1143 | void setRequiresImmediate(int Exact) { |
1144 | Flags |= CI_ImmediateConstant; |
1145 | ImmSet.insert(V: Exact); |
1146 | } |
1147 | void setRequiresImmediate() { |
1148 | Flags |= CI_ImmediateConstant; |
1149 | } |
1150 | |
1151 | /// Indicate that this is an input operand that is tied to |
1152 | /// the specified output operand. |
1153 | /// |
1154 | /// Copy over the various constraint information from the output. |
1155 | void setTiedOperand(unsigned N, ConstraintInfo &Output) { |
1156 | Output.setHasMatchingInput(); |
1157 | Flags = Output.Flags; |
1158 | TiedOperand = N; |
1159 | // Don't copy Name or constraint string. |
1160 | } |
1161 | }; |
1162 | |
1163 | /// Validate register name used for global register variables. |
1164 | /// |
1165 | /// This function returns true if the register passed in RegName can be used |
1166 | /// for global register variables on this target. In addition, it returns |
1167 | /// true in HasSizeMismatch if the size of the register doesn't match the |
1168 | /// variable size passed in RegSize. |
1169 | virtual bool validateGlobalRegisterVariable(StringRef RegName, |
1170 | unsigned RegSize, |
1171 | bool &HasSizeMismatch) const { |
1172 | HasSizeMismatch = false; |
1173 | return true; |
1174 | } |
1175 | |
1176 | // validateOutputConstraint, validateInputConstraint - Checks that |
1177 | // a constraint is valid and provides information about it. |
1178 | // FIXME: These should return a real error instead of just true/false. |
1179 | bool validateOutputConstraint(ConstraintInfo &Info) const; |
1180 | bool validateInputConstraint(MutableArrayRef<ConstraintInfo> OutputConstraints, |
1181 | ConstraintInfo &info) const; |
1182 | |
1183 | virtual bool validateOutputSize(const llvm::StringMap<bool> &FeatureMap, |
1184 | StringRef /*Constraint*/, |
1185 | unsigned /*Size*/) const { |
1186 | return true; |
1187 | } |
1188 | |
1189 | virtual bool validateInputSize(const llvm::StringMap<bool> &FeatureMap, |
1190 | StringRef /*Constraint*/, |
1191 | unsigned /*Size*/) const { |
1192 | return true; |
1193 | } |
1194 | virtual bool |
1195 | validateConstraintModifier(StringRef /*Constraint*/, |
1196 | char /*Modifier*/, |
1197 | unsigned /*Size*/, |
1198 | std::string &/*SuggestedModifier*/) const { |
1199 | return true; |
1200 | } |
1201 | virtual bool |
1202 | validateAsmConstraint(const char *&Name, |
1203 | TargetInfo::ConstraintInfo &info) const = 0; |
1204 | |
1205 | bool resolveSymbolicName(const char *&Name, |
1206 | ArrayRef<ConstraintInfo> OutputConstraints, |
1207 | unsigned &Index) const; |
1208 | |
1209 | // Constraint parm will be left pointing at the last character of |
1210 | // the constraint. In practice, it won't be changed unless the |
1211 | // constraint is longer than one character. |
1212 | virtual std::string convertConstraint(const char *&Constraint) const { |
1213 | // 'p' defaults to 'r', but can be overridden by targets. |
1214 | if (*Constraint == 'p') |
1215 | return std::string("r" ); |
1216 | return std::string(1, *Constraint); |
1217 | } |
1218 | |
1219 | /// Replace some escaped characters with another string based on |
1220 | /// target-specific rules |
1221 | virtual std::optional<std::string> handleAsmEscapedChar(char C) const { |
1222 | return std::nullopt; |
1223 | } |
1224 | |
1225 | /// Returns a string of target-specific clobbers, in LLVM format. |
1226 | virtual std::string_view getClobbers() const = 0; |
1227 | |
1228 | /// Returns true if NaN encoding is IEEE 754-2008. |
1229 | /// Only MIPS allows a different encoding. |
1230 | virtual bool isNan2008() const { |
1231 | return true; |
1232 | } |
1233 | |
1234 | /// Returns the target triple of the primary target. |
1235 | const llvm::Triple &getTriple() const { |
1236 | return Triple; |
1237 | } |
1238 | |
1239 | /// Returns the target ID if supported. |
1240 | virtual std::optional<std::string> getTargetID() const { |
1241 | return std::nullopt; |
1242 | } |
1243 | |
1244 | const char *getDataLayoutString() const { |
1245 | assert(!DataLayoutString.empty() && "Uninitialized DataLayout!" ); |
1246 | return DataLayoutString.c_str(); |
1247 | } |
1248 | |
1249 | struct GCCRegAlias { |
1250 | const char * const Aliases[5]; |
1251 | const char * const Register; |
1252 | }; |
1253 | |
1254 | struct AddlRegName { |
1255 | const char * const Names[5]; |
1256 | const unsigned RegNum; |
1257 | }; |
1258 | |
1259 | /// Does this target support "protected" visibility? |
1260 | /// |
1261 | /// Any target which dynamic libraries will naturally support |
1262 | /// something like "default" (meaning that the symbol is visible |
1263 | /// outside this shared object) and "hidden" (meaning that it isn't) |
1264 | /// visibilities, but "protected" is really an ELF-specific concept |
1265 | /// with weird semantics designed around the convenience of dynamic |
1266 | /// linker implementations. Which is not to suggest that there's |
1267 | /// consistent target-independent semantics for "default" visibility |
1268 | /// either; the entire thing is pretty badly mangled. |
1269 | virtual bool hasProtectedVisibility() const { return true; } |
1270 | |
1271 | /// Does this target aim for semantic compatibility with |
1272 | /// Microsoft C++ code using dllimport/export attributes? |
1273 | virtual bool shouldDLLImportComdatSymbols() const { |
1274 | return getTriple().isWindowsMSVCEnvironment() || |
1275 | getTriple().isWindowsItaniumEnvironment() || getTriple().isPS(); |
1276 | } |
1277 | |
1278 | // Does this target have PS4 specific dllimport/export handling? |
1279 | virtual bool hasPS4DLLImportExport() const { |
1280 | return getTriple().isPS() || |
1281 | // Windows Itanium support allows for testing the SCEI flavour of |
1282 | // dllimport/export handling on a Windows system. |
1283 | (getTriple().isWindowsItaniumEnvironment() && |
1284 | getTriple().getVendor() == llvm::Triple::SCEI); |
1285 | } |
1286 | |
1287 | /// Set forced language options. |
1288 | /// |
1289 | /// Apply changes to the target information with respect to certain |
1290 | /// language options which change the target configuration and adjust |
1291 | /// the language based on the target options where applicable. |
1292 | virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts); |
1293 | |
1294 | /// Initialize the map with the default set of target features for the |
1295 | /// CPU this should include all legal feature strings on the target. |
1296 | /// |
1297 | /// \return False on error (invalid features). |
1298 | virtual bool initFeatureMap(llvm::StringMap<bool> &Features, |
1299 | DiagnosticsEngine &Diags, StringRef CPU, |
1300 | const std::vector<std::string> &FeatureVec) const; |
1301 | |
1302 | /// Get the ABI currently in use. |
1303 | virtual StringRef getABI() const { return StringRef(); } |
1304 | |
1305 | /// Get the C++ ABI currently in use. |
1306 | TargetCXXABI getCXXABI() const { |
1307 | return TheCXXABI; |
1308 | } |
1309 | |
1310 | /// Target the specified CPU. |
1311 | /// |
1312 | /// \return False on error (invalid CPU name). |
1313 | virtual bool setCPU(const std::string &Name) { |
1314 | return false; |
1315 | } |
1316 | |
1317 | /// Fill a SmallVectorImpl with the valid values to setCPU. |
1318 | virtual void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {} |
1319 | |
1320 | /// Fill a SmallVectorImpl with the valid values for tuning CPU. |
1321 | virtual void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const { |
1322 | fillValidCPUList(Values); |
1323 | } |
1324 | |
1325 | /// Determine whether this TargetInfo supports the given CPU name. |
1326 | virtual bool isValidCPUName(StringRef Name) const { |
1327 | return true; |
1328 | } |
1329 | |
1330 | /// Determine whether this TargetInfo supports the given CPU name for |
1331 | /// tuning. |
1332 | virtual bool isValidTuneCPUName(StringRef Name) const { |
1333 | return isValidCPUName(Name); |
1334 | } |
1335 | |
1336 | virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const; |
1337 | |
1338 | /// Determine whether this TargetInfo supports tune in target attribute. |
1339 | virtual bool supportsTargetAttributeTune() const { |
1340 | return false; |
1341 | } |
1342 | |
1343 | /// Use the specified ABI. |
1344 | /// |
1345 | /// \return False on error (invalid ABI name). |
1346 | virtual bool setABI(const std::string &Name) { |
1347 | return false; |
1348 | } |
1349 | |
1350 | /// Use the specified unit for FP math. |
1351 | /// |
1352 | /// \return False on error (invalid unit name). |
1353 | virtual bool setFPMath(StringRef Name) { |
1354 | return false; |
1355 | } |
1356 | |
1357 | /// Check if target has a given feature enabled |
1358 | virtual bool hasFeatureEnabled(const llvm::StringMap<bool> &Features, |
1359 | StringRef Name) const { |
1360 | return Features.lookup(Key: Name); |
1361 | } |
1362 | |
1363 | /// Enable or disable a specific target feature; |
1364 | /// the feature name must be valid. |
1365 | virtual void setFeatureEnabled(llvm::StringMap<bool> &Features, |
1366 | StringRef Name, |
1367 | bool Enabled) const { |
1368 | Features[Name] = Enabled; |
1369 | } |
1370 | |
1371 | /// Determine whether this TargetInfo supports the given feature. |
1372 | virtual bool isValidFeatureName(StringRef Feature) const { |
1373 | return true; |
1374 | } |
1375 | |
1376 | /// Returns true if feature has an impact on target code |
1377 | /// generation. |
1378 | virtual bool doesFeatureAffectCodeGen(StringRef Feature) const { |
1379 | return true; |
1380 | } |
1381 | |
1382 | /// For given feature return dependent ones. |
1383 | virtual StringRef getFeatureDependencies(StringRef Feature) const { |
1384 | return StringRef(); |
1385 | } |
1386 | |
1387 | struct BranchProtectionInfo { |
1388 | LangOptions::SignReturnAddressScopeKind SignReturnAddr; |
1389 | LangOptions::SignReturnAddressKeyKind SignKey; |
1390 | bool BranchTargetEnforcement; |
1391 | bool BranchProtectionPAuthLR; |
1392 | bool GuardedControlStack; |
1393 | |
1394 | BranchProtectionInfo() = default; |
1395 | |
1396 | const char *getSignReturnAddrStr() const { |
1397 | switch (SignReturnAddr) { |
1398 | case LangOptions::SignReturnAddressScopeKind::None: |
1399 | return "none" ; |
1400 | case LangOptions::SignReturnAddressScopeKind::NonLeaf: |
1401 | return "non-leaf" ; |
1402 | case LangOptions::SignReturnAddressScopeKind::All: |
1403 | return "all" ; |
1404 | } |
1405 | llvm_unreachable("Unexpected SignReturnAddressScopeKind" ); |
1406 | } |
1407 | |
1408 | const char *getSignKeyStr() const { |
1409 | switch (SignKey) { |
1410 | case LangOptions::SignReturnAddressKeyKind::AKey: |
1411 | return "a_key" ; |
1412 | case LangOptions::SignReturnAddressKeyKind::BKey: |
1413 | return "b_key" ; |
1414 | } |
1415 | llvm_unreachable("Unexpected SignReturnAddressKeyKind" ); |
1416 | } |
1417 | }; |
1418 | |
1419 | /// Determine if the Architecture in this TargetInfo supports branch |
1420 | /// protection |
1421 | virtual bool isBranchProtectionSupportedArch(StringRef Arch) const { |
1422 | return false; |
1423 | } |
1424 | |
1425 | /// Determine if this TargetInfo supports the given branch protection |
1426 | /// specification |
1427 | virtual bool validateBranchProtection(StringRef Spec, StringRef Arch, |
1428 | BranchProtectionInfo &BPI, |
1429 | StringRef &Err) const { |
1430 | Err = "" ; |
1431 | return false; |
1432 | } |
1433 | |
1434 | /// Perform initialization based on the user configured |
1435 | /// set of features (e.g., +sse4). |
1436 | /// |
1437 | /// The list is guaranteed to have at most one entry per feature. |
1438 | /// |
1439 | /// The target may modify the features list, to change which options are |
1440 | /// passed onwards to the backend. |
1441 | /// FIXME: This part should be fixed so that we can change handleTargetFeatures |
1442 | /// to merely a TargetInfo initialization routine. |
1443 | /// |
1444 | /// \return False on error. |
1445 | virtual bool handleTargetFeatures(std::vector<std::string> &Features, |
1446 | DiagnosticsEngine &Diags) { |
1447 | return true; |
1448 | } |
1449 | |
1450 | /// Determine whether the given target has the given feature. |
1451 | virtual bool hasFeature(StringRef Feature) const { |
1452 | return false; |
1453 | } |
1454 | |
1455 | /// Determine whether the given target feature is read only. |
1456 | bool isReadOnlyFeature(StringRef Feature) const { |
1457 | return ReadOnlyFeatures.count(Key: Feature); |
1458 | } |
1459 | |
1460 | /// Identify whether this target supports multiversioning of functions, |
1461 | /// which requires support for cpu_supports and cpu_is functionality. |
1462 | bool supportsMultiVersioning() const { |
1463 | return getTriple().isX86() || getTriple().isAArch64(); |
1464 | } |
1465 | |
1466 | /// Identify whether this target supports IFuncs. |
1467 | bool supportsIFunc() const { |
1468 | if (getTriple().isOSBinFormatMachO()) |
1469 | return true; |
1470 | return getTriple().isOSBinFormatELF() && |
1471 | ((getTriple().isOSLinux() && !getTriple().isMusl()) || |
1472 | getTriple().isOSFreeBSD()); |
1473 | } |
1474 | |
1475 | // Identify whether this target supports __builtin_cpu_supports and |
1476 | // __builtin_cpu_is. |
1477 | virtual bool supportsCpuSupports() const { return false; } |
1478 | virtual bool supportsCpuIs() const { return false; } |
1479 | virtual bool supportsCpuInit() const { return false; } |
1480 | |
1481 | // Validate the contents of the __builtin_cpu_supports(const char*) |
1482 | // argument. |
1483 | virtual bool validateCpuSupports(StringRef Name) const { return false; } |
1484 | |
1485 | // Return the target-specific priority for features/cpus/vendors so |
1486 | // that they can be properly sorted for checking. |
1487 | virtual unsigned multiVersionSortPriority(StringRef Name) const { |
1488 | return 0; |
1489 | } |
1490 | |
1491 | // Return the target-specific cost for feature |
1492 | // that taken into account in priority sorting. |
1493 | virtual unsigned multiVersionFeatureCost() const { return 0; } |
1494 | |
1495 | // Validate the contents of the __builtin_cpu_is(const char*) |
1496 | // argument. |
1497 | virtual bool validateCpuIs(StringRef Name) const { return false; } |
1498 | |
1499 | // Validate a cpu_dispatch/cpu_specific CPU option, which is a different list |
1500 | // from cpu_is, since it checks via features rather than CPUs directly. |
1501 | virtual bool validateCPUSpecificCPUDispatch(StringRef Name) const { |
1502 | return false; |
1503 | } |
1504 | |
1505 | // Get the character to be added for mangling purposes for cpu_specific. |
1506 | virtual char CPUSpecificManglingCharacter(StringRef Name) const { |
1507 | llvm_unreachable( |
1508 | "cpu_specific Multiversioning not implemented on this target" ); |
1509 | } |
1510 | |
1511 | // Get the value for the 'tune-cpu' flag for a cpu_specific variant with the |
1512 | // programmer-specified 'Name'. |
1513 | virtual StringRef getCPUSpecificTuneName(StringRef Name) const { |
1514 | llvm_unreachable( |
1515 | "cpu_specific Multiversioning not implemented on this target" ); |
1516 | } |
1517 | |
1518 | // Get a list of the features that make up the CPU option for |
1519 | // cpu_specific/cpu_dispatch so that it can be passed to llvm as optimization |
1520 | // options. |
1521 | virtual void getCPUSpecificCPUDispatchFeatures( |
1522 | StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const { |
1523 | llvm_unreachable( |
1524 | "cpu_specific Multiversioning not implemented on this target" ); |
1525 | } |
1526 | |
1527 | // Get the cache line size of a given cpu. This method switches over |
1528 | // the given cpu and returns "std::nullopt" if the CPU is not found. |
1529 | virtual std::optional<unsigned> getCPUCacheLineSize() const { |
1530 | return std::nullopt; |
1531 | } |
1532 | |
1533 | // Returns maximal number of args passed in registers. |
1534 | unsigned getRegParmMax() const { |
1535 | assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle" ); |
1536 | return RegParmMax; |
1537 | } |
1538 | |
1539 | /// Whether the target supports thread-local storage. |
1540 | bool isTLSSupported() const { |
1541 | return TLSSupported; |
1542 | } |
1543 | |
1544 | /// Return the maximum alignment (in bits) of a TLS variable |
1545 | /// |
1546 | /// Gets the maximum alignment (in bits) of a TLS variable on this target. |
1547 | /// Returns zero if there is no such constraint. |
1548 | unsigned getMaxTLSAlign() const { return MaxTLSAlign; } |
1549 | |
1550 | /// Whether target supports variable-length arrays. |
1551 | bool isVLASupported() const { return VLASupported; } |
1552 | |
1553 | /// Whether the target supports SEH __try. |
1554 | bool isSEHTrySupported() const { |
1555 | return getTriple().isOSWindows() && |
1556 | (getTriple().isX86() || |
1557 | getTriple().getArch() == llvm::Triple::aarch64); |
1558 | } |
1559 | |
1560 | /// Return true if {|} are normal characters in the asm string. |
1561 | /// |
1562 | /// If this returns false (the default), then {abc|xyz} is syntax |
1563 | /// that says that when compiling for asm variant #0, "abc" should be |
1564 | /// generated, but when compiling for asm variant #1, "xyz" should be |
1565 | /// generated. |
1566 | bool hasNoAsmVariants() const { |
1567 | return NoAsmVariants; |
1568 | } |
1569 | |
1570 | /// Return the register number that __builtin_eh_return_regno would |
1571 | /// return with the specified argument. |
1572 | /// This corresponds with TargetLowering's getExceptionPointerRegister |
1573 | /// and getExceptionSelectorRegister in the backend. |
1574 | virtual int getEHDataRegisterNumber(unsigned RegNo) const { |
1575 | return -1; |
1576 | } |
1577 | |
1578 | /// Return the section to use for C++ static initialization functions. |
1579 | virtual const char *getStaticInitSectionSpecifier() const { |
1580 | return nullptr; |
1581 | } |
1582 | |
1583 | const LangASMap &getAddressSpaceMap() const { return *AddrSpaceMap; } |
1584 | unsigned getTargetAddressSpace(LangAS AS) const { |
1585 | if (isTargetAddressSpace(AS)) |
1586 | return toTargetAddressSpace(AS); |
1587 | return getAddressSpaceMap()[(unsigned)AS]; |
1588 | } |
1589 | |
1590 | /// Determine whether the given pointer-authentication key is valid. |
1591 | /// |
1592 | /// The value has been coerced to type 'int'. |
1593 | virtual bool validatePointerAuthKey(const llvm::APSInt &value) const; |
1594 | |
1595 | /// Map from the address space field in builtin description strings to the |
1596 | /// language address space. |
1597 | virtual LangAS getOpenCLBuiltinAddressSpace(unsigned AS) const { |
1598 | return getLangASFromTargetAS(TargetAS: AS); |
1599 | } |
1600 | |
1601 | /// Map from the address space field in builtin description strings to the |
1602 | /// language address space. |
1603 | virtual LangAS getCUDABuiltinAddressSpace(unsigned AS) const { |
1604 | return getLangASFromTargetAS(TargetAS: AS); |
1605 | } |
1606 | |
1607 | /// Return an AST address space which can be used opportunistically |
1608 | /// for constant global memory. It must be possible to convert pointers into |
1609 | /// this address space to LangAS::Default. If no such address space exists, |
1610 | /// this may return std::nullopt, and such optimizations will be disabled. |
1611 | virtual std::optional<LangAS> getConstantAddressSpace() const { |
1612 | return LangAS::Default; |
1613 | } |
1614 | |
1615 | // access target-specific GPU grid values that must be consistent between |
1616 | // host RTL (plugin), deviceRTL and clang. |
1617 | virtual const llvm::omp::GV &getGridValue() const { |
1618 | llvm_unreachable("getGridValue not implemented on this target" ); |
1619 | } |
1620 | |
1621 | /// Retrieve the name of the platform as it is used in the |
1622 | /// availability attribute. |
1623 | StringRef getPlatformName() const { return PlatformName; } |
1624 | |
1625 | /// Retrieve the minimum desired version of the platform, to |
1626 | /// which the program should be compiled. |
1627 | VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; } |
1628 | |
1629 | bool isBigEndian() const { return BigEndian; } |
1630 | bool isLittleEndian() const { return !BigEndian; } |
1631 | |
1632 | /// Whether the option -fextend-arguments={32,64} is supported on the target. |
1633 | virtual bool supportsExtendIntArgs() const { return false; } |
1634 | |
1635 | /// Controls if __arithmetic_fence is supported in the targeted backend. |
1636 | virtual bool checkArithmeticFenceSupported() const { return false; } |
1637 | |
1638 | /// Gets the default calling convention for the given target and |
1639 | /// declaration context. |
1640 | virtual CallingConv getDefaultCallingConv() const { |
1641 | // Not all targets will specify an explicit calling convention that we can |
1642 | // express. This will always do the right thing, even though it's not |
1643 | // an explicit calling convention. |
1644 | return CC_C; |
1645 | } |
1646 | |
1647 | enum CallingConvCheckResult { |
1648 | CCCR_OK, |
1649 | CCCR_Warning, |
1650 | CCCR_Ignore, |
1651 | CCCR_Error, |
1652 | }; |
1653 | |
1654 | /// Determines whether a given calling convention is valid for the |
1655 | /// target. A calling convention can either be accepted, produce a warning |
1656 | /// and be substituted with the default calling convention, or (someday) |
1657 | /// produce an error (such as using thiscall on a non-instance function). |
1658 | virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const { |
1659 | switch (CC) { |
1660 | default: |
1661 | return CCCR_Warning; |
1662 | case CC_C: |
1663 | return CCCR_OK; |
1664 | } |
1665 | } |
1666 | |
1667 | enum CallingConvKind { |
1668 | CCK_Default, |
1669 | CCK_ClangABI4OrPS4, |
1670 | CCK_MicrosoftWin64 |
1671 | }; |
1672 | |
1673 | virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const; |
1674 | |
1675 | /// Controls whether explicitly defaulted (`= default`) special member |
1676 | /// functions disqualify something from being POD-for-the-purposes-of-layout. |
1677 | /// Historically, Clang didn't consider these acceptable for POD, but GCC |
1678 | /// does. So in newer Clang ABIs they are acceptable for POD to be compatible |
1679 | /// with GCC/Itanium ABI, and remains disqualifying for targets that need |
1680 | /// Clang backwards compatibility rather than GCC/Itanium ABI compatibility. |
1681 | virtual bool areDefaultedSMFStillPOD(const LangOptions&) const; |
1682 | |
1683 | /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to |
1684 | /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp. |
1685 | virtual bool hasSjLjLowering() const { |
1686 | return false; |
1687 | } |
1688 | |
1689 | /// Check if the target supports CFProtection branch. |
1690 | virtual bool |
1691 | checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const; |
1692 | |
1693 | /// Check if the target supports CFProtection return. |
1694 | virtual bool |
1695 | checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const; |
1696 | |
1697 | /// Whether target allows to overalign ABI-specified preferred alignment |
1698 | virtual bool allowsLargerPreferedTypeAlignment() const { return true; } |
1699 | |
1700 | /// Whether target defaults to the `power` alignment rules of AIX. |
1701 | virtual bool defaultsToAIXPowerAlignment() const { return false; } |
1702 | |
1703 | /// Set supported OpenCL extensions and optional core features. |
1704 | virtual void setSupportedOpenCLOpts() {} |
1705 | |
1706 | virtual void supportAllOpenCLOpts(bool V = true) { |
1707 | #define OPENCLEXTNAME(Ext) \ |
1708 | setFeatureEnabled(getTargetOpts().OpenCLFeaturesMap, #Ext, V); |
1709 | #include "clang/Basic/OpenCLExtensions.def" |
1710 | } |
1711 | |
1712 | /// Set supported OpenCL extensions as written on command line |
1713 | virtual void setCommandLineOpenCLOpts() { |
1714 | for (const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) { |
1715 | bool IsPrefixed = (Ext[0] == '+' || Ext[0] == '-'); |
1716 | std::string Name = IsPrefixed ? Ext.substr(pos: 1) : Ext; |
1717 | bool V = IsPrefixed ? Ext[0] == '+' : true; |
1718 | |
1719 | if (Name == "all" ) { |
1720 | supportAllOpenCLOpts(V); |
1721 | continue; |
1722 | } |
1723 | |
1724 | getTargetOpts().OpenCLFeaturesMap[Name] = V; |
1725 | } |
1726 | } |
1727 | |
1728 | /// Get supported OpenCL extensions and optional core features. |
1729 | llvm::StringMap<bool> &getSupportedOpenCLOpts() { |
1730 | return getTargetOpts().OpenCLFeaturesMap; |
1731 | } |
1732 | |
1733 | /// Get const supported OpenCL extensions and optional core features. |
1734 | const llvm::StringMap<bool> &getSupportedOpenCLOpts() const { |
1735 | return getTargetOpts().OpenCLFeaturesMap; |
1736 | } |
1737 | |
1738 | /// Get address space for OpenCL type. |
1739 | virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const; |
1740 | |
1741 | /// \returns Target specific vtbl ptr address space. |
1742 | virtual unsigned getVtblPtrAddressSpace() const { |
1743 | return 0; |
1744 | } |
1745 | |
1746 | /// \returns If a target requires an address within a target specific address |
1747 | /// space \p AddressSpace to be converted in order to be used, then return the |
1748 | /// corresponding target specific DWARF address space. |
1749 | /// |
1750 | /// \returns Otherwise return std::nullopt and no conversion will be emitted |
1751 | /// in the DWARF. |
1752 | virtual std::optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace) |
1753 | const { |
1754 | return std::nullopt; |
1755 | } |
1756 | |
1757 | /// \returns The version of the SDK which was used during the compilation if |
1758 | /// one was specified, or an empty version otherwise. |
1759 | const llvm::VersionTuple &getSDKVersion() const { |
1760 | return getTargetOpts().SDKVersion; |
1761 | } |
1762 | |
1763 | /// Check the target is valid after it is fully initialized. |
1764 | virtual bool validateTarget(DiagnosticsEngine &Diags) const { |
1765 | return true; |
1766 | } |
1767 | |
1768 | /// Check that OpenCL target has valid options setting based on OpenCL |
1769 | /// version. |
1770 | virtual bool validateOpenCLTarget(const LangOptions &Opts, |
1771 | DiagnosticsEngine &Diags) const; |
1772 | |
1773 | virtual void setAuxTarget(const TargetInfo *Aux) {} |
1774 | |
1775 | /// Whether target allows debuginfo types for decl only variables/functions. |
1776 | virtual bool allowDebugInfoForExternalRef() const { return false; } |
1777 | |
1778 | /// Returns the darwin target variant triple, the variant of the deployment |
1779 | /// target for which the code is being compiled. |
1780 | const llvm::Triple *getDarwinTargetVariantTriple() const { |
1781 | return DarwinTargetVariantTriple ? &*DarwinTargetVariantTriple : nullptr; |
1782 | } |
1783 | |
1784 | /// Returns the version of the darwin target variant SDK which was used during |
1785 | /// the compilation if one was specified, or an empty version otherwise. |
1786 | const std::optional<VersionTuple> getDarwinTargetVariantSDKVersion() const { |
1787 | return !getTargetOpts().DarwinTargetVariantSDKVersion.empty() |
1788 | ? getTargetOpts().DarwinTargetVariantSDKVersion |
1789 | : std::optional<VersionTuple>(); |
1790 | } |
1791 | |
1792 | /// Whether to support HIP image/texture API's. |
1793 | virtual bool hasHIPImageSupport() const { return true; } |
1794 | |
1795 | protected: |
1796 | /// Copy type and layout related info. |
1797 | void copyAuxTarget(const TargetInfo *Aux); |
1798 | virtual uint64_t getPointerWidthV(LangAS AddrSpace) const { |
1799 | return PointerWidth; |
1800 | } |
1801 | virtual uint64_t getPointerAlignV(LangAS AddrSpace) const { |
1802 | return PointerAlign; |
1803 | } |
1804 | virtual enum IntType getPtrDiffTypeV(LangAS AddrSpace) const { |
1805 | return PtrDiffType; |
1806 | } |
1807 | virtual ArrayRef<const char *> getGCCRegNames() const = 0; |
1808 | virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0; |
1809 | virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const { |
1810 | return std::nullopt; |
1811 | } |
1812 | |
1813 | private: |
1814 | // Assert the values for the fractional and integral bits for each fixed point |
1815 | // type follow the restrictions given in clause 6.2.6.3 of N1169. |
1816 | void CheckFixedPointBits() const; |
1817 | }; |
1818 | |
1819 | } // end namespace clang |
1820 | |
1821 | #endif |
1822 | |