15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
92f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett///
102f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \file
112f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \brief Defines the clang::TargetInfo interface.
122f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett///
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_BASIC_TARGETINFO_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_BASIC_TARGETINFO_H
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1830a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Basic/AddressSpaces.h"
19686775deca8b8685eb90801495880e3abdd844c2Chris Lattner#include "clang/Basic/LLVM.h"
2030a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Basic/Specifiers.h"
21651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "clang/Basic/TargetCXXABI.h"
2230a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Basic/TargetOptions.h"
2330a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Basic/VersionTuple.h"
244f32786ac45210143654390177105eb749b614e9Ted Kremenek#include "llvm/ADT/IntrusiveRefCntPtr.h"
25868bd0aa9281929ef50d2e9a8c82a036906f53f5Daniel Dunbar#include "llvm/ADT/StringMap.h"
260a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor#include "llvm/ADT/StringRef.h"
2720cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis#include "llvm/ADT/StringSwitch.h"
281752ee4849f4c37f5e03193e658be92650b0e65aDaniel Dunbar#include "llvm/ADT/Triple.h"
2903013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/DataTypes.h"
305414fbac5f1749c0e85a8c4eeb5dfece59c3e30aTorok Edwin#include <cassert>
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <string>
3230a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include <vector>
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
34797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattnernamespace llvm {
35797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattnerstruct fltSemantics;
36797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner}
37525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
39d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieclass DiagnosticsEngine;
40d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbarclass LangOptions;
41103b71c37a3c3a3da7128c1d0232a89b1e8d0d90Chandler Carruthclass MacroBuilder;
42797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattnerclass SourceLocation;
437a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenekclass SourceManager;
44d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace Builtin { struct Info; }
461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// \brief Exposes information about the current target.
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
49c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmithclass TargetInfo : public RefCountedBase<TargetInfo> {
50ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  std::shared_ptr<TargetOptions> TargetOpts;
511752ee4849f4c37f5e03193e658be92650b0e65aDaniel Dunbar  llvm::Triple Triple;
520eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattnerprotected:
53cd4fc42896f926ffc081e1c4a8bf4cd647883c14Chris Lattner  // Target values set by the ctor of the actual target implementation.  Default
54cd4fc42896f926ffc081e1c4a8bf4cd647883c14Chris Lattner  // values are specified by the TargetInfo constructor.
55e6a24e83e71f361c7b7de82cf24ee6f5ddc7f1c2Eli Friedman  bool BigEndian;
56b030f0272500c6c5602f587ac029ee0dc0e5a05cEli Friedman  bool TLSSupported;
579bffb0701d02a10e77e1ac0f196074eed6466ed0Chris Lattner  bool NoAsmVariants;  // True if {|} are normal characters.
58927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  unsigned char PointerWidth, PointerAlign;
59c81f2a2c7f83e64b3ef2b77030536290d0e2b350Roman Divacky  unsigned char BoolWidth, BoolAlign;
60927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  unsigned char IntWidth, IntAlign;
61aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  unsigned char HalfWidth, HalfAlign;
6261538a7d1336f3ef3cb81e09f11a1cbb282bcf81Eli Friedman  unsigned char FloatWidth, FloatAlign;
63927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  unsigned char DoubleWidth, DoubleAlign;
6461538a7d1336f3ef3cb81e09f11a1cbb282bcf81Eli Friedman  unsigned char LongDoubleWidth, LongDoubleAlign;
656deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola  unsigned char LargeArrayMinWidth, LargeArrayAlign;
66927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  unsigned char LongWidth, LongAlign;
67927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  unsigned char LongLongWidth, LongLongAlign;
687ec59c78f1e19157767648cbe3f0e3630ca1afe7Nick Lewycky  unsigned char SuitableAlign;
696b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand  unsigned char MinGlobalAlign;
702be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman  unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
71f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier  unsigned short MaxVectorAlign;
7277e8b53fe3ff630d8d1454db94e38bedda14d5caDaniel Dunbar  const char *DescriptionString;
733fdf4678935b27c3d3fd4eb10bf9f5ab98dc0d99Chris Lattner  const char *UserLabelPrefix;
74be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky  const char *MCountName;
75aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
76aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov    *LongDoubleFormat;
77264a76cdf382c507f4d43e64c89f1503f003ac95Anton Korobeynikov  unsigned char RegParmMax, SSERegParmMax;
78b8b2c9da87e7d70a1679db026f40548b3192b705John McCall  TargetCXXABI TheCXXABI;
79207f4d8543529221932af82836016a2ef066c917Peter Collingbourne  const LangAS::Map *AddrSpaceMap;
80bbced580c92afa09cd4423a9bdc90ff61cb1e79aTed Kremenek
81686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  mutable StringRef PlatformName;
820a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  mutable VersionTuple PlatformMinVersion;
830a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
84613fd67e575ff1c038535b18dafebca070f3ed91Daniel Dunbar  unsigned HasAlignMac68kSupport : 1;
85dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  unsigned RealTypeUsesObjCFPRet : 3;
86eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson  unsigned ComplexLongDoubleUsesFP2Ret : 1;
87613fd67e575ff1c038535b18dafebca070f3ed91Daniel Dunbar
88cd4fc42896f926ffc081e1c4a8bf4cd647883c14Chris Lattner  // TargetInfo Constructor.  Default initializes all fields.
899df0823a4b82794f573e333115ad4dfff3ab0a34Benjamin Kramer  TargetInfo(const llvm::Triple &T);
901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
92af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Construct a target for the given options.
93b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4Daniel Dunbar  ///
94b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4Daniel Dunbar  /// \param Opts - The options to use to initialize the target. The target may
95b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4Daniel Dunbar  /// modify the options to canonicalize the target feature information to match
96b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4Daniel Dunbar  /// what the backend expects.
97ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  static TargetInfo *
98ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  CreateTargetInfo(DiagnosticsEngine &Diags,
99ef8225444452a1486bd721f3285301fe84643b00Stephen Hines                   const std::shared_ptr<TargetOptions> &Opts);
100bbced580c92afa09cd4423a9bdc90ff61cb1e79aTed Kremenek
1010eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattner  virtual ~TargetInfo();
102fb79f7cc00f9c1e04f11ed636eefb36d246b0fb8Ted Kremenek
1039a022bb007a3e77e1ac1330f955a239cfb1dd0fbDouglas Gregor  /// \brief Retrieve the target options.
1049a022bb007a3e77e1ac1330f955a239cfb1dd0fbDouglas Gregor  TargetOptions &getTargetOpts() const {
1059a022bb007a3e77e1ac1330f955a239cfb1dd0fbDouglas Gregor    assert(TargetOpts && "Missing target options");
1069a022bb007a3e77e1ac1330f955a239cfb1dd0fbDouglas Gregor    return *TargetOpts;
1079a022bb007a3e77e1ac1330f955a239cfb1dd0fbDouglas Gregor  }
1089a022bb007a3e77e1ac1330f955a239cfb1dd0fbDouglas Gregor
1099c4bea1fa7291035325575c02d33552a124d8ef3Chris Lattner  ///===---- Target Data Type Query Methods -------------------------------===//
11031fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta  enum IntType {
1112b5abf515f9696912452f431c7738691cf97f4f1Chris Lattner    NoInt = 0,
1127b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy    SignedChar,
1137b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy    UnsignedChar,
11431fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    SignedShort,
11531fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    UnsignedShort,
11631fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    SignedInt,
11731fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    UnsignedInt,
11831fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    SignedLong,
11931fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    UnsignedLong,
12031fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    SignedLongLong,
12131fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    UnsignedLongLong
1223fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattner  };
123dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar
124dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  enum RealType {
1257b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy    NoFloat = 255,
126dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar    Float = 0,
127dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar    Double,
128dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar    LongDouble
129dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  };
130dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar
131af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief The different kinds of __builtin_va_list types defined by
132af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// the target implementation.
133c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge  enum BuiltinVaListKind {
134c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// typedef char* __builtin_va_list;
135c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    CharPtrBuiltinVaList = 0,
136c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge
137c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// typedef void* __builtin_va_list;
138c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    VoidPtrBuiltinVaList,
139c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge
140c264e16a42b3f6c36521857a29ea0949d9781c22Tim Northover    /// __builtin_va_list as defind by the AArch64 ABI
141c264e16a42b3f6c36521857a29ea0949d9781c22Tim Northover    /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
142c264e16a42b3f6c36521857a29ea0949d9781c22Tim Northover    AArch64ABIBuiltinVaList,
143c264e16a42b3f6c36521857a29ea0949d9781c22Tim Northover
144c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// __builtin_va_list as defined by the PNaCl ABI:
145c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
146c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    PNaClABIBuiltinVaList,
147c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge
148c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// __builtin_va_list as defined by the Power ABI:
149c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// https://www.power.org
150c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    ///        /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
151c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    PowerABIBuiltinVaList,
152c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge
153c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// __builtin_va_list as defined by the x86-64 ABI:
154c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge    /// http://www.x86-64.org/documentation/abi.pdf
155eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien    X86_64ABIBuiltinVaList,
156eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien
157eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien    /// __builtin_va_list as defined by ARM AAPCS ABI
158eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien    /// http://infocenter.arm.com
159eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien    //        /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
160b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    AAPCSABIBuiltinVaList,
161b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand
162b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    // typedef struct __va_list_tag
163b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    //   {
164b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    //     long __gpr;
165b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    //     long __fpr;
166b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    //     void *__overflow_arg_area;
167b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    //     void *__reg_save_area;
168b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    //   } va_list[1];
169b8409215523e5478b8b0aa9cdcd10038cf7651feUlrich Weigand    SystemZBuiltinVaList
170c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge  };
171c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge
1723fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattnerprotected:
1733c7b6e46c5f9bdbe0676c52d80df98b68b02be99Eli Friedman  IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
1746902e4146d426998ff6a94b16776c1b3f805a048Eli Friedman          WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
1756902e4146d426998ff6a94b16776c1b3f805a048Eli Friedman          ProcessIDType;
176b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar
177af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Whether Objective-C's built-in boolean type should be signed char.
178af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
17993a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian  /// Otherwise, when this flag is not set, the normal built-in boolean type is
18093a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian  /// used.
18193a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian  unsigned UseSignedCharForObjCBool : 1;
18293a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian
183b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar  /// Control whether the alignment of bit-field types is respected when laying
184b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar  /// out structures. If true, then the alignment of the bit-field type will be
185b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar  /// used to (a) impact the alignment of the containing structure, and (b)
186b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar  /// ensure that the individual bit-field will not straddle an alignment
187b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar  /// boundary.
188b6830d616a068971f13e1e213e06a945c8c93ceaDaniel Dunbar  unsigned UseBitFieldTypeAlignment : 1;
189b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar
190af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
191af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// the next bitfield.
192af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
193af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// If the alignment of the zero length bitfield is greater than the member
194af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// that follows it, `bar', `bar' will be aligned as the type of the
195af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// zero-length bitfield.
19661a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  unsigned UseZeroLengthBitfieldAlignment : 1;
19761a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier
19861a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  /// If non-zero, specifies a fixed alignment value for bitfields that follow
19961a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  /// zero length bitfield, regardless of the zero length bitfield type.
20061a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  unsigned ZeroLengthBitfieldBoundary;
20161a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier
2021eef85246b411b55c493098266746d0d83c241eaDavid Tweed  /// \brief Specify if mangling based on address space map should be used or
2031eef85246b411b55c493098266746d0d83c241eaDavid Tweed  /// not for language specific address spaces
2041eef85246b411b55c493098266746d0d83c241eaDavid Tweed  bool UseAddrSpaceMapMangling;
2051eef85246b411b55c493098266746d0d83c241eaDavid Tweed
2063fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattnerpublic:
2073fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattner  IntType getSizeType() const { return SizeType; }
2083fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattner  IntType getIntMaxType() const { return IntMaxType; }
2093fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattner  IntType getUIntMaxType() const { return UIntMaxType; }
2103fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattner  IntType getPtrDiffType(unsigned AddrSpace) const {
21131fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
21231fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta  }
2136ad474f82f0cf32e13128d89fa5ad3a37ae73530Chris Lattner  IntType getIntPtrType() const { return IntPtrType; }
214ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  IntType getUIntPtrType() const {
215ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    return getIntTypeByWidth(getTypeWidth(IntPtrType), false);
216ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  }
2173fa8f7491a6a6c1445768ea23ec85d3554c3ba98Chris Lattner  IntType getWCharType() const { return WCharType; }
218e64ef80363c84f4f431e26b61db554c89beeddb6Chris Lattner  IntType getWIntType() const { return WIntType; }
219f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  IntType getChar16Type() const { return Char16Type; }
220f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  IntType getChar32Type() const { return Char32Type; }
2213c7b6e46c5f9bdbe0676c52d80df98b68b02be99Eli Friedman  IntType getInt64Type() const { return Int64Type; }
2229cf910efc4fb7001a6d276ed2eabf01f0f0efaaaEdward O'Callaghan  IntType getSigAtomicType() const { return SigAtomicType; }
2236902e4146d426998ff6a94b16776c1b3f805a048Eli Friedman  IntType getProcessIDType() const { return ProcessIDType; }
224b304f77cb621a47221f2aa2d35acdb5c730421ffChris Lattner
225af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the width (in bits) of the specified integer type enum.
226af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
227af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// For example, SignedInt -> getIntWidth().
228b304f77cb621a47221f2aa2d35acdb5c730421ffChris Lattner  unsigned getTypeWidth(IntType T) const;
229b304f77cb621a47221f2aa2d35acdb5c730421ffChris Lattner
2307b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy  /// \brief Return integer type with specified width.
2317b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
2327b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy
233ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  /// \brief Return the smallest integer type with at least the specified width.
234ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
235ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
2367b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy  /// \brief Return floating point type with specified width.
2377b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy  RealType getRealTypeByWidth(unsigned BitWidth) const;
2387b7bef1ec355fb46643349d77c266b913f36b656Stepan Dyatkovskiy
239af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the alignment (in bits) of the specified integer type enum.
240af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
241af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// For example, SignedInt -> getIntAlign().
2429099e7bcda3922cee0cffcdf21332ac4aa193ceaChris Lattner  unsigned getTypeAlign(IntType T) const;
2439099e7bcda3922cee0cffcdf21332ac4aa193ceaChris Lattner
244af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns true if the type is signed; false otherwise.
2453f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner  static bool isTypeSigned(IntType T);
246b304f77cb621a47221f2aa2d35acdb5c730421ffChris Lattner
247af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the width of pointers on this target, for the
248927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  /// specified address space.
249927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  uint64_t getPointerWidth(unsigned AddrSpace) const {
250927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner    return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
251927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  }
252927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  uint64_t getPointerAlign(unsigned AddrSpace) const {
253927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner    return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
254927686fe8c968ca786fa44d2353eebf59c4f5b8aChris Lattner  }
2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
256af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
257c81f2a2c7f83e64b3ef2b77030536290d0e2b350Roman Divacky  unsigned getBoolWidth() const { return BoolWidth; }
258af50aab0c317462129d73ae8000c6394c718598dJames Dennett
259af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
260c81f2a2c7f83e64b3ef2b77030536290d0e2b350Roman Divacky  unsigned getBoolAlign() const { return BoolAlign; }
2611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
262f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  unsigned getCharWidth() const { return 8; } // FIXME
263f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  unsigned getCharAlign() const { return 8; } // FIXME
2641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
265af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the size of 'signed short' and 'unsigned short' for this
266af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// target, in bits.
2679e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  unsigned getShortWidth() const { return 16; } // FIXME
268af50aab0c317462129d73ae8000c6394c718598dJames Dennett
269af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the alignment of 'signed short' and 'unsigned short' for
270af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// this target.
2719e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  unsigned getShortAlign() const { return 16; } // FIXME
2721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2739e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
2749e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// this target, in bits.
2752621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner  unsigned getIntWidth() const { return IntWidth; }
2762621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner  unsigned getIntAlign() const { return IntAlign; }
2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2789e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
2799e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// for this target, in bits.
2808059e997ee05e4aa87f7e21fed630429a140ee53Chris Lattner  unsigned getLongWidth() const { return LongWidth; }
2818059e997ee05e4aa87f7e21fed630429a140ee53Chris Lattner  unsigned getLongAlign() const { return LongAlign; }
2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2839e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// getLongLongWidth/Align - Return the size of 'signed long long' and
2849e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// 'unsigned long long' for this target, in bits.
285ec10f5886526124ba733fbd0ef8665d576285daaChris Lattner  unsigned getLongLongWidth() const { return LongLongWidth; }
286ec10f5886526124ba733fbd0ef8665d576285daaChris Lattner  unsigned getLongLongAlign() const { return LongLongAlign; }
2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28884268904947ada7e251932a6f5b0f4364df7a2c7Richard Smith  /// \brief Determine whether the __int128 type is supported on this target.
2896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME
29084268904947ada7e251932a6f5b0f4364df7a2c7Richard Smith
291af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the alignment that is suitable for storing any
2927ec59c78f1e19157767648cbe3f0e3630ca1afe7Nick Lewycky  /// object with a fundamental alignment requirement.
2937ec59c78f1e19157767648cbe3f0e3630ca1afe7Nick Lewycky  unsigned getSuitableAlign() const { return SuitableAlign; }
2947ec59c78f1e19157767648cbe3f0e3630ca1afe7Nick Lewycky
2956b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand  /// getMinGlobalAlign - Return the minimum alignment of a global variable,
2966b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand  /// unless its alignment is explicitly reduced via attributes.
2976b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand  unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
2986b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand
299f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
3009e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// bits.
3019184646509d015ea66e796113a8c68598681374bChris Lattner  unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
3029184646509d015ea66e796113a8c68598681374bChris Lattner  unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
303f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner
304f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
305f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  /// bits.
3069184646509d015ea66e796113a8c68598681374bChris Lattner  unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
3079184646509d015ea66e796113a8c68598681374bChris Lattner  unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
308f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith
309f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
310f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  /// bits.
3119184646509d015ea66e796113a8c68598681374bChris Lattner  unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
3129184646509d015ea66e796113a8c68598681374bChris Lattner  unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
313f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith
314aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
315aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  unsigned getHalfWidth() const { return HalfWidth; }
316aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  unsigned getHalfAlign() const { return HalfAlign; }
317aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
318aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov
3199e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
32061538a7d1336f3ef3cb81e09f11a1cbb282bcf81Eli Friedman  unsigned getFloatWidth() const { return FloatWidth; }
32161538a7d1336f3ef3cb81e09f11a1cbb282bcf81Eli Friedman  unsigned getFloatAlign() const { return FloatAlign; }
322b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner  const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
3239e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner
3249e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
325c8b1227fa8c17d9881815e40c04e19334be536f8Nate Begeman  unsigned getDoubleWidth() const { return DoubleWidth; }
326c8b1227fa8c17d9881815e40c04e19334be536f8Nate Begeman  unsigned getDoubleAlign() const { return DoubleAlign; }
327b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner  const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
3289e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner
3299e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
3309e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner  /// double'.
33161538a7d1336f3ef3cb81e09f11a1cbb282bcf81Eli Friedman  unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
33261538a7d1336f3ef3cb81e09f11a1cbb282bcf81Eli Friedman  unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
333b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner  const llvm::fltSemantics &getLongDoubleFormat() const {
334b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner    return *LongDoubleFormat;
335cd4fc42896f926ffc081e1c4a8bf4cd647883c14Chris Lattner  }
3361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
337af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
338b406669fea7c8db83a377f368f1689c848296974Benjamin Kramer  virtual unsigned getFloatEvalMethod() const { return 0; }
339b406669fea7c8db83a377f368f1689c848296974Benjamin Kramer
3406deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola  // getLargeArrayMinWidth/Align - Return the minimum array size that is
3416deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola  // 'large' and its alignment.
3426deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola  unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
3436deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola  unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
3446deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola
345af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the maximum width lock-free atomic operation which will
346af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// ever be supported for the given target
3472be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman  unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
348af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the maximum width lock-free atomic operation which can be
349af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// inlined given the supported features of the given target.
3502be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman  unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
3512be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman
352f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier  /// \brief Return the maximum vector alignment supported for the given target.
353f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier  unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
354f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier
355af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
3560eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattner  unsigned getIntMaxTWidth() const {
3579184646509d015ea66e796113a8c68598681374bChris Lattner    return getTypeWidth(IntMaxType);
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3608e721b714a92de803000c65fb8a57a1d8a810322Rafael Espindola  // Return the size of unwind_word for this target.
3618e721b714a92de803000c65fb8a57a1d8a810322Rafael Espindola  unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
3628e721b714a92de803000c65fb8a57a1d8a810322Rafael Espindola
363af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the "preferred" register width on this target.
3648bc56022db2d9b16aab25ce3b6fccda9dd8991fcDavid Tweed  unsigned getRegisterWidth() const {
36508737c49bd98f73b50fe90fd19f97c41cd29e3d1Daniel Dunbar    // Currently we assume the register width on the target matches the pointer
36608737c49bd98f73b50fe90fd19f97c41cd29e3d1Daniel Dunbar    // width, we can introduce a new variable for this if/when some target wants
36708737c49bd98f73b50fe90fd19f97c41cd29e3d1Daniel Dunbar    // it.
3688bc56022db2d9b16aab25ce3b6fccda9dd8991fcDavid Tweed    return PointerWidth;
36908737c49bd98f73b50fe90fd19f97c41cd29e3d1Daniel Dunbar  }
37008737c49bd98f73b50fe90fd19f97c41cd29e3d1Daniel Dunbar
371af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
372af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// which is the prefix given to user symbols by default.
373af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
374af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// On most platforms this is "_", but it is "" on some, and "." on others.
3753fdf4678935b27c3d3fd4eb10bf9f5ab98dc0d99Chris Lattner  const char *getUserLabelPrefix() const {
3763fdf4678935b27c3d3fd4eb10bf9f5ab98dc0d99Chris Lattner    return UserLabelPrefix;
3773fdf4678935b27c3d3fd4eb10bf9f5ab98dc0d99Chris Lattner  }
3781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
379af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns the name of the mcount instrumentation function.
380be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky  const char *getMCountName() const {
381be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky    return MCountName;
382be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky  }
383be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky
384af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Check if the Objective-C built-in boolean type should be signed
385af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// char.
386af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
387af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// Otherwise, if this returns false, the normal built-in boolean type
388af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// should also be used for Objective-C.
38993a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian  bool useSignedCharForObjCBool() const {
39093a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian    return UseSignedCharForObjCBool;
39193a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian  }
39293a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian  void noSignedCharForObjCBool() {
39393a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian    UseSignedCharForObjCBool = false;
39493a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian  }
39593a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian
396af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Check whether the alignment of bit-field types is respected
397af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// when laying out structures.
398b6830d616a068971f13e1e213e06a945c8c93ceaDaniel Dunbar  bool useBitFieldTypeAlignment() const {
399b6830d616a068971f13e1e213e06a945c8c93ceaDaniel Dunbar    return UseBitFieldTypeAlignment;
400b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar  }
401b6a169395c1b30c76daffebcbd2164b6247a5d21Daniel Dunbar
402af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Check whether zero length bitfields should force alignment of
403af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// the next member.
40461a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  bool useZeroLengthBitfieldAlignment() const {
40561a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier    return UseZeroLengthBitfieldAlignment;
40661a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  }
40761a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier
408af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Get the fixed alignment value in bits for a member that follows
409af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// a zero length bitfield.
41061a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  unsigned getZeroLengthBitfieldBoundary() const {
41161a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier    return ZeroLengthBitfieldBoundary;
41261a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier  }
41361a62216a0bb33fb668ab653d9f9a704e43d2fc6Chad Rosier
41411db92c2721da09e8ffc2f58994ed3bb5d23d8b9James Dennett  /// \brief Check whether this target support '\#pragma options align=mac68k'.
415613fd67e575ff1c038535b18dafebca070f3ed91Daniel Dunbar  bool hasAlignMac68kSupport() const {
416613fd67e575ff1c038535b18dafebca070f3ed91Daniel Dunbar    return HasAlignMac68kSupport;
417613fd67e575ff1c038535b18dafebca070f3ed91Daniel Dunbar  }
418613fd67e575ff1c038535b18dafebca070f3ed91Daniel Dunbar
419af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the user string for the specified integer type enum.
420af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
4212b5abf515f9696912452f431c7738691cf97f4f1Chris Lattner  /// For example, SignedShort -> "short".
4222b5abf515f9696912452f431c7738691cf97f4f1Chris Lattner  static const char *getTypeName(IntType T);
4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
424af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the constant suffix for the specified integer type enum.
425af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
426af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// For example, SignedLong -> "L".
427b304f77cb621a47221f2aa2d35acdb5c730421ffChris Lattner  static const char *getTypeConstantSuffix(IntType T);
428b304f77cb621a47221f2aa2d35acdb5c730421ffChris Lattner
429dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  /// \brief Check whether the given real type should use the "fpret" flavor of
430af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// Objective-C message passing on this target.
431dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  bool useObjCFPRetForRealType(RealType T) const {
432dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar    return RealTypeUsesObjCFPRet & (1 << T);
433dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  }
434dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar
435eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson  /// \brief Check whether _Complex long double should use the "fp2ret" flavor
436af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// of Objective-C message passing on this target.
437eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson  bool useObjCFP2RetForComplexLongDouble() const {
438eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson    return ComplexLongDoubleUsesFP2Ret;
439eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson  }
440eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson
4411eef85246b411b55c493098266746d0d83c241eaDavid Tweed  /// \brief Specify if mangling based on address space map should be used or
4421eef85246b411b55c493098266746d0d83c241eaDavid Tweed  /// not for language specific address spaces
4431eef85246b411b55c493098266746d0d83c241eaDavid Tweed  bool useAddressSpaceMapMangling() const {
4441eef85246b411b55c493098266746d0d83c241eaDavid Tweed    return UseAddrSpaceMapMangling;
4451eef85246b411b55c493098266746d0d83c241eaDavid Tweed  }
4461eef85246b411b55c493098266746d0d83c241eaDavid Tweed
4479c4bea1fa7291035325575c02d33552a124d8ef3Chris Lattner  ///===---- Other target property query methods --------------------------===//
4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44911db92c2721da09e8ffc2f58994ed3bb5d23d8b9James Dennett  /// \brief Appends the target-specific \#define values for this
4509c4bea1fa7291035325575c02d33552a124d8ef3Chris Lattner  /// target set to the specified buffer.
45133328642a7a8a126918814ddcbcebf83c121ad54Chris Lattner  virtual void getTargetDefines(const LangOptions &Opts,
452a99927774d07af9c6f0e1945531eadc910592945Benjamin Kramer                                MacroBuilder &Builder) const = 0;
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
454b304f77cb621a47221f2aa2d35acdb5c730421ffChris Lattner
455af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// Return information about target-specific builtins for
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the current primary target, and info about which builtins are non-portable
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// across the current set of primary and secondary targets.
4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void getTargetBuiltins(const Builtin::Info *&Records,
4590eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattner                                 unsigned &NumRecords) const = 0;
4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
461af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// The __builtin_clz* and __builtin_ctz* built-in
4628b30a9379f730875ba8fb2d0fe2d43611e0c20ffBob Wilson  /// functions are specified to have undefined results for zero inputs, but
4638b30a9379f730875ba8fb2d0fe2d43611e0c20ffBob Wilson  /// on targets that support these operations in a way that provides
4648b30a9379f730875ba8fb2d0fe2d43611e0c20ffBob Wilson  /// well-defined results for zero without loss of performance, it is a good
4658b30a9379f730875ba8fb2d0fe2d43611e0c20ffBob Wilson  /// idea to avoid optimizing based on that undef behavior.
4668b30a9379f730875ba8fb2d0fe2d43611e0c20ffBob Wilson  virtual bool isCLZForZeroUndef() const { return true; }
4678b30a9379f730875ba8fb2d0fe2d43611e0c20ffBob Wilson
468af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns the kind of __builtin_va_list type that should be used
469af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// with this target.
470c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge  virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
471fb5e5ba3c7708f3aef4db0ed30e8470b3ed4206aAnders Carlsson
472af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns whether the passed in string is a valid clobber in an
473af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// inline asm statement.
474af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
475af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// This is used by Sema.
476686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool isValidClobber(StringRef Name) const;
477de31fd7eeebdc64fb043463e7f515dab8eccac8dEric Christopher
478af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns whether the passed in string is a valid register name
479af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// according to GCC.
480af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
481af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// This is used by Sema for inline asm statements.
482686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool isValidGCCRegisterName(StringRef Name) const;
483d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson
484af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns the "normalized" GCC register name.
485af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
486af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// For example, on x86 it will return "ax" when "eax" is passed in.
487686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getNormalizedGCCRegisterName(StringRef Name) const;
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48944def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner  struct ConstraintInfo {
49044def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    enum {
49144def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner      CI_None = 0x00,
49244def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner      CI_AllowsMemory = 0x01,
49344def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner      CI_AllowsRegister = 0x02,
494fa780fc4a4983003633c9b560387266101839923Chris Lattner      CI_ReadWrite = 0x04,       // "+r" output constraint (read and write).
495fa780fc4a4983003633c9b560387266101839923Chris Lattner      CI_HasMatchingInput = 0x08 // This output operand has a matching input.
49644def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    };
49744def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    unsigned Flags;
49844def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    int TiedOperand;
4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5002819fa85651526d59ade4fdc9da2cadd7b132973Chris Lattner    std::string ConstraintStr;  // constraint: "=rm"
5012819fa85651526d59ade4fdc9da2cadd7b132973Chris Lattner    std::string Name;           // Operand name: [foo] with no []'s.
502432c86969eced2ce658b3f3f2aa7407c8864f21bChris Lattner  public:
503686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    ConstraintInfo(StringRef ConstraintStr, StringRef Name)
504237cf582b89bbcc22640cea15426ddc7ada8412bMichael J. Spencer      : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
505f959fb5fb82ae2cbdf8635d734613a01818fb7bfAnders Carlsson      Name(Name.str()) {}
506432c86969eced2ce658b3f3f2aa7407c8864f21bChris Lattner
507432c86969eced2ce658b3f3f2aa7407c8864f21bChris Lattner    const std::string &getConstraintStr() const { return ConstraintStr; }
5082819fa85651526d59ade4fdc9da2cadd7b132973Chris Lattner    const std::string &getName() const { return Name; }
50944def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
51044def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
51144def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
5121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// \brief Return true if this output operand has a matching
514fa780fc4a4983003633c9b560387266101839923Chris Lattner    /// (tied) input operand.
515fa780fc4a4983003633c9b560387266101839923Chris Lattner    bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
5161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
517af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// \brief Return true if this input operand is a matching
518af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// constraint that ties it to an output operand.
519af50aab0c317462129d73ae8000c6394c718598dJames Dennett    ///
520af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// If this returns true then getTiedOperand will indicate which output
521af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// operand this is tied to.
52244def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    bool hasTiedOperand() const { return TiedOperand != -1; }
52344def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    unsigned getTiedOperand() const {
52444def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner      assert(hasTiedOperand() && "Has no tied operand!");
52544def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner      return (unsigned)TiedOperand;
52644def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    }
5271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52844def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    void setIsReadWrite() { Flags |= CI_ReadWrite; }
52944def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    void setAllowsMemory() { Flags |= CI_AllowsMemory; }
53044def070435a2b5d67f0534f7a3a85a7389d60f2Chris Lattner    void setAllowsRegister() { Flags |= CI_AllowsRegister; }
531fa780fc4a4983003633c9b560387266101839923Chris Lattner    void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
533af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// \brief Indicate that this is an input operand that is tied to
534af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// the specified output operand.
535af50aab0c317462129d73ae8000c6394c718598dJames Dennett    ///
536af50aab0c317462129d73ae8000c6394c718598dJames Dennett    /// Copy over the various constraint information from the output.
537d68876176a0d2c19e3864e7d38f6036c4f72f0a3Chris Lattner    void setTiedOperand(unsigned N, ConstraintInfo &Output) {
538fa780fc4a4983003633c9b560387266101839923Chris Lattner      Output.setHasMatchingInput();
539d68876176a0d2c19e3864e7d38f6036c4f72f0a3Chris Lattner      Flags = Output.Flags;
540d68876176a0d2c19e3864e7d38f6036c4f72f0a3Chris Lattner      TiedOperand = N;
541d68876176a0d2c19e3864e7d38f6036c4f72f0a3Chris Lattner      // Don't copy Name or constraint string.
542d68876176a0d2c19e3864e7d38f6036c4f72f0a3Chris Lattner    }
543d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson  };
544d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson
545d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson  // validateOutputConstraint, validateInputConstraint - Checks that
546d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson  // a constraint is valid and provides information about it.
547d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson  // FIXME: These should return a real error instead of just true/false.
548432c86969eced2ce658b3f3f2aa7407c8864f21bChris Lattner  bool validateOutputConstraint(ConstraintInfo &Info) const;
5492819fa85651526d59ade4fdc9da2cadd7b132973Chris Lattner  bool validateInputConstraint(ConstraintInfo *OutputConstraints,
5502819fa85651526d59ade4fdc9da2cadd7b132973Chris Lattner                               unsigned NumOutputs,
55145b050e72d058131e6f169fe54888bb91a003fb5Anders Carlsson                               ConstraintInfo &info) const;
55268fd608c2c0866064e974c3d43778c47c1cbb080Bill Wendling  virtual bool validateInputSize(StringRef /*Constraint*/,
55368fd608c2c0866064e974c3d43778c47c1cbb080Bill Wendling                                 unsigned /*Size*/) const {
55468fd608c2c0866064e974c3d43778c47c1cbb080Bill Wendling    return true;
55568fd608c2c0866064e974c3d43778c47c1cbb080Bill Wendling  }
55650d46caf00c743312e0ea1f87a693d504b12ef51Bill Wendling  virtual bool validateConstraintModifier(StringRef /*Constraint*/,
55750d46caf00c743312e0ea1f87a693d504b12ef51Bill Wendling                                          const char /*Modifier*/,
55850d46caf00c743312e0ea1f87a693d504b12ef51Bill Wendling                                          unsigned /*Size*/) const {
55950d46caf00c743312e0ea1f87a693d504b12ef51Bill Wendling    return true;
56050d46caf00c743312e0ea1f87a693d504b12ef51Bill Wendling  }
56142e1ee0702d8267d632df0fdb5c479a582877c6fAnders Carlsson  bool resolveSymbolicName(const char *&Name,
5622819fa85651526d59ade4fdc9da2cadd7b132973Chris Lattner                           ConstraintInfo *OutputConstraints,
5632819fa85651526d59ade4fdc9da2cadd7b132973Chris Lattner                           unsigned NumOutputs, unsigned &Index) const;
5641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5656ce33d67e2ed4f8c9395a807bebd25be04580c0fStuart Hastings  // Constraint parm will be left pointing at the last character of
5666ce33d67e2ed4f8c9395a807bebd25be04580c0fStuart Hastings  // the constraint.  In practice, it won't be changed unless the
5676ce33d67e2ed4f8c9395a807bebd25be04580c0fStuart Hastings  // constraint is longer than one character.
568002333f8b2cf1a8614e532f6ce366b21af85142cStuart Hastings  virtual std::string convertConstraint(const char *&Constraint) const {
569cee55018570c0c46262c6e4ef7beaa707c93fc86Dale Johannesen    // 'p' defaults to 'r', but can be overridden by targets.
570002333f8b2cf1a8614e532f6ce366b21af85142cStuart Hastings    if (*Constraint == 'p')
571cee55018570c0c46262c6e4ef7beaa707c93fc86Dale Johannesen      return std::string("r");
572002333f8b2cf1a8614e532f6ce366b21af85142cStuart Hastings    return std::string(1, *Constraint);
5730eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattner  }
5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
575af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns a string of target-specific clobbers, in LLVM format.
5760eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattner  virtual const char *getClobbers() const = 0;
5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5787a4718e813e5e99d478567a482217c7eef8572c5Devang Patel
579af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Returns the target triple of the primary target.
5801752ee4849f4c37f5e03193e658be92650b0e65aDaniel Dunbar  const llvm::Triple &getTriple() const {
5811752ee4849f4c37f5e03193e658be92650b0e65aDaniel Dunbar    return Triple;
5820eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattner  }
5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
584ae3607684c5978dc2d877141015056c9d24f17eaTed Kremenek  const char *getTargetDescription() const {
585651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    assert(DescriptionString);
586364af81157a81cf34bb058a7d5b0185020e5164bSanjiv Gupta    return DescriptionString;
5877a4718e813e5e99d478567a482217c7eef8572c5Devang Patel  }
5883346ae6bba10da0d08c8d548134ddab4e13d040fAnders Carlsson
5893346ae6bba10da0d08c8d548134ddab4e13d040fAnders Carlsson  struct GCCRegAlias {
5903346ae6bba10da0d08c8d548134ddab4e13d040fAnders Carlsson    const char * const Aliases[5];
5913346ae6bba10da0d08c8d548134ddab4e13d040fAnders Carlsson    const char * const Register;
5923346ae6bba10da0d08c8d548134ddab4e13d040fAnders Carlsson  };
5932621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
594cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher  struct AddlRegName {
595cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher    const char * const Names[5];
596cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher    const unsigned RegNum;
597cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher  };
598cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher
599af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Does this target support "protected" visibility?
6004188760f6bb20f91c6883dffd89204419f852deeJohn McCall  ///
6014188760f6bb20f91c6883dffd89204419f852deeJohn McCall  /// Any target which dynamic libraries will naturally support
6024188760f6bb20f91c6883dffd89204419f852deeJohn McCall  /// something like "default" (meaning that the symbol is visible
6034188760f6bb20f91c6883dffd89204419f852deeJohn McCall  /// outside this shared object) and "hidden" (meaning that it isn't)
6044188760f6bb20f91c6883dffd89204419f852deeJohn McCall  /// visibilities, but "protected" is really an ELF-specific concept
60548d798ce32447607144db70a484cdb99c1180663Benjamin Kramer  /// with weird semantics designed around the convenience of dynamic
6064188760f6bb20f91c6883dffd89204419f852deeJohn McCall  /// linker implementations.  Which is not to suggest that there's
6074188760f6bb20f91c6883dffd89204419f852deeJohn McCall  /// consistent target-independent semantics for "default" visibility
6084188760f6bb20f91c6883dffd89204419f852deeJohn McCall  /// either; the entire thing is pretty badly mangled.
6094188760f6bb20f91c6883dffd89204419f852deeJohn McCall  virtual bool hasProtectedVisibility() const { return true; }
6104188760f6bb20f91c6883dffd89204419f852deeJohn McCall
611af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief An optional hook that targets can implement to perform semantic
612af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// checking on attribute((section("foo"))) specifiers.
613af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
614af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// In this case, "foo" is passed in to be checked.  If the section
615af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// specifier is invalid, the backend should return a non-empty string
616797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner  /// that indicates the problem.
617797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner  ///
618797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner  /// This hook is a simple quality of implementation feature to catch errors
619797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner  /// and give good diagnostics in cases when the assembler or code generator
620797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner  /// would otherwise reject the section specifier.
621797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner  ///
622686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  virtual std::string isValidSectionSpecifier(StringRef SR) const {
623797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner    return "";
624797c3c4f5dc4fda735e55c6b5d6270a54cf6d263Chris Lattner  }
6258e5c2b8072f4409c7c0004331d1db9652d5209c0Daniel Dunbar
626af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Set forced language options.
627af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
628a6fda124bf380479529d6a80b84b62cacd3cb707John Thompson  /// Apply changes to the target information with respect to certain
629a6fda124bf380479529d6a80b84b62cacd3cb707John Thompson  /// language options which change the target configuration.
630ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  virtual void adjust(const LangOptions &Opts);
631a6fda124bf380479529d6a80b84b62cacd3cb707John Thompson
632af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Get the default set of target features for the CPU;
633c3a2e654f1e1c5cf956d0666d9c4c2f60a66f112Chandler Carruth  /// this should include all legal feature strings on the target.
634c3a2e654f1e1c5cf956d0666d9c4c2f60a66f112Chandler Carruth  virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
63517ca3638e852ba81f389e9f896ed0420b52ae606Daniel Dunbar  }
63617ca3638e852ba81f389e9f896ed0420b52ae606Daniel Dunbar
637af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Get the ABI currently in use.
638ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  virtual StringRef getABI() const { return StringRef(); }
639018ba5ab0671d9b6eefecaffc118c869bea151a1Daniel Dunbar
640af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Get the C++ ABI currently in use.
641b8b2c9da87e7d70a1679db026f40548b3192b705John McCall  TargetCXXABI getCXXABI() const {
642b8b2c9da87e7d70a1679db026f40548b3192b705John McCall    return TheCXXABI;
64398b7c5c496dfccb39287b8f7d8f1444594936d10Charles Davis  }
64498b7c5c496dfccb39287b8f7d8f1444594936d10Charles Davis
645af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Target the specified CPU.
646eac7c53f16bc12bcd9baac756b6f9bb77b74b0adDaniel Dunbar  ///
647af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \return  False on error (invalid CPU name).
648eac7c53f16bc12bcd9baac756b6f9bb77b74b0adDaniel Dunbar  virtual bool setCPU(const std::string &Name) {
649c3a2e654f1e1c5cf956d0666d9c4c2f60a66f112Chandler Carruth    return false;
650eac7c53f16bc12bcd9baac756b6f9bb77b74b0adDaniel Dunbar  }
651eac7c53f16bc12bcd9baac756b6f9bb77b74b0adDaniel Dunbar
652af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Use the specified ABI.
65373b79596bac6f6169e5979d0c7241924259d2a76Daniel Dunbar  ///
654af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \return False on error (invalid ABI name).
65573b79596bac6f6169e5979d0c7241924259d2a76Daniel Dunbar  virtual bool setABI(const std::string &Name) {
65673b79596bac6f6169e5979d0c7241924259d2a76Daniel Dunbar    return false;
65773b79596bac6f6169e5979d0c7241924259d2a76Daniel Dunbar  }
65873b79596bac6f6169e5979d0c7241924259d2a76Daniel Dunbar
6595389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola  /// \brief Use the specified unit for FP math.
6605389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola  ///
6615389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola  /// \return False on error (invalid unit name).
6625389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola  virtual bool setFPMath(StringRef Name) {
6635389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola    return false;
6645389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola  }
6655389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola
666af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Use this specified C++ ABI.
66798b7c5c496dfccb39287b8f7d8f1444594936d10Charles Davis  ///
668af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \return False on error (invalid C++ ABI name).
669b8b2c9da87e7d70a1679db026f40548b3192b705John McCall  bool setCXXABI(llvm::StringRef name) {
670b8b2c9da87e7d70a1679db026f40548b3192b705John McCall    TargetCXXABI ABI;
671b8b2c9da87e7d70a1679db026f40548b3192b705John McCall    if (!ABI.tryParse(name)) return false;
672ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall    return setCXXABI(ABI);
673ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall  }
674ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall
675af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Set the C++ ABI to be used by this implementation.
676ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall  ///
677af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \return False on error (ABI not valid on this target)
678ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall  virtual bool setCXXABI(TargetCXXABI ABI) {
679b8b2c9da87e7d70a1679db026f40548b3192b705John McCall    TheCXXABI = ABI;
68098b7c5c496dfccb39287b8f7d8f1444594936d10Charles Davis    return true;
68198b7c5c496dfccb39287b8f7d8f1444594936d10Charles Davis  }
68298b7c5c496dfccb39287b8f7d8f1444594936d10Charles Davis
683af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Enable or disable a specific target feature;
68417ca3638e852ba81f389e9f896ed0420b52ae606Daniel Dunbar  /// the feature name must be valid.
685ade7cd45d5bf510c8599b805691e6402edb0d203Rafael Espindola  virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
686713575afdac1f31de39b4a730143b8d96eeadb6dBenjamin Kramer                                 StringRef Name,
68717ca3638e852ba81f389e9f896ed0420b52ae606Daniel Dunbar                                 bool Enabled) const {
688ade7cd45d5bf510c8599b805691e6402edb0d203Rafael Espindola    Features[Name] = Enabled;
689868bd0aa9281929ef50d2e9a8c82a036906f53f5Daniel Dunbar  }
690868bd0aa9281929ef50d2e9a8c82a036906f53f5Daniel Dunbar
691af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Perform initialization based on the user configured
692af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// set of features (e.g., +sse4).
693af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
694af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// The list is guaranteed to have at most one entry per feature.
695b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4Daniel Dunbar  ///
696b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4Daniel Dunbar  /// The target may modify the features list, to change which options are
697b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4Daniel Dunbar  /// passed onwards to the backend.
6985389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola  ///
6995389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola  /// \return  False on error.
7003d11cedeb5ed610dbfb0da733d65d8e95ed217daEric Christopher  virtual bool handleTargetFeatures(std::vector<std::string> &Features,
7015389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola                                    DiagnosticsEngine &Diags) {
7025389b84a780ac17b63c10ad97cd5e3aaa41595b7Rafael Espindola    return true;
70316167a6e3f7dfb7ed0babc5e0baab9fd140e959dChris Lattner  }
704264a76cdf382c507f4d43e64c89f1503f003ac95Anton Korobeynikov
705e727d21d3fd5f6f68d9e7a260bbf84dc2fc8ae3aDouglas Gregor  /// \brief Determine whether the given target has the given feature.
706e727d21d3fd5f6f68d9e7a260bbf84dc2fc8ae3aDouglas Gregor  virtual bool hasFeature(StringRef Feature) const {
707e727d21d3fd5f6f68d9e7a260bbf84dc2fc8ae3aDouglas Gregor    return false;
708e727d21d3fd5f6f68d9e7a260bbf84dc2fc8ae3aDouglas Gregor  }
709e727d21d3fd5f6f68d9e7a260bbf84dc2fc8ae3aDouglas Gregor
710af50aab0c317462129d73ae8000c6394c718598dJames Dennett  // \brief Returns maximal number of args passed in registers.
711264a76cdf382c507f4d43e64c89f1503f003ac95Anton Korobeynikov  unsigned getRegParmMax() const {
7127e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
713264a76cdf382c507f4d43e64c89f1503f003ac95Anton Korobeynikov    return RegParmMax;
714264a76cdf382c507f4d43e64c89f1503f003ac95Anton Korobeynikov  }
715264a76cdf382c507f4d43e64c89f1503f003ac95Anton Korobeynikov
716af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Whether the target supports thread-local storage.
7176a3bc6df36848188e9d0c1d978170c2b0918c6a3Chris Lattner  bool isTLSSupported() const {
718b030f0272500c6c5602f587ac029ee0dc0e5a05cEli Friedman    return TLSSupported;
719b030f0272500c6c5602f587ac029ee0dc0e5a05cEli Friedman  }
720237cf582b89bbcc22640cea15426ddc7ada8412bMichael J. Spencer
721af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return true if {|} are normal characters in the asm string.
722af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
723af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// If this returns false (the default), then {abc|xyz} is syntax
72437de281ac149a5c5f14e4935a3738d87370da3edChris Lattner  /// that says that when compiling for asm variant #0, "abc" should be
7259bffb0701d02a10e77e1ac0f196074eed6466ed0Chris Lattner  /// generated, but when compiling for asm variant #1, "xyz" should be
7269bffb0701d02a10e77e1ac0f196074eed6466ed0Chris Lattner  /// generated.
7279bffb0701d02a10e77e1ac0f196074eed6466ed0Chris Lattner  bool hasNoAsmVariants() const {
7289bffb0701d02a10e77e1ac0f196074eed6466ed0Chris Lattner    return NoAsmVariants;
7299bffb0701d02a10e77e1ac0f196074eed6466ed0Chris Lattner  }
730237cf582b89bbcc22640cea15426ddc7ada8412bMichael J. Spencer
731af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the register number that __builtin_eh_return_regno would
732af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// return with the specified argument.
73321fb98ee003e992b0c4e204d98a19e0ef544cae3Chris Lattner  virtual int getEHDataRegisterNumber(unsigned RegNo) const {
734237cf582b89bbcc22640cea15426ddc7ada8412bMichael J. Spencer    return -1;
73521fb98ee003e992b0c4e204d98a19e0ef544cae3Chris Lattner  }
736237cf582b89bbcc22640cea15426ddc7ada8412bMichael J. Spencer
737af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return the section to use for C++ static initialization functions.
73818af368c080b9d60e34e670cd01f7d2d3ad2ba48Anders Carlsson  virtual const char *getStaticInitSectionSpecifier() const {
7396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return nullptr;
74018af368c080b9d60e34e670cd01f7d2d3ad2ba48Anders Carlsson  }
741207f4d8543529221932af82836016a2ef066c917Peter Collingbourne
742207f4d8543529221932af82836016a2ef066c917Peter Collingbourne  const LangAS::Map &getAddressSpaceMap() const {
743207f4d8543529221932af82836016a2ef066c917Peter Collingbourne    return *AddrSpaceMap;
744207f4d8543529221932af82836016a2ef066c917Peter Collingbourne  }
745207f4d8543529221932af82836016a2ef066c917Peter Collingbourne
7460a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Retrieve the name of the platform as it is used in the
7470a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// availability attribute.
748686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getPlatformName() const { return PlatformName; }
7490a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
7500a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Retrieve the minimum desired version of the platform, to
7510a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// which the program should be compiled.
7520a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
7530a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
754e6a24e83e71f361c7b7de82cf24ee6f5ddc7f1c2Eli Friedman  bool isBigEndian() const { return BigEndian; }
755e6a24e83e71f361c7b7de82cf24ee6f5ddc7f1c2Eli Friedman
756fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman  enum CallingConvMethodType {
757fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman    CCMT_Unknown,
758fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman    CCMT_Member,
759fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman    CCMT_NonMember
760fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman  };
761fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman
76282bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  /// \brief Gets the default calling convention for the given target and
76382bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  /// declaration context.
764fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman  virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
76582bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman    // Not all targets will specify an explicit calling convention that we can
76682bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman    // express.  This will always do the right thing, even though it's not
76782bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman    // an explicit calling convention.
768fff3248e69c478cfb4d1a1ffdefb808d5885535bAaron Ballman    return CC_C;
76982bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  }
77082bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman
77182bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  enum CallingConvCheckResult {
77282bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman    CCCR_OK,
77382bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman    CCCR_Warning
77482bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  };
77582bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman
77682bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  /// \brief Determines whether a given calling convention is valid for the
77782bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  /// target. A calling convention can either be accepted, produce a warning
77882bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  /// and be substituted with the default calling convention, or (someday)
77982bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  /// produce an error (such as using thiscall on a non-instance function).
78082bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
7817728cddd7866fadd07f1191eee40985e3cdbc6bfPeter Collingbourne    switch (CC) {
7827728cddd7866fadd07f1191eee40985e3cdbc6bfPeter Collingbourne      default:
7837728cddd7866fadd07f1191eee40985e3cdbc6bfPeter Collingbourne        return CCCR_Warning;
7847728cddd7866fadd07f1191eee40985e3cdbc6bfPeter Collingbourne      case CC_C:
7857728cddd7866fadd07f1191eee40985e3cdbc6bfPeter Collingbourne        return CCCR_OK;
7867728cddd7866fadd07f1191eee40985e3cdbc6bfPeter Collingbourne    }
78782bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman  }
78882bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman
7890eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattnerprotected:
7900e5d4ef3155651af17a90fdc07d9f80b33935c0cChris Lattner  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
7910e5d4ef3155651af17a90fdc07d9f80b33935c0cChris Lattner    return PointerWidth;
7920e5d4ef3155651af17a90fdc07d9f80b33935c0cChris Lattner  }
7930e5d4ef3155651af17a90fdc07d9f80b33935c0cChris Lattner  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
7940e5d4ef3155651af17a90fdc07d9f80b33935c0cChris Lattner    return PointerAlign;
7950e5d4ef3155651af17a90fdc07d9f80b33935c0cChris Lattner  }
79631fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta  virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
79731fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta    return PtrDiffType;
79831fc07df7f0fc89ebf83ca05a20b29de45a7598dSanjiv Gupta  }
7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void getGCCRegNames(const char * const *&Names,
8000eaed12e634dfd14f44620f63b8d3276fed028ddChris Lattner                              unsigned &NumNames) const = 0;
8011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
8023346ae6bba10da0d08c8d548134ddab4e13d040fAnders Carlsson                                unsigned &NumAliases) const = 0;
803cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher  virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
8043d11cedeb5ed610dbfb0da733d65d8e95ed217daEric Christopher                                  unsigned &NumAddl) const {
8056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Addl = nullptr;
806cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher    NumAddl = 0;
807cfd323d0d4476dd4ff64097c91b114067ecaa82bEric Christopher  }
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual bool validateAsmConstraint(const char *&Name,
809d04c6e23f2e10eeb9936778d67f4a1c4a14cc4f6Anders Carlsson                                     TargetInfo::ConstraintInfo &info) const= 0;
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
815