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