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