]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Support/Host.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Support / Host.h
1 //===- llvm/Support/Host.h - Host machine characteristics --------*- 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 // Methods for querying the nature of the host machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_HOST_H
15 #define LLVM_SUPPORT_HOST_H
16
17 #include "llvm/ADT/StringMap.h"
18
19 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__)
20 #include <endian.h>
21 #elif defined(_AIX)
22 #include <sys/machine.h>
23 #elif defined(__sun)
24 /* Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h */
25 #include <sys/types.h>
26 #define BIG_ENDIAN 4321
27 #define LITTLE_ENDIAN 1234
28 #if defined(_BIG_ENDIAN)
29 #define BYTE_ORDER BIG_ENDIAN
30 #else
31 #define BYTE_ORDER LITTLE_ENDIAN
32 #endif
33 #else
34 #if !defined(BYTE_ORDER) && !defined(_WIN32)
35 #include <machine/endian.h>
36 #endif
37 #endif
38
39 #include <string>
40
41 namespace llvm {
42 namespace sys {
43
44 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
45 constexpr bool IsBigEndianHost = true;
46 #else
47 constexpr bool IsBigEndianHost = false;
48 #endif
49
50   static const bool IsLittleEndianHost = !IsBigEndianHost;
51
52   /// getDefaultTargetTriple() - Return the default target triple the compiler
53   /// has been configured to produce code for.
54   ///
55   /// The target triple is a string in the format of:
56   ///   CPU_TYPE-VENDOR-OPERATING_SYSTEM
57   /// or
58   ///   CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
59   std::string getDefaultTargetTriple();
60
61   /// getProcessTriple() - Return an appropriate target triple for generating
62   /// code to be loaded into the current process, e.g. when using the JIT.
63   std::string getProcessTriple();
64
65   /// getHostCPUName - Get the LLVM name for the host CPU. The particular format
66   /// of the name is target dependent, and suitable for passing as -mcpu to the
67   /// target which matches the host.
68   ///
69   /// \return - The host CPU name, or empty if the CPU could not be determined.
70   StringRef getHostCPUName();
71
72   /// getHostCPUFeatures - Get the LLVM names for the host CPU features.
73   /// The particular format of the names are target dependent, and suitable for
74   /// passing as -mattr to the target which matches the host.
75   ///
76   /// \param Features - A string mapping feature names to either
77   /// true (if enabled) or false (if disabled). This routine makes no guarantees
78   /// about exactly which features may appear in this map, except that they are
79   /// all valid LLVM feature names.
80   ///
81   /// \return - True on success.
82   bool getHostCPUFeatures(StringMap<bool> &Features);
83
84   /// Get the number of physical cores (as opposed to logical cores returned
85   /// from thread::hardware_concurrency(), which includes hyperthreads).
86   /// Returns -1 if unknown for the current host system.
87   int getHostNumPhysicalCores();
88
89   namespace detail {
90   /// Helper functions to extract HostCPUName from /proc/cpuinfo on linux.
91   StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent);
92   StringRef getHostCPUNameForARM(StringRef ProcCpuinfoContent);
93   StringRef getHostCPUNameForS390x(StringRef ProcCpuinfoContent);
94   StringRef getHostCPUNameForBPF();
95   }
96 }
97 }
98
99 #endif