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