clang  3.7.0
include/clang/Basic/TargetInfo.h
Go to the documentation of this file.
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 /// \brief Defines the clang::TargetInfo interface.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_BASIC_TARGETINFO_H
16 #define LLVM_CLANG_BASIC_TARGETINFO_H
17 
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/Specifiers.h"
24 #include "llvm/ADT/IntrusiveRefCntPtr.h"
25 #include "llvm/ADT/StringMap.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/ADT/StringSwitch.h"
28 #include "llvm/ADT/Triple.h"
29 #include "llvm/Support/DataTypes.h"
30 #include <cassert>
31 #include <string>
32 #include <vector>
33 
34 namespace llvm {
35 struct fltSemantics;
36 }
37 
38 namespace clang {
39 class DiagnosticsEngine;
40 class LangOptions;
41 class MacroBuilder;
42 class SourceLocation;
43 class SourceManager;
44 
45 namespace Builtin { struct Info; }
46 
47 /// \brief Exposes information about the current target.
48 ///
49 class TargetInfo : public RefCountedBase<TargetInfo> {
50  std::shared_ptr<TargetOptions> TargetOpts;
51  llvm::Triple Triple;
52 protected:
53  // Target values set by the ctor of the actual target implementation. Default
54  // values are specified by the TargetInfo constructor.
55  bool BigEndian;
57  bool NoAsmVariants; // True if {|} are normal characters.
58  unsigned char PointerWidth, PointerAlign;
59  unsigned char BoolWidth, BoolAlign;
60  unsigned char IntWidth, IntAlign;
61  unsigned char HalfWidth, HalfAlign;
62  unsigned char FloatWidth, FloatAlign;
63  unsigned char DoubleWidth, DoubleAlign;
66  unsigned char LongWidth, LongAlign;
67  unsigned char LongLongWidth, LongLongAlign;
68  unsigned char SuitableAlign;
70  unsigned char MinGlobalAlign;
72  unsigned short MaxVectorAlign;
73  unsigned short MaxTLSAlign;
74  unsigned short SimdDefaultAlign;
75  const char *DescriptionString;
76  const char *UserLabelPrefix;
77  const char *MCountName;
78  const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
80  unsigned char RegParmMax, SSERegParmMax;
83 
84  mutable StringRef PlatformName;
86 
87  unsigned HasAlignMac68kSupport : 1;
88  unsigned RealTypeUsesObjCFPRet : 3;
90 
91  // TargetInfo Constructor. Default initializes all fields.
92  TargetInfo(const llvm::Triple &T);
93 
94 public:
95  /// \brief Construct a target for the given options.
96  ///
97  /// \param Opts - The options to use to initialize the target. The target may
98  /// modify the options to canonicalize the target feature information to match
99  /// what the backend expects.
100  static TargetInfo *
102  const std::shared_ptr<TargetOptions> &Opts);
103 
104  virtual ~TargetInfo();
105 
106  /// \brief Retrieve the target options.
108  assert(TargetOpts && "Missing target options");
109  return *TargetOpts;
110  }
111 
112  ///===---- Target Data Type Query Methods -------------------------------===//
113  enum IntType {
114  NoInt = 0,
125  };
126 
127  enum RealType {
128  NoFloat = 255,
129  Float = 0,
132  };
133 
134  /// \brief The different kinds of __builtin_va_list types defined by
135  /// the target implementation.
137  /// typedef char* __builtin_va_list;
139 
140  /// typedef void* __builtin_va_list;
142 
143  /// __builtin_va_list as defind by the AArch64 ABI
144  /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
146 
147  /// __builtin_va_list as defined by the PNaCl ABI:
148  /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
150 
151  /// __builtin_va_list as defined by the Power ABI:
152  /// https://www.power.org
153  /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
155 
156  /// __builtin_va_list as defined by the x86-64 ABI:
157  /// http://www.x86-64.org/documentation/abi.pdf
159 
160  /// __builtin_va_list as defined by ARM AAPCS ABI
161  /// http://infocenter.arm.com
162  // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
164 
165  // typedef struct __va_list_tag
166  // {
167  // long __gpr;
168  // long __fpr;
169  // void *__overflow_arg_area;
170  // void *__reg_save_area;
171  // } va_list[1];
173  };
174 
175 protected:
179 
180  /// \brief Whether Objective-C's built-in boolean type should be signed char.
181  ///
182  /// Otherwise, when this flag is not set, the normal built-in boolean type is
183  /// used.
185 
186  /// Control whether the alignment of bit-field types is respected when laying
187  /// out structures. If true, then the alignment of the bit-field type will be
188  /// used to (a) impact the alignment of the containing structure, and (b)
189  /// ensure that the individual bit-field will not straddle an alignment
190  /// boundary.
192 
193  /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
194  /// the next bitfield.
195  ///
196  /// If the alignment of the zero length bitfield is greater than the member
197  /// that follows it, `bar', `bar' will be aligned as the type of the
198  /// zero-length bitfield.
200 
201  /// If non-zero, specifies a fixed alignment value for bitfields that follow
202  /// zero length bitfield, regardless of the zero length bitfield type.
204 
205  /// \brief Specify if mangling based on address space map should be used or
206  /// not for language specific address spaces
208 
209 public:
210  IntType getSizeType() const { return SizeType; }
211  IntType getIntMaxType() const { return IntMaxType; }
214  }
215  IntType getPtrDiffType(unsigned AddrSpace) const {
216  return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
217  }
218  IntType getIntPtrType() const { return IntPtrType; }
221  }
222  IntType getWCharType() const { return WCharType; }
223  IntType getWIntType() const { return WIntType; }
224  IntType getChar16Type() const { return Char16Type; }
225  IntType getChar32Type() const { return Char32Type; }
226  IntType getInt64Type() const { return Int64Type; }
229  }
232 
234  switch (T) {
235  case SignedChar:
236  return UnsignedChar;
237  case SignedShort:
238  return UnsignedShort;
239  case SignedInt:
240  return UnsignedInt;
241  case SignedLong:
242  return UnsignedLong;
243  case SignedLongLong:
244  return UnsignedLongLong;
245  default:
246  llvm_unreachable("Unexpected signed integer type");
247  }
248  }
249 
250  /// \brief Return the width (in bits) of the specified integer type enum.
251  ///
252  /// For example, SignedInt -> getIntWidth().
253  unsigned getTypeWidth(IntType T) const;
254 
255  /// \brief Return integer type with specified width.
256  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
257 
258  /// \brief Return the smallest integer type with at least the specified width.
259  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
260 
261  /// \brief Return floating point type with specified width.
262  RealType getRealTypeByWidth(unsigned BitWidth) const;
263 
264  /// \brief Return the alignment (in bits) of the specified integer type enum.
265  ///
266  /// For example, SignedInt -> getIntAlign().
267  unsigned getTypeAlign(IntType T) const;
268 
269  /// \brief Returns true if the type is signed; false otherwise.
270  static bool isTypeSigned(IntType T);
271 
272  /// \brief Return the width of pointers on this target, for the
273  /// specified address space.
274  uint64_t getPointerWidth(unsigned AddrSpace) const {
275  return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
276  }
277  uint64_t getPointerAlign(unsigned AddrSpace) const {
278  return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
279  }
280 
281  /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
282  unsigned getBoolWidth() const { return BoolWidth; }
283 
284  /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
285  unsigned getBoolAlign() const { return BoolAlign; }
286 
287  unsigned getCharWidth() const { return 8; } // FIXME
288  unsigned getCharAlign() const { return 8; } // FIXME
289 
290  /// \brief Return the size of 'signed short' and 'unsigned short' for this
291  /// target, in bits.
292  unsigned getShortWidth() const { return 16; } // FIXME
293 
294  /// \brief Return the alignment of 'signed short' and 'unsigned short' for
295  /// this target.
296  unsigned getShortAlign() const { return 16; } // FIXME
297 
298  /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
299  /// this target, in bits.
300  unsigned getIntWidth() const { return IntWidth; }
301  unsigned getIntAlign() const { return IntAlign; }
302 
303  /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
304  /// for this target, in bits.
305  unsigned getLongWidth() const { return LongWidth; }
306  unsigned getLongAlign() const { return LongAlign; }
307 
308  /// getLongLongWidth/Align - Return the size of 'signed long long' and
309  /// 'unsigned long long' for this target, in bits.
310  unsigned getLongLongWidth() const { return LongLongWidth; }
311  unsigned getLongLongAlign() const { return LongLongAlign; }
312 
313  /// \brief Determine whether the __int128 type is supported on this target.
314  virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME
315 
316  /// \brief Return the alignment that is suitable for storing any
317  /// object with a fundamental alignment requirement.
318  unsigned getSuitableAlign() const { return SuitableAlign; }
319 
320  /// \brief Return the default alignment for __attribute__((aligned)) on
321  /// this target, to be used if no alignment value is specified.
324  }
325 
326  /// getMinGlobalAlign - Return the minimum alignment of a global variable,
327  /// unless its alignment is explicitly reduced via attributes.
328  unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
329 
330  /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
331  /// bits.
332  unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
333  unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
334 
335  /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
336  /// bits.
337  unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
338  unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
339 
340  /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
341  /// bits.
342  unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
343  unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
344 
345  /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
346  unsigned getHalfWidth() const { return HalfWidth; }
347  unsigned getHalfAlign() const { return HalfAlign; }
348  const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
349 
350  /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
351  unsigned getFloatWidth() const { return FloatWidth; }
352  unsigned getFloatAlign() const { return FloatAlign; }
353  const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
354 
355  /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
356  unsigned getDoubleWidth() const { return DoubleWidth; }
357  unsigned getDoubleAlign() const { return DoubleAlign; }
358  const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
359 
360  /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
361  /// double'.
362  unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
363  unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
364  const llvm::fltSemantics &getLongDoubleFormat() const {
365  return *LongDoubleFormat;
366  }
367 
368  /// \brief Return true if the 'long double' type should be mangled like
369  /// __float128.
370  virtual bool useFloat128ManglingForLongDouble() const { return false; }
371 
372  /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
373  virtual unsigned getFloatEvalMethod() const { return 0; }
374 
375  // getLargeArrayMinWidth/Align - Return the minimum array size that is
376  // 'large' and its alignment.
377  unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
378  unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
379 
380  /// \brief Return the maximum width lock-free atomic operation which will
381  /// ever be supported for the given target
382  unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
383  /// \brief Return the maximum width lock-free atomic operation which can be
384  /// inlined given the supported features of the given target.
385  unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
386  /// \brief Returns true if the given target supports lock-free atomic
387  /// operations at the specified width and alignment.
388  virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
389  uint64_t AlignmentInBits) const {
390  return AtomicSizeInBits <= AlignmentInBits &&
391  AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
392  (AtomicSizeInBits <= getCharWidth() ||
393  llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth()));
394  }
395 
396  /// \brief Return the maximum vector alignment supported for the given target.
397  unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
398  /// \brief Return default simd alignment for the given target. Generally, this
399  /// value is type-specific, but this alignment can be used for most of the
400  /// types for the given target.
401  unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
402 
403  /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
404  unsigned getIntMaxTWidth() const {
405  return getTypeWidth(IntMaxType);
406  }
407 
408  // Return the size of unwind_word for this target.
409  unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
410 
411  /// \brief Return the "preferred" register width on this target.
412  unsigned getRegisterWidth() const {
413  // Currently we assume the register width on the target matches the pointer
414  // width, we can introduce a new variable for this if/when some target wants
415  // it.
416  return PointerWidth;
417  }
418 
419  /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
420  /// which is the prefix given to user symbols by default.
421  ///
422  /// On most platforms this is "_", but it is "" on some, and "." on others.
423  const char *getUserLabelPrefix() const {
424  return UserLabelPrefix;
425  }
426 
427  /// \brief Returns the name of the mcount instrumentation function.
428  const char *getMCountName() const {
429  return MCountName;
430  }
431 
432  /// \brief Check if the Objective-C built-in boolean type should be signed
433  /// char.
434  ///
435  /// Otherwise, if this returns false, the normal built-in boolean type
436  /// should also be used for Objective-C.
439  }
441  UseSignedCharForObjCBool = false;
442  }
443 
444  /// \brief Check whether the alignment of bit-field types is respected
445  /// when laying out structures.
448  }
449 
450  /// \brief Check whether zero length bitfields should force alignment of
451  /// the next member.
454  }
455 
456  /// \brief Get the fixed alignment value in bits for a member that follows
457  /// a zero length bitfield.
458  unsigned getZeroLengthBitfieldBoundary() const {
460  }
461 
462  /// \brief Check whether this target support '\#pragma options align=mac68k'.
463  bool hasAlignMac68kSupport() const {
464  return HasAlignMac68kSupport;
465  }
466 
467  /// \brief Return the user string for the specified integer type enum.
468  ///
469  /// For example, SignedShort -> "short".
470  static const char *getTypeName(IntType T);
471 
472  /// \brief Return the constant suffix for the specified integer type enum.
473  ///
474  /// For example, SignedLong -> "L".
475  const char *getTypeConstantSuffix(IntType T) const;
476 
477  /// \brief Return the printf format modifier for the specified
478  /// integer type enum.
479  ///
480  /// For example, SignedLong -> "l".
481  static const char *getTypeFormatModifier(IntType T);
482 
483  /// \brief Check whether the given real type should use the "fpret" flavor of
484  /// Objective-C message passing on this target.
486  return RealTypeUsesObjCFPRet & (1 << T);
487  }
488 
489  /// \brief Check whether _Complex long double should use the "fp2ret" flavor
490  /// of Objective-C message passing on this target.
493  }
494 
495  /// \brief Specify if mangling based on address space map should be used or
496  /// not for language specific address spaces
499  }
500 
501  ///===---- Other target property query methods --------------------------===//
502 
503  /// \brief Appends the target-specific \#define values for this
504  /// target set to the specified buffer.
505  virtual void getTargetDefines(const LangOptions &Opts,
506  MacroBuilder &Builder) const = 0;
507 
508 
509  /// Return information about target-specific builtins for
510  /// the current primary target, and info about which builtins are non-portable
511  /// across the current set of primary and secondary targets.
512  virtual void getTargetBuiltins(const Builtin::Info *&Records,
513  unsigned &NumRecords) const = 0;
514 
515  /// The __builtin_clz* and __builtin_ctz* built-in
516  /// functions are specified to have undefined results for zero inputs, but
517  /// on targets that support these operations in a way that provides
518  /// well-defined results for zero without loss of performance, it is a good
519  /// idea to avoid optimizing based on that undef behavior.
520  virtual bool isCLZForZeroUndef() const { return true; }
521 
522  /// \brief Returns the kind of __builtin_va_list type that should be used
523  /// with this target.
524  virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
525 
526  /// \brief Returns whether the passed in string is a valid clobber in an
527  /// inline asm statement.
528  ///
529  /// This is used by Sema.
530  bool isValidClobber(StringRef Name) const;
531 
532  /// \brief Returns whether the passed in string is a valid register name
533  /// according to GCC.
534  ///
535  /// This is used by Sema for inline asm statements.
536  bool isValidGCCRegisterName(StringRef Name) const;
537 
538  /// \brief Returns the "normalized" GCC register name.
539  ///
540  /// For example, on x86 it will return "ax" when "eax" is passed in.
541  StringRef getNormalizedGCCRegisterName(StringRef Name) const;
542 
543  struct ConstraintInfo {
544  enum {
545  CI_None = 0x00,
548  CI_ReadWrite = 0x04, // "+r" output constraint (read and write).
549  CI_HasMatchingInput = 0x08, // This output operand has a matching input.
550  CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
551  CI_EarlyClobber = 0x20, // "&" output constraint (early clobber).
552  };
553  unsigned Flags;
555  struct {
556  int Min;
557  int Max;
558  } ImmRange;
559 
560  std::string ConstraintStr; // constraint: "=rm"
561  std::string Name; // Operand name: [foo] with no []'s.
562  public:
563  ConstraintInfo(StringRef ConstraintStr, StringRef Name)
564  : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
565  Name(Name.str()) {
566  ImmRange.Min = ImmRange.Max = 0;
567  }
568 
569  const std::string &getConstraintStr() const { return ConstraintStr; }
570  const std::string &getName() const { return Name; }
571  bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
572  bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
573  bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
574  bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
575 
576  /// \brief Return true if this output operand has a matching
577  /// (tied) input operand.
578  bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
579 
580  /// \brief Return true if this input operand is a matching
581  /// constraint that ties it to an output operand.
582  ///
583  /// If this returns true then getTiedOperand will indicate which output
584  /// operand this is tied to.
585  bool hasTiedOperand() const { return TiedOperand != -1; }
586  unsigned getTiedOperand() const {
587  assert(hasTiedOperand() && "Has no tied operand!");
588  return (unsigned)TiedOperand;
589  }
590 
592  return (Flags & CI_ImmediateConstant) != 0;
593  }
594  int getImmConstantMin() const { return ImmRange.Min; }
595  int getImmConstantMax() const { return ImmRange.Max; }
596 
602  void setRequiresImmediate(int Min, int Max) {
604  ImmRange.Min = Min;
605  ImmRange.Max = Max;
606  }
607 
608  /// \brief Indicate that this is an input operand that is tied to
609  /// the specified output operand.
610  ///
611  /// Copy over the various constraint information from the output.
612  void setTiedOperand(unsigned N, ConstraintInfo &Output) {
613  Output.setHasMatchingInput();
614  Flags = Output.Flags;
615  TiedOperand = N;
616  // Don't copy Name or constraint string.
617  }
618  };
619 
620  // Validate the contents of the __builtin_cpu_supports(const char*) argument.
621  virtual bool validateCpuSupports(StringRef Name) const { return false; }
622 
623  // validateOutputConstraint, validateInputConstraint - Checks that
624  // a constraint is valid and provides information about it.
625  // FIXME: These should return a real error instead of just true/false.
626  bool validateOutputConstraint(ConstraintInfo &Info) const;
627  bool validateInputConstraint(ConstraintInfo *OutputConstraints,
628  unsigned NumOutputs,
629  ConstraintInfo &info) const;
630 
631  virtual bool validateOutputSize(StringRef /*Constraint*/,
632  unsigned /*Size*/) const {
633  return true;
634  }
635 
636  virtual bool validateInputSize(StringRef /*Constraint*/,
637  unsigned /*Size*/) const {
638  return true;
639  }
640  virtual bool
641  validateConstraintModifier(StringRef /*Constraint*/,
642  char /*Modifier*/,
643  unsigned /*Size*/,
644  std::string &/*SuggestedModifier*/) const {
645  return true;
646  }
647  bool resolveSymbolicName(const char *&Name,
648  ConstraintInfo *OutputConstraints,
649  unsigned NumOutputs, unsigned &Index) const;
650 
651  // Constraint parm will be left pointing at the last character of
652  // the constraint. In practice, it won't be changed unless the
653  // constraint is longer than one character.
654  virtual std::string convertConstraint(const char *&Constraint) const {
655  // 'p' defaults to 'r', but can be overridden by targets.
656  if (*Constraint == 'p')
657  return std::string("r");
658  return std::string(1, *Constraint);
659  }
660 
661  /// \brief Returns true if NaN encoding is IEEE 754-2008.
662  /// Only MIPS allows a different encoding.
663  virtual bool isNan2008() const {
664  return true;
665  }
666 
667  /// \brief Returns a string of target-specific clobbers, in LLVM format.
668  virtual const char *getClobbers() const = 0;
669 
670 
671  /// \brief Returns the target triple of the primary target.
672  const llvm::Triple &getTriple() const {
673  return Triple;
674  }
675 
676  const char *getTargetDescription() const {
677  assert(DescriptionString);
678  return DescriptionString;
679  }
680 
681  struct GCCRegAlias {
682  const char * const Aliases[5];
683  const char * const Register;
684  };
685 
686  struct AddlRegName {
687  const char * const Names[5];
688  const unsigned RegNum;
689  };
690 
691  /// \brief Does this target support "protected" visibility?
692  ///
693  /// Any target which dynamic libraries will naturally support
694  /// something like "default" (meaning that the symbol is visible
695  /// outside this shared object) and "hidden" (meaning that it isn't)
696  /// visibilities, but "protected" is really an ELF-specific concept
697  /// with weird semantics designed around the convenience of dynamic
698  /// linker implementations. Which is not to suggest that there's
699  /// consistent target-independent semantics for "default" visibility
700  /// either; the entire thing is pretty badly mangled.
701  virtual bool hasProtectedVisibility() const { return true; }
702 
703  /// \brief An optional hook that targets can implement to perform semantic
704  /// checking on attribute((section("foo"))) specifiers.
705  ///
706  /// In this case, "foo" is passed in to be checked. If the section
707  /// specifier is invalid, the backend should return a non-empty string
708  /// that indicates the problem.
709  ///
710  /// This hook is a simple quality of implementation feature to catch errors
711  /// and give good diagnostics in cases when the assembler or code generator
712  /// would otherwise reject the section specifier.
713  ///
714  virtual std::string isValidSectionSpecifier(StringRef SR) const {
715  return "";
716  }
717 
718  /// \brief Set forced language options.
719  ///
720  /// Apply changes to the target information with respect to certain
721  /// language options which change the target configuration.
722  virtual void adjust(const LangOptions &Opts);
723 
724  /// \brief Get the default set of target features for the CPU;
725  /// this should include all legal feature strings on the target.
726  virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
727  }
728 
729  /// \brief Get the ABI currently in use.
730  virtual StringRef getABI() const { return StringRef(); }
731 
732  /// \brief Get the C++ ABI currently in use.
734  return TheCXXABI;
735  }
736 
737  /// \brief Target the specified CPU.
738  ///
739  /// \return False on error (invalid CPU name).
740  virtual bool setCPU(const std::string &Name) {
741  return false;
742  }
743 
744  /// \brief Use the specified ABI.
745  ///
746  /// \return False on error (invalid ABI name).
747  virtual bool setABI(const std::string &Name) {
748  return false;
749  }
750 
751  /// \brief Use the specified unit for FP math.
752  ///
753  /// \return False on error (invalid unit name).
754  virtual bool setFPMath(StringRef Name) {
755  return false;
756  }
757 
758  /// \brief Use this specified C++ ABI.
759  ///
760  /// \return False on error (invalid C++ ABI name).
761  bool setCXXABI(llvm::StringRef name) {
762  TargetCXXABI ABI;
763  if (!ABI.tryParse(name)) return false;
764  return setCXXABI(ABI);
765  }
766 
767  /// \brief Set the C++ ABI to be used by this implementation.
768  ///
769  /// \return False on error (ABI not valid on this target)
770  virtual bool setCXXABI(TargetCXXABI ABI) {
771  TheCXXABI = ABI;
772  return true;
773  }
774 
775  /// \brief Enable or disable a specific target feature;
776  /// the feature name must be valid.
777  virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
778  StringRef Name,
779  bool Enabled) const {
780  Features[Name] = Enabled;
781  }
782 
783  /// \brief Perform initialization based on the user configured
784  /// set of features (e.g., +sse4).
785  ///
786  /// The list is guaranteed to have at most one entry per feature.
787  ///
788  /// The target may modify the features list, to change which options are
789  /// passed onwards to the backend.
790  ///
791  /// \return False on error.
792  virtual bool handleTargetFeatures(std::vector<std::string> &Features,
793  DiagnosticsEngine &Diags) {
794  return true;
795  }
796 
797  /// \brief Determine whether the given target has the given feature.
798  virtual bool hasFeature(StringRef Feature) const {
799  return false;
800  }
801 
802  // \brief Returns maximal number of args passed in registers.
803  unsigned getRegParmMax() const {
804  assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
805  return RegParmMax;
806  }
807 
808  /// \brief Whether the target supports thread-local storage.
809  bool isTLSSupported() const {
810  return TLSSupported;
811  }
812 
813  /// \brief Return the maximum alignment (in bits) of a TLS variable
814  ///
815  /// Gets the maximum alignment (in bits) of a TLS variable on this target.
816  /// Returns zero if there is no such constraint.
817  unsigned short getMaxTLSAlign() const {
818  return MaxTLSAlign;
819  }
820 
821  /// \brief Whether the target supports SEH __try.
822  bool isSEHTrySupported() const {
823  return getTriple().isOSWindows() &&
824  (getTriple().getArch() == llvm::Triple::x86 ||
825  getTriple().getArch() == llvm::Triple::x86_64);
826  }
827 
828  /// \brief Return true if {|} are normal characters in the asm string.
829  ///
830  /// If this returns false (the default), then {abc|xyz} is syntax
831  /// that says that when compiling for asm variant #0, "abc" should be
832  /// generated, but when compiling for asm variant #1, "xyz" should be
833  /// generated.
834  bool hasNoAsmVariants() const {
835  return NoAsmVariants;
836  }
837 
838  /// \brief Return the register number that __builtin_eh_return_regno would
839  /// return with the specified argument.
840  virtual int getEHDataRegisterNumber(unsigned RegNo) const {
841  return -1;
842  }
843 
844  /// \brief Return the section to use for C++ static initialization functions.
845  virtual const char *getStaticInitSectionSpecifier() const {
846  return nullptr;
847  }
848 
850  return *AddrSpaceMap;
851  }
852 
853  /// \brief Retrieve the name of the platform as it is used in the
854  /// availability attribute.
855  StringRef getPlatformName() const { return PlatformName; }
856 
857  /// \brief Retrieve the minimum desired version of the platform, to
858  /// which the program should be compiled.
860 
861  bool isBigEndian() const { return BigEndian; }
862 
867  };
868 
869  /// \brief Gets the default calling convention for the given target and
870  /// declaration context.
872  // Not all targets will specify an explicit calling convention that we can
873  // express. This will always do the right thing, even though it's not
874  // an explicit calling convention.
875  return CC_C;
876  }
877 
882  };
883 
884  /// \brief Determines whether a given calling convention is valid for the
885  /// target. A calling convention can either be accepted, produce a warning
886  /// and be substituted with the default calling convention, or (someday)
887  /// produce an error (such as using thiscall on a non-instance function).
889  switch (CC) {
890  default:
891  return CCCR_Warning;
892  case CC_C:
893  return CCCR_OK;
894  }
895  }
896 
897  /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
898  /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
899  virtual bool hasSjLjLowering() const {
900  return false;
901  }
902 
903 protected:
904  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
905  return PointerWidth;
906  }
907  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
908  return PointerAlign;
909  }
910  virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
911  return PtrDiffType;
912  }
913  virtual void getGCCRegNames(const char * const *&Names,
914  unsigned &NumNames) const = 0;
915  virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
916  unsigned &NumAliases) const = 0;
917  virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
918  unsigned &NumAddl) const {
919  Addl = nullptr;
920  NumAddl = 0;
921  }
922  virtual bool validateAsmConstraint(const char *&Name,
923  TargetInfo::ConstraintInfo &info) const= 0;
924 };
925 
926 } // end namespace clang
927 
928 #endif
bool useObjCFP2RetForComplexLongDouble() const
Check whether _Complex long double should use the "fp2ret" flavor of Objective-C message passing on t...
RealType getRealTypeByWidth(unsigned BitWidth) const
Return floating point type with specified width.
unsigned getSimdDefaultAlign() const
Return default simd alignment for the given target. Generally, this value is type-specific, but this alignment can be used for most of the types for the given target.
unsigned getZeroLengthBitfieldBoundary() const
Get the fixed alignment value in bits for a member that follows a zero length bitfield.
bool useObjCFPRetForRealType(RealType T) const
Check whether the given real type should use the "fpret" flavor of Objective-C message passing on thi...
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
bool resolveSymbolicName(const char *&Name, ConstraintInfo *OutputConstraints, unsigned NumOutputs, unsigned &Index) const
The basic abstraction for the target C++ ABI.
Definition: TargetCXXABI.h:25
bool hasMatchingInput() const
Return true if this output operand has a matching (tied) input operand.
unsigned getDefaultAlignForAttributeAligned() const
Return the default alignment for attribute((aligned)) on this target, to be used if no alignment valu...
virtual bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const =0
unsigned getRegisterWidth() const
Return the "preferred" register width on this target.
const llvm::fltSemantics * DoubleFormat
virtual void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) const =0
bool validateOutputConstraint(ConstraintInfo &Info) const
virtual bool setCXXABI(TargetCXXABI ABI)
Set the C++ ABI to be used by this implementation.
TargetInfo(const llvm::Triple &T)
unsigned getBoolAlign() const
Return the alignment of '_Bool' and C++ 'bool' for this target.
virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled...
Options for controlling the target.
Definition: TargetOptions.h:24
virtual bool validateConstraintModifier(StringRef, char, unsigned, std::string &) const
virtual void adjust(const LangOptions &Opts)
Set forced language options.
unsigned getFloatWidth() const
getFloatWidth/Align/Format - Return the size/align/format of 'float'.
unsigned getLargeArrayMinWidth() const
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
virtual bool validateCpuSupports(StringRef Name) const
unsigned getDoubleWidth() const
getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
const char * getTypeConstantSuffix(IntType T) const
Return the constant suffix for the specified integer type enum.
virtual bool validateOutputSize(StringRef, unsigned) const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
virtual int getEHDataRegisterNumber(unsigned RegNo) const
Return the register number that __builtin_eh_return_regno would return with the specified argument...
virtual bool validateInputSize(StringRef, unsigned) const
virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const
Gets the default calling convention for the given target and declaration context. ...
static bool isTypeSigned(IntType T)
Returns true if the type is signed; false otherwise.
virtual unsigned getFloatEvalMethod() const
Return the value for the C99 FLT_EVAL_METHOD macro.
unsigned char DefaultAlignForAttributeAligned
const char * getMCountName() const
Returns the name of the mcount instrumentation function.
virtual bool isNan2008() const
Returns true if NaN encoding is IEEE 754-2008. Only MIPS allows a different encoding.
const llvm::fltSemantics & getDoubleFormat() const
bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
virtual const char * getStaticInitSectionSpecifier() const
Return the section to use for C++ static initialization functions.
virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits, uint64_t AlignmentInBits) const
Returns true if the given target supports lock-free atomic operations at the specified width and alig...
virtual void getDefaultFeatures(llvm::StringMap< bool > &Features) const
Get the default set of target features for the CPU; this should include all legal feature strings on ...
virtual StringRef getABI() const
Get the ABI currently in use.
unsigned getHalfWidth() const
getHalfWidth/Align/Format - Return the size/align/format of 'half'.
Provides definitions for the various language-specific address spaces.
bool hasNoAsmVariants() const
Return true if {|} are normal characters in the asm string.
virtual std::string convertConstraint(const char *&Constraint) const
unsigned getTypeWidth(IntType T) const
Return the width (in bits) of the specified integer type enum.
Exposes information about the current target.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting...
const char * getUserLabelPrefix() const
Returns the default value of the USER_LABEL_PREFIX macro, which is the prefix given to user symbols b...
const llvm::fltSemantics & getFloatFormat() const
virtual std::string isValidSectionSpecifier(StringRef SR) const
An optional hook that targets can implement to perform semantic checking on attribute((section("foo")...
bool isValidClobber(StringRef Name) const
Returns whether the passed in string is a valid clobber in an inline asm statement.
bool useZeroLengthBitfieldAlignment() const
Check whether zero length bitfields should force alignment of the next member.
unsigned getIntMaxTWidth() const
Return the size of intmax_t and uintmax_t for this target, in bits.
bool setCXXABI(llvm::StringRef name)
Use this specified C++ ABI.
virtual bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags)
Perform initialization based on the user configured set of features (e.g., +sse4).
virtual bool hasProtectedVisibility() const
Does this target support "protected" visibility?
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
Definition: Targets.cpp:7387
bool useBitFieldTypeAlignment() const
Check whether the alignment of bit-field types is respected when laying out structures.
const LangAS::Map & getAddressSpaceMap() const
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:204
static const char * getTypeName(IntType T)
Return the user string for the specified integer type enum.
unsigned getTypeAlign(IntType T) const
Return the alignment (in bits) of the specified integer type enum.
unsigned getMaxVectorAlign() const
Return the maximum vector alignment supported for the given target.
virtual uint64_t getPointerAlignV(unsigned AddrSpace) const
virtual bool useFloat128ManglingForLongDouble() const
Return true if the 'long double' type should be mangled like __float128.
virtual bool setABI(const std::string &Name)
Use the specified ABI.
uint64_t getPointerAlign(unsigned AddrSpace) const
bool isSEHTrySupported() const
Whether the target supports SEH __try.
const LangAS::Map * AddrSpaceMap
const char * getTargetDescription() const
Defines the clang::TargetOptions class.
virtual bool hasSjLjLowering() const
struct clang::TargetInfo::ConstraintInfo::@150 ImmRange
virtual void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const
Enable or disable a specific target feature; the feature name must be valid.
bool tryParse(llvm::StringRef name)
Try to parse an ABI name, returning false on error.
virtual BuiltinVaListKind getBuiltinVaListKind() const =0
Returns the kind of __builtin_va_list type that should be used with this target.
IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
unsigned UseZeroLengthBitfieldAlignment
Whether zero length bitfields (e.g., int : 0;) force alignment of the next bitfield.
virtual bool isCLZForZeroUndef() const
Defines various enumerations that describe declaration and type specifiers.
IntType
===-— Target Data Type Query Methods ----------------------------—===//
const llvm::fltSemantics & getLongDoubleFormat() const
static const char * getTypeFormatModifier(IntType T)
Return the printf format modifier for the specified integer type enum.
ConstraintInfo(StringRef ConstraintStr, StringRef Name)
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand...
unsigned getShortWidth() const
Return the size of 'signed short' and 'unsigned short' for this target, in bits.
IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
unsigned short getMaxTLSAlign() const
Return the maximum alignment (in bits) of a TLS variable.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
unsigned UseSignedCharForObjCBool
Whether Objective-C's built-in boolean type should be signed char.
virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, unsigned &NumAliases) const =0
const llvm::fltSemantics & getHalfFormat() const
virtual bool hasInt128Type() const
Determine whether the __int128 type is supported on this target.
unsigned getMaxAtomicInlineWidth() const
Return the maximum width lock-free atomic operation which can be inlined given the supported features...
unsigned Map[Count]
Definition: AddressSpaces.h:45
const llvm::fltSemantics * FloatFormat
TargetOptions & getTargetOpts() const
Retrieve the target options.
const llvm::fltSemantics * HalfFormat
virtual void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const =0
===-— Other target property query methods --------------------——===//
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
bool isTLSSupported() const
Whether the target supports thread-local storage.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
bool useSignedCharForObjCBool() const
Check if the Objective-C built-in boolean type should be signed char.
static IntType getCorrespondingUnsignedType(IntType T)
virtual void getGCCAddlRegNames(const AddlRegName *&Addl, unsigned &NumAddl) const
virtual bool setCPU(const std::string &Name)
Target the specified CPU.
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target. A calling convention can eithe...
BoundNodesTreeBuilder *const Builder
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
bool useAddressSpaceMapMangling() const
Specify if mangling based on address space map should be used or not for language specific address sp...
virtual void getGCCRegNames(const char *const *&Names, unsigned &NumNames) const =0
unsigned getBoolWidth() const
Return the size of '_Bool' and C++ 'bool' for this target, in bits.
unsigned getMaxAtomicPromoteWidth() const
Return the maximum width lock-free atomic operation which will ever be supported for the given target...
StringRef getNormalizedGCCRegisterName(StringRef Name) const
Returns the "normalized" GCC register name.
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
const llvm::fltSemantics * LongDoubleFormat
bool validateInputConstraint(ConstraintInfo *OutputConstraints, unsigned NumOutputs, ConstraintInfo &info) const
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
unsigned getSuitableAlign() const
Return the alignment that is suitable for storing any object with a fundamental alignment requirement...
void setTiedOperand(unsigned N, ConstraintInfo &Output)
Indicate that this is an input operand that is tied to the specified output operand.
virtual bool setFPMath(StringRef Name)
Use the specified unit for FP math.
IntType getPtrDiffType(unsigned AddrSpace) const
unsigned getShortAlign() const
Return the alignment of 'signed short' and 'unsigned short' for this target.
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
bool UseAddrSpaceMapMangling
Specify if mangling based on address space map should be used or not for language specific address sp...
virtual uint64_t getPointerWidthV(unsigned AddrSpace) const
virtual const char * getClobbers() const =0
Returns a string of target-specific clobbers, in LLVM format.