1 //===- llvm/TargetParser/Host.h - Host machine detection -------*- 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 13 #ifndef LLVM_TARGETPARSER_HOST_H 14 #define LLVM_TARGETPARSER_HOST_H 15 16 #include <string> 17 18 namespace llvm { 19 class MallocAllocator; 20 class StringRef; 21 template <typename ValueTy, typename AllocatorTy> class StringMap; 22 class raw_ostream; 23 24 namespace sys { 25 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 35 /// getProcessTriple() - Return an appropriate target triple for generating 36 /// code to be loaded into the current process, e.g. when using the JIT. 37 std::string getProcessTriple(); 38 39 /// getHostCPUName - Get the LLVM name for the host CPU. The particular format 40 /// of the name is target dependent, and suitable for passing as -mcpu to the 41 /// target which matches the host. 42 /// 43 /// \return - The host CPU name, or empty if the CPU could not be determined. 44 StringRef getHostCPUName(); 45 46 /// getHostCPUFeatures - Get the LLVM names for the host CPU features. 47 /// The particular format of the names are target dependent, and suitable for 48 /// passing as -mattr to the target which matches the host. 49 /// 50 /// \return - A string map mapping feature names to either true (if enabled) 51 /// or false (if disabled). This routine makes no guarantees about exactly 52 /// which features may appear in this map, except that they are all valid LLVM 53 /// feature names. The map can be empty, for example if feature detection 54 /// fails. 55 const StringMap<bool, MallocAllocator> getHostCPUFeatures(); 56 57 /// This is a function compatible with cl::AddExtraVersionPrinter, which adds 58 /// info about the current target triple and detected CPU. 59 void printDefaultTargetAndDetectedCPU(raw_ostream &OS); 60 61 namespace detail { 62 /// Helper functions to extract HostCPUName from /proc/cpuinfo on linux. 63 StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent); 64 StringRef getHostCPUNameForARM(StringRef ProcCpuinfoContent); 65 StringRef getHostCPUNameForS390x(StringRef ProcCpuinfoContent); 66 StringRef getHostCPUNameForRISCV(StringRef ProcCpuinfoContent); 67 StringRef getHostCPUNameForSPARC(StringRef ProcCpuinfoContent); 68 StringRef getHostCPUNameForBPF(); 69 70 /// Helper functions to extract CPU details from CPUID on x86. 71 namespace x86 { 72 enum class VendorSignatures { 73 UNKNOWN, 74 GENUINE_INTEL, 75 AUTHENTIC_AMD, 76 }; 77 78 /// Returns the host CPU's vendor. 79 /// MaxLeaf: if a non-nullptr pointer is specified, the EAX value will be 80 /// assigned to its pointee. 81 VendorSignatures getVendorSignature(unsigned *MaxLeaf = nullptr); 82 } // namespace x86 83 } 84 } 85 } 86 87 #endif 88