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