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