Delete support for AuroraUX.
[oota-llvm.git] / include / llvm / ADT / Triple.h
1 //===-- llvm/ADT/Triple.h - Target triple helper 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 #ifndef LLVM_ADT_TRIPLE_H
11 #define LLVM_ADT_TRIPLE_H
12
13 #include "llvm/ADT/Twine.h"
14
15 // Some system headers or GCC predefined macros conflict with identifiers in
16 // this file.  Undefine them here.
17 #undef NetBSD
18 #undef mips
19 #undef sparc
20
21 namespace llvm {
22
23 /// Triple - Helper class for working with autoconf configuration names. For
24 /// historical reasons, we also call these 'triples' (they used to contain
25 /// exactly three fields).
26 ///
27 /// Configuration names are strings in the canonical form:
28 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM
29 /// or
30 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
31 ///
32 /// This class is used for clients which want to support arbitrary
33 /// configuration names, but also want to implement certain special
34 /// behavior for particular configurations. This class isolates the mapping
35 /// from the components of the configuration name to well known IDs.
36 ///
37 /// At its core the Triple class is designed to be a wrapper for a triple
38 /// string; the constructor does not change or normalize the triple string.
39 /// Clients that need to handle the non-canonical triples that users often
40 /// specify should use the normalize method.
41 ///
42 /// See autoconf/config.guess for a glimpse into what configuration names
43 /// look like in practice.
44 class Triple {
45 public:
46   enum ArchType {
47     UnknownArch,
48
49     arm,        // ARM (little endian): arm, armv.*, xscale
50     armeb,      // ARM (big endian): armeb
51     aarch64,    // AArch64 (little endian): aarch64
52     aarch64_be, // AArch64 (big endian): aarch64_be
53     hexagon,    // Hexagon: hexagon
54     mips,       // MIPS: mips, mipsallegrex
55     mipsel,     // MIPSEL: mipsel, mipsallegrexel
56     mips64,     // MIPS64: mips64
57     mips64el,   // MIPS64EL: mips64el
58     msp430,     // MSP430: msp430
59     ppc,        // PPC: powerpc
60     ppc64,      // PPC64: powerpc64, ppu
61     ppc64le,    // PPC64LE: powerpc64le
62     r600,       // R600: AMD GPUs HD2XXX - HD6XXX
63     sparc,      // Sparc: sparc
64     sparcv9,    // Sparcv9: Sparcv9
65     systemz,    // SystemZ: s390x
66     tce,        // TCE (http://tce.cs.tut.fi/): tce
67     thumb,      // Thumb (little endian): thumb, thumbv.*
68     thumbeb,    // Thumb (big endian): thumbeb
69     x86,        // X86: i[3-9]86
70     x86_64,     // X86-64: amd64, x86_64
71     xcore,      // XCore: xcore
72     nvptx,      // NVPTX: 32-bit
73     nvptx64,    // NVPTX: 64-bit
74     le32,       // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
75     amdil,      // amdil: amd IL
76     spir,       // SPIR: standard portable IR for OpenCL 32-bit version
77     spir64,     // SPIR: standard portable IR for OpenCL 64-bit version
78     kalimba     // Kalimba: generic kalimba
79   };
80   enum SubArchType {
81     NoSubArch,
82
83     ARMSubArch_v8,
84     ARMSubArch_v7,
85     ARMSubArch_v7em,
86     ARMSubArch_v7m,
87     ARMSubArch_v7s,
88     ARMSubArch_v6,
89     ARMSubArch_v6m,
90     ARMSubArch_v6t2,
91     ARMSubArch_v5,
92     ARMSubArch_v5te,
93     ARMSubArch_v4t
94   };
95   enum VendorType {
96     UnknownVendor,
97
98     Apple,
99     PC,
100     SCEI,
101     BGP,
102     BGQ,
103     Freescale,
104     IBM,
105     ImaginationTechnologies,
106     MipsTechnologies,
107     NVIDIA,
108     CSR
109   };
110   enum OSType {
111     UnknownOS,
112
113     Darwin,
114     DragonFly,
115     FreeBSD,
116     IOS,
117     KFreeBSD,
118     Linux,
119     Lv2,        // PS3
120     MacOSX,
121     NetBSD,
122     OpenBSD,
123     Solaris,
124     Win32,
125     Haiku,
126     Minix,
127     RTEMS,
128     NaCl,       // Native Client
129     CNK,        // BG/P Compute-Node Kernel
130     Bitrig,
131     AIX,
132     CUDA,       // NVIDIA CUDA
133     NVCL        // NVIDIA OpenCL
134   };
135   enum EnvironmentType {
136     UnknownEnvironment,
137
138     GNU,
139     GNUEABI,
140     GNUEABIHF,
141     GNUX32,
142     CODE16,
143     EABI,
144     EABIHF,
145     Android,
146
147     MSVC,
148     Itanium,
149     Cygnus,
150   };
151   enum ObjectFormatType {
152     UnknownObjectFormat,
153
154     COFF,
155     ELF,
156     MachO,
157   };
158
159 private:
160   std::string Data;
161
162   /// The parsed arch type.
163   ArchType Arch;
164
165   /// The parsed subarchitecture type.
166   SubArchType SubArch;
167
168   /// The parsed vendor type.
169   VendorType Vendor;
170
171   /// The parsed OS type.
172   OSType OS;
173
174   /// The parsed Environment type.
175   EnvironmentType Environment;
176
177   /// The object format type.
178   ObjectFormatType ObjectFormat;
179
180 public:
181   /// @name Constructors
182   /// @{
183
184   /// \brief Default constructor is the same as an empty string and leaves all
185   /// triple fields unknown.
186   Triple() : Data(), Arch(), Vendor(), OS(), Environment(), ObjectFormat() {}
187
188   explicit Triple(const Twine &Str);
189   Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
190   Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
191          const Twine &EnvironmentStr);
192
193   /// @}
194   /// @name Normalization
195   /// @{
196
197   /// normalize - Turn an arbitrary machine specification into the canonical
198   /// triple form (or something sensible that the Triple class understands if
199   /// nothing better can reasonably be done).  In particular, it handles the
200   /// common case in which otherwise valid components are in the wrong order.
201   static std::string normalize(StringRef Str);
202
203   /// @}
204   /// @name Typed Component Access
205   /// @{
206
207   /// getArch - Get the parsed architecture type of this triple.
208   ArchType getArch() const { return Arch; }
209
210   /// getSubArch - get the parsed subarchitecture type for this triple.
211   SubArchType getSubArch() const { return SubArch; }
212
213   /// getVendor - Get the parsed vendor type of this triple.
214   VendorType getVendor() const { return Vendor; }
215
216   /// getOS - Get the parsed operating system type of this triple.
217   OSType getOS() const { return OS; }
218
219   /// hasEnvironment - Does this triple have the optional environment
220   /// (fourth) component?
221   bool hasEnvironment() const {
222     return getEnvironmentName() != "";
223   }
224
225   /// getEnvironment - Get the parsed environment type of this triple.
226   EnvironmentType getEnvironment() const { return Environment; }
227
228   /// getFormat - Get the object format for this triple.
229   ObjectFormatType getObjectFormat() const { return ObjectFormat; }
230
231   /// getOSVersion - Parse the version number from the OS name component of the
232   /// triple, if present.
233   ///
234   /// For example, "fooos1.2.3" would return (1, 2, 3).
235   ///
236   /// If an entry is not defined, it will be returned as 0.
237   void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
238
239   /// getOSMajorVersion - Return just the major version number, this is
240   /// specialized because it is a common query.
241   unsigned getOSMajorVersion() const {
242     unsigned Maj, Min, Micro;
243     getOSVersion(Maj, Min, Micro);
244     return Maj;
245   }
246
247   /// getMacOSXVersion - Parse the version number as with getOSVersion and then
248   /// translate generic "darwin" versions to the corresponding OS X versions.
249   /// This may also be called with IOS triples but the OS X version number is
250   /// just set to a constant 10.4.0 in that case.  Returns true if successful.
251   bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
252                         unsigned &Micro) const;
253
254   /// getiOSVersion - Parse the version number as with getOSVersion.  This should
255   /// only be called with IOS triples.
256   void getiOSVersion(unsigned &Major, unsigned &Minor,
257                      unsigned &Micro) const;
258
259   /// @}
260   /// @name Direct Component Access
261   /// @{
262
263   const std::string &str() const { return Data; }
264
265   const std::string &getTriple() const { return Data; }
266
267   /// getArchName - Get the architecture (first) component of the
268   /// triple.
269   StringRef getArchName() const;
270
271   /// getVendorName - Get the vendor (second) component of the triple.
272   StringRef getVendorName() const;
273
274   /// getOSName - Get the operating system (third) component of the
275   /// triple.
276   StringRef getOSName() const;
277
278   /// getEnvironmentName - Get the optional environment (fourth)
279   /// component of the triple, or "" if empty.
280   StringRef getEnvironmentName() const;
281
282   /// getOSAndEnvironmentName - Get the operating system and optional
283   /// environment components as a single string (separated by a '-'
284   /// if the environment component is present).
285   StringRef getOSAndEnvironmentName() const;
286
287   /// @}
288   /// @name Convenience Predicates
289   /// @{
290
291   /// \brief Test whether the architecture is 64-bit
292   ///
293   /// Note that this tests for 64-bit pointer width, and nothing else. Note
294   /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
295   /// 16-bit. The inner details of pointer width for particular architectures
296   /// is not summed up in the triple, and so only a coarse grained predicate
297   /// system is provided.
298   bool isArch64Bit() const;
299
300   /// \brief Test whether the architecture is 32-bit
301   ///
302   /// Note that this tests for 32-bit pointer width, and nothing else.
303   bool isArch32Bit() const;
304
305   /// \brief Test whether the architecture is 16-bit
306   ///
307   /// Note that this tests for 16-bit pointer width, and nothing else.
308   bool isArch16Bit() const;
309
310   /// isOSVersionLT - Helper function for doing comparisons against version
311   /// numbers included in the target triple.
312   bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
313                      unsigned Micro = 0) const {
314     unsigned LHS[3];
315     getOSVersion(LHS[0], LHS[1], LHS[2]);
316
317     if (LHS[0] != Major)
318       return LHS[0] < Major;
319     if (LHS[1] != Minor)
320       return LHS[1] < Minor;
321     if (LHS[2] != Micro)
322       return LHS[1] < Micro;
323
324     return false;
325   }
326
327   /// isMacOSXVersionLT - Comparison function for checking OS X version
328   /// compatibility, which handles supporting skewed version numbering schemes
329   /// used by the "darwin" triples.
330   unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
331                              unsigned Micro = 0) const {
332     assert(isMacOSX() && "Not an OS X triple!");
333
334     // If this is OS X, expect a sane version number.
335     if (getOS() == Triple::MacOSX)
336       return isOSVersionLT(Major, Minor, Micro);
337
338     // Otherwise, compare to the "Darwin" number.
339     assert(Major == 10 && "Unexpected major version");
340     return isOSVersionLT(Minor + 4, Micro, 0);
341   }
342
343   /// isMacOSX - 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 {
346     return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
347   }
348
349   /// Is this an iOS triple.
350   bool isiOS() const {
351     return getOS() == Triple::IOS;
352   }
353
354   /// isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
355   bool isOSDarwin() const {
356     return isMacOSX() || isiOS();
357   }
358
359   bool isOSFreeBSD() const {
360     return getOS() == Triple::FreeBSD;
361   }
362
363   bool isWindowsMSVCEnvironment() const {
364     return getOS() == Triple::Win32 &&
365            (getEnvironment() == Triple::UnknownEnvironment ||
366             getEnvironment() == Triple::MSVC);
367   }
368
369   bool isKnownWindowsMSVCEnvironment() const {
370     return getOS() == Triple::Win32 && getEnvironment() == Triple::MSVC;
371   }
372
373   bool isWindowsItaniumEnvironment() const {
374     return getOS() == Triple::Win32 && getEnvironment() == Triple::Itanium;
375   }
376
377   bool isWindowsCygwinEnvironment() const {
378     return getOS() == Triple::Win32 && getEnvironment() == Triple::Cygnus;
379   }
380
381   bool isWindowsGNUEnvironment() const {
382     return getOS() == Triple::Win32 && getEnvironment() == Triple::GNU;
383   }
384
385   /// \brief Tests for either Cygwin or MinGW OS
386   bool isOSCygMing() const {
387     return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment();
388   }
389
390   /// \brief Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
391   bool isOSMSVCRT() const {
392     return isWindowsMSVCEnvironment() || isWindowsGNUEnvironment();
393   }
394
395   /// \brief Tests whether the OS is Windows.
396   bool isOSWindows() const {
397     return getOS() == Triple::Win32 || isOSCygMing();
398   }
399
400   /// \brief Tests whether the OS is NaCl (Native Client)
401   bool isOSNaCl() const {
402     return getOS() == Triple::NaCl;
403   }
404
405   /// \brief Tests whether the OS is Linux.
406   bool isOSLinux() const {
407     return getOS() == Triple::Linux;
408   }
409
410   /// \brief Tests whether the OS uses the ELF binary format.
411   bool isOSBinFormatELF() const {
412     return getObjectFormat() == Triple::ELF;
413   }
414
415   /// \brief Tests whether the OS uses the COFF binary format.
416   bool isOSBinFormatCOFF() const {
417     return getObjectFormat() == Triple::COFF;
418   }
419
420   /// \brief Tests whether the environment is MachO.
421   bool isOSBinFormatMachO() const {
422     return getObjectFormat() == Triple::MachO;
423   }
424
425   /// @}
426   /// @name Mutators
427   /// @{
428
429   /// setArch - Set the architecture (first) component of the triple
430   /// to a known type.
431   void setArch(ArchType Kind);
432
433   /// setVendor - Set the vendor (second) component of the triple to a
434   /// known type.
435   void setVendor(VendorType Kind);
436
437   /// setOS - Set the operating system (third) component of the triple
438   /// to a known type.
439   void setOS(OSType Kind);
440
441   /// setEnvironment - Set the environment (fourth) component of the triple
442   /// to a known type.
443   void setEnvironment(EnvironmentType Kind);
444
445   /// setObjectFormat - Set the object file format
446   void setObjectFormat(ObjectFormatType Kind);
447
448   /// setTriple - Set all components to the new triple \p Str.
449   void setTriple(const Twine &Str);
450
451   /// setArchName - Set the architecture (first) component of the
452   /// triple by name.
453   void setArchName(StringRef Str);
454
455   /// setVendorName - Set the vendor (second) component of the triple
456   /// by name.
457   void setVendorName(StringRef Str);
458
459   /// setOSName - Set the operating system (third) component of the
460   /// triple by name.
461   void setOSName(StringRef Str);
462
463   /// setEnvironmentName - Set the optional environment (fourth)
464   /// component of the triple by name.
465   void setEnvironmentName(StringRef Str);
466
467   /// setOSAndEnvironmentName - Set the operating system and optional
468   /// environment components with a single string.
469   void setOSAndEnvironmentName(StringRef Str);
470
471   /// @}
472   /// @name Helpers to build variants of a particular triple.
473   /// @{
474
475   /// \brief Form a triple with a 32-bit variant of the current architecture.
476   ///
477   /// This can be used to move across "families" of architectures where useful.
478   ///
479   /// \returns A new triple with a 32-bit architecture or an unknown
480   ///          architecture if no such variant can be found.
481   llvm::Triple get32BitArchVariant() const;
482
483   /// \brief Form a triple with a 64-bit variant of the current architecture.
484   ///
485   /// This can be used to move across "families" of architectures where useful.
486   ///
487   /// \returns A new triple with a 64-bit architecture or an unknown
488   ///          architecture if no such variant can be found.
489   llvm::Triple get64BitArchVariant() const;
490
491   /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
492   ///
493   /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
494   /// string then the triple's arch name is used.
495   const char* getARMCPUForArch(StringRef Arch = StringRef()) const;
496
497   /// @}
498   /// @name Static helpers for IDs.
499   /// @{
500
501   /// getArchTypeName - Get the canonical name for the \p Kind architecture.
502   static const char *getArchTypeName(ArchType Kind);
503
504   /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
505   /// architecture. This is the prefix used by the architecture specific
506   /// builtins, and is suitable for passing to \see
507   /// Intrinsic::getIntrinsicForGCCBuiltin().
508   ///
509   /// \return - The architecture prefix, or 0 if none is defined.
510   static const char *getArchTypePrefix(ArchType Kind);
511
512   /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
513   static const char *getVendorTypeName(VendorType Kind);
514
515   /// getOSTypeName - Get the canonical name for the \p Kind operating system.
516   static const char *getOSTypeName(OSType Kind);
517
518   /// getEnvironmentTypeName - Get the canonical name for the \p Kind
519   /// environment.
520   static const char *getEnvironmentTypeName(EnvironmentType Kind);
521
522   /// @}
523   /// @name Static helpers for converting alternate architecture names.
524   /// @{
525
526   /// getArchTypeForLLVMName - The canonical type for the given LLVM
527   /// architecture name (e.g., "x86").
528   static ArchType getArchTypeForLLVMName(StringRef Str);
529
530   /// @}
531 };
532
533 } // End llvm namespace
534
535
536 #endif