Host.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/TargetParser/Host.h - Host machine detection -------*- 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_TARGETPARSER_HOST_H
  18. #define LLVM_TARGETPARSER_HOST_H
  19. #include <string>
  20. namespace llvm {
  21. class MallocAllocator;
  22. class StringRef;
  23. template <typename ValueTy, typename AllocatorTy> class StringMap;
  24. class raw_ostream;
  25. namespace sys {
  26. /// getDefaultTargetTriple() - Return the default target triple the compiler
  27. /// has been configured to produce code for.
  28. ///
  29. /// The target triple is a string in the format of:
  30. /// CPU_TYPE-VENDOR-OPERATING_SYSTEM
  31. /// or
  32. /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
  33. std::string getDefaultTargetTriple();
  34. /// getProcessTriple() - Return an appropriate target triple for generating
  35. /// code to be loaded into the current process, e.g. when using the JIT.
  36. std::string getProcessTriple();
  37. /// getHostCPUName - Get the LLVM name for the host CPU. The particular format
  38. /// of the name is target dependent, and suitable for passing as -mcpu to the
  39. /// target which matches the host.
  40. ///
  41. /// \return - The host CPU name, or empty if the CPU could not be determined.
  42. StringRef getHostCPUName();
  43. /// getHostCPUFeatures - Get the LLVM names for the host CPU features.
  44. /// The particular format of the names are target dependent, and suitable for
  45. /// passing as -mattr to the target which matches the host.
  46. ///
  47. /// \param Features - A string mapping feature names to either
  48. /// true (if enabled) or false (if disabled). This routine makes no guarantees
  49. /// about exactly which features may appear in this map, except that they are
  50. /// all valid LLVM feature names.
  51. ///
  52. /// \return - True on success.
  53. bool getHostCPUFeatures(StringMap<bool, MallocAllocator> &Features);
  54. /// This is a function compatible with cl::AddExtraVersionPrinter, which adds
  55. /// info about the current target triple and detected CPU.
  56. void printDefaultTargetAndDetectedCPU(raw_ostream &OS);
  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 getHostCPUNameForRISCV(StringRef ProcCpuinfoContent);
  63. StringRef getHostCPUNameForSPARC(StringRef ProcCpuinfoContent);
  64. StringRef getHostCPUNameForBPF();
  65. /// Helper functions to extract CPU details from CPUID on x86.
  66. namespace x86 {
  67. enum class VendorSignatures {
  68. UNKNOWN,
  69. GENUINE_INTEL,
  70. AUTHENTIC_AMD,
  71. };
  72. /// Returns the host CPU's vendor.
  73. /// MaxLeaf: if a non-nullptr pointer is specified, the EAX value will be
  74. /// assigned to its pointee.
  75. VendorSignatures getVendorSignature(unsigned *MaxLeaf = nullptr);
  76. } // namespace x86
  77. }
  78. }
  79. }
  80. #endif
  81. #ifdef __GNUC__
  82. #pragma GCC diagnostic pop
  83. #endif