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"
18 #include "llvm/Support/MemoryBuffer.h"
20 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__)
23 #include <sys/machine.h>
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
32 #define BYTE_ORDER LITTLE_ENDIAN
35 #if !defined(BYTE_ORDER) && !defined(LLVM_ON_WIN32)
36 #include <machine/endian.h>
45 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
46 constexpr bool IsBigEndianHost = true;
48 constexpr bool IsBigEndianHost = false;
51 static const bool IsLittleEndianHost = !IsBigEndianHost;
53 /// getDefaultTargetTriple() - Return the default target triple the compiler
54 /// has been configured to produce code for.
56 /// The target triple is a string in the format of:
57 /// CPU_TYPE-VENDOR-OPERATING_SYSTEM
59 /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
60 std::string getDefaultTargetTriple();
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();
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.
70 /// \return - The host CPU name, or empty if the CPU could not be determined.
71 StringRef getHostCPUName();
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.
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.
82 /// \return - True on success.
83 bool getHostCPUFeatures(StringMap<bool> &Features);
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.
88 int getHostNumPhysicalCores();
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);