1193326Sed//===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9239462Sdim///
10239462Sdim/// \file
11239462Sdim/// \brief Defines the clang::TargetInfo interface.
12239462Sdim///
13193326Sed//===----------------------------------------------------------------------===//
14193326Sed
15193326Sed#ifndef LLVM_CLANG_BASIC_TARGETINFO_H
16193326Sed#define LLVM_CLANG_BASIC_TARGETINFO_H
17193326Sed
18249423Sdim#include "clang/Basic/AddressSpaces.h"
19249423Sdim#include "clang/Basic/TargetCXXABI.h"
20226633Sdim#include "clang/Basic/LLVM.h"
21249423Sdim#include "clang/Basic/Specifiers.h"
22249423Sdim#include "clang/Basic/TargetOptions.h"
23249423Sdim#include "clang/Basic/VersionTuple.h"
24221345Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h"
25193326Sed#include "llvm/ADT/StringMap.h"
26221345Sdim#include "llvm/ADT/StringRef.h"
27212904Sdim#include "llvm/ADT/StringSwitch.h"
28198092Srdivacky#include "llvm/ADT/Triple.h"
29218893Sdim#include "llvm/Support/DataTypes.h"
30193326Sed#include <cassert>
31249423Sdim#include <string>
32193326Sed#include <vector>
33193326Sed
34198092Srdivackynamespace llvm {
35198092Srdivackystruct fltSemantics;
36198092Srdivacky}
37193326Sed
38193326Sednamespace clang {
39226633Sdimclass DiagnosticsEngine;
40199482Srdivackyclass LangOptions;
41202379Srdivackyclass MacroBuilder;
42198092Srdivackyclass SourceLocation;
43193326Sedclass SourceManager;
44199482Srdivacky
45193326Sednamespace Builtin { struct Info; }
46198092Srdivacky
47239462Sdim/// \brief Exposes information about the current target.
48193326Sed///
49234353Sdimclass TargetInfo : public RefCountedBase<TargetInfo> {
50249423Sdim  IntrusiveRefCntPtr<TargetOptions> TargetOpts;
51198092Srdivacky  llvm::Triple Triple;
52193326Sedprotected:
53193326Sed  // Target values set by the ctor of the actual target implementation.  Default
54193326Sed  // values are specified by the TargetInfo constructor.
55234353Sdim  bool BigEndian;
56193326Sed  bool TLSSupported;
57207619Srdivacky  bool NoAsmVariants;  // True if {|} are normal characters.
58193326Sed  unsigned char PointerWidth, PointerAlign;
59218893Sdim  unsigned char BoolWidth, BoolAlign;
60193326Sed  unsigned char IntWidth, IntAlign;
61226633Sdim  unsigned char HalfWidth, HalfAlign;
62193326Sed  unsigned char FloatWidth, FloatAlign;
63193326Sed  unsigned char DoubleWidth, DoubleAlign;
64193326Sed  unsigned char LongDoubleWidth, LongDoubleAlign;
65210299Sed  unsigned char LargeArrayMinWidth, LargeArrayAlign;
66193326Sed  unsigned char LongWidth, LongAlign;
67193326Sed  unsigned char LongLongWidth, LongLongAlign;
68234353Sdim  unsigned char SuitableAlign;
69251662Sdim  unsigned char MinGlobalAlign;
70226633Sdim  unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
71239462Sdim  unsigned short MaxVectorAlign;
72193326Sed  const char *DescriptionString;
73193326Sed  const char *UserLabelPrefix;
74218893Sdim  const char *MCountName;
75226633Sdim  const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
76226633Sdim    *LongDoubleFormat;
77193326Sed  unsigned char RegParmMax, SSERegParmMax;
78249423Sdim  TargetCXXABI TheCXXABI;
79221345Sdim  const LangAS::Map *AddrSpaceMap;
80193326Sed
81226633Sdim  mutable StringRef PlatformName;
82221345Sdim  mutable VersionTuple PlatformMinVersion;
83221345Sdim
84208600Srdivacky  unsigned HasAlignMac68kSupport : 1;
85210299Sed  unsigned RealTypeUsesObjCFPRet : 3;
86234353Sdim  unsigned ComplexLongDoubleUsesFP2Ret : 1;
87208600Srdivacky
88193326Sed  // TargetInfo Constructor.  Default initializes all fields.
89263508Sdim  TargetInfo(const llvm::Triple &T);
90198092Srdivacky
91198092Srdivackypublic:
92239462Sdim  /// \brief Construct a target for the given options.
93201361Srdivacky  ///
94201361Srdivacky  /// \param Opts - The options to use to initialize the target. The target may
95201361Srdivacky  /// modify the options to canonicalize the target feature information to match
96201361Srdivacky  /// what the backend expects.
97226633Sdim  static TargetInfo* CreateTargetInfo(DiagnosticsEngine &Diags,
98249423Sdim                                      TargetOptions *Opts);
99193326Sed
100193326Sed  virtual ~TargetInfo();
101193326Sed
102243830Sdim  /// \brief Retrieve the target options.
103243830Sdim  TargetOptions &getTargetOpts() const {
104243830Sdim    assert(TargetOpts && "Missing target options");
105243830Sdim    return *TargetOpts;
106243830Sdim  }
107243830Sdim
108249423Sdim  void setTargetOpts(TargetOptions *TargetOpts) {
109249423Sdim    this->TargetOpts = TargetOpts;
110243830Sdim  }
111243830Sdim
112193326Sed  ///===---- Target Data Type Query Methods -------------------------------===//
113193326Sed  enum IntType {
114193326Sed    NoInt = 0,
115263508Sdim    SignedChar,
116263508Sdim    UnsignedChar,
117193326Sed    SignedShort,
118193326Sed    UnsignedShort,
119193326Sed    SignedInt,
120193326Sed    UnsignedInt,
121193326Sed    SignedLong,
122193326Sed    UnsignedLong,
123193326Sed    SignedLongLong,
124193326Sed    UnsignedLongLong
125193326Sed  };
126210299Sed
127210299Sed  enum RealType {
128263508Sdim    NoFloat = 255,
129210299Sed    Float = 0,
130210299Sed    Double,
131210299Sed    LongDouble
132210299Sed  };
133210299Sed
134239462Sdim  /// \brief The different kinds of __builtin_va_list types defined by
135239462Sdim  /// the target implementation.
136239462Sdim  enum BuiltinVaListKind {
137239462Sdim    /// typedef char* __builtin_va_list;
138239462Sdim    CharPtrBuiltinVaList = 0,
139239462Sdim
140239462Sdim    /// typedef void* __builtin_va_list;
141239462Sdim    VoidPtrBuiltinVaList,
142239462Sdim
143249423Sdim    /// __builtin_va_list as defind by the AArch64 ABI
144249423Sdim    /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
145249423Sdim    AArch64ABIBuiltinVaList,
146249423Sdim
147239462Sdim    /// __builtin_va_list as defined by the PNaCl ABI:
148239462Sdim    /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
149239462Sdim    PNaClABIBuiltinVaList,
150239462Sdim
151239462Sdim    /// __builtin_va_list as defined by the Power ABI:
152239462Sdim    /// https://www.power.org
153239462Sdim    ///        /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
154239462Sdim    PowerABIBuiltinVaList,
155239462Sdim
156239462Sdim    /// __builtin_va_list as defined by the x86-64 ABI:
157239462Sdim    /// http://www.x86-64.org/documentation/abi.pdf
158243830Sdim    X86_64ABIBuiltinVaList,
159243830Sdim
160243830Sdim    /// __builtin_va_list as defined by ARM AAPCS ABI
161243830Sdim    /// http://infocenter.arm.com
162243830Sdim    //        /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
163251662Sdim    AAPCSABIBuiltinVaList,
164251662Sdim
165251662Sdim    // typedef struct __va_list_tag
166251662Sdim    //   {
167251662Sdim    //     long __gpr;
168251662Sdim    //     long __fpr;
169251662Sdim    //     void *__overflow_arg_area;
170251662Sdim    //     void *__reg_save_area;
171251662Sdim    //   } va_list[1];
172251662Sdim    SystemZBuiltinVaList
173239462Sdim  };
174239462Sdim
175193326Sedprotected:
176195341Sed  IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
177243830Sdim          WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
178243830Sdim          ProcessIDType;
179207619Srdivacky
180239462Sdim  /// \brief Whether Objective-C's built-in boolean type should be signed char.
181239462Sdim  ///
182234982Sdim  /// Otherwise, when this flag is not set, the normal built-in boolean type is
183234982Sdim  /// used.
184234982Sdim  unsigned UseSignedCharForObjCBool : 1;
185234982Sdim
186207619Srdivacky  /// Control whether the alignment of bit-field types is respected when laying
187207619Srdivacky  /// out structures. If true, then the alignment of the bit-field type will be
188207619Srdivacky  /// used to (a) impact the alignment of the containing structure, and (b)
189207619Srdivacky  /// ensure that the individual bit-field will not straddle an alignment
190207619Srdivacky  /// boundary.
191207619Srdivacky  unsigned UseBitFieldTypeAlignment : 1;
192207619Srdivacky
193239462Sdim  /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
194239462Sdim  /// the next bitfield.
195239462Sdim  ///
196239462Sdim  /// If the alignment of the zero length bitfield is greater than the member
197239462Sdim  /// that follows it, `bar', `bar' will be aligned as the type of the
198239462Sdim  /// zero-length bitfield.
199226633Sdim  unsigned UseZeroLengthBitfieldAlignment : 1;
200226633Sdim
201226633Sdim  /// If non-zero, specifies a fixed alignment value for bitfields that follow
202226633Sdim  /// zero length bitfield, regardless of the zero length bitfield type.
203226633Sdim  unsigned ZeroLengthBitfieldBoundary;
204226633Sdim
205263508Sdim  /// \brief Specify if mangling based on address space map should be used or
206263508Sdim  /// not for language specific address spaces
207263508Sdim  bool UseAddrSpaceMapMangling;
208263508Sdim
209193326Sedpublic:
210193326Sed  IntType getSizeType() const { return SizeType; }
211193326Sed  IntType getIntMaxType() const { return IntMaxType; }
212193326Sed  IntType getUIntMaxType() const { return UIntMaxType; }
213193326Sed  IntType getPtrDiffType(unsigned AddrSpace) const {
214193326Sed    return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
215193326Sed  }
216193326Sed  IntType getIntPtrType() const { return IntPtrType; }
217193326Sed  IntType getWCharType() const { return WCharType; }
218198398Srdivacky  IntType getWIntType() const { return WIntType; }
219198092Srdivacky  IntType getChar16Type() const { return Char16Type; }
220198092Srdivacky  IntType getChar32Type() const { return Char32Type; }
221195341Sed  IntType getInt64Type() const { return Int64Type; }
222199990Srdivacky  IntType getSigAtomicType() const { return SigAtomicType; }
223243830Sdim  IntType getProcessIDType() const { return ProcessIDType; }
224193326Sed
225239462Sdim  /// \brief Return the width (in bits) of the specified integer type enum.
226239462Sdim  ///
227239462Sdim  /// For example, SignedInt -> getIntWidth().
228198398Srdivacky  unsigned getTypeWidth(IntType T) const;
229198398Srdivacky
230263508Sdim  /// \brief Return integer type with specified width.
231263508Sdim  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
232263508Sdim
233263508Sdim  /// \brief Return floating point type with specified width.
234263508Sdim  RealType getRealTypeByWidth(unsigned BitWidth) const;
235263508Sdim
236239462Sdim  /// \brief Return the alignment (in bits) of the specified integer type enum.
237239462Sdim  ///
238239462Sdim  /// For example, SignedInt -> getIntAlign().
239199482Srdivacky  unsigned getTypeAlign(IntType T) const;
240199482Srdivacky
241239462Sdim  /// \brief Returns true if the type is signed; false otherwise.
242218893Sdim  static bool isTypeSigned(IntType T);
243198398Srdivacky
244239462Sdim  /// \brief Return the width of pointers on this target, for the
245193326Sed  /// specified address space.
246193326Sed  uint64_t getPointerWidth(unsigned AddrSpace) const {
247193326Sed    return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
248193326Sed  }
249193326Sed  uint64_t getPointerAlign(unsigned AddrSpace) const {
250193326Sed    return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
251193326Sed  }
252198092Srdivacky
253239462Sdim  /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
254218893Sdim  unsigned getBoolWidth() const { return BoolWidth; }
255239462Sdim
256239462Sdim  /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
257218893Sdim  unsigned getBoolAlign() const { return BoolAlign; }
258198092Srdivacky
259198092Srdivacky  unsigned getCharWidth() const { return 8; } // FIXME
260198092Srdivacky  unsigned getCharAlign() const { return 8; } // FIXME
261198092Srdivacky
262239462Sdim  /// \brief Return the size of 'signed short' and 'unsigned short' for this
263239462Sdim  /// target, in bits.
264193326Sed  unsigned getShortWidth() const { return 16; } // FIXME
265239462Sdim
266239462Sdim  /// \brief Return the alignment of 'signed short' and 'unsigned short' for
267239462Sdim  /// this target.
268193326Sed  unsigned getShortAlign() const { return 16; } // FIXME
269198092Srdivacky
270193326Sed  /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
271193326Sed  /// this target, in bits.
272193326Sed  unsigned getIntWidth() const { return IntWidth; }
273193326Sed  unsigned getIntAlign() const { return IntAlign; }
274198092Srdivacky
275193326Sed  /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
276193326Sed  /// for this target, in bits.
277193326Sed  unsigned getLongWidth() const { return LongWidth; }
278193326Sed  unsigned getLongAlign() const { return LongAlign; }
279198092Srdivacky
280193326Sed  /// getLongLongWidth/Align - Return the size of 'signed long long' and
281193326Sed  /// 'unsigned long long' for this target, in bits.
282193326Sed  unsigned getLongLongWidth() const { return LongLongWidth; }
283193326Sed  unsigned getLongLongAlign() const { return LongLongAlign; }
284198092Srdivacky
285249423Sdim  /// \brief Determine whether the __int128 type is supported on this target.
286249423Sdim  bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME
287249423Sdim
288239462Sdim  /// \brief Return the alignment that is suitable for storing any
289234353Sdim  /// object with a fundamental alignment requirement.
290234353Sdim  unsigned getSuitableAlign() const { return SuitableAlign; }
291234353Sdim
292251662Sdim  /// getMinGlobalAlign - Return the minimum alignment of a global variable,
293251662Sdim  /// unless its alignment is explicitly reduced via attributes.
294251662Sdim  unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
295251662Sdim
296198092Srdivacky  /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
297193326Sed  /// bits.
298199482Srdivacky  unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
299199482Srdivacky  unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
300193326Sed
301198092Srdivacky  /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
302198092Srdivacky  /// bits.
303199482Srdivacky  unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
304199482Srdivacky  unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
305198092Srdivacky
306198092Srdivacky  /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
307198092Srdivacky  /// bits.
308199482Srdivacky  unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
309199482Srdivacky  unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
310198092Srdivacky
311226633Sdim  /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
312226633Sdim  unsigned getHalfWidth() const { return HalfWidth; }
313226633Sdim  unsigned getHalfAlign() const { return HalfAlign; }
314226633Sdim  const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
315226633Sdim
316193326Sed  /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
317193326Sed  unsigned getFloatWidth() const { return FloatWidth; }
318193326Sed  unsigned getFloatAlign() const { return FloatAlign; }
319193326Sed  const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
320193326Sed
321193326Sed  /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
322193326Sed  unsigned getDoubleWidth() const { return DoubleWidth; }
323193326Sed  unsigned getDoubleAlign() const { return DoubleAlign; }
324193326Sed  const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
325193326Sed
326193326Sed  /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
327193326Sed  /// double'.
328193326Sed  unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
329193326Sed  unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
330193326Sed  const llvm::fltSemantics &getLongDoubleFormat() const {
331193326Sed    return *LongDoubleFormat;
332193326Sed  }
333198092Srdivacky
334239462Sdim  /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
335234353Sdim  virtual unsigned getFloatEvalMethod() const { return 0; }
336234353Sdim
337210299Sed  // getLargeArrayMinWidth/Align - Return the minimum array size that is
338210299Sed  // 'large' and its alignment.
339210299Sed  unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
340210299Sed  unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
341210299Sed
342239462Sdim  /// \brief Return the maximum width lock-free atomic operation which will
343239462Sdim  /// ever be supported for the given target
344226633Sdim  unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
345239462Sdim  /// \brief Return the maximum width lock-free atomic operation which can be
346239462Sdim  /// inlined given the supported features of the given target.
347226633Sdim  unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
348226633Sdim
349239462Sdim  /// \brief Return the maximum vector alignment supported for the given target.
350239462Sdim  unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
351239462Sdim
352239462Sdim  /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
353193326Sed  unsigned getIntMaxTWidth() const {
354199482Srdivacky    return getTypeWidth(IntMaxType);
355193326Sed  }
356198092Srdivacky
357249423Sdim  // Return the size of unwind_word for this target.
358249423Sdim  unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
359249423Sdim
360239462Sdim  /// \brief Return the "preferred" register width on this target.
361263508Sdim  unsigned getRegisterWidth() const {
362224145Sdim    // Currently we assume the register width on the target matches the pointer
363224145Sdim    // width, we can introduce a new variable for this if/when some target wants
364224145Sdim    // it.
365263508Sdim    return PointerWidth;
366224145Sdim  }
367224145Sdim
368239462Sdim  /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
369239462Sdim  /// which is the prefix given to user symbols by default.
370239462Sdim  ///
371239462Sdim  /// On most platforms this is "_", but it is "" on some, and "." on others.
372193326Sed  const char *getUserLabelPrefix() const {
373193326Sed    return UserLabelPrefix;
374193326Sed  }
375198092Srdivacky
376239462Sdim  /// \brief Returns the name of the mcount instrumentation function.
377218893Sdim  const char *getMCountName() const {
378218893Sdim    return MCountName;
379218893Sdim  }
380218893Sdim
381239462Sdim  /// \brief Check if the Objective-C built-in boolean type should be signed
382239462Sdim  /// char.
383239462Sdim  ///
384239462Sdim  /// Otherwise, if this returns false, the normal built-in boolean type
385239462Sdim  /// should also be used for Objective-C.
386234982Sdim  bool useSignedCharForObjCBool() const {
387234982Sdim    return UseSignedCharForObjCBool;
388234982Sdim  }
389234982Sdim  void noSignedCharForObjCBool() {
390234982Sdim    UseSignedCharForObjCBool = false;
391234982Sdim  }
392234982Sdim
393239462Sdim  /// \brief Check whether the alignment of bit-field types is respected
394239462Sdim  /// when laying out structures.
395207619Srdivacky  bool useBitFieldTypeAlignment() const {
396207619Srdivacky    return UseBitFieldTypeAlignment;
397207619Srdivacky  }
398207619Srdivacky
399239462Sdim  /// \brief Check whether zero length bitfields should force alignment of
400239462Sdim  /// the next member.
401226633Sdim  bool useZeroLengthBitfieldAlignment() const {
402226633Sdim    return UseZeroLengthBitfieldAlignment;
403226633Sdim  }
404226633Sdim
405239462Sdim  /// \brief Get the fixed alignment value in bits for a member that follows
406239462Sdim  /// a zero length bitfield.
407226633Sdim  unsigned getZeroLengthBitfieldBoundary() const {
408226633Sdim    return ZeroLengthBitfieldBoundary;
409226633Sdim  }
410226633Sdim
411239462Sdim  /// \brief Check whether this target support '\#pragma options align=mac68k'.
412208600Srdivacky  bool hasAlignMac68kSupport() const {
413208600Srdivacky    return HasAlignMac68kSupport;
414208600Srdivacky  }
415208600Srdivacky
416239462Sdim  /// \brief Return the user string for the specified integer type enum.
417239462Sdim  ///
418193326Sed  /// For example, SignedShort -> "short".
419193326Sed  static const char *getTypeName(IntType T);
420198092Srdivacky
421239462Sdim  /// \brief Return the constant suffix for the specified integer type enum.
422239462Sdim  ///
423239462Sdim  /// For example, SignedLong -> "L".
424198398Srdivacky  static const char *getTypeConstantSuffix(IntType T);
425198398Srdivacky
426210299Sed  /// \brief Check whether the given real type should use the "fpret" flavor of
427239462Sdim  /// Objective-C message passing on this target.
428210299Sed  bool useObjCFPRetForRealType(RealType T) const {
429210299Sed    return RealTypeUsesObjCFPRet & (1 << T);
430210299Sed  }
431210299Sed
432234353Sdim  /// \brief Check whether _Complex long double should use the "fp2ret" flavor
433239462Sdim  /// of Objective-C message passing on this target.
434234353Sdim  bool useObjCFP2RetForComplexLongDouble() const {
435234353Sdim    return ComplexLongDoubleUsesFP2Ret;
436234353Sdim  }
437234353Sdim
438263508Sdim  /// \brief Specify if mangling based on address space map should be used or
439263508Sdim  /// not for language specific address spaces
440263508Sdim  bool useAddressSpaceMapMangling() const {
441263508Sdim    return UseAddrSpaceMapMangling;
442263508Sdim  }
443263508Sdim
444193326Sed  ///===---- Other target property query methods --------------------------===//
445198092Srdivacky
446239462Sdim  /// \brief Appends the target-specific \#define values for this
447193326Sed  /// target set to the specified buffer.
448193326Sed  virtual void getTargetDefines(const LangOptions &Opts,
449202379Srdivacky                                MacroBuilder &Builder) const = 0;
450198092Srdivacky
451198398Srdivacky
452239462Sdim  /// Return information about target-specific builtins for
453193326Sed  /// the current primary target, and info about which builtins are non-portable
454193326Sed  /// across the current set of primary and secondary targets.
455198092Srdivacky  virtual void getTargetBuiltins(const Builtin::Info *&Records,
456193326Sed                                 unsigned &NumRecords) const = 0;
457193326Sed
458239462Sdim  /// The __builtin_clz* and __builtin_ctz* built-in
459234353Sdim  /// functions are specified to have undefined results for zero inputs, but
460234353Sdim  /// on targets that support these operations in a way that provides
461234353Sdim  /// well-defined results for zero without loss of performance, it is a good
462234353Sdim  /// idea to avoid optimizing based on that undef behavior.
463234353Sdim  virtual bool isCLZForZeroUndef() const { return true; }
464234353Sdim
465239462Sdim  /// \brief Returns the kind of __builtin_va_list type that should be used
466239462Sdim  /// with this target.
467239462Sdim  virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
468193326Sed
469239462Sdim  /// \brief Returns whether the passed in string is a valid clobber in an
470239462Sdim  /// inline asm statement.
471239462Sdim  ///
472239462Sdim  /// This is used by Sema.
473226633Sdim  bool isValidClobber(StringRef Name) const;
474224145Sdim
475239462Sdim  /// \brief Returns whether the passed in string is a valid register name
476239462Sdim  /// according to GCC.
477239462Sdim  ///
478239462Sdim  /// This is used by Sema for inline asm statements.
479226633Sdim  bool isValidGCCRegisterName(StringRef Name) const;
480193326Sed
481239462Sdim  /// \brief Returns the "normalized" GCC register name.
482239462Sdim  ///
483239462Sdim  /// For example, on x86 it will return "ax" when "eax" is passed in.
484226633Sdim  StringRef getNormalizedGCCRegisterName(StringRef Name) const;
485198092Srdivacky
486193326Sed  struct ConstraintInfo {
487193326Sed    enum {
488193326Sed      CI_None = 0x00,
489193326Sed      CI_AllowsMemory = 0x01,
490193326Sed      CI_AllowsRegister = 0x02,
491193326Sed      CI_ReadWrite = 0x04,       // "+r" output constraint (read and write).
492193326Sed      CI_HasMatchingInput = 0x08 // This output operand has a matching input.
493193326Sed    };
494193326Sed    unsigned Flags;
495193326Sed    int TiedOperand;
496198092Srdivacky
497193326Sed    std::string ConstraintStr;  // constraint: "=rm"
498193326Sed    std::string Name;           // Operand name: [foo] with no []'s.
499193326Sed  public:
500226633Sdim    ConstraintInfo(StringRef ConstraintStr, StringRef Name)
501218893Sdim      : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
502203955Srdivacky      Name(Name.str()) {}
503193326Sed
504193326Sed    const std::string &getConstraintStr() const { return ConstraintStr; }
505193326Sed    const std::string &getName() const { return Name; }
506193326Sed    bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
507193326Sed    bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
508193326Sed    bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
509198092Srdivacky
510239462Sdim    /// \brief Return true if this output operand has a matching
511193326Sed    /// (tied) input operand.
512193326Sed    bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
513198092Srdivacky
514239462Sdim    /// \brief Return true if this input operand is a matching
515239462Sdim    /// constraint that ties it to an output operand.
516239462Sdim    ///
517239462Sdim    /// If this returns true then getTiedOperand will indicate which output
518239462Sdim    /// operand this is tied to.
519193326Sed    bool hasTiedOperand() const { return TiedOperand != -1; }
520193326Sed    unsigned getTiedOperand() const {
521193326Sed      assert(hasTiedOperand() && "Has no tied operand!");
522193326Sed      return (unsigned)TiedOperand;
523193326Sed    }
524198092Srdivacky
525193326Sed    void setIsReadWrite() { Flags |= CI_ReadWrite; }
526193326Sed    void setAllowsMemory() { Flags |= CI_AllowsMemory; }
527193326Sed    void setAllowsRegister() { Flags |= CI_AllowsRegister; }
528193326Sed    void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
529198092Srdivacky
530239462Sdim    /// \brief Indicate that this is an input operand that is tied to
531239462Sdim    /// the specified output operand.
532239462Sdim    ///
533239462Sdim    /// Copy over the various constraint information from the output.
534193326Sed    void setTiedOperand(unsigned N, ConstraintInfo &Output) {
535193326Sed      Output.setHasMatchingInput();
536193326Sed      Flags = Output.Flags;
537193326Sed      TiedOperand = N;
538193326Sed      // Don't copy Name or constraint string.
539193326Sed    }
540193326Sed  };
541193326Sed
542193326Sed  // validateOutputConstraint, validateInputConstraint - Checks that
543193326Sed  // a constraint is valid and provides information about it.
544193326Sed  // FIXME: These should return a real error instead of just true/false.
545193326Sed  bool validateOutputConstraint(ConstraintInfo &Info) const;
546193326Sed  bool validateInputConstraint(ConstraintInfo *OutputConstraints,
547193326Sed                               unsigned NumOutputs,
548193326Sed                               ConstraintInfo &info) const;
549249423Sdim  virtual bool validateInputSize(StringRef /*Constraint*/,
550249423Sdim                                 unsigned /*Size*/) const {
551249423Sdim    return true;
552249423Sdim  }
553243830Sdim  virtual bool validateConstraintModifier(StringRef /*Constraint*/,
554243830Sdim                                          const char /*Modifier*/,
555243830Sdim                                          unsigned /*Size*/) const {
556243830Sdim    return true;
557243830Sdim  }
558193326Sed  bool resolveSymbolicName(const char *&Name,
559193326Sed                           ConstraintInfo *OutputConstraints,
560193326Sed                           unsigned NumOutputs, unsigned &Index) const;
561198092Srdivacky
562223017Sdim  // Constraint parm will be left pointing at the last character of
563223017Sdim  // the constraint.  In practice, it won't be changed unless the
564223017Sdim  // constraint is longer than one character.
565223017Sdim  virtual std::string convertConstraint(const char *&Constraint) const {
566218893Sdim    // 'p' defaults to 'r', but can be overridden by targets.
567223017Sdim    if (*Constraint == 'p')
568218893Sdim      return std::string("r");
569223017Sdim    return std::string(1, *Constraint);
570193326Sed  }
571198092Srdivacky
572239462Sdim  /// \brief Returns a string of target-specific clobbers, in LLVM format.
573193326Sed  virtual const char *getClobbers() const = 0;
574193326Sed
575198092Srdivacky
576239462Sdim  /// \brief Returns the target triple of the primary target.
577198092Srdivacky  const llvm::Triple &getTriple() const {
578198092Srdivacky    return Triple;
579193326Sed  }
580198092Srdivacky
581193326Sed  const char *getTargetDescription() const {
582193326Sed    return DescriptionString;
583193326Sed  }
584193326Sed
585193326Sed  struct GCCRegAlias {
586193326Sed    const char * const Aliases[5];
587193326Sed    const char * const Register;
588193326Sed  };
589193326Sed
590224145Sdim  struct AddlRegName {
591224145Sdim    const char * const Names[5];
592224145Sdim    const unsigned RegNum;
593224145Sdim  };
594224145Sdim
595239462Sdim  /// \brief Does this target support "protected" visibility?
596234353Sdim  ///
597234353Sdim  /// Any target which dynamic libraries will naturally support
598234353Sdim  /// something like "default" (meaning that the symbol is visible
599234353Sdim  /// outside this shared object) and "hidden" (meaning that it isn't)
600234353Sdim  /// visibilities, but "protected" is really an ELF-specific concept
601239462Sdim  /// with weird semantics designed around the convenience of dynamic
602234353Sdim  /// linker implementations.  Which is not to suggest that there's
603234353Sdim  /// consistent target-independent semantics for "default" visibility
604234353Sdim  /// either; the entire thing is pretty badly mangled.
605234353Sdim  virtual bool hasProtectedVisibility() const { return true; }
606234353Sdim
607239462Sdim  /// \brief Return the section to use for CFString literals, or 0 if no
608239462Sdim  /// special section is used.
609198092Srdivacky  virtual const char *getCFStringSection() const {
610193326Sed    return "__DATA,__cfstring";
611193326Sed  }
612193326Sed
613239462Sdim  /// \brief Return the section to use for NSString literals, or 0 if no
614239462Sdim  /// special section is used.
615207619Srdivacky  virtual const char *getNSStringSection() const {
616207619Srdivacky    return "__OBJC,__cstring_object,regular,no_dead_strip";
617207619Srdivacky  }
618207619Srdivacky
619239462Sdim  /// \brief Return the section to use for NSString literals, or 0 if no
620239462Sdim  /// special section is used (NonFragile ABI).
621207619Srdivacky  virtual const char *getNSStringNonFragileABISection() const {
622207619Srdivacky    return "__DATA, __objc_stringobj, regular, no_dead_strip";
623207619Srdivacky  }
624207619Srdivacky
625239462Sdim  /// \brief An optional hook that targets can implement to perform semantic
626239462Sdim  /// checking on attribute((section("foo"))) specifiers.
627239462Sdim  ///
628239462Sdim  /// In this case, "foo" is passed in to be checked.  If the section
629239462Sdim  /// specifier is invalid, the backend should return a non-empty string
630198092Srdivacky  /// that indicates the problem.
631198092Srdivacky  ///
632198092Srdivacky  /// This hook is a simple quality of implementation feature to catch errors
633198092Srdivacky  /// and give good diagnostics in cases when the assembler or code generator
634198092Srdivacky  /// would otherwise reject the section specifier.
635198092Srdivacky  ///
636226633Sdim  virtual std::string isValidSectionSpecifier(StringRef SR) const {
637198092Srdivacky    return "";
638193326Sed  }
639193326Sed
640239462Sdim  /// \brief Set forced language options.
641239462Sdim  ///
642199482Srdivacky  /// Apply changes to the target information with respect to certain
643199482Srdivacky  /// language options which change the target configuration.
644199482Srdivacky  virtual void setForcedLangOptions(LangOptions &Opts);
645193326Sed
646239462Sdim  /// \brief Get the default set of target features for the CPU;
647226633Sdim  /// this should include all legal feature strings on the target.
648226633Sdim  virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
649193326Sed  }
650193326Sed
651239462Sdim  /// \brief Get the ABI currently in use.
652198092Srdivacky  virtual const char *getABI() const {
653198092Srdivacky    return "";
654198092Srdivacky  }
655198092Srdivacky
656239462Sdim  /// \brief Get the C++ ABI currently in use.
657249423Sdim  TargetCXXABI getCXXABI() const {
658249423Sdim    return TheCXXABI;
659210299Sed  }
660210299Sed
661239462Sdim  /// \brief Target the specified CPU.
662201361Srdivacky  ///
663239462Sdim  /// \return  False on error (invalid CPU name).
664201361Srdivacky  virtual bool setCPU(const std::string &Name) {
665226633Sdim    return false;
666201361Srdivacky  }
667201361Srdivacky
668239462Sdim  /// \brief Use the specified ABI.
669198092Srdivacky  ///
670239462Sdim  /// \return False on error (invalid ABI name).
671198092Srdivacky  virtual bool setABI(const std::string &Name) {
672198092Srdivacky    return false;
673198092Srdivacky  }
674198092Srdivacky
675263508Sdim  /// \brief Use the specified unit for FP math.
676263508Sdim  ///
677263508Sdim  /// \return False on error (invalid unit name).
678263508Sdim  virtual bool setFPMath(StringRef Name) {
679263508Sdim    return false;
680263508Sdim  }
681263508Sdim
682239462Sdim  /// \brief Use this specified C++ ABI.
683210299Sed  ///
684239462Sdim  /// \return False on error (invalid C++ ABI name).
685249423Sdim  bool setCXXABI(llvm::StringRef name) {
686249423Sdim    TargetCXXABI ABI;
687249423Sdim    if (!ABI.tryParse(name)) return false;
688212904Sdim    return setCXXABI(ABI);
689212904Sdim  }
690212904Sdim
691239462Sdim  /// \brief Set the C++ ABI to be used by this implementation.
692212904Sdim  ///
693239462Sdim  /// \return False on error (ABI not valid on this target)
694212904Sdim  virtual bool setCXXABI(TargetCXXABI ABI) {
695249423Sdim    TheCXXABI = ABI;
696210299Sed    return true;
697210299Sed  }
698210299Sed
699239462Sdim  /// \brief Enable or disable a specific target feature;
700193326Sed  /// the feature name must be valid.
701263508Sdim  virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
702234353Sdim                                 StringRef Name,
703193326Sed                                 bool Enabled) const {
704263508Sdim    Features[Name] = Enabled;
705193326Sed  }
706193326Sed
707239462Sdim  /// \brief Perform initialization based on the user configured
708239462Sdim  /// set of features (e.g., +sse4).
709201361Srdivacky  ///
710239462Sdim  /// The list is guaranteed to have at most one entry per feature.
711239462Sdim  ///
712201361Srdivacky  /// The target may modify the features list, to change which options are
713201361Srdivacky  /// passed onwards to the backend.
714263508Sdim  ///
715263508Sdim  /// \return  False on error.
716263508Sdim  virtual bool handleTargetFeatures(std::vector<std::string> &Features,
717263508Sdim                                    DiagnosticsEngine &Diags) {
718263508Sdim    return true;
719193326Sed  }
720193326Sed
721234353Sdim  /// \brief Determine whether the given target has the given feature.
722234353Sdim  virtual bool hasFeature(StringRef Feature) const {
723234353Sdim    return false;
724234353Sdim  }
725234353Sdim
726239462Sdim  // \brief Returns maximal number of args passed in registers.
727193326Sed  unsigned getRegParmMax() const {
728224145Sdim    assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
729193326Sed    return RegParmMax;
730193326Sed  }
731193326Sed
732239462Sdim  /// \brief Whether the target supports thread-local storage.
733198092Srdivacky  bool isTLSSupported() const {
734193326Sed    return TLSSupported;
735193326Sed  }
736218893Sdim
737239462Sdim  /// \brief Return true if {|} are normal characters in the asm string.
738239462Sdim  ///
739239462Sdim  /// If this returns false (the default), then {abc|xyz} is syntax
740207619Srdivacky  /// that says that when compiling for asm variant #0, "abc" should be
741207619Srdivacky  /// generated, but when compiling for asm variant #1, "xyz" should be
742207619Srdivacky  /// generated.
743207619Srdivacky  bool hasNoAsmVariants() const {
744207619Srdivacky    return NoAsmVariants;
745207619Srdivacky  }
746218893Sdim
747239462Sdim  /// \brief Return the register number that __builtin_eh_return_regno would
748239462Sdim  /// return with the specified argument.
749198092Srdivacky  virtual int getEHDataRegisterNumber(unsigned RegNo) const {
750218893Sdim    return -1;
751198092Srdivacky  }
752218893Sdim
753239462Sdim  /// \brief Return the section to use for C++ static initialization functions.
754210299Sed  virtual const char *getStaticInitSectionSpecifier() const {
755210299Sed    return 0;
756210299Sed  }
757221345Sdim
758221345Sdim  const LangAS::Map &getAddressSpaceMap() const {
759221345Sdim    return *AddrSpaceMap;
760221345Sdim  }
761221345Sdim
762221345Sdim  /// \brief Retrieve the name of the platform as it is used in the
763221345Sdim  /// availability attribute.
764226633Sdim  StringRef getPlatformName() const { return PlatformName; }
765221345Sdim
766221345Sdim  /// \brief Retrieve the minimum desired version of the platform, to
767221345Sdim  /// which the program should be compiled.
768221345Sdim  VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
769221345Sdim
770234353Sdim  bool isBigEndian() const { return BigEndian; }
771234353Sdim
772249423Sdim  enum CallingConvMethodType {
773249423Sdim    CCMT_Unknown,
774249423Sdim    CCMT_Member,
775249423Sdim    CCMT_NonMember
776249423Sdim  };
777249423Sdim
778243830Sdim  /// \brief Gets the default calling convention for the given target and
779243830Sdim  /// declaration context.
780249423Sdim  virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
781243830Sdim    // Not all targets will specify an explicit calling convention that we can
782243830Sdim    // express.  This will always do the right thing, even though it's not
783243830Sdim    // an explicit calling convention.
784249423Sdim    return CC_C;
785243830Sdim  }
786243830Sdim
787243830Sdim  enum CallingConvCheckResult {
788243830Sdim    CCCR_OK,
789243830Sdim    CCCR_Warning
790243830Sdim  };
791243830Sdim
792243830Sdim  /// \brief Determines whether a given calling convention is valid for the
793243830Sdim  /// target. A calling convention can either be accepted, produce a warning
794243830Sdim  /// and be substituted with the default calling convention, or (someday)
795243830Sdim  /// produce an error (such as using thiscall on a non-instance function).
796243830Sdim  virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
797243830Sdim    switch (CC) {
798243830Sdim      default:
799243830Sdim        return CCCR_Warning;
800243830Sdim      case CC_C:
801243830Sdim        return CCCR_OK;
802243830Sdim    }
803243830Sdim  }
804243830Sdim
805193326Sedprotected:
806193326Sed  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
807193326Sed    return PointerWidth;
808193326Sed  }
809193326Sed  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
810193326Sed    return PointerAlign;
811193326Sed  }
812193326Sed  virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
813193326Sed    return PtrDiffType;
814193326Sed  }
815198092Srdivacky  virtual void getGCCRegNames(const char * const *&Names,
816193326Sed                              unsigned &NumNames) const = 0;
817198092Srdivacky  virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
818193326Sed                                unsigned &NumAliases) const = 0;
819224145Sdim  virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
820263508Sdim                                  unsigned &NumAddl) const {
821224145Sdim    Addl = 0;
822224145Sdim    NumAddl = 0;
823224145Sdim  }
824198092Srdivacky  virtual bool validateAsmConstraint(const char *&Name,
825193326Sed                                     TargetInfo::ConstraintInfo &info) const= 0;
826193326Sed};
827193326Sed
828193326Sed}  // end namespace clang
829193326Sed
830193326Sed#endif
831