Host.h 3.1 KB

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