1 //===- llvm/Support/Host.h - Host machine characteristics --------*- 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 //===----------------------------------------------------------------------===//
10 // Methods for querying the nature of the host machine.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_HOST_H
15 #define LLVM_SUPPORT_HOST_H
17 #include "llvm/ADT/StringMap.h"
19 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__)
22 #include <sys/machine.h>
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
31 #define BYTE_ORDER LITTLE_ENDIAN
34 #if !defined(BYTE_ORDER) && !defined(_WIN32)
35 #include <machine/endian.h>
44 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
45 constexpr bool IsBigEndianHost = true;
47 constexpr bool IsBigEndianHost = false;
50 static const bool IsLittleEndianHost = !IsBigEndianHost;
52 /// getDefaultTargetTriple() - Return the default target triple the compiler
53 /// has been configured to produce code for.
55 /// The target triple is a string in the format of:
56 /// CPU_TYPE-VENDOR-OPERATING_SYSTEM
58 /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
59 std::string getDefaultTargetTriple();
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();
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.
69 /// \return - The host CPU name, or empty if the CPU could not be determined.
70 StringRef getHostCPUName();
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.
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.
81 /// \return - True on success.
82 bool getHostCPUFeatures(StringMap<bool> &Features);
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();
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();