1 /* 2 * Copyright (c) 2015 Andrew Kelley 3 * 4 * This file is part of zig, which is MIT licensed. 5 * See http://opensource.org/licenses/MIT 6 */ 7 8 #ifndef ZIG_ZIG_LLVM_HPP 9 #define ZIG_ZIG_LLVM_HPP 10 11 #include <stdbool.h> 12 #include <stddef.h> 13 #include <llvm-c/Core.h> 14 #include <llvm-c/Analysis.h> 15 #include <llvm-c/Target.h> 16 #include <llvm-c/Initialization.h> 17 #include <llvm-c/TargetMachine.h> 18 19 #ifdef __cplusplus 20 #define ZIG_EXTERN_C extern "C" 21 #else 22 #define ZIG_EXTERN_C 23 #endif 24 25 // ATTENTION: If you modify this file, be sure to update the corresponding 26 // extern function declarations in the self-hosted compiler. 27 28 struct ZigLLVMDIType; 29 struct ZigLLVMDIBuilder; 30 struct ZigLLVMDICompileUnit; 31 struct ZigLLVMDIScope; 32 struct ZigLLVMDIFile; 33 struct ZigLLVMDILexicalBlock; 34 struct ZigLLVMDISubprogram; 35 struct ZigLLVMDISubroutineType; 36 struct ZigLLVMDILocalVariable; 37 struct ZigLLVMDIGlobalVariable; 38 struct ZigLLVMDILocation; 39 struct ZigLLVMDIEnumerator; 40 struct ZigLLVMInsertionPoint; 41 42 ZIG_EXTERN_C void ZigLLVMInitializeLoopStrengthReducePass(LLVMPassRegistryRef R); 43 ZIG_EXTERN_C void ZigLLVMInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R); 44 45 /// Caller must free memory with LLVMDisposeMessage 46 ZIG_EXTERN_C char *ZigLLVMGetHostCPUName(void); 47 ZIG_EXTERN_C char *ZigLLVMGetNativeFeatures(void); 48 49 ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, 50 char **error_message, bool is_debug, 51 bool is_small, bool time_report, bool tsan, bool lto, 52 const char *asm_filename, const char *bin_filename, 53 const char *llvm_ir_filename, const char *bitcode_filename); 54 55 56 enum ZigLLVMABIType { 57 ZigLLVMABITypeDefault, // Target-specific (either soft or hard depending on triple, etc). 58 ZigLLVMABITypeSoft, // Soft float. 59 ZigLLVMABITypeHard // Hard float. 60 }; 61 62 ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, 63 const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, 64 LLVMCodeModel CodeModel, bool function_sections, enum ZigLLVMABIType float_abi, const char *abi_name); 65 66 ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref); 67 68 ZIG_EXTERN_C LLVMValueRef ZigLLVMAddFunctionInAddressSpace(LLVMModuleRef M, const char *Name, 69 LLVMTypeRef FunctionTy, unsigned AddressSpace); 70 71 enum ZigLLVM_CallingConv { 72 ZigLLVM_C = 0, 73 ZigLLVM_Fast = 8, 74 ZigLLVM_Cold = 9, 75 ZigLLVM_GHC = 10, 76 ZigLLVM_HiPE = 11, 77 ZigLLVM_WebKit_JS = 12, 78 ZigLLVM_AnyReg = 13, 79 ZigLLVM_PreserveMost = 14, 80 ZigLLVM_PreserveAll = 15, 81 ZigLLVM_Swift = 16, 82 ZigLLVM_CXX_FAST_TLS = 17, 83 ZigLLVM_FirstTargetCC = 64, 84 ZigLLVM_X86_StdCall = 64, 85 ZigLLVM_X86_FastCall = 65, 86 ZigLLVM_ARM_APCS = 66, 87 ZigLLVM_ARM_AAPCS = 67, 88 ZigLLVM_ARM_AAPCS_VFP = 68, 89 ZigLLVM_MSP430_INTR = 69, 90 ZigLLVM_X86_ThisCall = 70, 91 ZigLLVM_PTX_Kernel = 71, 92 ZigLLVM_PTX_Device = 72, 93 ZigLLVM_SPIR_FUNC = 75, 94 ZigLLVM_SPIR_KERNEL = 76, 95 ZigLLVM_Intel_OCL_BI = 77, 96 ZigLLVM_X86_64_SysV = 78, 97 ZigLLVM_Win64 = 79, 98 ZigLLVM_X86_VectorCall = 80, 99 ZigLLVM_HHVM = 81, 100 ZigLLVM_HHVM_C = 82, 101 ZigLLVM_X86_INTR = 83, 102 ZigLLVM_AVR_INTR = 84, 103 ZigLLVM_AVR_SIGNAL = 85, 104 ZigLLVM_AVR_BUILTIN = 86, 105 ZigLLVM_AMDGPU_VS = 87, 106 ZigLLVM_AMDGPU_GS = 88, 107 ZigLLVM_AMDGPU_PS = 89, 108 ZigLLVM_AMDGPU_CS = 90, 109 ZigLLVM_AMDGPU_KERNEL = 91, 110 ZigLLVM_X86_RegCall = 92, 111 ZigLLVM_AMDGPU_HS = 93, 112 ZigLLVM_MSP430_BUILTIN = 94, 113 ZigLLVM_AMDGPU_LS = 95, 114 ZigLLVM_AMDGPU_ES = 96, 115 ZigLLVM_AArch64_VectorCall = 97, 116 ZigLLVM_MaxID = 1023, 117 }; 118 119 enum ZigLLVM_CallAttr { 120 ZigLLVM_CallAttrAuto, 121 ZigLLVM_CallAttrNeverTail, 122 ZigLLVM_CallAttrNeverInline, 123 ZigLLVM_CallAttrAlwaysTail, 124 ZigLLVM_CallAttrAlwaysInline, 125 }; 126 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, 127 unsigned NumArgs, enum ZigLLVM_CallingConv CC, enum ZigLLVM_CallAttr attr, const char *Name); 128 129 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign, 130 LLVMValueRef Src, unsigned SrcAlign, LLVMValueRef Size, bool isVolatile); 131 132 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Val, LLVMValueRef Size, 133 unsigned Align, bool isVolatile); 134 135 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildMaxNum(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 136 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildMinNum(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 137 138 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildUMax(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 139 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildUMin(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 140 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildSMax(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 141 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildSMin(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 142 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildUAddSat(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 143 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildSAddSat(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 144 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildUSubSat(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 145 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildSSubSat(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 146 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildSMulFixSat(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *name); 147 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildUMulFixSat(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *name); 148 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildUShlSat(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 149 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildSShlSat(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, const char* name); 150 151 152 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildNSWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, 153 const char *name); 154 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildNUWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, 155 const char *name); 156 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildLShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, 157 const char *name); 158 ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, 159 const char *name); 160 161 162 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugPointerType(struct ZigLLVMDIBuilder *dibuilder, 163 struct ZigLLVMDIType *pointee_type, uint64_t size_in_bits, uint64_t align_in_bits, const char *name); 164 165 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugBasicType(struct ZigLLVMDIBuilder *dibuilder, const char *name, 166 uint64_t size_in_bits, unsigned encoding); 167 168 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugArrayType(struct ZigLLVMDIBuilder *dibuilder, 169 uint64_t size_in_bits, uint64_t align_in_bits, struct ZigLLVMDIType *elem_type, 170 int elem_count); 171 172 ZIG_EXTERN_C struct ZigLLVMDIEnumerator *ZigLLVMCreateDebugEnumerator(struct ZigLLVMDIBuilder *dibuilder, 173 const char *name, int64_t val); 174 175 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugEnumerationType(struct ZigLLVMDIBuilder *dibuilder, 176 struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_number, 177 uint64_t size_in_bits, uint64_t align_in_bits, struct ZigLLVMDIEnumerator **enumerator_array, 178 int enumerator_array_len, struct ZigLLVMDIType *underlying_type, const char *unique_id); 179 180 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugStructType(struct ZigLLVMDIBuilder *dibuilder, 181 struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_number, 182 uint64_t size_in_bits, uint64_t align_in_bits, unsigned flags, struct ZigLLVMDIType *derived_from, 183 struct ZigLLVMDIType **types_array, int types_array_len, unsigned run_time_lang, 184 struct ZigLLVMDIType *vtable_holder, const char *unique_id); 185 186 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugUnionType(struct ZigLLVMDIBuilder *dibuilder, 187 struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_number, 188 uint64_t size_in_bits, uint64_t align_in_bits, unsigned flags, struct ZigLLVMDIType **types_array, 189 int types_array_len, unsigned run_time_lang, const char *unique_id); 190 191 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugMemberType(struct ZigLLVMDIBuilder *dibuilder, 192 struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line, 193 uint64_t size_in_bits, uint64_t align_in_bits, uint64_t offset_in_bits, unsigned flags, 194 struct ZigLLVMDIType *type); 195 196 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateReplaceableCompositeType(struct ZigLLVMDIBuilder *dibuilder, 197 unsigned tag, const char *name, struct ZigLLVMDIScope *scope, struct ZigLLVMDIFile *file, unsigned line); 198 199 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugForwardDeclType(struct ZigLLVMDIBuilder *dibuilder, unsigned tag, 200 const char *name, struct ZigLLVMDIScope *scope, struct ZigLLVMDIFile *file, unsigned line); 201 202 ZIG_EXTERN_C void ZigLLVMReplaceTemporary(struct ZigLLVMDIBuilder *dibuilder, struct ZigLLVMDIType *type, 203 struct ZigLLVMDIType *replacement); 204 205 ZIG_EXTERN_C void ZigLLVMReplaceDebugArrays(struct ZigLLVMDIBuilder *dibuilder, struct ZigLLVMDIType *type, 206 struct ZigLLVMDIType **types_array, int types_array_len); 207 208 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateSubroutineType(struct ZigLLVMDIBuilder *dibuilder_wrapped, 209 struct ZigLLVMDIType **types_array, int types_array_len, unsigned flags); 210 211 ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_unsigned(void); 212 ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_signed(void); 213 ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_float(void); 214 ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_boolean(void); 215 ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_unsigned_char(void); 216 ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_signed_char(void); 217 ZIG_EXTERN_C unsigned ZigLLVMLang_DW_LANG_C99(void); 218 ZIG_EXTERN_C unsigned ZigLLVMTag_DW_variable(void); 219 ZIG_EXTERN_C unsigned ZigLLVMTag_DW_structure_type(void); 220 ZIG_EXTERN_C unsigned ZigLLVMTag_DW_enumeration_type(void); 221 ZIG_EXTERN_C unsigned ZigLLVMTag_DW_union_type(void); 222 223 ZIG_EXTERN_C struct ZigLLVMDIBuilder *ZigLLVMCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved); 224 ZIG_EXTERN_C void ZigLLVMDisposeDIBuilder(struct ZigLLVMDIBuilder *dbuilder); 225 ZIG_EXTERN_C void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module); 226 ZIG_EXTERN_C void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module); 227 ZIG_EXTERN_C void ZigLLVMSetModulePICLevel(LLVMModuleRef module); 228 ZIG_EXTERN_C void ZigLLVMSetModulePIELevel(LLVMModuleRef module); 229 ZIG_EXTERN_C void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model); 230 231 ZIG_EXTERN_C void ZigLLVMSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, 232 struct ZigLLVMDIScope *scope); 233 ZIG_EXTERN_C void ZigLLVMClearCurrentDebugLocation(LLVMBuilderRef builder); 234 235 ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMLexicalBlockToScope(struct ZigLLVMDILexicalBlock *lexical_block); 236 ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMCompileUnitToScope(struct ZigLLVMDICompileUnit *compile_unit); 237 ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMFileToScope(struct ZigLLVMDIFile *difile); 238 ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMSubprogramToScope(struct ZigLLVMDISubprogram *subprogram); 239 ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMTypeToScope(struct ZigLLVMDIType *type); 240 241 ZIG_EXTERN_C struct ZigLLVMDILocalVariable *ZigLLVMCreateAutoVariable(struct ZigLLVMDIBuilder *dbuilder, 242 struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_no, 243 struct ZigLLVMDIType *type, bool always_preserve, unsigned flags); 244 245 ZIG_EXTERN_C struct ZigLLVMDIGlobalVariable *ZigLLVMCreateGlobalVariable(struct ZigLLVMDIBuilder *dbuilder, 246 struct ZigLLVMDIScope *scope, const char *name, const char *linkage_name, struct ZigLLVMDIFile *file, 247 unsigned line_no, struct ZigLLVMDIType *di_type, bool is_local_to_unit); 248 249 ZIG_EXTERN_C struct ZigLLVMDILocalVariable *ZigLLVMCreateParameterVariable(struct ZigLLVMDIBuilder *dbuilder, 250 struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_no, 251 struct ZigLLVMDIType *type, bool always_preserve, unsigned flags, unsigned arg_no); 252 253 ZIG_EXTERN_C struct ZigLLVMDILexicalBlock *ZigLLVMCreateLexicalBlock(struct ZigLLVMDIBuilder *dbuilder, 254 struct ZigLLVMDIScope *scope, struct ZigLLVMDIFile *file, unsigned line, unsigned col); 255 256 ZIG_EXTERN_C struct ZigLLVMDICompileUnit *ZigLLVMCreateCompileUnit(struct ZigLLVMDIBuilder *dibuilder, 257 unsigned lang, struct ZigLLVMDIFile *difile, const char *producer, 258 bool is_optimized, const char *flags, unsigned runtime_version, const char *split_name, 259 uint64_t dwo_id, bool emit_debug_info); 260 261 ZIG_EXTERN_C struct ZigLLVMDIFile *ZigLLVMCreateFile(struct ZigLLVMDIBuilder *dibuilder, const char *filename, 262 const char *directory); 263 264 ZIG_EXTERN_C struct ZigLLVMDISubprogram *ZigLLVMCreateFunction(struct ZigLLVMDIBuilder *dibuilder, 265 struct ZigLLVMDIScope *scope, const char *name, const char *linkage_name, struct ZigLLVMDIFile *file, 266 unsigned lineno, struct ZigLLVMDIType *fn_di_type, bool is_local_to_unit, bool is_definition, 267 unsigned scope_line, unsigned flags, bool is_optimized, struct ZigLLVMDISubprogram *decl_subprogram); 268 269 ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMDIBuilderCreateVectorType(struct ZigLLVMDIBuilder *dibuilder, 270 uint64_t SizeInBits, uint32_t AlignInBits, struct ZigLLVMDIType *Ty, uint32_t elem_count); 271 272 ZIG_EXTERN_C void ZigLLVMFnSetSubprogram(LLVMValueRef fn, struct ZigLLVMDISubprogram *subprogram); 273 274 ZIG_EXTERN_C void ZigLLVMDIBuilderFinalize(struct ZigLLVMDIBuilder *dibuilder); 275 276 ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclareAtEnd(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, 277 struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, 278 LLVMBasicBlockRef basic_block_ref); 279 280 ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclare(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, 281 struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr); 282 ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, struct ZigLLVMDIScope *scope); 283 284 ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); 285 ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call); 286 ZIG_EXTERN_C void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type); 287 ZIG_EXTERN_C void ZigLLVMFunctionSetPrefixData(LLVMValueRef fn, LLVMValueRef data); 288 ZIG_EXTERN_C void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, enum ZigLLVM_CallingConv cc); 289 290 ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); 291 ZIG_EXTERN_C void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val); 292 ZIG_EXTERN_C void ZigLLVMAddSretAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val); 293 ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); 294 295 ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); 296 297 298 // copied from include/llvm/ADT/Triple.h 299 // synchronize with target.cpp::arch_list 300 enum ZigLLVM_ArchType { 301 ZigLLVM_UnknownArch, 302 303 ZigLLVM_arm, // ARM (little endian): arm, armv.*, xscale 304 ZigLLVM_armeb, // ARM (big endian): armeb 305 ZigLLVM_aarch64, // AArch64 (little endian): aarch64 306 ZigLLVM_aarch64_be, // AArch64 (big endian): aarch64_be 307 ZigLLVM_aarch64_32, // AArch64 (little endian) ILP32: aarch64_32 308 ZigLLVM_arc, // ARC: Synopsys ARC 309 ZigLLVM_avr, // AVR: Atmel AVR microcontroller 310 ZigLLVM_bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) 311 ZigLLVM_bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) 312 ZigLLVM_csky, // CSKY: csky 313 ZigLLVM_hexagon, // Hexagon: hexagon 314 ZigLLVM_m68k, // M68k: Motorola 680x0 family 315 ZigLLVM_mips, // MIPS: mips, mipsallegrex, mipsr6 316 ZigLLVM_mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el 317 ZigLLVM_mips64, // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6 318 ZigLLVM_mips64el, // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el 319 ZigLLVM_msp430, // MSP430: msp430 320 ZigLLVM_ppc, // PPC: powerpc 321 ZigLLVM_ppcle, // PPCLE: powerpc (little endian) 322 ZigLLVM_ppc64, // PPC64: powerpc64, ppu 323 ZigLLVM_ppc64le, // PPC64LE: powerpc64le 324 ZigLLVM_r600, // R600: AMD GPUs HD2XXX - HD6XXX 325 ZigLLVM_amdgcn, // AMDGCN: AMD GCN GPUs 326 ZigLLVM_riscv32, // RISC-V (32-bit): riscv32 327 ZigLLVM_riscv64, // RISC-V (64-bit): riscv64 328 ZigLLVM_sparc, // Sparc: sparc 329 ZigLLVM_sparcv9, // Sparcv9: Sparcv9 330 ZigLLVM_sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant 331 ZigLLVM_systemz, // SystemZ: s390x 332 ZigLLVM_tce, // TCE (http://tce.cs.tut.fi/): tce 333 ZigLLVM_tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele 334 ZigLLVM_thumb, // Thumb (little endian): thumb, thumbv.* 335 ZigLLVM_thumbeb, // Thumb (big endian): thumbeb 336 ZigLLVM_x86, // X86: i[3-9]86 337 ZigLLVM_x86_64, // X86-64: amd64, x86_64 338 ZigLLVM_xcore, // XCore: xcore 339 ZigLLVM_nvptx, // NVPTX: 32-bit 340 ZigLLVM_nvptx64, // NVPTX: 64-bit 341 ZigLLVM_le32, // le32: generic little-endian 32-bit CPU (PNaCl) 342 ZigLLVM_le64, // le64: generic little-endian 64-bit CPU (PNaCl) 343 ZigLLVM_amdil, // AMDIL 344 ZigLLVM_amdil64, // AMDIL with 64-bit pointers 345 ZigLLVM_hsail, // AMD HSAIL 346 ZigLLVM_hsail64, // AMD HSAIL with 64-bit pointers 347 ZigLLVM_spir, // SPIR: standard portable IR for OpenCL 32-bit version 348 ZigLLVM_spir64, // SPIR: standard portable IR for OpenCL 64-bit version 349 ZigLLVM_kalimba, // Kalimba: generic kalimba 350 ZigLLVM_shave, // SHAVE: Movidius vector VLIW processors 351 ZigLLVM_lanai, // Lanai: Lanai 32-bit 352 ZigLLVM_wasm32, // WebAssembly with 32-bit pointers 353 ZigLLVM_wasm64, // WebAssembly with 64-bit pointers 354 ZigLLVM_renderscript32, // 32-bit RenderScript 355 ZigLLVM_renderscript64, // 64-bit RenderScript 356 ZigLLVM_ve, // NEC SX-Aurora Vector Engine 357 ZigLLVM_LastArchType = ZigLLVM_ve 358 }; 359 360 enum ZigLLVM_VendorType { 361 ZigLLVM_UnknownVendor, 362 363 ZigLLVM_Apple, 364 ZigLLVM_PC, 365 ZigLLVM_SCEI, 366 ZigLLVM_Freescale, 367 ZigLLVM_IBM, 368 ZigLLVM_ImaginationTechnologies, 369 ZigLLVM_MipsTechnologies, 370 ZigLLVM_NVIDIA, 371 ZigLLVM_CSR, 372 ZigLLVM_Myriad, 373 ZigLLVM_AMD, 374 ZigLLVM_Mesa, 375 ZigLLVM_SUSE, 376 ZigLLVM_OpenEmbedded, 377 378 ZigLLVM_LastVendorType = ZigLLVM_OpenEmbedded 379 }; 380 381 enum ZigLLVM_OSType { 382 ZigLLVM_UnknownOS, 383 384 ZigLLVM_Ananas, 385 ZigLLVM_CloudABI, 386 ZigLLVM_Darwin, 387 ZigLLVM_DragonFly, 388 ZigLLVM_FreeBSD, 389 ZigLLVM_Fuchsia, 390 ZigLLVM_IOS, 391 ZigLLVM_KFreeBSD, 392 ZigLLVM_Linux, 393 ZigLLVM_Lv2, // PS3 394 ZigLLVM_MacOSX, 395 ZigLLVM_NetBSD, 396 ZigLLVM_OpenBSD, 397 ZigLLVM_Solaris, 398 ZigLLVM_Win32, 399 ZigLLVM_ZOS, 400 ZigLLVM_Haiku, 401 ZigLLVM_Minix, 402 ZigLLVM_RTEMS, 403 ZigLLVM_NaCl, // Native Client 404 ZigLLVM_AIX, 405 ZigLLVM_CUDA, // NVIDIA CUDA 406 ZigLLVM_NVCL, // NVIDIA OpenCL 407 ZigLLVM_AMDHSA, // AMD HSA Runtime 408 ZigLLVM_PS4, 409 ZigLLVM_ELFIAMCU, 410 ZigLLVM_TvOS, // Apple tvOS 411 ZigLLVM_WatchOS, // Apple watchOS 412 ZigLLVM_Mesa3D, 413 ZigLLVM_Contiki, 414 ZigLLVM_AMDPAL, // AMD PAL Runtime 415 ZigLLVM_HermitCore, // HermitCore Unikernel/Multikernel 416 ZigLLVM_Hurd, // GNU/Hurd 417 ZigLLVM_WASI, // Experimental WebAssembly OS 418 ZigLLVM_Emscripten, 419 420 ZigLLVM_LastOSType = ZigLLVM_Emscripten 421 }; 422 423 // Synchronize with target.cpp::abi_list 424 enum ZigLLVM_EnvironmentType { 425 ZigLLVM_UnknownEnvironment, 426 427 ZigLLVM_GNU, 428 ZigLLVM_GNUABIN32, 429 ZigLLVM_GNUABI64, 430 ZigLLVM_GNUEABI, 431 ZigLLVM_GNUEABIHF, 432 ZigLLVM_GNUX32, 433 ZigLLVM_GNUILP32, 434 ZigLLVM_CODE16, 435 ZigLLVM_EABI, 436 ZigLLVM_EABIHF, 437 ZigLLVM_Android, 438 ZigLLVM_Musl, 439 ZigLLVM_MuslEABI, 440 ZigLLVM_MuslEABIHF, 441 ZigLLVM_MuslX32, 442 443 ZigLLVM_MSVC, 444 ZigLLVM_Itanium, 445 ZigLLVM_Cygnus, 446 ZigLLVM_CoreCLR, 447 ZigLLVM_Simulator, // Simulator variants of other systems, e.g., Apple's iOS 448 ZigLLVM_MacABI, // Mac Catalyst variant of Apple's iOS deployment target. 449 ZigLLVM_LastEnvironmentType = ZigLLVM_MacABI 450 }; 451 452 enum ZigLLVM_ObjectFormatType { 453 ZigLLVM_UnknownObjectFormat, 454 455 ZigLLVM_COFF, 456 ZigLLVM_ELF, 457 ZigLLVM_GOFF, 458 ZigLLVM_MachO, 459 ZigLLVM_Wasm, 460 ZigLLVM_XCOFF, 461 }; 462 463 LLVMValueRef ZigLLVMBuildAndReduce(LLVMBuilderRef B, LLVMValueRef Val); 464 LLVMValueRef ZigLLVMBuildOrReduce(LLVMBuilderRef B, LLVMValueRef Val); 465 LLVMValueRef ZigLLVMBuildXorReduce(LLVMBuilderRef B, LLVMValueRef Val); 466 LLVMValueRef ZigLLVMBuildIntMaxReduce(LLVMBuilderRef B, LLVMValueRef Val, bool is_signed); 467 LLVMValueRef ZigLLVMBuildIntMinReduce(LLVMBuilderRef B, LLVMValueRef Val, bool is_signed); 468 LLVMValueRef ZigLLVMBuildFPMaxReduce(LLVMBuilderRef B, LLVMValueRef Val); 469 LLVMValueRef ZigLLVMBuildFPMinReduce(LLVMBuilderRef B, LLVMValueRef Val); 470 LLVMValueRef ZigLLVMBuildAddReduce(LLVMBuilderRef B, LLVMValueRef Val); 471 LLVMValueRef ZigLLVMBuildMulReduce(LLVMBuilderRef B, LLVMValueRef Val); 472 LLVMValueRef ZigLLVMBuildFPAddReduce(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Val); 473 LLVMValueRef ZigLLVMBuildFPMulReduce(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Val); 474 475 #define ZigLLVM_DIFlags_Zero 0U 476 #define ZigLLVM_DIFlags_Private 1U 477 #define ZigLLVM_DIFlags_Protected 2U 478 #define ZigLLVM_DIFlags_Public 3U 479 #define ZigLLVM_DIFlags_FwdDecl (1U << 2) 480 #define ZigLLVM_DIFlags_AppleBlock (1U << 3) 481 #define ZigLLVM_DIFlags_BlockByrefStruct (1U << 4) 482 #define ZigLLVM_DIFlags_Virtual (1U << 5) 483 #define ZigLLVM_DIFlags_Artificial (1U << 6) 484 #define ZigLLVM_DIFlags_Explicit (1U << 7) 485 #define ZigLLVM_DIFlags_Prototyped (1U << 8) 486 #define ZigLLVM_DIFlags_ObjcClassComplete (1U << 9) 487 #define ZigLLVM_DIFlags_ObjectPointer (1U << 10) 488 #define ZigLLVM_DIFlags_Vector (1U << 11) 489 #define ZigLLVM_DIFlags_StaticMember (1U << 12) 490 #define ZigLLVM_DIFlags_LValueReference (1U << 13) 491 #define ZigLLVM_DIFlags_RValueReference (1U << 14) 492 #define ZigLLVM_DIFlags_Reserved (1U << 15) 493 #define ZigLLVM_DIFlags_SingleInheritance (1U << 16) 494 #define ZigLLVM_DIFlags_MultipleInheritance (2 << 16) 495 #define ZigLLVM_DIFlags_VirtualInheritance (3 << 16) 496 #define ZigLLVM_DIFlags_IntroducedVirtual (1U << 18) 497 #define ZigLLVM_DIFlags_BitField (1U << 19) 498 #define ZigLLVM_DIFlags_NoReturn (1U << 20) 499 #define ZigLLVM_DIFlags_TypePassByValue (1U << 22) 500 #define ZigLLVM_DIFlags_TypePassByReference (1U << 23) 501 #define ZigLLVM_DIFlags_EnumClass (1U << 24) 502 #define ZigLLVM_DIFlags_Thunk (1U << 25) 503 #define ZigLLVM_DIFlags_NonTrivial (1U << 26) 504 #define ZigLLVM_DIFlags_BigEndian (1U << 27) 505 #define ZigLLVM_DIFlags_LittleEndian (1U << 28) 506 #define ZigLLVM_DIFlags_AllCallsDescribed (1U << 29) 507 508 ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch); 509 ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor); 510 ZIG_EXTERN_C const char *ZigLLVMGetOSTypeName(enum ZigLLVM_OSType os); 511 ZIG_EXTERN_C const char *ZigLLVMGetEnvironmentTypeName(enum ZigLLVM_EnvironmentType abi); 512 513 ZIG_EXTERN_C int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early); 514 ZIG_EXTERN_C int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early); 515 ZIG_EXTERN_C int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early); 516 517 ZIG_EXTERN_C bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size_t file_name_count, 518 enum ZigLLVM_OSType os_type); 519 520 ZIG_EXTERN_C bool ZigLLVMWriteImportLibrary(const char *def_path, const enum ZigLLVM_ArchType arch, 521 const char *output_lib_path, bool kill_at); 522 523 ZIG_EXTERN_C void ZigLLVMGetNativeTarget(enum ZigLLVM_ArchType *arch_type, 524 enum ZigLLVM_VendorType *vendor_type, enum ZigLLVM_OSType *os_type, enum ZigLLVM_EnvironmentType *environ_type, 525 enum ZigLLVM_ObjectFormatType *oformat); 526 527 ZIG_EXTERN_C unsigned ZigLLVMDataLayoutGetStackAlignment(LLVMTargetDataRef TD); 528 ZIG_EXTERN_C unsigned ZigLLVMDataLayoutGetProgramAddressSpace(LLVMTargetDataRef TD); 529 530 #endif 531