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 #else 24 #if !defined(BYTE_ORDER) && !defined(LLVM_ON_WIN32) 25 #include <machine/endian.h> 26 #endif 27 #endif 28 29 #include <string> 30 31 namespace llvm { 32 namespace sys { 33 34 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN 35 static const bool IsBigEndianHost = true; 36 #else 37 static const bool IsBigEndianHost = false; 38 #endif 39 40 static const bool IsLittleEndianHost = !IsBigEndianHost; 41 42 /// getDefaultTargetTriple() - Return the default target triple the compiler 43 /// has been configured to produce code for. 44 /// 45 /// The target triple is a string in the format of: 46 /// CPU_TYPE-VENDOR-OPERATING_SYSTEM 47 /// or 48 /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM 49 std::string getDefaultTargetTriple(); 50 51 /// getProcessTriple() - Return an appropriate target triple for generating 52 /// code to be loaded into the current process, e.g. when using the JIT. 53 std::string getProcessTriple(); 54 55 /// getHostCPUName - Get the LLVM name for the host CPU. The particular format 56 /// of the name is target dependent, and suitable for passing as -mcpu to the 57 /// target which matches the host. 58 /// 59 /// \return - The host CPU name, or empty if the CPU could not be determined. 60 StringRef getHostCPUName(); 61 62 /// getHostCPUFeatures - Get the LLVM names for the host CPU features. 63 /// The particular format of the names are target dependent, and suitable for 64 /// passing as -mattr to the target which matches the host. 65 /// 66 /// \param Features - A string mapping feature names to either 67 /// true (if enabled) or false (if disabled). This routine makes no guarantees 68 /// about exactly which features may appear in this map, except that they are 69 /// all valid LLVM feature names. 70 /// 71 /// \return - True on success. 72 bool getHostCPUFeatures(StringMap<bool> &Features); 73 74 /// Get the number of physical cores (as opposed to logical cores returned 75 /// from thread::hardware_concurrency(), which includes hyperthreads). 76 /// Returns -1 if unknown for the current host system. 77 int getHostNumPhysicalCores(); 78 } 79 } 80 81 #endif 82