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