Replace Triple with a new TargetTuple in MCTargetDesc/* and related. NFC.
[oota-llvm.git] / include / llvm / ADT / TargetTuple.h
1 //===-- llvm/ADT/TargetTuple.h - Target tuple class -------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// @file
11 /// This file contains the definitions for TargetTuples which describe the
12 /// target in a unique unambiguous way. This is in contrast to the GNU triples
13 /// handled by the Triple class which are more of a guideline than a
14 /// description and whose meaning can be overridden by vendors and distributors.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_ADT_TARGETTUPLE_H
19 #define LLVM_ADT_TARGETTUPLE_H
20
21 #include "llvm/ADT/Twine.h"
22 #include "llvm/ADT/Triple.h"
23
24 // Some system headers or GCC predefined macros conflict with identifiers in
25 // this file.  Undefine them here.
26 #undef NetBSD
27 #undef mips
28 #undef sparc
29
30 namespace llvm {
31
32 /// TargetTuple is currently a proxy for Triple but will become an unambiguous,
33 /// authoratitive, and mutable counterpart to the GNU triples handled by Triple.
34 class TargetTuple {
35 public:
36   // FIXME: Don't duplicate Triple::ArchType. It's worth mentioning that these
37   //        these values don't have to match Triple::ArchType. For example, it
38   //        would be fairly sensible to have a single 'mips' architecture and
39   //        distinguish endianness and ABI elsewhere.
40   enum ArchType {
41     UnknownArch,
42
43     arm,        // ARM (little endian): arm, armv.*, xscale
44     armeb,      // ARM (big endian): armeb
45     aarch64,    // AArch64 (little endian): aarch64
46     aarch64_be, // AArch64 (big endian): aarch64_be
47     bpfel,      // eBPF or extended BPF or 64-bit BPF (little endian)
48     bpfeb,      // eBPF or extended BPF or 64-bit BPF (big endian)
49     hexagon,    // Hexagon: hexagon
50     mips,       // MIPS: mips, mipsallegrex
51     mipsel,     // MIPSEL: mipsel, mipsallegrexel
52     mips64,     // MIPS64: mips64
53     mips64el,   // MIPS64EL: mips64el
54     msp430,     // MSP430: msp430
55     ppc,        // PPC: powerpc
56     ppc64,      // PPC64: powerpc64, ppu
57     ppc64le,    // PPC64LE: powerpc64le
58     r600,       // R600: AMD GPUs HD2XXX - HD6XXX
59     amdgcn,     // AMDGCN: AMD GCN GPUs
60     sparc,      // Sparc: sparc
61     sparcv9,    // Sparcv9: Sparcv9
62     sparcel,    // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant
63     systemz,    // SystemZ: s390x
64     tce,        // TCE (http://tce.cs.tut.fi/): tce
65                 // FIXME: thumb/thumbeb will be merged into arm/armeb soon.
66     thumb,      // Thumb (little endian): thumb, thumbv.*
67     thumbeb,    // Thumb (big endian): thumbeb
68     x86,        // X86: i[3-9]86
69     x86_64,     // X86-64: amd64, x86_64
70     xcore,      // XCore: xcore
71     nvptx,      // NVPTX: 32-bit
72     nvptx64,    // NVPTX: 64-bit
73     le32,       // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
74     le64,       // le64: generic little-endian 64-bit CPU (PNaCl / Emscripten)
75     amdil,      // AMDIL
76     amdil64,    // AMDIL with 64-bit pointers
77     hsail,      // AMD HSAIL
78     hsail64,    // AMD HSAIL with 64-bit pointers
79     spir,       // SPIR: standard portable IR for OpenCL 32-bit version
80     spir64,     // SPIR: standard portable IR for OpenCL 64-bit version
81     kalimba,    // Kalimba: generic kalimba
82     shave,      // SHAVE: Movidius vector VLIW processors
83     wasm32,     // WebAssembly with 32-bit pointers
84     wasm64,     // WebAssembly with 64-bit pointers
85     LastArchType = wasm64
86   };
87
88   enum SubArchType {
89     NoSubArch,
90
91     ARMSubArch_v8_1a,
92     ARMSubArch_v8,
93     ARMSubArch_v7,
94     ARMSubArch_v7em,
95     ARMSubArch_v7m,
96     ARMSubArch_v7s,
97     ARMSubArch_v6,
98     ARMSubArch_v6m,
99     ARMSubArch_v6k,
100     ARMSubArch_v6t2,
101     ARMSubArch_v5,
102     ARMSubArch_v5te,
103     ARMSubArch_v4t,
104
105     KalimbaSubArch_v3,
106     KalimbaSubArch_v4,
107     KalimbaSubArch_v5
108   };
109
110   enum VendorType {
111     UnknownVendor,
112
113     Apple,
114     PC,
115     SCEI,
116     BGP,
117     BGQ,
118     Freescale,
119     IBM,
120     ImaginationTechnologies,
121     MipsTechnologies,
122     NVIDIA,
123     CSR,
124     Myriad,
125     LastVendorType = Myriad
126   };
127
128   enum OSType {
129     UnknownOS,
130
131     CloudABI,
132     Darwin,
133     DragonFly,
134     FreeBSD,
135     IOS,
136     KFreeBSD,
137     Linux,
138     Lv2, // PS3
139     MacOSX,
140     NetBSD,
141     OpenBSD,
142     Solaris,
143     Win32,
144     Haiku,
145     Minix,
146     RTEMS,
147     NaCl, // Native Client
148     CNK,  // BG/P Compute-Node Kernel
149     Bitrig,
150     AIX,
151     CUDA,   // NVIDIA CUDA
152     NVCL,   // NVIDIA OpenCL
153     AMDHSA, // AMD HSA Runtime
154     PS4,
155     LastOSType = PS4
156   };
157
158   enum EnvironmentType {
159     UnknownEnvironment,
160
161     GNU,
162     GNUEABI,
163     GNUEABIHF,
164     GNUX32,
165     CODE16,
166     EABI,
167     EABIHF,
168     Android,
169
170     MSVC,
171     Itanium,
172     Cygnus,
173     AMDOpenCL,
174     CoreCLR,
175     LastEnvironmentType = CoreCLR
176   };
177
178   enum ObjectFormatType {
179     UnknownObjectFormat,
180
181     COFF,
182     ELF,
183     MachO,
184   };
185
186 public:
187   /// @name Constructors
188   /// @{
189
190   /// Default constructor leaves all fields unknown.
191   TargetTuple() : GnuTT() {}
192
193   /// Convert a GNU Triple to a TargetTuple.
194   ///
195   /// This conversion assumes that GNU Triple's have a specific defined meaning
196   /// which isn't strictly true. A single Triple can potentially have multiple
197   /// contradictory meanings depending on compiler options and configure-time
198   /// options. Despite this, Triple's do tend to have a 'usual' meaning, or
199   /// rather a default behaviour and this function selects it.
200   ///
201   /// When tool options affect the desired TargetTuple, the tool should obtain
202   /// the usual meaning of the GNU Triple using this constructor and then use
203   /// the mutator methods to apply the tool options.
204   explicit TargetTuple(const Triple &GnuTT) : GnuTT(GnuTT) {}
205
206   /// @}
207   /// @name Typed Component Access
208   /// @{
209
210   /// Get the parsed architecture type of this triple.
211   ArchType getArch() const;
212
213   /// get the parsed subarchitecture type for this triple.
214   SubArchType getSubArch() const;
215
216   /// Get the parsed vendor type of this triple.
217   VendorType getVendor() const;
218
219   /// Get the parsed operating system type of this triple.
220   OSType getOS() const;
221
222   /// Does this triple have the optional environment
223   /// (fourth) component?
224   bool hasEnvironment() const { return GnuTT.hasEnvironment(); }
225
226   /// Get the parsed environment type of this triple.
227   EnvironmentType getEnvironment() const;
228
229   /// Parse the version number from the OS name component of the
230   /// triple, if present.
231   ///
232   /// For example, "fooos1.2.3" would return (1, 2, 3).
233   ///
234   /// If an entry is not defined, it will be returned as 0.
235   void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
236                              unsigned &Micro) const;
237
238   /// Get the object format for this triple.
239   ObjectFormatType getObjectFormat() const;
240
241   /// Parse the version number from the OS name component of the
242   /// triple, if present.
243   ///
244   /// For example, "fooos1.2.3" would return (1, 2, 3).
245   ///
246   /// If an entry is not defined, it will be returned as 0.
247   void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const {
248     return GnuTT.getOSVersion(Major, Minor, Micro);
249   }
250
251   /// Return just the major version number, this is
252   /// specialized because it is a common query.
253   unsigned getOSMajorVersion() const { return GnuTT.getOSMajorVersion(); }
254
255   /// Parse the version number as with getOSVersion and then
256   /// translate generic "darwin" versions to the corresponding OS X versions.
257   /// This may also be called with IOS triples but the OS X version number is
258   /// just set to a constant 10.4.0 in that case.  Returns true if successful.
259   bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
260                         unsigned &Micro) const {
261     return GnuTT.getMacOSXVersion(Major, Minor, Micro);
262   }
263
264   /// Parse the version number as with getOSVersion.  This
265   /// should
266   /// only be called with IOS triples.
267   void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const {
268     return GnuTT.getiOSVersion(Major, Minor, Micro);
269   }
270
271   /// @}
272   /// @name Direct Component Access
273   /// @{
274
275   const std::string &str() const { return GnuTT.str(); }
276
277   const std::string &getTriple() const { return GnuTT.str(); }
278
279   /// Get the architecture (first) component of the
280   /// triple.
281   StringRef getArchName() const { return GnuTT.getArchName(); }
282
283   /// Get the vendor (second) component of the triple.
284   StringRef getVendorName() const { return GnuTT.getVendorName(); }
285
286   /// Get the operating system (third) component of the
287   /// triple.
288   StringRef getOSName() const { return GnuTT.getOSName(); }
289
290   /// Get the optional environment (fourth)
291   /// component of the triple, or "" if empty.
292   StringRef getEnvironmentName() const { return GnuTT.getEnvironmentName(); }
293
294   /// Get the operating system and optional
295   /// environment components as a single string (separated by a '-'
296   /// if the environment component is present).
297   StringRef getOSAndEnvironmentName() const {
298     return GnuTT.getOSAndEnvironmentName();
299   }
300
301   /// @}
302   /// @name Convenience Predicates
303   /// @{
304
305   /// Test whether the architecture is 64-bit
306   ///
307   /// Note that this tests for 64-bit pointer width, and nothing else. Note
308   /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
309   /// 16-bit. The inner details of pointer width for particular architectures
310   /// is not summed up in the triple, and so only a coarse grained predicate
311   /// system is provided.
312   bool isArch64Bit() const { return GnuTT.isArch64Bit(); }
313
314   /// Test whether the architecture is 32-bit
315   ///
316   /// Note that this tests for 32-bit pointer width, and nothing else.
317   bool isArch32Bit() const { return GnuTT.isArch32Bit(); }
318
319   /// Test whether the architecture is 16-bit
320   ///
321   /// Note that this tests for 16-bit pointer width, and nothing else.
322   bool isArch16Bit() const { return GnuTT.isArch16Bit(); }
323
324   /// Helper function for doing comparisons against version
325   /// numbers included in the target triple.
326   bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
327                      unsigned Micro = 0) const {
328     return GnuTT.isOSVersionLT(Major, Minor, Micro);
329   }
330
331   bool isOSVersionLT(const Triple &Other) const {
332     return GnuTT.isOSVersionLT(Other);
333   }
334
335   /// Comparison function for checking OS X version
336   /// compatibility, which handles supporting skewed version numbering schemes
337   /// used by the "darwin" triples.
338   unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
339                              unsigned Micro = 0) const {
340     return GnuTT.isMacOSXVersionLT(Major, Minor, Micro);
341   }
342
343   /// Is this a Mac OS X triple. For legacy reasons, we support both
344   /// "darwin" and "osx" as OS X triples.
345   bool isMacOSX() const { return GnuTT.isMacOSX(); }
346
347   /// Is this an iOS triple.
348   bool isiOS() const { return GnuTT.isiOS(); }
349
350   /// Is this a "Darwin" OS (OS X or iOS).
351   bool isOSDarwin() const { return GnuTT.isOSDarwin(); }
352
353   bool isOSNetBSD() const { return GnuTT.isOSNetBSD(); }
354
355   bool isOSOpenBSD() const { return GnuTT.isOSOpenBSD(); }
356
357   bool isOSFreeBSD() const { return GnuTT.isOSFreeBSD(); }
358
359   bool isOSDragonFly() const { return GnuTT.isOSDragonFly(); }
360
361   bool isOSSolaris() const { return GnuTT.isOSSolaris(); }
362
363   bool isOSBitrig() const { return GnuTT.isOSBitrig(); }
364
365   bool isWindowsMSVCEnvironment() const {
366     return GnuTT.isWindowsMSVCEnvironment();
367   }
368
369   bool isKnownWindowsMSVCEnvironment() const {
370     return GnuTT.isKnownWindowsMSVCEnvironment();
371   }
372
373   bool isWindowsCoreCLREnvironment() const {
374     return GnuTT.isWindowsCoreCLREnvironment();
375   }
376
377   bool isWindowsItaniumEnvironment() const {
378     return GnuTT.isWindowsItaniumEnvironment();
379   }
380
381   bool isWindowsCygwinEnvironment() const {
382     return GnuTT.isWindowsCygwinEnvironment();
383   }
384
385   bool isWindowsGNUEnvironment() const {
386     return GnuTT.isWindowsGNUEnvironment();
387   }
388
389   /// Tests for either Cygwin or MinGW OS
390   bool isOSCygMing() const { return GnuTT.isOSCygMing(); }
391
392   /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
393   bool isOSMSVCRT() const { return GnuTT.isOSMSVCRT(); }
394
395   /// Tests whether the OS is Windows.
396   bool isOSWindows() const { return GnuTT.isOSWindows(); }
397
398   /// Tests whether the OS is NaCl (Native Client)
399   bool isOSNaCl() const { return GnuTT.isOSNaCl(); }
400
401   /// Tests whether the OS is Linux.
402   bool isOSLinux() const { return GnuTT.isOSLinux(); }
403
404   /// Tests whether the OS uses the ELF binary format.
405   bool isOSBinFormatELF() const { return GnuTT.isOSBinFormatELF(); }
406
407   /// Tests whether the OS uses the COFF binary format.
408   bool isOSBinFormatCOFF() const { return GnuTT.isOSBinFormatCOFF(); }
409
410   /// Tests whether the environment is MachO.
411   bool isOSBinFormatMachO() const { return GnuTT.isOSBinFormatMachO(); }
412
413   /// Tests whether the target is the PS4 CPU
414   bool isPS4CPU() const { return GnuTT.isPS4CPU(); }
415
416   /// Tests whether the target is the PS4 platform
417   bool isPS4() const { return GnuTT.isPS4(); }
418
419   /// @}
420
421   // FIXME: Remove. This function exists to avoid having to migrate everything
422   //        at once.
423   const Triple &getTargetTriple() const { return GnuTT; }
424
425 private:
426   Triple GnuTT;
427 };
428
429 } // End llvm namespace
430
431 #endif