TargetInfo.h revision 57016dda61498294120b1a881d9e6606337b29d9
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
33namespace llvm {
34struct fltSemantics;
35}
36
37namespace clang {
38class DiagnosticsEngine;
39class LangOptions;
40class MacroBuilder;
41class SourceLocation;
42class SourceManager;
43
44namespace Builtin { struct Info; }
45
46/// \brief The types of C++ ABIs for which we can generate code.
47enum 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///
64class TargetInfo : public RefCountedBase<TargetInfo> {
65  llvm::IntrusiveRefCntPtr<TargetOptions> TargetOpts;
66  llvm::Triple Triple;
67protected:
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
105public:
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
173protected:
174  IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
175          WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType;
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
202public:
203  IntType getSizeType() const { return SizeType; }
204  IntType getIntMaxType() const { return IntMaxType; }
205  IntType getUIntMaxType() const { return UIntMaxType; }
206  IntType getPtrDiffType(unsigned AddrSpace) const {
207    return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
208  }
209  IntType getIntPtrType() const { return IntPtrType; }
210  IntType getWCharType() const { return WCharType; }
211  IntType getWIntType() const { return WIntType; }
212  IntType getChar16Type() const { return Char16Type; }
213  IntType getChar32Type() const { return Char32Type; }
214  IntType getInt64Type() const { return Int64Type; }
215  IntType getSigAtomicType() const { return SigAtomicType; }
216
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.
233  uint64_t getPointerWidth(unsigned AddrSpace) const {
234    return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
235  }
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.
241  unsigned getBoolWidth() const { return BoolWidth; }
242
243  /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
244  unsigned getBoolAlign() const { return BoolAlign; }
245
246  unsigned getCharWidth() const { return 8; } // FIXME
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.
251  unsigned getShortWidth() const { return 16; } // FIXME
252
253  /// \brief Return the alignment of 'signed short' and 'unsigned short' for
254  /// this target.
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.
259  unsigned getIntWidth() const { return IntWidth; }
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.
264  unsigned getLongWidth() const { return LongWidth; }
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.
269  unsigned getLongLongWidth() const { return LongLongWidth; }
270  unsigned getLongLongAlign() const { return LongLongAlign; }
271
272  /// \brief Return the alignment that is suitable for storing any
273  /// object with a fundamental alignment requirement.
274  unsigned getSuitableAlign() const { return SuitableAlign; }
275
276  /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
277  /// bits.
278  unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
279  unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
280
281  /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
282  /// bits.
283  unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
284  unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
285
286  /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
287  /// bits.
288  unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
289  unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
290
291  /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
292  unsigned getHalfWidth() const { return HalfWidth; }
293  unsigned getHalfAlign() const { return HalfAlign; }
294  const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
295
296  /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
297  unsigned getFloatWidth() const { return FloatWidth; }
298  unsigned getFloatAlign() const { return FloatAlign; }
299  const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
300
301  /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
302  unsigned getDoubleWidth() const { return DoubleWidth; }
303  unsigned getDoubleAlign() const { return DoubleAlign; }
304  const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
305
306  /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
307  /// double'.
308  unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
309  unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
310  const llvm::fltSemantics &getLongDoubleFormat() const {
311    return *LongDoubleFormat;
312  }
313
314  /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
315  virtual unsigned getFloatEvalMethod() const { return 0; }
316
317  // getLargeArrayMinWidth/Align - Return the minimum array size that is
318  // 'large' and its alignment.
319  unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
320  unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
321
322  /// \brief Return the maximum width lock-free atomic operation which will
323  /// ever be supported for the given target
324  unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
325  /// \brief Return the maximum width lock-free atomic operation which can be
326  /// inlined given the supported features of the given target.
327  unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
328
329  /// \brief Return the maximum vector alignment supported for the given target.
330  unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
331
332  /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
333  unsigned getIntMaxTWidth() const {
334    return getTypeWidth(IntMaxType);
335  }
336
337  /// \brief Return the "preferred" register width on this target.
338  uint64_t getRegisterWidth() const {
339    // Currently we assume the register width on the target matches the pointer
340    // width, we can introduce a new variable for this if/when some target wants
341    // it.
342    return LongWidth;
343  }
344
345  /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
346  /// which is the prefix given to user symbols by default.
347  ///
348  /// On most platforms this is "_", but it is "" on some, and "." on others.
349  const char *getUserLabelPrefix() const {
350    return UserLabelPrefix;
351  }
352
353  /// \brief Returns the name of the mcount instrumentation function.
354  const char *getMCountName() const {
355    return MCountName;
356  }
357
358  /// \brief Check if the Objective-C built-in boolean type should be signed
359  /// char.
360  ///
361  /// Otherwise, if this returns false, the normal built-in boolean type
362  /// should also be used for Objective-C.
363  bool useSignedCharForObjCBool() const {
364    return UseSignedCharForObjCBool;
365  }
366  void noSignedCharForObjCBool() {
367    UseSignedCharForObjCBool = false;
368  }
369
370  /// \brief Check whether the alignment of bit-field types is respected
371  /// when laying out structures.
372  bool useBitFieldTypeAlignment() const {
373    return UseBitFieldTypeAlignment;
374  }
375
376  /// \brief Check whether zero length bitfields should force alignment of
377  /// the next member.
378  bool useZeroLengthBitfieldAlignment() const {
379    return UseZeroLengthBitfieldAlignment;
380  }
381
382  /// \brief Get the fixed alignment value in bits for a member that follows
383  /// a zero length bitfield.
384  unsigned getZeroLengthBitfieldBoundary() const {
385    return ZeroLengthBitfieldBoundary;
386  }
387
388  /// \brief Check whether this target support '\#pragma options align=mac68k'.
389  bool hasAlignMac68kSupport() const {
390    return HasAlignMac68kSupport;
391  }
392
393  /// \brief Return the user string for the specified integer type enum.
394  ///
395  /// For example, SignedShort -> "short".
396  static const char *getTypeName(IntType T);
397
398  /// \brief Return the constant suffix for the specified integer type enum.
399  ///
400  /// For example, SignedLong -> "L".
401  static const char *getTypeConstantSuffix(IntType T);
402
403  /// \brief Check whether the given real type should use the "fpret" flavor of
404  /// Objective-C message passing on this target.
405  bool useObjCFPRetForRealType(RealType T) const {
406    return RealTypeUsesObjCFPRet & (1 << T);
407  }
408
409  /// \brief Check whether _Complex long double should use the "fp2ret" flavor
410  /// of Objective-C message passing on this target.
411  bool useObjCFP2RetForComplexLongDouble() const {
412    return ComplexLongDoubleUsesFP2Ret;
413  }
414
415  ///===---- Other target property query methods --------------------------===//
416
417  /// \brief Appends the target-specific \#define values for this
418  /// target set to the specified buffer.
419  virtual void getTargetDefines(const LangOptions &Opts,
420                                MacroBuilder &Builder) const = 0;
421
422
423  /// Return information about target-specific builtins for
424  /// the current primary target, and info about which builtins are non-portable
425  /// across the current set of primary and secondary targets.
426  virtual void getTargetBuiltins(const Builtin::Info *&Records,
427                                 unsigned &NumRecords) const = 0;
428
429  /// The __builtin_clz* and __builtin_ctz* built-in
430  /// functions are specified to have undefined results for zero inputs, but
431  /// on targets that support these operations in a way that provides
432  /// well-defined results for zero without loss of performance, it is a good
433  /// idea to avoid optimizing based on that undef behavior.
434  virtual bool isCLZForZeroUndef() const { return true; }
435
436  /// \brief Returns the kind of __builtin_va_list type that should be used
437  /// with this target.
438  virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
439
440  /// \brief Returns whether the passed in string is a valid clobber in an
441  /// inline asm statement.
442  ///
443  /// This is used by Sema.
444  bool isValidClobber(StringRef Name) const;
445
446  /// \brief Returns whether the passed in string is a valid register name
447  /// according to GCC.
448  ///
449  /// This is used by Sema for inline asm statements.
450  bool isValidGCCRegisterName(StringRef Name) const;
451
452  /// \brief Returns the "normalized" GCC register name.
453  ///
454  /// For example, on x86 it will return "ax" when "eax" is passed in.
455  StringRef getNormalizedGCCRegisterName(StringRef Name) const;
456
457  struct ConstraintInfo {
458    enum {
459      CI_None = 0x00,
460      CI_AllowsMemory = 0x01,
461      CI_AllowsRegister = 0x02,
462      CI_ReadWrite = 0x04,       // "+r" output constraint (read and write).
463      CI_HasMatchingInput = 0x08 // This output operand has a matching input.
464    };
465    unsigned Flags;
466    int TiedOperand;
467
468    std::string ConstraintStr;  // constraint: "=rm"
469    std::string Name;           // Operand name: [foo] with no []'s.
470  public:
471    ConstraintInfo(StringRef ConstraintStr, StringRef Name)
472      : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
473      Name(Name.str()) {}
474
475    const std::string &getConstraintStr() const { return ConstraintStr; }
476    const std::string &getName() const { return Name; }
477    bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
478    bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
479    bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
480
481    /// \brief Return true if this output operand has a matching
482    /// (tied) input operand.
483    bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
484
485    /// \brief Return true if this input operand is a matching
486    /// constraint that ties it to an output operand.
487    ///
488    /// If this returns true then getTiedOperand will indicate which output
489    /// operand this is tied to.
490    bool hasTiedOperand() const { return TiedOperand != -1; }
491    unsigned getTiedOperand() const {
492      assert(hasTiedOperand() && "Has no tied operand!");
493      return (unsigned)TiedOperand;
494    }
495
496    void setIsReadWrite() { Flags |= CI_ReadWrite; }
497    void setAllowsMemory() { Flags |= CI_AllowsMemory; }
498    void setAllowsRegister() { Flags |= CI_AllowsRegister; }
499    void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
500
501    /// \brief Indicate that this is an input operand that is tied to
502    /// the specified output operand.
503    ///
504    /// Copy over the various constraint information from the output.
505    void setTiedOperand(unsigned N, ConstraintInfo &Output) {
506      Output.setHasMatchingInput();
507      Flags = Output.Flags;
508      TiedOperand = N;
509      // Don't copy Name or constraint string.
510    }
511  };
512
513  // validateOutputConstraint, validateInputConstraint - Checks that
514  // a constraint is valid and provides information about it.
515  // FIXME: These should return a real error instead of just true/false.
516  bool validateOutputConstraint(ConstraintInfo &Info) const;
517  bool validateInputConstraint(ConstraintInfo *OutputConstraints,
518                               unsigned NumOutputs,
519                               ConstraintInfo &info) const;
520  bool resolveSymbolicName(const char *&Name,
521                           ConstraintInfo *OutputConstraints,
522                           unsigned NumOutputs, unsigned &Index) const;
523
524  // Constraint parm will be left pointing at the last character of
525  // the constraint.  In practice, it won't be changed unless the
526  // constraint is longer than one character.
527  virtual std::string convertConstraint(const char *&Constraint) const {
528    // 'p' defaults to 'r', but can be overridden by targets.
529    if (*Constraint == 'p')
530      return std::string("r");
531    return std::string(1, *Constraint);
532  }
533
534  /// \brief Returns a string of target-specific clobbers, in LLVM format.
535  virtual const char *getClobbers() const = 0;
536
537
538  /// \brief Returns the target triple of the primary target.
539  const llvm::Triple &getTriple() const {
540    return Triple;
541  }
542
543  const char *getTargetDescription() const {
544    return DescriptionString;
545  }
546
547  struct GCCRegAlias {
548    const char * const Aliases[5];
549    const char * const Register;
550  };
551
552  struct AddlRegName {
553    const char * const Names[5];
554    const unsigned RegNum;
555  };
556
557  /// \brief Does this target support "protected" visibility?
558  ///
559  /// Any target which dynamic libraries will naturally support
560  /// something like "default" (meaning that the symbol is visible
561  /// outside this shared object) and "hidden" (meaning that it isn't)
562  /// visibilities, but "protected" is really an ELF-specific concept
563  /// with weird semantics designed around the convenience of dynamic
564  /// linker implementations.  Which is not to suggest that there's
565  /// consistent target-independent semantics for "default" visibility
566  /// either; the entire thing is pretty badly mangled.
567  virtual bool hasProtectedVisibility() const { return true; }
568
569  virtual bool useGlobalsForAutomaticVariables() const { return false; }
570
571  /// \brief Return the section to use for CFString literals, or 0 if no
572  /// special section is used.
573  virtual const char *getCFStringSection() const {
574    return "__DATA,__cfstring";
575  }
576
577  /// \brief Return the section to use for NSString literals, or 0 if no
578  /// special section is used.
579  virtual const char *getNSStringSection() const {
580    return "__OBJC,__cstring_object,regular,no_dead_strip";
581  }
582
583  /// \brief Return the section to use for NSString literals, or 0 if no
584  /// special section is used (NonFragile ABI).
585  virtual const char *getNSStringNonFragileABISection() const {
586    return "__DATA, __objc_stringobj, regular, no_dead_strip";
587  }
588
589  /// \brief An optional hook that targets can implement to perform semantic
590  /// checking on attribute((section("foo"))) specifiers.
591  ///
592  /// In this case, "foo" is passed in to be checked.  If the section
593  /// specifier is invalid, the backend should return a non-empty string
594  /// that indicates the problem.
595  ///
596  /// This hook is a simple quality of implementation feature to catch errors
597  /// and give good diagnostics in cases when the assembler or code generator
598  /// would otherwise reject the section specifier.
599  ///
600  virtual std::string isValidSectionSpecifier(StringRef SR) const {
601    return "";
602  }
603
604  /// \brief Set forced language options.
605  ///
606  /// Apply changes to the target information with respect to certain
607  /// language options which change the target configuration.
608  virtual void setForcedLangOptions(LangOptions &Opts);
609
610  /// \brief Get the default set of target features for the CPU;
611  /// this should include all legal feature strings on the target.
612  virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
613  }
614
615  /// \brief Get the ABI currently in use.
616  virtual const char *getABI() const {
617    return "";
618  }
619
620  /// \brief Get the C++ ABI currently in use.
621  virtual TargetCXXABI getCXXABI() const {
622    return CXXABI;
623  }
624
625  /// \brief Target the specified CPU.
626  ///
627  /// \return  False on error (invalid CPU name).
628  virtual bool setCPU(const std::string &Name) {
629    return false;
630  }
631
632  /// \brief Use the specified ABI.
633  ///
634  /// \return False on error (invalid ABI name).
635  virtual bool setABI(const std::string &Name) {
636    return false;
637  }
638
639  /// \brief Use this specified C++ ABI.
640  ///
641  /// \return False on error (invalid C++ ABI name).
642  bool setCXXABI(const std::string &Name) {
643    static const TargetCXXABI Unknown = static_cast<TargetCXXABI>(-1);
644    TargetCXXABI ABI = llvm::StringSwitch<TargetCXXABI>(Name)
645      .Case("arm", CXXABI_ARM)
646      .Case("itanium", CXXABI_Itanium)
647      .Case("microsoft", CXXABI_Microsoft)
648      .Default(Unknown);
649    if (ABI == Unknown) return false;
650    return setCXXABI(ABI);
651  }
652
653  /// \brief Set the C++ ABI to be used by this implementation.
654  ///
655  /// \return False on error (ABI not valid on this target)
656  virtual bool setCXXABI(TargetCXXABI ABI) {
657    CXXABI = ABI;
658    return true;
659  }
660
661  /// \brief Enable or disable a specific target feature;
662  /// the feature name must be valid.
663  ///
664  /// \return False on error (invalid feature name).
665  virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
666                                 StringRef Name,
667                                 bool Enabled) const {
668    return false;
669  }
670
671  /// \brief Perform initialization based on the user configured
672  /// set of features (e.g., +sse4).
673  ///
674  /// The list is guaranteed to have at most one entry per feature.
675  ///
676  /// The target may modify the features list, to change which options are
677  /// passed onwards to the backend.
678  virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
679  }
680
681  /// \brief Determine whether the given target has the given feature.
682  virtual bool hasFeature(StringRef Feature) const {
683    return false;
684  }
685
686  // \brief Returns maximal number of args passed in registers.
687  unsigned getRegParmMax() const {
688    assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
689    return RegParmMax;
690  }
691
692  /// \brief Whether the target supports thread-local storage.
693  bool isTLSSupported() const {
694    return TLSSupported;
695  }
696
697  /// \brief Return true if {|} are normal characters in the asm string.
698  ///
699  /// If this returns false (the default), then {abc|xyz} is syntax
700  /// that says that when compiling for asm variant #0, "abc" should be
701  /// generated, but when compiling for asm variant #1, "xyz" should be
702  /// generated.
703  bool hasNoAsmVariants() const {
704    return NoAsmVariants;
705  }
706
707  /// \brief Return the register number that __builtin_eh_return_regno would
708  /// return with the specified argument.
709  virtual int getEHDataRegisterNumber(unsigned RegNo) const {
710    return -1;
711  }
712
713  /// \brief Return the section to use for C++ static initialization functions.
714  virtual const char *getStaticInitSectionSpecifier() const {
715    return 0;
716  }
717
718  const LangAS::Map &getAddressSpaceMap() const {
719    return *AddrSpaceMap;
720  }
721
722  /// \brief Retrieve the name of the platform as it is used in the
723  /// availability attribute.
724  StringRef getPlatformName() const { return PlatformName; }
725
726  /// \brief Retrieve the minimum desired version of the platform, to
727  /// which the program should be compiled.
728  VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
729
730  bool isBigEndian() const { return BigEndian; }
731
732  /// \brief Gets the default calling convention for the given target and
733  /// declaration context.
734  virtual CallingConv getDefaultCallingConv() const {
735    // Not all targets will specify an explicit calling convention that we can
736    // express.  This will always do the right thing, even though it's not
737    // an explicit calling convention.
738    return CC_Default;
739  }
740
741  enum CallingConvCheckResult {
742    CCCR_OK,
743    CCCR_Warning
744  };
745
746  /// \brief Determines whether a given calling convention is valid for the
747  /// target. A calling convention can either be accepted, produce a warning
748  /// and be substituted with the default calling convention, or (someday)
749  /// produce an error (such as using thiscall on a non-instance function).
750  virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
751    switch (CC) {
752      default:
753        return CCCR_Warning;
754      case CC_C:
755      case CC_Default:
756        return CCCR_OK;
757    }
758  }
759
760protected:
761  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
762    return PointerWidth;
763  }
764  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
765    return PointerAlign;
766  }
767  virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
768    return PtrDiffType;
769  }
770  virtual void getGCCRegNames(const char * const *&Names,
771                              unsigned &NumNames) const = 0;
772  virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
773                                unsigned &NumAliases) const = 0;
774  virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
775				  unsigned &NumAddl) const {
776    Addl = 0;
777    NumAddl = 0;
778  }
779  virtual bool validateAsmConstraint(const char *&Name,
780                                     TargetInfo::ConstraintInfo &info) const= 0;
781};
782
783}  // end namespace clang
784
785#endif
786