Host.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Support/Host.h - Host machine characteristics --------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Methods for querying the nature of the host machine.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_SUPPORT_HOST_H
  18. #define LLVM_SUPPORT_HOST_H
  19. #include <string>
  20. namespace llvm {
  21. class MallocAllocator;
  22. class StringRef;
  23. template <typename ValueTy, typename AllocatorTy> class StringMap;
  24. namespace sys {
  25. /// getDefaultTargetTriple() - Return the default target triple the compiler
  26. /// has been configured to produce code for.
  27. ///
  28. /// The target triple is a string in the format of:
  29. /// CPU_TYPE-VENDOR-OPERATING_SYSTEM
  30. /// or
  31. /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
  32. std::string getDefaultTargetTriple();
  33. /// getProcessTriple() - Return an appropriate target triple for generating
  34. /// code to be loaded into the current process, e.g. when using the JIT.
  35. std::string getProcessTriple();
  36. /// getHostCPUName - Get the LLVM name for the host CPU. The particular format
  37. /// of the name is target dependent, and suitable for passing as -mcpu to the
  38. /// target which matches the host.
  39. ///
  40. /// \return - The host CPU name, or empty if the CPU could not be determined.
  41. StringRef getHostCPUName();
  42. /// getHostCPUFeatures - Get the LLVM names for the host CPU features.
  43. /// The particular format of the names are target dependent, and suitable for
  44. /// passing as -mattr to the target which matches the host.
  45. ///
  46. /// \param Features - A string mapping feature names to either
  47. /// true (if enabled) or false (if disabled). This routine makes no guarantees
  48. /// about exactly which features may appear in this map, except that they are
  49. /// all valid LLVM feature names.
  50. ///
  51. /// \return - True on success.
  52. bool getHostCPUFeatures(StringMap<bool, MallocAllocator> &Features);
  53. /// Get the number of physical cores (as opposed to logical cores returned
  54. /// from thread::hardware_concurrency(), which includes hyperthreads).
  55. /// Returns -1 if unknown for the current host system.
  56. int getHostNumPhysicalCores();
  57. namespace detail {
  58. /// Helper functions to extract HostCPUName from /proc/cpuinfo on linux.
  59. StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent);
  60. StringRef getHostCPUNameForARM(StringRef ProcCpuinfoContent);
  61. StringRef getHostCPUNameForS390x(StringRef ProcCpuinfoContent);
  62. StringRef getHostCPUNameForBPF();
  63. /// Helper functions to extract CPU details from CPUID on x86.
  64. namespace x86 {
  65. enum class VendorSignatures {
  66. UNKNOWN,
  67. GENUINE_INTEL,
  68. AUTHENTIC_AMD,
  69. };
  70. /// Returns the host CPU's vendor.
  71. /// MaxLeaf: if a non-nullptr pointer is specified, the EAX value will be
  72. /// assigned to its pointee.
  73. VendorSignatures getVendorSignature(unsigned *MaxLeaf = nullptr);
  74. } // namespace x86
  75. }
  76. }
  77. }
  78. #endif
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif