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