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