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