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