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