• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/StringSwitch.h"
23 #include "llvm/ADT/Triple.h"
24 #include "llvm/Support/DataTypes.h"
25 #include "clang/Basic/AddressSpaces.h"
26 #include "clang/Basic/VersionTuple.h"
27 #include <cassert>
28 #include <vector>
29 #include <string>
30 
31 namespace llvm {
32 struct fltSemantics;
33 }
34 
35 namespace clang {
36 class DiagnosticsEngine;
37 class LangOptions;
38 class MacroBuilder;
39 class SourceLocation;
40 class SourceManager;
41 class TargetOptions;
42 
43 namespace Builtin { struct Info; }
44 
45 /// \brief The types of C++ ABIs for which we can generate code.
46 enum TargetCXXABI {
47   /// The generic ("Itanium") C++ ABI, documented at:
48   ///   http://www.codesourcery.com/public/cxx-abi/
49   CXXABI_Itanium,
50 
51   /// The ARM C++ ABI, based largely on the Itanium ABI but with
52   /// significant differences.
53   ///    http://infocenter.arm.com
54   ///                    /help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf
55   CXXABI_ARM,
56 
57   /// The Visual Studio ABI.  Only scattered official documentation exists.
58   CXXABI_Microsoft
59 };
60 
61 /// \brief Exposes information about the current target.
62 ///
63 class TargetInfo : public RefCountedBase<TargetInfo> {
64   llvm::Triple Triple;
65 protected:
66   // Target values set by the ctor of the actual target implementation.  Default
67   // values are specified by the TargetInfo constructor.
68   bool BigEndian;
69   bool TLSSupported;
70   bool NoAsmVariants;  // True if {|} are normal characters.
71   unsigned char PointerWidth, PointerAlign;
72   unsigned char BoolWidth, BoolAlign;
73   unsigned char IntWidth, IntAlign;
74   unsigned char HalfWidth, HalfAlign;
75   unsigned char FloatWidth, FloatAlign;
76   unsigned char DoubleWidth, DoubleAlign;
77   unsigned char LongDoubleWidth, LongDoubleAlign;
78   unsigned char LargeArrayMinWidth, LargeArrayAlign;
79   unsigned char LongWidth, LongAlign;
80   unsigned char LongLongWidth, LongLongAlign;
81   unsigned char SuitableAlign;
82   unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
83   unsigned short MaxVectorAlign;
84   const char *DescriptionString;
85   const char *UserLabelPrefix;
86   const char *MCountName;
87   const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
88     *LongDoubleFormat;
89   unsigned char RegParmMax, SSERegParmMax;
90   TargetCXXABI CXXABI;
91   const LangAS::Map *AddrSpaceMap;
92 
93   mutable StringRef PlatformName;
94   mutable VersionTuple PlatformMinVersion;
95 
96   unsigned HasAlignMac68kSupport : 1;
97   unsigned RealTypeUsesObjCFPRet : 3;
98   unsigned ComplexLongDoubleUsesFP2Ret : 1;
99 
100   // TargetInfo Constructor.  Default initializes all fields.
101   TargetInfo(const std::string &T);
102 
103 public:
104   /// \brief Construct a target for the given options.
105   ///
106   /// \param Opts - The options to use to initialize the target. The target may
107   /// modify the options to canonicalize the target feature information to match
108   /// what the backend expects.
109   static TargetInfo* CreateTargetInfo(DiagnosticsEngine &Diags,
110                                       TargetOptions &Opts);
111 
112   virtual ~TargetInfo();
113 
114   ///===---- Target Data Type Query Methods -------------------------------===//
115   enum IntType {
116     NoInt = 0,
117     SignedShort,
118     UnsignedShort,
119     SignedInt,
120     UnsignedInt,
121     SignedLong,
122     UnsignedLong,
123     SignedLongLong,
124     UnsignedLongLong
125   };
126 
127   enum RealType {
128     Float = 0,
129     Double,
130     LongDouble
131   };
132 
133   /// \brief The different kinds of __builtin_va_list types defined by
134   /// the target implementation.
135   enum BuiltinVaListKind {
136     /// typedef char* __builtin_va_list;
137     CharPtrBuiltinVaList = 0,
138 
139     /// typedef void* __builtin_va_list;
140     VoidPtrBuiltinVaList,
141 
142     /// __builtin_va_list as defined by the PNaCl ABI:
143     /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
144     PNaClABIBuiltinVaList,
145 
146     /// __builtin_va_list as defined by the Power ABI:
147     /// https://www.power.org
148     ///        /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
149     PowerABIBuiltinVaList,
150 
151     /// __builtin_va_list as defined by the x86-64 ABI:
152     /// http://www.x86-64.org/documentation/abi.pdf
153     X86_64ABIBuiltinVaList
154   };
155 
156 protected:
157   IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
158           WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType;
159 
160   /// \brief Whether Objective-C's built-in boolean type should be signed char.
161   ///
162   /// Otherwise, when this flag is not set, the normal built-in boolean type is
163   /// used.
164   unsigned UseSignedCharForObjCBool : 1;
165 
166   /// Control whether the alignment of bit-field types is respected when laying
167   /// out structures. If true, then the alignment of the bit-field type will be
168   /// used to (a) impact the alignment of the containing structure, and (b)
169   /// ensure that the individual bit-field will not straddle an alignment
170   /// boundary.
171   unsigned UseBitFieldTypeAlignment : 1;
172 
173   /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
174   /// the next bitfield.
175   ///
176   /// If the alignment of the zero length bitfield is greater than the member
177   /// that follows it, `bar', `bar' will be aligned as the type of the
178   /// zero-length bitfield.
179   unsigned UseZeroLengthBitfieldAlignment : 1;
180 
181   /// If non-zero, specifies a fixed alignment value for bitfields that follow
182   /// zero length bitfield, regardless of the zero length bitfield type.
183   unsigned ZeroLengthBitfieldBoundary;
184 
185 public:
getSizeType()186   IntType getSizeType() const { return SizeType; }
getIntMaxType()187   IntType getIntMaxType() const { return IntMaxType; }
getUIntMaxType()188   IntType getUIntMaxType() const { return UIntMaxType; }
getPtrDiffType(unsigned AddrSpace)189   IntType getPtrDiffType(unsigned AddrSpace) const {
190     return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
191   }
getIntPtrType()192   IntType getIntPtrType() const { return IntPtrType; }
getWCharType()193   IntType getWCharType() const { return WCharType; }
getWIntType()194   IntType getWIntType() const { return WIntType; }
getChar16Type()195   IntType getChar16Type() const { return Char16Type; }
getChar32Type()196   IntType getChar32Type() const { return Char32Type; }
getInt64Type()197   IntType getInt64Type() const { return Int64Type; }
getSigAtomicType()198   IntType getSigAtomicType() const { return SigAtomicType; }
199 
200 
201   /// \brief Return the width (in bits) of the specified integer type enum.
202   ///
203   /// For example, SignedInt -> getIntWidth().
204   unsigned getTypeWidth(IntType T) const;
205 
206   /// \brief Return the alignment (in bits) of the specified integer type enum.
207   ///
208   /// For example, SignedInt -> getIntAlign().
209   unsigned getTypeAlign(IntType T) const;
210 
211   /// \brief Returns true if the type is signed; false otherwise.
212   static bool isTypeSigned(IntType T);
213 
214   /// \brief Return the width of pointers on this target, for the
215   /// specified address space.
getPointerWidth(unsigned AddrSpace)216   uint64_t getPointerWidth(unsigned AddrSpace) const {
217     return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
218   }
getPointerAlign(unsigned AddrSpace)219   uint64_t getPointerAlign(unsigned AddrSpace) const {
220     return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
221   }
222 
223   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
getBoolWidth()224   unsigned getBoolWidth() const { return BoolWidth; }
225 
226   /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
getBoolAlign()227   unsigned getBoolAlign() const { return BoolAlign; }
228 
getCharWidth()229   unsigned getCharWidth() const { return 8; } // FIXME
getCharAlign()230   unsigned getCharAlign() const { return 8; } // FIXME
231 
232   /// \brief Return the size of 'signed short' and 'unsigned short' for this
233   /// target, in bits.
getShortWidth()234   unsigned getShortWidth() const { return 16; } // FIXME
235 
236   /// \brief Return the alignment of 'signed short' and 'unsigned short' for
237   /// this target.
getShortAlign()238   unsigned getShortAlign() const { return 16; } // FIXME
239 
240   /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
241   /// this target, in bits.
getIntWidth()242   unsigned getIntWidth() const { return IntWidth; }
getIntAlign()243   unsigned getIntAlign() const { return IntAlign; }
244 
245   /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
246   /// for this target, in bits.
getLongWidth()247   unsigned getLongWidth() const { return LongWidth; }
getLongAlign()248   unsigned getLongAlign() const { return LongAlign; }
249 
250   /// getLongLongWidth/Align - Return the size of 'signed long long' and
251   /// 'unsigned long long' for this target, in bits.
getLongLongWidth()252   unsigned getLongLongWidth() const { return LongLongWidth; }
getLongLongAlign()253   unsigned getLongLongAlign() const { return LongLongAlign; }
254 
255   /// \brief Return the alignment that is suitable for storing any
256   /// object with a fundamental alignment requirement.
getSuitableAlign()257   unsigned getSuitableAlign() const { return SuitableAlign; }
258 
259   /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
260   /// bits.
getWCharWidth()261   unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
getWCharAlign()262   unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
263 
264   /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
265   /// bits.
getChar16Width()266   unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
getChar16Align()267   unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
268 
269   /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
270   /// bits.
getChar32Width()271   unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
getChar32Align()272   unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
273 
274   /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
getHalfWidth()275   unsigned getHalfWidth() const { return HalfWidth; }
getHalfAlign()276   unsigned getHalfAlign() const { return HalfAlign; }
getHalfFormat()277   const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
278 
279   /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
getFloatWidth()280   unsigned getFloatWidth() const { return FloatWidth; }
getFloatAlign()281   unsigned getFloatAlign() const { return FloatAlign; }
getFloatFormat()282   const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
283 
284   /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
getDoubleWidth()285   unsigned getDoubleWidth() const { return DoubleWidth; }
getDoubleAlign()286   unsigned getDoubleAlign() const { return DoubleAlign; }
getDoubleFormat()287   const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
288 
289   /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
290   /// double'.
getLongDoubleWidth()291   unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
getLongDoubleAlign()292   unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
getLongDoubleFormat()293   const llvm::fltSemantics &getLongDoubleFormat() const {
294     return *LongDoubleFormat;
295   }
296 
297   /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
getFloatEvalMethod()298   virtual unsigned getFloatEvalMethod() const { return 0; }
299 
300   // getLargeArrayMinWidth/Align - Return the minimum array size that is
301   // 'large' and its alignment.
getLargeArrayMinWidth()302   unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
getLargeArrayAlign()303   unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
304 
305   /// \brief Return the maximum width lock-free atomic operation which will
306   /// ever be supported for the given target
getMaxAtomicPromoteWidth()307   unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
308   /// \brief Return the maximum width lock-free atomic operation which can be
309   /// inlined given the supported features of the given target.
getMaxAtomicInlineWidth()310   unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
311 
312   /// \brief Return the maximum vector alignment supported for the given target.
getMaxVectorAlign()313   unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
314 
315   /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
getIntMaxTWidth()316   unsigned getIntMaxTWidth() const {
317     return getTypeWidth(IntMaxType);
318   }
319 
320   /// \brief Return the "preferred" register width on this target.
getRegisterWidth()321   uint64_t getRegisterWidth() const {
322     // Currently we assume the register width on the target matches the pointer
323     // width, we can introduce a new variable for this if/when some target wants
324     // it.
325     return LongWidth;
326   }
327 
328   /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
329   /// which is the prefix given to user symbols by default.
330   ///
331   /// On most platforms this is "_", but it is "" on some, and "." on others.
getUserLabelPrefix()332   const char *getUserLabelPrefix() const {
333     return UserLabelPrefix;
334   }
335 
336   /// \brief Returns the name of the mcount instrumentation function.
getMCountName()337   const char *getMCountName() const {
338     return MCountName;
339   }
340 
341   /// \brief Check if the Objective-C built-in boolean type should be signed
342   /// char.
343   ///
344   /// Otherwise, if this returns false, the normal built-in boolean type
345   /// should also be used for Objective-C.
useSignedCharForObjCBool()346   bool useSignedCharForObjCBool() const {
347     return UseSignedCharForObjCBool;
348   }
noSignedCharForObjCBool()349   void noSignedCharForObjCBool() {
350     UseSignedCharForObjCBool = false;
351   }
352 
353   /// \brief Check whether the alignment of bit-field types is respected
354   /// when laying out structures.
useBitFieldTypeAlignment()355   bool useBitFieldTypeAlignment() const {
356     return UseBitFieldTypeAlignment;
357   }
358 
359   /// \brief Check whether zero length bitfields should force alignment of
360   /// the next member.
useZeroLengthBitfieldAlignment()361   bool useZeroLengthBitfieldAlignment() const {
362     return UseZeroLengthBitfieldAlignment;
363   }
364 
365   /// \brief Get the fixed alignment value in bits for a member that follows
366   /// a zero length bitfield.
getZeroLengthBitfieldBoundary()367   unsigned getZeroLengthBitfieldBoundary() const {
368     return ZeroLengthBitfieldBoundary;
369   }
370 
371   /// \brief Check whether this target support '\#pragma options align=mac68k'.
hasAlignMac68kSupport()372   bool hasAlignMac68kSupport() const {
373     return HasAlignMac68kSupport;
374   }
375 
376   /// \brief Return the user string for the specified integer type enum.
377   ///
378   /// For example, SignedShort -> "short".
379   static const char *getTypeName(IntType T);
380 
381   /// \brief Return the constant suffix for the specified integer type enum.
382   ///
383   /// For example, SignedLong -> "L".
384   static const char *getTypeConstantSuffix(IntType T);
385 
386   /// \brief Check whether the given real type should use the "fpret" flavor of
387   /// Objective-C message passing on this target.
useObjCFPRetForRealType(RealType T)388   bool useObjCFPRetForRealType(RealType T) const {
389     return RealTypeUsesObjCFPRet & (1 << T);
390   }
391 
392   /// \brief Check whether _Complex long double should use the "fp2ret" flavor
393   /// of Objective-C message passing on this target.
useObjCFP2RetForComplexLongDouble()394   bool useObjCFP2RetForComplexLongDouble() const {
395     return ComplexLongDoubleUsesFP2Ret;
396   }
397 
398   ///===---- Other target property query methods --------------------------===//
399 
400   /// \brief Appends the target-specific \#define values for this
401   /// target set to the specified buffer.
402   virtual void getTargetDefines(const LangOptions &Opts,
403                                 MacroBuilder &Builder) const = 0;
404 
405 
406   /// Return information about target-specific builtins for
407   /// the current primary target, and info about which builtins are non-portable
408   /// across the current set of primary and secondary targets.
409   virtual void getTargetBuiltins(const Builtin::Info *&Records,
410                                  unsigned &NumRecords) const = 0;
411 
412   /// The __builtin_clz* and __builtin_ctz* built-in
413   /// functions are specified to have undefined results for zero inputs, but
414   /// on targets that support these operations in a way that provides
415   /// well-defined results for zero without loss of performance, it is a good
416   /// idea to avoid optimizing based on that undef behavior.
isCLZForZeroUndef()417   virtual bool isCLZForZeroUndef() const { return true; }
418 
419   /// \brief Returns the kind of __builtin_va_list type that should be used
420   /// with this target.
421   virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
422 
423   /// \brief Returns whether the passed in string is a valid clobber in an
424   /// inline asm statement.
425   ///
426   /// This is used by Sema.
427   bool isValidClobber(StringRef Name) const;
428 
429   /// \brief Returns whether the passed in string is a valid register name
430   /// according to GCC.
431   ///
432   /// This is used by Sema for inline asm statements.
433   bool isValidGCCRegisterName(StringRef Name) const;
434 
435   /// \brief Returns the "normalized" GCC register name.
436   ///
437   /// For example, on x86 it will return "ax" when "eax" is passed in.
438   StringRef getNormalizedGCCRegisterName(StringRef Name) const;
439 
440   struct ConstraintInfo {
441     enum {
442       CI_None = 0x00,
443       CI_AllowsMemory = 0x01,
444       CI_AllowsRegister = 0x02,
445       CI_ReadWrite = 0x04,       // "+r" output constraint (read and write).
446       CI_HasMatchingInput = 0x08 // This output operand has a matching input.
447     };
448     unsigned Flags;
449     int TiedOperand;
450 
451     std::string ConstraintStr;  // constraint: "=rm"
452     std::string Name;           // Operand name: [foo] with no []'s.
453   public:
ConstraintInfoConstraintInfo454     ConstraintInfo(StringRef ConstraintStr, StringRef Name)
455       : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
456       Name(Name.str()) {}
457 
getConstraintStrConstraintInfo458     const std::string &getConstraintStr() const { return ConstraintStr; }
getNameConstraintInfo459     const std::string &getName() const { return Name; }
isReadWriteConstraintInfo460     bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
allowsRegisterConstraintInfo461     bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
allowsMemoryConstraintInfo462     bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
463 
464     /// \brief Return true if this output operand has a matching
465     /// (tied) input operand.
hasMatchingInputConstraintInfo466     bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
467 
468     /// \brief Return true if this input operand is a matching
469     /// constraint that ties it to an output operand.
470     ///
471     /// If this returns true then getTiedOperand will indicate which output
472     /// operand this is tied to.
hasTiedOperandConstraintInfo473     bool hasTiedOperand() const { return TiedOperand != -1; }
getTiedOperandConstraintInfo474     unsigned getTiedOperand() const {
475       assert(hasTiedOperand() && "Has no tied operand!");
476       return (unsigned)TiedOperand;
477     }
478 
setIsReadWriteConstraintInfo479     void setIsReadWrite() { Flags |= CI_ReadWrite; }
setAllowsMemoryConstraintInfo480     void setAllowsMemory() { Flags |= CI_AllowsMemory; }
setAllowsRegisterConstraintInfo481     void setAllowsRegister() { Flags |= CI_AllowsRegister; }
setHasMatchingInputConstraintInfo482     void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
483 
484     /// \brief Indicate that this is an input operand that is tied to
485     /// the specified output operand.
486     ///
487     /// Copy over the various constraint information from the output.
setTiedOperandConstraintInfo488     void setTiedOperand(unsigned N, ConstraintInfo &Output) {
489       Output.setHasMatchingInput();
490       Flags = Output.Flags;
491       TiedOperand = N;
492       // Don't copy Name or constraint string.
493     }
494   };
495 
496   // validateOutputConstraint, validateInputConstraint - Checks that
497   // a constraint is valid and provides information about it.
498   // FIXME: These should return a real error instead of just true/false.
499   bool validateOutputConstraint(ConstraintInfo &Info) const;
500   bool validateInputConstraint(ConstraintInfo *OutputConstraints,
501                                unsigned NumOutputs,
502                                ConstraintInfo &info) const;
503   bool resolveSymbolicName(const char *&Name,
504                            ConstraintInfo *OutputConstraints,
505                            unsigned NumOutputs, unsigned &Index) const;
506 
507   // Constraint parm will be left pointing at the last character of
508   // the constraint.  In practice, it won't be changed unless the
509   // constraint is longer than one character.
convertConstraint(const char * & Constraint)510   virtual std::string convertConstraint(const char *&Constraint) const {
511     // 'p' defaults to 'r', but can be overridden by targets.
512     if (*Constraint == 'p')
513       return std::string("r");
514     return std::string(1, *Constraint);
515   }
516 
517   /// \brief Returns a string of target-specific clobbers, in LLVM format.
518   virtual const char *getClobbers() const = 0;
519 
520 
521   /// \brief Returns the target triple of the primary target.
getTriple()522   const llvm::Triple &getTriple() const {
523     return Triple;
524   }
525 
getTargetDescription()526   const char *getTargetDescription() const {
527     return DescriptionString;
528   }
529 
530   struct GCCRegAlias {
531     const char * const Aliases[5];
532     const char * const Register;
533   };
534 
535   struct AddlRegName {
536     const char * const Names[5];
537     const unsigned RegNum;
538   };
539 
540   /// \brief Does this target support "protected" visibility?
541   ///
542   /// Any target which dynamic libraries will naturally support
543   /// something like "default" (meaning that the symbol is visible
544   /// outside this shared object) and "hidden" (meaning that it isn't)
545   /// visibilities, but "protected" is really an ELF-specific concept
546   /// with weird semantics designed around the convenience of dynamic
547   /// linker implementations.  Which is not to suggest that there's
548   /// consistent target-independent semantics for "default" visibility
549   /// either; the entire thing is pretty badly mangled.
hasProtectedVisibility()550   virtual bool hasProtectedVisibility() const { return true; }
551 
useGlobalsForAutomaticVariables()552   virtual bool useGlobalsForAutomaticVariables() const { return false; }
553 
554   /// \brief Return the section to use for CFString literals, or 0 if no
555   /// special section is used.
getCFStringSection()556   virtual const char *getCFStringSection() const {
557     return "__DATA,__cfstring";
558   }
559 
560   /// \brief Return the section to use for NSString literals, or 0 if no
561   /// special section is used.
getNSStringSection()562   virtual const char *getNSStringSection() const {
563     return "__OBJC,__cstring_object,regular,no_dead_strip";
564   }
565 
566   /// \brief Return the section to use for NSString literals, or 0 if no
567   /// special section is used (NonFragile ABI).
getNSStringNonFragileABISection()568   virtual const char *getNSStringNonFragileABISection() const {
569     return "__DATA, __objc_stringobj, regular, no_dead_strip";
570   }
571 
572   /// \brief An optional hook that targets can implement to perform semantic
573   /// checking on attribute((section("foo"))) specifiers.
574   ///
575   /// In this case, "foo" is passed in to be checked.  If the section
576   /// specifier is invalid, the backend should return a non-empty string
577   /// that indicates the problem.
578   ///
579   /// This hook is a simple quality of implementation feature to catch errors
580   /// and give good diagnostics in cases when the assembler or code generator
581   /// would otherwise reject the section specifier.
582   ///
isValidSectionSpecifier(StringRef SR)583   virtual std::string isValidSectionSpecifier(StringRef SR) const {
584     return "";
585   }
586 
587   /// \brief Set forced language options.
588   ///
589   /// Apply changes to the target information with respect to certain
590   /// language options which change the target configuration.
591   virtual void setForcedLangOptions(LangOptions &Opts);
592 
593   /// \brief Get the default set of target features for the CPU;
594   /// this should include all legal feature strings on the target.
getDefaultFeatures(llvm::StringMap<bool> & Features)595   virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
596   }
597 
598   /// \brief Get the ABI currently in use.
getABI()599   virtual const char *getABI() const {
600     return "";
601   }
602 
603   /// \brief Get the C++ ABI currently in use.
getCXXABI()604   virtual TargetCXXABI getCXXABI() const {
605     return CXXABI;
606   }
607 
608   /// \brief Target the specified CPU.
609   ///
610   /// \return  False on error (invalid CPU name).
setCPU(const std::string & Name)611   virtual bool setCPU(const std::string &Name) {
612     return false;
613   }
614 
615   /// \brief Use the specified ABI.
616   ///
617   /// \return False on error (invalid ABI name).
setABI(const std::string & Name)618   virtual bool setABI(const std::string &Name) {
619     return false;
620   }
621 
622   /// \brief Use this specified C++ ABI.
623   ///
624   /// \return False on error (invalid C++ ABI name).
setCXXABI(const std::string & Name)625   bool setCXXABI(const std::string &Name) {
626     static const TargetCXXABI Unknown = static_cast<TargetCXXABI>(-1);
627     TargetCXXABI ABI = llvm::StringSwitch<TargetCXXABI>(Name)
628       .Case("arm", CXXABI_ARM)
629       .Case("itanium", CXXABI_Itanium)
630       .Case("microsoft", CXXABI_Microsoft)
631       .Default(Unknown);
632     if (ABI == Unknown) return false;
633     return setCXXABI(ABI);
634   }
635 
636   /// \brief Set the C++ ABI to be used by this implementation.
637   ///
638   /// \return False on error (ABI not valid on this target)
setCXXABI(TargetCXXABI ABI)639   virtual bool setCXXABI(TargetCXXABI ABI) {
640     CXXABI = ABI;
641     return true;
642   }
643 
644   /// \brief Enable or disable a specific target feature;
645   /// the feature name must be valid.
646   ///
647   /// \return False on error (invalid feature name).
setFeatureEnabled(llvm::StringMap<bool> & Features,StringRef Name,bool Enabled)648   virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
649                                  StringRef Name,
650                                  bool Enabled) const {
651     return false;
652   }
653 
654   /// \brief Perform initialization based on the user configured
655   /// set of features (e.g., +sse4).
656   ///
657   /// The list is guaranteed to have at most one entry per feature.
658   ///
659   /// The target may modify the features list, to change which options are
660   /// passed onwards to the backend.
HandleTargetFeatures(std::vector<std::string> & Features)661   virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
662   }
663 
664   /// \brief Determine whether the given target has the given feature.
hasFeature(StringRef Feature)665   virtual bool hasFeature(StringRef Feature) const {
666     return false;
667   }
668 
669   // \brief Returns maximal number of args passed in registers.
getRegParmMax()670   unsigned getRegParmMax() const {
671     assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
672     return RegParmMax;
673   }
674 
675   /// \brief Whether the target supports thread-local storage.
isTLSSupported()676   bool isTLSSupported() const {
677     return TLSSupported;
678   }
679 
680   /// \brief Return true if {|} are normal characters in the asm string.
681   ///
682   /// If this returns false (the default), then {abc|xyz} is syntax
683   /// that says that when compiling for asm variant #0, "abc" should be
684   /// generated, but when compiling for asm variant #1, "xyz" should be
685   /// generated.
hasNoAsmVariants()686   bool hasNoAsmVariants() const {
687     return NoAsmVariants;
688   }
689 
690   /// \brief Return the register number that __builtin_eh_return_regno would
691   /// return with the specified argument.
getEHDataRegisterNumber(unsigned RegNo)692   virtual int getEHDataRegisterNumber(unsigned RegNo) const {
693     return -1;
694   }
695 
696   /// \brief Return the section to use for C++ static initialization functions.
getStaticInitSectionSpecifier()697   virtual const char *getStaticInitSectionSpecifier() const {
698     return 0;
699   }
700 
getAddressSpaceMap()701   const LangAS::Map &getAddressSpaceMap() const {
702     return *AddrSpaceMap;
703   }
704 
705   /// \brief Retrieve the name of the platform as it is used in the
706   /// availability attribute.
getPlatformName()707   StringRef getPlatformName() const { return PlatformName; }
708 
709   /// \brief Retrieve the minimum desired version of the platform, to
710   /// which the program should be compiled.
getPlatformMinVersion()711   VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
712 
isBigEndian()713   bool isBigEndian() const { return BigEndian; }
714 
715 protected:
getPointerWidthV(unsigned AddrSpace)716   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
717     return PointerWidth;
718   }
getPointerAlignV(unsigned AddrSpace)719   virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
720     return PointerAlign;
721   }
getPtrDiffTypeV(unsigned AddrSpace)722   virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
723     return PtrDiffType;
724   }
725   virtual void getGCCRegNames(const char * const *&Names,
726                               unsigned &NumNames) const = 0;
727   virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
728                                 unsigned &NumAliases) const = 0;
getGCCAddlRegNames(const AddlRegName * & Addl,unsigned & NumAddl)729   virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
730 				  unsigned &NumAddl) const {
731     Addl = 0;
732     NumAddl = 0;
733   }
734   virtual bool validateAsmConstraint(const char *&Name,
735                                      TargetInfo::ConstraintInfo &info) const= 0;
736 };
737 
738 }  // end namespace clang
739 
740 #endif
741