1218885Sdim//===- llvm/Support/Host.h - Host machine characteristics --------*- C++ -*-===//
2218885Sdim//
3218885Sdim//                     The LLVM Compiler Infrastructure
4218885Sdim//
5218885Sdim// This file is distributed under the University of Illinois Open Source
6218885Sdim// License. See LICENSE.TXT for details.
7218885Sdim//
8218885Sdim//===----------------------------------------------------------------------===//
9218885Sdim//
10218885Sdim// Methods for querying the nature of the host machine.
11218885Sdim//
12218885Sdim//===----------------------------------------------------------------------===//
13218885Sdim
14249423Sdim#ifndef LLVM_SUPPORT_HOST_H
15249423Sdim#define LLVM_SUPPORT_HOST_H
16218885Sdim
17218885Sdim#include "llvm/ADT/StringMap.h"
18251662Sdim
19251662Sdim#if defined(__linux__)
20251662Sdim#include <endian.h>
21251662Sdim#else
22251662Sdim#ifndef LLVM_ON_WIN32
23251662Sdim#include <machine/endian.h>
24251662Sdim#endif
25251662Sdim#endif
26251662Sdim
27218885Sdim#include <string>
28218885Sdim
29218885Sdimnamespace llvm {
30218885Sdimnamespace sys {
31218885Sdim
32251662Sdim#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
33251662Sdim  static const bool IsBigEndianHost = true;
34251662Sdim#else
35251662Sdim  static const bool IsBigEndianHost = false;
36251662Sdim#endif
37218885Sdim
38251662Sdim  static const bool IsLittleEndianHost = !IsBigEndianHost;
39218885Sdim
40234353Sdim  /// getDefaultTargetTriple() - Return the default target triple the compiler
41234353Sdim  /// has been configured to produce code for.
42218885Sdim  ///
43218885Sdim  /// The target triple is a string in the format of:
44218885Sdim  ///   CPU_TYPE-VENDOR-OPERATING_SYSTEM
45218885Sdim  /// or
46218885Sdim  ///   CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
47234353Sdim  std::string getDefaultTargetTriple();
48218885Sdim
49249423Sdim  /// getProcessTriple() - Return an appropriate target triple for generating
50249423Sdim  /// code to be loaded into the current process, e.g. when using the JIT.
51249423Sdim  std::string getProcessTriple();
52249423Sdim
53218885Sdim  /// getHostCPUName - Get the LLVM name for the host CPU. The particular format
54218885Sdim  /// of the name is target dependent, and suitable for passing as -mcpu to the
55218885Sdim  /// target which matches the host.
56218885Sdim  ///
57218885Sdim  /// \return - The host CPU name, or empty if the CPU could not be determined.
58218885Sdim  std::string getHostCPUName();
59218885Sdim
60218885Sdim  /// getHostCPUFeatures - Get the LLVM names for the host CPU features.
61218885Sdim  /// The particular format of the names are target dependent, and suitable for
62218885Sdim  /// passing as -mattr to the target which matches the host.
63218885Sdim  ///
64218885Sdim  /// \param Features - A string mapping feature names to either
65218885Sdim  /// true (if enabled) or false (if disabled). This routine makes no guarantees
66218885Sdim  /// about exactly which features may appear in this map, except that they are
67218885Sdim  /// all valid LLVM feature names.
68218885Sdim  ///
69218885Sdim  /// \return - True on success.
70218885Sdim  bool getHostCPUFeatures(StringMap<bool> &Features);
71218885Sdim}
72218885Sdim}
73218885Sdim
74218885Sdim#endif
75