Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\ |
| 2 | |* *| |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| |
| 4 | |* Exceptions. *| |
| 5 | |* See https://llvm.org/LICENSE.txt for license information. *| |
| 6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 7 | |* *| |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* *| |
| 10 | |* This header declares the C interface to the Target and TargetMachine *| |
| 11 | |* classes, which can be used to generate assembly or object files. *| |
| 12 | |* *| |
| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| |
| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| |
| 15 | |* tools written in such languages. *| |
| 16 | |* *| |
| 17 | \*===----------------------------------------------------------------------===*/ |
| 18 | |
| 19 | #ifndef LLVM_C_TARGETMACHINE_H |
| 20 | #define LLVM_C_TARGETMACHINE_H |
| 21 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 22 | #include "llvm-c/ExternC.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 23 | #include "llvm-c/Target.h" |
| 24 | #include "llvm-c/Types.h" |
| 25 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 26 | LLVM_C_EXTERN_C_BEGIN |
| 27 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 28 | typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef; |
| 29 | typedef struct LLVMTarget *LLVMTargetRef; |
| 30 | |
| 31 | typedef enum { |
| 32 | LLVMCodeGenLevelNone, |
| 33 | LLVMCodeGenLevelLess, |
| 34 | LLVMCodeGenLevelDefault, |
| 35 | LLVMCodeGenLevelAggressive |
| 36 | } LLVMCodeGenOptLevel; |
| 37 | |
| 38 | typedef enum { |
| 39 | LLVMRelocDefault, |
| 40 | LLVMRelocStatic, |
| 41 | LLVMRelocPIC, |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 42 | LLVMRelocDynamicNoPic, |
| 43 | LLVMRelocROPI, |
| 44 | LLVMRelocRWPI, |
| 45 | LLVMRelocROPI_RWPI |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 46 | } LLVMRelocMode; |
| 47 | |
| 48 | typedef enum { |
| 49 | LLVMCodeModelDefault, |
| 50 | LLVMCodeModelJITDefault, |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 51 | LLVMCodeModelTiny, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 52 | LLVMCodeModelSmall, |
| 53 | LLVMCodeModelKernel, |
| 54 | LLVMCodeModelMedium, |
| 55 | LLVMCodeModelLarge |
| 56 | } LLVMCodeModel; |
| 57 | |
| 58 | typedef enum { |
| 59 | LLVMAssemblyFile, |
| 60 | LLVMObjectFile |
| 61 | } LLVMCodeGenFileType; |
| 62 | |
| 63 | /** Returns the first llvm::Target in the registered targets list. */ |
| 64 | LLVMTargetRef LLVMGetFirstTarget(void); |
| 65 | /** Returns the next llvm::Target given a previous one (or null if there's none) */ |
| 66 | LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T); |
| 67 | |
| 68 | /*===-- Target ------------------------------------------------------------===*/ |
| 69 | /** Finds the target corresponding to the given name and stores it in \p T. |
| 70 | Returns 0 on success. */ |
| 71 | LLVMTargetRef LLVMGetTargetFromName(const char *Name); |
| 72 | |
| 73 | /** Finds the target corresponding to the given triple and stores it in \p T. |
| 74 | Returns 0 on success. Optionally returns any error in ErrorMessage. |
| 75 | Use LLVMDisposeMessage to dispose the message. */ |
| 76 | LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T, |
| 77 | char **ErrorMessage); |
| 78 | |
| 79 | /** Returns the name of a target. See llvm::Target::getName */ |
| 80 | const char *LLVMGetTargetName(LLVMTargetRef T); |
| 81 | |
| 82 | /** Returns the description of a target. See llvm::Target::getDescription */ |
| 83 | const char *LLVMGetTargetDescription(LLVMTargetRef T); |
| 84 | |
| 85 | /** Returns if the target has a JIT */ |
| 86 | LLVMBool LLVMTargetHasJIT(LLVMTargetRef T); |
| 87 | |
| 88 | /** Returns if the target has a TargetMachine associated */ |
| 89 | LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T); |
| 90 | |
| 91 | /** Returns if the target as an ASM backend (required for emitting output) */ |
| 92 | LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T); |
| 93 | |
| 94 | /*===-- Target Machine ----------------------------------------------------===*/ |
| 95 | /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */ |
| 96 | LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, |
| 97 | const char *Triple, const char *CPU, const char *Features, |
| 98 | LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel); |
| 99 | |
| 100 | /** Dispose the LLVMTargetMachineRef instance generated by |
| 101 | LLVMCreateTargetMachine. */ |
| 102 | void LLVMDisposeTargetMachine(LLVMTargetMachineRef T); |
| 103 | |
| 104 | /** Returns the Target used in a TargetMachine */ |
| 105 | LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T); |
| 106 | |
| 107 | /** Returns the triple used creating this target machine. See |
| 108 | llvm::TargetMachine::getTriple. The result needs to be disposed with |
| 109 | LLVMDisposeMessage. */ |
| 110 | char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T); |
| 111 | |
| 112 | /** Returns the cpu used creating this target machine. See |
| 113 | llvm::TargetMachine::getCPU. The result needs to be disposed with |
| 114 | LLVMDisposeMessage. */ |
| 115 | char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T); |
| 116 | |
| 117 | /** Returns the feature string used creating this target machine. See |
| 118 | llvm::TargetMachine::getFeatureString. The result needs to be disposed with |
| 119 | LLVMDisposeMessage. */ |
| 120 | char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T); |
| 121 | |
| 122 | /** Create a DataLayout based on the targetMachine. */ |
| 123 | LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T); |
| 124 | |
| 125 | /** Set the target machine's ASM verbosity. */ |
| 126 | void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, |
| 127 | LLVMBool VerboseAsm); |
| 128 | |
| 129 | /** Emits an asm or object file for the given module to the filename. This |
| 130 | wraps several c++ only classes (among them a file stream). Returns any |
| 131 | error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */ |
| 132 | LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, |
| 133 | char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage); |
| 134 | |
| 135 | /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */ |
| 136 | LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M, |
| 137 | LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf); |
| 138 | |
| 139 | /*===-- Triple ------------------------------------------------------------===*/ |
| 140 | /** Get a triple for the host machine as a string. The result needs to be |
| 141 | disposed with LLVMDisposeMessage. */ |
| 142 | char* LLVMGetDefaultTargetTriple(void); |
| 143 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 144 | /** Normalize a target triple. The result needs to be disposed with |
| 145 | LLVMDisposeMessage. */ |
| 146 | char* LLVMNormalizeTargetTriple(const char* triple); |
| 147 | |
| 148 | /** Get the host CPU as a string. The result needs to be disposed with |
| 149 | LLVMDisposeMessage. */ |
| 150 | char* LLVMGetHostCPUName(void); |
| 151 | |
| 152 | /** Get the host CPU's features as a string. The result needs to be disposed |
| 153 | with LLVMDisposeMessage. */ |
| 154 | char* LLVMGetHostCPUFeatures(void); |
| 155 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 156 | /** Adds the target-specific analysis passes to the pass manager. */ |
| 157 | void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM); |
| 158 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 159 | LLVM_C_EXTERN_C_END |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 160 | |
| 161 | #endif |