1 //===-- llvm/ADT/TargetTuple.h - Target tuple class -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_ADT_TARGETTUPLE_H
19 #define LLVM_ADT_TARGETTUPLE_H
21 #include "llvm/ADT/Twine.h"
22 #include "llvm/ADT/Triple.h"
24 // Some system headers or GCC predefined macros conflict with identifiers in
25 // this file. Undefine them here.
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.
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.
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
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
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)
76 amdil64, // AMDIL with 64-bit pointers
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
120 ImaginationTechnologies,
125 LastVendorType = Myriad
147 NaCl, // Native Client
148 CNK, // BG/P Compute-Node Kernel
152 NVCL, // NVIDIA OpenCL
153 AMDHSA, // AMD HSA Runtime
158 enum EnvironmentType {
175 LastEnvironmentType = CoreCLR
178 enum ObjectFormatType {
187 /// @name Constructors
190 /// Default constructor leaves all fields unknown.
191 TargetTuple() : GnuTT() {}
193 /// Convert a GNU Triple to a TargetTuple.
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.
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) {}
207 /// @name Typed Component Access
210 /// Get the parsed architecture type of this triple.
211 ArchType getArch() const;
213 /// get the parsed subarchitecture type for this triple.
214 SubArchType getSubArch() const;
216 /// Get the parsed vendor type of this triple.
217 VendorType getVendor() const;
219 /// Get the parsed operating system type of this triple.
220 OSType getOS() const;
222 /// Does this triple have the optional environment
223 /// (fourth) component?
224 bool hasEnvironment() const { return GnuTT.hasEnvironment(); }
226 /// Get the parsed environment type of this triple.
227 EnvironmentType getEnvironment() const;
229 /// Parse the version number from the OS name component of the
230 /// triple, if present.
232 /// For example, "fooos1.2.3" would return (1, 2, 3).
234 /// If an entry is not defined, it will be returned as 0.
235 void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
236 unsigned &Micro) const;
238 /// Get the object format for this triple.
239 ObjectFormatType getObjectFormat() const;
241 /// Parse the version number from the OS name component of the
242 /// triple, if present.
244 /// For example, "fooos1.2.3" would return (1, 2, 3).
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);
251 /// Return just the major version number, this is
252 /// specialized because it is a common query.
253 unsigned getOSMajorVersion() const { return GnuTT.getOSMajorVersion(); }
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);
264 /// Parse the version number as with getOSVersion. This
266 /// only be called with IOS triples.
267 void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const {
268 return GnuTT.getiOSVersion(Major, Minor, Micro);
272 /// @name Direct Component Access
275 const std::string &str() const { return GnuTT.str(); }
277 const std::string &getTriple() const { return GnuTT.str(); }
279 /// Get the architecture (first) component of the
281 StringRef getArchName() const { return GnuTT.getArchName(); }
283 /// Get the vendor (second) component of the triple.
284 StringRef getVendorName() const { return GnuTT.getVendorName(); }
286 /// Get the operating system (third) component of the
288 StringRef getOSName() const { return GnuTT.getOSName(); }
290 /// Get the optional environment (fourth)
291 /// component of the triple, or "" if empty.
292 StringRef getEnvironmentName() const { return GnuTT.getEnvironmentName(); }
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();
302 /// @name Convenience Predicates
305 /// Test whether the architecture is 64-bit
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(); }
314 /// Test whether the architecture is 32-bit
316 /// Note that this tests for 32-bit pointer width, and nothing else.
317 bool isArch32Bit() const { return GnuTT.isArch32Bit(); }
319 /// Test whether the architecture is 16-bit
321 /// Note that this tests for 16-bit pointer width, and nothing else.
322 bool isArch16Bit() const { return GnuTT.isArch16Bit(); }
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);
331 bool isOSVersionLT(const Triple &Other) const {
332 return GnuTT.isOSVersionLT(Other);
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);
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(); }
347 /// Is this an iOS triple.
348 bool isiOS() const { return GnuTT.isiOS(); }
350 /// Is this a "Darwin" OS (OS X or iOS).
351 bool isOSDarwin() const { return GnuTT.isOSDarwin(); }
353 bool isOSNetBSD() const { return GnuTT.isOSNetBSD(); }
355 bool isOSOpenBSD() const { return GnuTT.isOSOpenBSD(); }
357 bool isOSFreeBSD() const { return GnuTT.isOSFreeBSD(); }
359 bool isOSDragonFly() const { return GnuTT.isOSDragonFly(); }
361 bool isOSSolaris() const { return GnuTT.isOSSolaris(); }
363 bool isOSBitrig() const { return GnuTT.isOSBitrig(); }
365 bool isWindowsMSVCEnvironment() const {
366 return GnuTT.isWindowsMSVCEnvironment();
369 bool isKnownWindowsMSVCEnvironment() const {
370 return GnuTT.isKnownWindowsMSVCEnvironment();
373 bool isWindowsCoreCLREnvironment() const {
374 return GnuTT.isWindowsCoreCLREnvironment();
377 bool isWindowsItaniumEnvironment() const {
378 return GnuTT.isWindowsItaniumEnvironment();
381 bool isWindowsCygwinEnvironment() const {
382 return GnuTT.isWindowsCygwinEnvironment();
385 bool isWindowsGNUEnvironment() const {
386 return GnuTT.isWindowsGNUEnvironment();
389 /// Tests for either Cygwin or MinGW OS
390 bool isOSCygMing() const { return GnuTT.isOSCygMing(); }
392 /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
393 bool isOSMSVCRT() const { return GnuTT.isOSMSVCRT(); }
395 /// Tests whether the OS is Windows.
396 bool isOSWindows() const { return GnuTT.isOSWindows(); }
398 /// Tests whether the OS is NaCl (Native Client)
399 bool isOSNaCl() const { return GnuTT.isOSNaCl(); }
401 /// Tests whether the OS is Linux.
402 bool isOSLinux() const { return GnuTT.isOSLinux(); }
404 /// Tests whether the OS uses the ELF binary format.
405 bool isOSBinFormatELF() const { return GnuTT.isOSBinFormatELF(); }
407 /// Tests whether the OS uses the COFF binary format.
408 bool isOSBinFormatCOFF() const { return GnuTT.isOSBinFormatCOFF(); }
410 /// Tests whether the environment is MachO.
411 bool isOSBinFormatMachO() const { return GnuTT.isOSBinFormatMachO(); }
413 /// Tests whether the target is the PS4 CPU
414 bool isPS4CPU() const { return GnuTT.isPS4CPU(); }
416 /// Tests whether the target is the PS4 platform
417 bool isPS4() const { return GnuTT.isPS4(); }
421 // FIXME: Remove. This function exists to avoid having to migrate everything
423 const Triple &getTargetTriple() const { return GnuTT; }
429 } // End llvm namespace