Eric Christopher | eec5008 | 2010-08-08 02:44:17 +0000 | [diff] [blame] | 1 | /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- 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 libLLVMTarget.a, which */ |
| 11 | /* implements target information. */ |
| 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 | /*===----------------------------------------------------------------------===*/ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 18 | |
| 19 | #ifndef LLVM_C_TARGET_H |
| 20 | #define LLVM_C_TARGET_H |
| 21 | |
| 22 | #include "llvm-c/Core.h" |
Eric Christopher | eec5008 | 2010-08-08 02:44:17 +0000 | [diff] [blame] | 23 | #include "llvm/Config/llvm-config.h" |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 29 | /** |
| 30 | * @defgroup LLVMCTarget Target information |
| 31 | * @ingroup LLVMC |
| 32 | * |
| 33 | * @{ |
| 34 | */ |
| 35 | |
Chris Lattner | d686c8e | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 36 | enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian }; |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 37 | |
| 38 | typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef; |
Rafael Espindola | 5160d38 | 2011-07-25 21:20:54 +0000 | [diff] [blame] | 39 | typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef; |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 40 | typedef struct LLVMStructLayout *LLVMStructLayoutRef; |
| 41 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 42 | /* Declare all of the target-initialization functions that are available. */ |
Eric Christopher | ca3ca13 | 2010-07-12 05:13:35 +0000 | [diff] [blame] | 43 | #define LLVM_TARGET(TargetName) \ |
| 44 | void LLVMInitialize##TargetName##TargetInfo(void); |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 45 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 46 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 47 | |
Chris Lattner | ff33d83 | 2010-04-28 20:24:45 +0000 | [diff] [blame] | 48 | #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void); |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 49 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 50 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 51 | |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 52 | #define LLVM_TARGET(TargetName) \ |
Evan Cheng | e78085a | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 53 | void LLVMInitialize##TargetName##TargetMC(void); |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 54 | #include "llvm/Config/Targets.def" |
| 55 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 56 | |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 57 | /* Declare all of the available assembly printer initialization functions. */ |
| 58 | #define LLVM_ASM_PRINTER(TargetName) \ |
Anders Waldenborg | 8ed9951 | 2012-05-02 16:15:32 +0000 | [diff] [blame] | 59 | void LLVMInitialize##TargetName##AsmPrinter(void); |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 60 | #include "llvm/Config/AsmPrinters.def" |
Bill Wendling | 29a776b | 2012-03-26 22:15:12 +0000 | [diff] [blame] | 61 | #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */ |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 62 | |
| 63 | /* Declare all of the available assembly parser initialization functions. */ |
| 64 | #define LLVM_ASM_PARSER(TargetName) \ |
Anders Waldenborg | 8ed9951 | 2012-05-02 16:15:32 +0000 | [diff] [blame] | 65 | void LLVMInitialize##TargetName##AsmParser(void); |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 66 | #include "llvm/Config/AsmParsers.def" |
Bill Wendling | 29a776b | 2012-03-26 22:15:12 +0000 | [diff] [blame] | 67 | #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */ |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 68 | |
| 69 | /* Declare all of the available disassembler initialization functions. */ |
| 70 | #define LLVM_DISASSEMBLER(TargetName) \ |
Anders Waldenborg | 8ed9951 | 2012-05-02 16:15:32 +0000 | [diff] [blame] | 71 | void LLVMInitialize##TargetName##Disassembler(void); |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 72 | #include "llvm/Config/Disassemblers.def" |
Bill Wendling | 29a776b | 2012-03-26 22:15:12 +0000 | [diff] [blame] | 73 | #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */ |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 74 | |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 75 | /** LLVMInitializeAllTargetInfos - The main program should call this function if |
| 76 | it wants access to all available targets that LLVM is configured to |
| 77 | support. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 78 | static inline void LLVMInitializeAllTargetInfos(void) { |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 79 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo(); |
| 80 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 81 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 84 | /** LLVMInitializeAllTargets - The main program should call this function if it |
| 85 | wants to link in all available targets that LLVM is configured to |
| 86 | support. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 87 | static inline void LLVMInitializeAllTargets(void) { |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 88 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target(); |
| 89 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 90 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 91 | } |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 92 | |
| 93 | /** LLVMInitializeAllTargetMCs - The main program should call this function if |
| 94 | it wants access to all available target MC that LLVM is configured to |
| 95 | support. */ |
| 96 | static inline void LLVMInitializeAllTargetMCs(void) { |
| 97 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC(); |
| 98 | #include "llvm/Config/Targets.def" |
| 99 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 100 | } |
| 101 | |
| 102 | /** LLVMInitializeAllAsmPrinters - The main program should call this function if |
| 103 | it wants all asm printers that LLVM is configured to support, to make them |
| 104 | available via the TargetRegistry. */ |
Anders Waldenborg | 8ed9951 | 2012-05-02 16:15:32 +0000 | [diff] [blame] | 105 | static inline void LLVMInitializeAllAsmPrinters(void) { |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 106 | #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter(); |
| 107 | #include "llvm/Config/AsmPrinters.def" |
| 108 | #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */ |
| 109 | } |
| 110 | |
| 111 | /** LLVMInitializeAllAsmParsers - The main program should call this function if |
| 112 | it wants all asm parsers that LLVM is configured to support, to make them |
| 113 | available via the TargetRegistry. */ |
Anders Waldenborg | 8ed9951 | 2012-05-02 16:15:32 +0000 | [diff] [blame] | 114 | static inline void LLVMInitializeAllAsmParsers(void) { |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 115 | #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser(); |
| 116 | #include "llvm/Config/AsmParsers.def" |
| 117 | #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */ |
| 118 | } |
| 119 | |
| 120 | /** LLVMInitializeAllDisassemblers - The main program should call this function |
| 121 | if it wants all disassemblers that LLVM is configured to support, to make |
| 122 | them available via the TargetRegistry. */ |
Anders Waldenborg | 8ed9951 | 2012-05-02 16:15:32 +0000 | [diff] [blame] | 123 | static inline void LLVMInitializeAllDisassemblers(void) { |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 124 | #define LLVM_DISASSEMBLER(TargetName) \ |
| 125 | LLVMInitialize##TargetName##Disassembler(); |
| 126 | #include "llvm/Config/Disassemblers.def" |
| 127 | #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */ |
| 128 | } |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 129 | |
| 130 | /** LLVMInitializeNativeTarget - The main program should call this function to |
| 131 | initialize the native target corresponding to the host. This is useful |
| 132 | for JIT applications to ensure that the target gets linked in correctly. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 133 | static inline LLVMBool LLVMInitializeNativeTarget(void) { |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 134 | /* If we have a native target, initialize it to ensure it is linked in. */ |
Eric Christopher | 753f326 | 2010-08-30 18:34:48 +0000 | [diff] [blame] | 135 | #ifdef LLVM_NATIVE_TARGET |
| 136 | LLVM_NATIVE_TARGETINFO(); |
| 137 | LLVM_NATIVE_TARGET(); |
Evan Cheng | e78085a | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 138 | LLVM_NATIVE_TARGETMC(); |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 139 | return 0; |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 140 | #else |
| 141 | return 1; |
| 142 | #endif |
| 143 | } |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 144 | |
| 145 | /*===-- Target Data -------------------------------------------------------===*/ |
| 146 | |
| 147 | /** Creates target data from a target layout string. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 148 | See the constructor llvm::DataLayout::DataLayout. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 149 | LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep); |
| 150 | |
| 151 | /** Adds target data information to a pass manager. This does not take ownership |
| 152 | of the target data. |
| 153 | See the method llvm::PassManagerBase::add. */ |
| 154 | void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef); |
| 155 | |
Rafael Espindola | 5160d38 | 2011-07-25 21:20:54 +0000 | [diff] [blame] | 156 | /** Adds target library information to a pass manager. This does not take |
| 157 | ownership of the target library info. |
| 158 | See the method llvm::PassManagerBase::add. */ |
| 159 | void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef); |
| 160 | |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 161 | /** Converts target data to a target layout string. The string must be disposed |
| 162 | with LLVMDisposeMessage. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 163 | See the constructor llvm::DataLayout::DataLayout. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 164 | char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef); |
| 165 | |
| 166 | /** Returns the byte order of a target, either LLVMBigEndian or |
| 167 | LLVMLittleEndian. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 168 | See the method llvm::DataLayout::isLittleEndian. */ |
Chris Lattner | 10bc755 | 2010-01-09 23:25:21 +0000 | [diff] [blame] | 169 | enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef); |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 170 | |
| 171 | /** Returns the pointer size in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 172 | See the method llvm::DataLayout::getPointerSize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 173 | unsigned LLVMPointerSize(LLVMTargetDataRef); |
| 174 | |
Micah Villmow | 2c39b15 | 2012-10-15 16:24:29 +0000 | [diff] [blame] | 175 | /** Returns the pointer size in bytes for a target for a specified |
| 176 | address space. |
| 177 | See the method llvm::DataLayout::getPointerSize. */ |
| 178 | unsigned LLVMPointerSizeForAS(LLVMTargetDataRef, unsigned AS); |
| 179 | |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 180 | /** Returns the integer type that is the same size as a pointer on a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 181 | See the method llvm::DataLayout::getIntPtrType. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 182 | LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef); |
| 183 | |
Micah Villmow | 2c39b15 | 2012-10-15 16:24:29 +0000 | [diff] [blame] | 184 | /** Returns the integer type that is the same size as a pointer on a target. |
| 185 | This version allows the address space to be specified. |
| 186 | See the method llvm::DataLayout::getIntPtrType. */ |
| 187 | LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef, unsigned AS); |
| 188 | |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 189 | /** Computes the size of a type in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 190 | See the method llvm::DataLayout::getTypeSizeInBits. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 191 | unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef); |
| 192 | |
| 193 | /** Computes the storage size of a type in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 194 | See the method llvm::DataLayout::getTypeStoreSize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 195 | unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 196 | |
| 197 | /** Computes the ABI size of a type in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 198 | See the method llvm::DataLayout::getTypeAllocSize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 199 | unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 200 | |
| 201 | /** Computes the ABI alignment of a type in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 202 | See the method llvm::DataLayout::getTypeABISize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 203 | unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 204 | |
| 205 | /** Computes the call frame alignment of a type in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 206 | See the method llvm::DataLayout::getTypeABISize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 207 | unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 208 | |
| 209 | /** Computes the preferred alignment of a type in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 210 | See the method llvm::DataLayout::getTypeABISize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 211 | unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 212 | |
| 213 | /** Computes the preferred alignment of a global variable in bytes for a target. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 214 | See the method llvm::DataLayout::getPreferredAlignment. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 215 | unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef, |
| 216 | LLVMValueRef GlobalVar); |
| 217 | |
| 218 | /** Computes the structure element that contains the byte offset for a target. |
| 219 | See the method llvm::StructLayout::getElementContainingOffset. */ |
| 220 | unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy, |
| 221 | unsigned long long Offset); |
| 222 | |
| 223 | /** Computes the byte offset of the indexed struct element for a target. |
| 224 | See the method llvm::StructLayout::getElementContainingOffset. */ |
| 225 | unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy, |
| 226 | unsigned Element); |
| 227 | |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 228 | /** Deallocates a TargetData. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 229 | See the destructor llvm::DataLayout::~DataLayout. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 230 | void LLVMDisposeTargetData(LLVMTargetDataRef); |
| 231 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 232 | /** |
| 233 | * @} |
| 234 | */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 235 | |
| 236 | #ifdef __cplusplus |
| 237 | } |
Evan Cheng | 9313da5 | 2013-04-04 17:40:53 +0000 | [diff] [blame] | 238 | #endif /* defined(__cplusplus) */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 239 | |
| 240 | #endif |