| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 1 | /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\ | 
|  | 2 | |*                                                                            *| | 
|  | 3 | |*                     The LLVM Compiler Infrastructure                       *| | 
|  | 4 | |*                                                                            *| | 
|  | 5 | |* This file is distributed under the University of Illinois Open Source      *| | 
|  | 6 | |* License. See LICENSE.TXT for details.                                      *| | 
|  | 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 |  | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm-c/Target.h" | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 23 | #include "llvm-c/Types.h" | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 24 |  | 
|  | 25 | #ifdef __cplusplus | 
|  | 26 | extern "C" { | 
|  | 27 | #endif | 
| Filip Pizlo | c65a6d7 | 2013-05-01 22:41:26 +0000 | [diff] [blame] | 28 | typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef; | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 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, | 
|  | 42 | LLVMRelocDynamicNoPic | 
|  | 43 | } LLVMRelocMode; | 
|  | 44 |  | 
|  | 45 | typedef enum { | 
|  | 46 | LLVMCodeModelDefault, | 
|  | 47 | LLVMCodeModelJITDefault, | 
|  | 48 | LLVMCodeModelSmall, | 
|  | 49 | LLVMCodeModelKernel, | 
|  | 50 | LLVMCodeModelMedium, | 
|  | 51 | LLVMCodeModelLarge | 
|  | 52 | } LLVMCodeModel; | 
|  | 53 |  | 
|  | 54 | typedef enum { | 
|  | 55 | LLVMAssemblyFile, | 
|  | 56 | LLVMObjectFile | 
|  | 57 | } LLVMCodeGenFileType; | 
|  | 58 |  | 
|  | 59 | /** Returns the first llvm::Target in the registered targets list. */ | 
| Anders Waldenborg | 5b15455 | 2013-09-19 19:43:55 +0000 | [diff] [blame] | 60 | LLVMTargetRef LLVMGetFirstTarget(void); | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 61 | /** Returns the next llvm::Target given a previous one (or null if there's none) */ | 
|  | 62 | LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T); | 
|  | 63 |  | 
|  | 64 | /*===-- Target ------------------------------------------------------------===*/ | 
| NAKAMURA Takumi | ea1ff6f | 2014-01-10 11:12:01 +0000 | [diff] [blame] | 65 | /** Finds the target corresponding to the given name and stores it in \p T. | 
| Peter Zotov | 7b61b75 | 2013-11-06 10:25:18 +0000 | [diff] [blame] | 66 | Returns 0 on success. */ | 
| Peter Zotov | b2c8b8a | 2013-11-15 02:51:01 +0000 | [diff] [blame] | 67 | LLVMTargetRef LLVMGetTargetFromName(const char *Name); | 
| Peter Zotov | 7b61b75 | 2013-11-06 10:25:18 +0000 | [diff] [blame] | 68 |  | 
|  | 69 | /** Finds the target corresponding to the given triple and stores it in \p T. | 
|  | 70 | Returns 0 on success. Optionally returns any error in ErrorMessage. | 
|  | 71 | Use LLVMDisposeMessage to dispose the message. */ | 
|  | 72 | LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T, | 
|  | 73 | char **ErrorMessage); | 
|  | 74 |  | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 75 | /** Returns the name of a target. See llvm::Target::getName */ | 
|  | 76 | const char *LLVMGetTargetName(LLVMTargetRef T); | 
|  | 77 |  | 
|  | 78 | /** Returns the description  of a target. See llvm::Target::getDescription */ | 
|  | 79 | const char *LLVMGetTargetDescription(LLVMTargetRef T); | 
|  | 80 |  | 
|  | 81 | /** Returns if the target has a JIT */ | 
|  | 82 | LLVMBool LLVMTargetHasJIT(LLVMTargetRef T); | 
|  | 83 |  | 
|  | 84 | /** Returns if the target has a TargetMachine associated */ | 
|  | 85 | LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T); | 
|  | 86 |  | 
|  | 87 | /** Returns if the target as an ASM backend (required for emitting output) */ | 
|  | 88 | LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T); | 
|  | 89 |  | 
|  | 90 | /*===-- Target Machine ----------------------------------------------------===*/ | 
|  | 91 | /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */ | 
| Peter Zotov | 0e38fc8 | 2013-11-15 02:51:12 +0000 | [diff] [blame] | 92 | LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, | 
|  | 93 | const char *Triple, const char *CPU, const char *Features, | 
|  | 94 | LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel); | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 95 |  | 
|  | 96 | /** Dispose the LLVMTargetMachineRef instance generated by | 
|  | 97 | LLVMCreateTargetMachine. */ | 
|  | 98 | void LLVMDisposeTargetMachine(LLVMTargetMachineRef T); | 
|  | 99 |  | 
|  | 100 | /** Returns the Target used in a TargetMachine */ | 
|  | 101 | LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T); | 
|  | 102 |  | 
|  | 103 | /** Returns the triple used creating this target machine. See | 
|  | 104 | llvm::TargetMachine::getTriple. The result needs to be disposed with | 
|  | 105 | LLVMDisposeMessage. */ | 
|  | 106 | char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T); | 
|  | 107 |  | 
|  | 108 | /** Returns the cpu used creating this target machine. See | 
|  | 109 | llvm::TargetMachine::getCPU. The result needs to be disposed with | 
|  | 110 | LLVMDisposeMessage. */ | 
|  | 111 | char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T); | 
|  | 112 |  | 
|  | 113 | /** Returns the feature string used creating this target machine. See | 
|  | 114 | llvm::TargetMachine::getFeatureString. The result needs to be disposed with | 
|  | 115 | LLVMDisposeMessage. */ | 
|  | 116 | char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T); | 
|  | 117 |  | 
| Amaury Sechet | 5590967 | 2016-02-16 05:11:24 +0000 | [diff] [blame] | 118 | /** Create a DataLayout based on the targetMachine. */ | 
|  | 119 | LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T); | 
|  | 120 |  | 
| Peter Zotov | 7b61b75 | 2013-11-06 10:25:18 +0000 | [diff] [blame] | 121 | /** Set the target machine's ASM verbosity. */ | 
|  | 122 | void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, | 
|  | 123 | LLVMBool VerboseAsm); | 
|  | 124 |  | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 125 | /** Emits an asm or object file for the given module to the filename. This | 
|  | 126 | wraps several c++ only classes (among them a file stream). Returns any | 
|  | 127 | error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */ | 
|  | 128 | LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, | 
|  | 129 | char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage); | 
|  | 130 |  | 
| Tom Stellard | ec924c5 | 2013-04-16 23:12:56 +0000 | [diff] [blame] | 131 | /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */ | 
|  | 132 | LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M, | 
|  | 133 | LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf); | 
| Peter Zotov | 7b61b75 | 2013-11-06 10:25:18 +0000 | [diff] [blame] | 134 |  | 
|  | 135 | /*===-- Triple ------------------------------------------------------------===*/ | 
|  | 136 | /** Get a triple for the host machine as a string. The result needs to be | 
|  | 137 | disposed with LLVMDisposeMessage. */ | 
|  | 138 | char* LLVMGetDefaultTargetTriple(void); | 
|  | 139 |  | 
| Juergen Ributzka | 5fe955c | 2014-01-23 19:23:28 +0000 | [diff] [blame] | 140 | /** Adds the target-specific analysis passes to the pass manager. */ | 
|  | 141 | void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM); | 
|  | 142 |  | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 143 | #ifdef __cplusplus | 
|  | 144 | } | 
| Evan Cheng | 2e254d0 | 2013-04-04 17:40:53 +0000 | [diff] [blame] | 145 | #endif | 
| Duncan Sands | 264d2e7 | 2012-04-11 10:25:24 +0000 | [diff] [blame] | 146 |  | 
|  | 147 | #endif |