authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-03 16:49:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-03 16:49:24-07:00
log5466e87fce581f2ef90ac23bb80b1dbc05836fc6
tree76924d4c30f3dfbd0e01ce8a7b3d8132bb4538b8
parent397e055ddd944b2a730458b70c389f1c6588c058

update C API bindings to LLVM 14

* zig_clang is fully updated * zig_llvm is fully updated Some initial work on codegen.cpp is in place for upgrading to LLVM's new opaque pointers. However there is much more to be done. A few of zig llvm bindings for deprecated functions have been updated; more need to be updated.

9 files changed, 83 insertions(+), 76 deletions(-)

lib/std/target.zig+2-2
......@@ -804,6 +804,8 @@ pub const Target = struct {
804804 hsail64,
805805 spir,
806806 spir64,
807 spirv32,
808 spirv64,
807809 kalimba,
808810 shave,
809811 lanai,
......@@ -815,8 +817,6 @@ pub const Target = struct {
815817 // Stage1 currently assumes that architectures above this comment
816818 // map one-to-one with the ZigLLVM_ArchType enum.
817819 spu_2,
818 spirv32,
819 spirv64,
820820
821821 pub fn isX86(arch: Arch) bool {
822822 return switch (arch) {
src/clang.zig+6-2
......@@ -1104,6 +1104,7 @@ pub const TypeClass = enum(c_int) {
11041104 VariableArray,
11051105 Atomic,
11061106 Attributed,
1107 BitInt,
11071108 BlockPointer,
11081109 Builtin,
11091110 Complex,
......@@ -1111,13 +1112,12 @@ pub const TypeClass = enum(c_int) {
11111112 Auto,
11121113 DeducedTemplateSpecialization,
11131114 DependentAddressSpace,
1114 DependentExtInt,
1115 DependentBitInt,
11151116 DependentName,
11161117 DependentSizedExtVector,
11171118 DependentTemplateSpecialization,
11181119 DependentVector,
11191120 Elaborated,
1120 ExtInt,
11211121 FunctionNoProto,
11221122 FunctionProto,
11231123 InjectedClassName,
......@@ -1146,6 +1146,7 @@ pub const TypeClass = enum(c_int) {
11461146 Typedef,
11471147 UnaryTransform,
11481148 UnresolvedUsing,
1149 Using,
11491150 Vector,
11501151 ExtVector,
11511152};
......@@ -1187,6 +1188,7 @@ const StmtClass = enum(c_int) {
11871188 OMPDistributeSimdDirectiveClass,
11881189 OMPForDirectiveClass,
11891190 OMPForSimdDirectiveClass,
1191 OMPGenericLoopDirectiveClass,
11901192 OMPMasterTaskLoopDirectiveClass,
11911193 OMPMasterTaskLoopSimdDirectiveClass,
11921194 OMPParallelForDirectiveClass,
......@@ -1210,6 +1212,7 @@ const StmtClass = enum(c_int) {
12101212 OMPUnrollDirectiveClass,
12111213 OMPMaskedDirectiveClass,
12121214 OMPMasterDirectiveClass,
1215 OMPMetaDirectiveClass,
12131216 OMPOrderedDirectiveClass,
12141217 OMPParallelDirectiveClass,
12151218 OMPParallelMasterDirectiveClass,
......@@ -1746,6 +1749,7 @@ pub const BuiltinTypeKind = enum(c_int) {
17461749 Float16,
17471750 BFloat16,
17481751 Float128,
1752 Ibm128,
17491753 NullPtr,
17501754 ObjCId,
17511755 ObjCClass,
src/codegen/llvm/bindings.zig+8-7
......@@ -331,10 +331,11 @@ pub const Module = opaque {
331331 pub const getLastGlobalAlias = LLVMGetLastGlobalAlias;
332332 extern fn LLVMGetLastGlobalAlias(M: *const Module) *const Value;
333333
334 pub const addAlias = LLVMAddAlias;
335 extern fn LLVMAddAlias(
334 pub const addAlias = LLVMAddAlias2;
335 extern fn LLVMAddAlias2(
336336 M: *const Module,
337337 Ty: *const Type,
338 AddrSpace: c_uint,
338339 Aliasee: *const Value,
339340 Name: [*:0]const u8,
340341 ) *const Value;
......@@ -458,8 +459,8 @@ pub const Builder = opaque {
458459 pub const buildStore = LLVMBuildStore;
459460 extern fn LLVMBuildStore(*const Builder, Val: *const Value, Ptr: *const Value) *const Value;
460461
461 pub const buildLoad = LLVMBuildLoad;
462 extern fn LLVMBuildLoad(*const Builder, PointerVal: *const Value, Name: [*:0]const u8) *const Value;
462 pub const buildLoad = LLVMBuildLoad2;
463 extern fn LLVMBuildLoad2(*const Builder, Ty: *const Type, PointerVal: *const Value, Name: [*:0]const u8) *const Value;
463464
464465 pub const buildNeg = LLVMBuildNeg;
465466 extern fn LLVMBuildNeg(*const Builder, V: *const Value, Name: [*:0]const u8) *const Value;
......@@ -1067,9 +1068,9 @@ pub extern fn LLVMInitializeM68kAsmParser() void;
10671068pub extern fn LLVMInitializeCSKYAsmParser() void;
10681069pub extern fn LLVMInitializeVEAsmParser() void;
10691070
1070extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
1071extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
1072extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
1071extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) c_int;
1072extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) c_int;
1073extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) c_int;
10731074
10741075pub const LinkCOFF = ZigLLDLinkCOFF;
10751076pub const LinkELF = ZigLLDLinkELF;
src/stage1/codegen.cpp+12-9
......@@ -490,7 +490,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
490490
491491 for (size_t i = 1; i < fn->export_list.length; i += 1) {
492492 GlobalExport *fn_export = &fn->export_list.items[i];
493 LLVMAddAlias(g->module, LLVMTypeOf(llvm_fn), llvm_fn, buf_ptr(&fn_export->name));
493 LLVMAddAlias2(g->module, LLVMTypeOf(llvm_fn), 0, llvm_fn, buf_ptr(&fn_export->name));
494494 }
495495 }
496496
......@@ -901,10 +901,10 @@ static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr,
901901 return gen_store_untyped(g, value, ptr, alignment, ptr_type->data.pointer.is_volatile);
902902}
903903
904static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alignment, bool is_volatile,
905 const char *name)
904static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMTypeRef elem_type, LLVMValueRef ptr,
905 uint32_t alignment, bool is_volatile, const char *name)
906906{
907 LLVMValueRef result = LLVMBuildLoad(g->builder, ptr, name);
907 LLVMValueRef result = LLVMBuildLoad2(g->builder, elem_type, ptr, name);
908908 if (is_volatile) LLVMSetVolatile(result, true);
909909 if (alignment == 0) {
910910 LLVMSetAlignment(result, LLVMABIAlignmentOfType(g->target_data_ref, LLVMGetElementType(LLVMTypeOf(ptr))));
......@@ -916,8 +916,10 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig
916916
917917static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {
918918 assert(ptr_type->id == ZigTypeIdPointer);
919 ZigType *elem_type = ptr_type->data.pointer.child_type;
919920 uint32_t alignment = get_ptr_align(g, ptr_type);
920 return gen_load_untyped(g, ptr, alignment, ptr_type->data.pointer.is_volatile, name);
921 return gen_load_untyped(g, get_llvm_type(g, elem_type), ptr, alignment,
922 ptr_type->data.pointer.is_volatile, name);
921923}
922924
923925static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {
......@@ -1265,15 +1267,16 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
12651267 size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index;
12661268 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, "");
12671269
1268 LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, "");
1269 LLVMValueRef index_val = gen_load_untyped(g, index_field_ptr, 0, false, "");
1270 LLVMValueRef len_value = gen_load_untyped(g, usize_type_ref, len_field_ptr, 0, false, "");
1271 LLVMValueRef index_val = gen_load_untyped(g, usize_type_ref, index_field_ptr, 0, false, "");
12701272 LLVMValueRef len_val_minus_one = LLVMBuildSub(g->builder, len_value, LLVMConstInt(usize_type_ref, 1, false), "");
12711273 LLVMValueRef masked_val = LLVMBuildAnd(g->builder, index_val, len_val_minus_one, "");
12721274 LLVMValueRef address_indices[] = {
12731275 masked_val,
12741276 };
12751277
1276 LLVMValueRef ptr_value = gen_load_untyped(g, ptr_field_ptr, 0, false, "");
1278 LLVMTypeRef ptr_to_usize = LLVMPointerType(usize_type_ref, 0);
1279 LLVMValueRef ptr_value = gen_load_untyped(g, ptr_to_usize, ptr_field_ptr, 0, false, "");
12771280 LLVMValueRef address_slot = LLVMBuildInBoundsGEP(g->builder, ptr_value, address_indices, 1, "");
12781281
12791282 gen_store_untyped(g, address_value, address_slot, 0, false);
......@@ -8802,7 +8805,7 @@ static void do_code_gen(CodeGen *g) {
88028805
88038806 for (size_t export_i = 1; export_i < var->export_list.length; export_i += 1) {
88048807 GlobalExport *global_export = &var->export_list.items[export_i];
8805 LLVMAddAlias(g->module, LLVMTypeOf(var->value_ref), var->value_ref, buf_ptr(&global_export->name));
8808 LLVMAddAlias2(g->module, LLVMTypeOf(var->value_ref), 0, var->value_ref, buf_ptr(&global_export->name));
88068809 }
88078810 }
88088811
src/stage1/target.cpp+2
......@@ -60,6 +60,8 @@ static const ZigLLVM_ArchType arch_list[] = {
6060 ZigLLVM_hsail64, // AMD HSAIL with 64-bit pointers
6161 ZigLLVM_spir, // SPIR: standard portable IR for OpenCL 32-bit version
6262 ZigLLVM_spir64, // SPIR: standard portable IR for OpenCL 64-bit version
63 ZigLLVM_spirv32, // SPIR-V with 32-bit pointers
64 ZigLLVM_spirv64, // SPIR-V with 64-bit pointers
6365 ZigLLVM_kalimba, // Kalimba: generic kalimba
6466 ZigLLVM_shave, // SHAVE: Movidius vector VLIW processors
6567 ZigLLVM_lanai, // Lanai: Lanai 32-bit
src/zig_clang.cpp+12-4
......@@ -294,13 +294,14 @@ void ZigClang_detect_enum_TypeClass(clang::Type::TypeClass ty) {
294294 case clang::Type::DependentSizedArray:
295295 case clang::Type::DependentSizedExtVector:
296296 case clang::Type::DependentAddressSpace:
297 case clang::Type::DependentExtInt:
297 case clang::Type::DependentBitInt:
298298 case clang::Type::Vector:
299299 case clang::Type::DependentVector:
300300 case clang::Type::ExtVector:
301301 case clang::Type::FunctionProto:
302302 case clang::Type::FunctionNoProto:
303303 case clang::Type::UnresolvedUsing:
304 case clang::Type::Using:
304305 case clang::Type::Paren:
305306 case clang::Type::Typedef:
306307 case clang::Type::MacroQualified:
......@@ -315,8 +316,8 @@ void ZigClang_detect_enum_TypeClass(clang::Type::TypeClass ty) {
315316 case clang::Type::Record:
316317 case clang::Type::Enum:
317318 case clang::Type::Elaborated:
318 case clang::Type::ExtInt:
319319 case clang::Type::Attributed:
320 case clang::Type::BitInt:
320321 case clang::Type::TemplateTypeParm:
321322 case clang::Type::SubstTemplateTypeParm:
322323 case clang::Type::SubstTemplateTypeParmPack:
......@@ -345,6 +346,7 @@ static_assert((clang::Type::TypeClass)ZigClangType_IncompleteArray == clang::Typ
345346static_assert((clang::Type::TypeClass)ZigClangType_VariableArray == clang::Type::VariableArray, "");
346347static_assert((clang::Type::TypeClass)ZigClangType_Atomic == clang::Type::Atomic, "");
347348static_assert((clang::Type::TypeClass)ZigClangType_Attributed == clang::Type::Attributed, "");
349static_assert((clang::Type::TypeClass)ZigClangType_BitInt == clang::Type::BitInt, "");
348350static_assert((clang::Type::TypeClass)ZigClangType_BlockPointer == clang::Type::BlockPointer, "");
349351static_assert((clang::Type::TypeClass)ZigClangType_Builtin == clang::Type::Builtin, "");
350352static_assert((clang::Type::TypeClass)ZigClangType_Complex == clang::Type::Complex, "");
......@@ -352,13 +354,12 @@ static_assert((clang::Type::TypeClass)ZigClangType_Decltype == clang::Type::Decl
352354static_assert((clang::Type::TypeClass)ZigClangType_Auto == clang::Type::Auto, "");
353355static_assert((clang::Type::TypeClass)ZigClangType_DeducedTemplateSpecialization == clang::Type::DeducedTemplateSpecialization, "");
354356static_assert((clang::Type::TypeClass)ZigClangType_DependentAddressSpace == clang::Type::DependentAddressSpace, "");
355static_assert((clang::Type::TypeClass)ZigClangType_DependentExtInt == clang::Type::DependentExtInt, "");
357static_assert((clang::Type::TypeClass)ZigClangType_DependentBitInt == clang::Type::DependentBitInt, "");
356358static_assert((clang::Type::TypeClass)ZigClangType_DependentName == clang::Type::DependentName, "");
357359static_assert((clang::Type::TypeClass)ZigClangType_DependentSizedExtVector == clang::Type::DependentSizedExtVector, "");
358360static_assert((clang::Type::TypeClass)ZigClangType_DependentTemplateSpecialization == clang::Type::DependentTemplateSpecialization, "");
359361static_assert((clang::Type::TypeClass)ZigClangType_DependentVector == clang::Type::DependentVector, "");
360362static_assert((clang::Type::TypeClass)ZigClangType_Elaborated == clang::Type::Elaborated, "");
361static_assert((clang::Type::TypeClass)ZigClangType_ExtInt == clang::Type::ExtInt, "");
362363static_assert((clang::Type::TypeClass)ZigClangType_FunctionNoProto == clang::Type::FunctionNoProto, "");
363364static_assert((clang::Type::TypeClass)ZigClangType_FunctionProto == clang::Type::FunctionProto, "");
364365static_assert((clang::Type::TypeClass)ZigClangType_InjectedClassName == clang::Type::InjectedClassName, "");
......@@ -387,6 +388,7 @@ static_assert((clang::Type::TypeClass)ZigClangType_TypeOf == clang::Type::TypeOf
387388static_assert((clang::Type::TypeClass)ZigClangType_Typedef == clang::Type::Typedef, "");
388389static_assert((clang::Type::TypeClass)ZigClangType_UnaryTransform == clang::Type::UnaryTransform, "");
389390static_assert((clang::Type::TypeClass)ZigClangType_UnresolvedUsing == clang::Type::UnresolvedUsing, "");
391static_assert((clang::Type::TypeClass)ZigClangType_Using == clang::Type::Using, "");
390392static_assert((clang::Type::TypeClass)ZigClangType_Vector == clang::Type::Vector, "");
391393static_assert((clang::Type::TypeClass)ZigClangType_ExtVector == clang::Type::ExtVector, "");
392394
......@@ -429,6 +431,7 @@ void ZigClang_detect_enum_StmtClass(clang::Stmt::StmtClass x) {
429431 case clang::Stmt::OMPDistributeSimdDirectiveClass:
430432 case clang::Stmt::OMPForDirectiveClass:
431433 case clang::Stmt::OMPForSimdDirectiveClass:
434 case clang::Stmt::OMPGenericLoopDirectiveClass:
432435 case clang::Stmt::OMPMasterTaskLoopDirectiveClass:
433436 case clang::Stmt::OMPMasterTaskLoopSimdDirectiveClass:
434437 case clang::Stmt::OMPParallelForDirectiveClass:
......@@ -452,6 +455,7 @@ void ZigClang_detect_enum_StmtClass(clang::Stmt::StmtClass x) {
452455 case clang::Stmt::OMPUnrollDirectiveClass:
453456 case clang::Stmt::OMPMaskedDirectiveClass:
454457 case clang::Stmt::OMPMasterDirectiveClass:
458 case clang::Stmt::OMPMetaDirectiveClass:
455459 case clang::Stmt::OMPOrderedDirectiveClass:
456460 case clang::Stmt::OMPParallelDirectiveClass:
457461 case clang::Stmt::OMPParallelMasterDirectiveClass:
......@@ -654,6 +658,7 @@ static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPDistributeParallelForSimdD
654658static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPDistributeSimdDirectiveClass == clang::Stmt::OMPDistributeSimdDirectiveClass, "");
655659static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPForDirectiveClass == clang::Stmt::OMPForDirectiveClass, "");
656660static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPForSimdDirectiveClass == clang::Stmt::OMPForSimdDirectiveClass, "");
661static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPGenericLoopDirectiveClass == clang::Stmt::OMPGenericLoopDirectiveClass, "");
657662static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMasterTaskLoopDirectiveClass == clang::Stmt::OMPMasterTaskLoopDirectiveClass, "");
658663static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMasterTaskLoopSimdDirectiveClass == clang::Stmt::OMPMasterTaskLoopSimdDirectiveClass, "");
659664static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPParallelForDirectiveClass == clang::Stmt::OMPParallelForDirectiveClass, "");
......@@ -677,6 +682,7 @@ static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTileDirectiveClass == clan
677682static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPUnrollDirectiveClass == clang::Stmt::OMPUnrollDirectiveClass, "");
678683static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMaskedDirectiveClass == clang::Stmt::OMPMaskedDirectiveClass, "");
679684static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMasterDirectiveClass == clang::Stmt::OMPMasterDirectiveClass, "");
685static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMetaDirectiveClass == clang::Stmt::OMPMetaDirectiveClass, "");
680686static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPOrderedDirectiveClass == clang::Stmt::OMPOrderedDirectiveClass, "");
681687static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPParallelDirectiveClass == clang::Stmt::OMPParallelDirectiveClass, "");
682688static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPParallelMasterDirectiveClass == clang::Stmt::OMPParallelMasterDirectiveClass, "");
......@@ -1269,6 +1275,7 @@ void ZigClang_detect_enum_BuiltinTypeKind(clang::BuiltinType::Kind x) {
12691275 case clang::BuiltinType::Float16:
12701276 case clang::BuiltinType::BFloat16:
12711277 case clang::BuiltinType::Float128:
1278 case clang::BuiltinType::Ibm128:
12721279 case clang::BuiltinType::NullPtr:
12731280 case clang::BuiltinType::ObjCId:
12741281 case clang::BuiltinType::ObjCClass:
......@@ -1510,6 +1517,7 @@ static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeLongDouble == clang::
15101517static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeFloat16 == clang::BuiltinType::Float16, "");
15111518static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeBFloat16 == clang::BuiltinType::BFloat16, "");
15121519static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeFloat128 == clang::BuiltinType::Float128, "");
1520static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeIbm128 == clang::BuiltinType::Ibm128, "");
15131521static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeNullPtr == clang::BuiltinType::NullPtr, "");
15141522static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeObjCId == clang::BuiltinType::ObjCId, "");
15151523static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeObjCClass == clang::BuiltinType::ObjCClass, "");
src/zig_clang.h+6-2
......@@ -251,6 +251,7 @@ enum ZigClangTypeClass {
251251 ZigClangType_VariableArray,
252252 ZigClangType_Atomic,
253253 ZigClangType_Attributed,
254 ZigClangType_BitInt,
254255 ZigClangType_BlockPointer,
255256 ZigClangType_Builtin,
256257 ZigClangType_Complex,
......@@ -258,13 +259,12 @@ enum ZigClangTypeClass {
258259 ZigClangType_Auto,
259260 ZigClangType_DeducedTemplateSpecialization,
260261 ZigClangType_DependentAddressSpace,
261 ZigClangType_DependentExtInt,
262 ZigClangType_DependentBitInt,
262263 ZigClangType_DependentName,
263264 ZigClangType_DependentSizedExtVector,
264265 ZigClangType_DependentTemplateSpecialization,
265266 ZigClangType_DependentVector,
266267 ZigClangType_Elaborated,
267 ZigClangType_ExtInt,
268268 ZigClangType_FunctionNoProto,
269269 ZigClangType_FunctionProto,
270270 ZigClangType_InjectedClassName,
......@@ -293,6 +293,7 @@ enum ZigClangTypeClass {
293293 ZigClangType_Typedef,
294294 ZigClangType_UnaryTransform,
295295 ZigClangType_UnresolvedUsing,
296 ZigClangType_Using,
296297 ZigClangType_Vector,
297298 ZigClangType_ExtVector,
298299};
......@@ -334,6 +335,7 @@ enum ZigClangStmtClass {
334335 ZigClangStmt_OMPDistributeSimdDirectiveClass,
335336 ZigClangStmt_OMPForDirectiveClass,
336337 ZigClangStmt_OMPForSimdDirectiveClass,
338 ZigClangStmt_OMPGenericLoopDirectiveClass,
337339 ZigClangStmt_OMPMasterTaskLoopDirectiveClass,
338340 ZigClangStmt_OMPMasterTaskLoopSimdDirectiveClass,
339341 ZigClangStmt_OMPParallelForDirectiveClass,
......@@ -357,6 +359,7 @@ enum ZigClangStmtClass {
357359 ZigClangStmt_OMPUnrollDirectiveClass,
358360 ZigClangStmt_OMPMaskedDirectiveClass,
359361 ZigClangStmt_OMPMasterDirectiveClass,
362 ZigClangStmt_OMPMetaDirectiveClass,
360363 ZigClangStmt_OMPOrderedDirectiveClass,
361364 ZigClangStmt_OMPParallelDirectiveClass,
362365 ZigClangStmt_OMPParallelMasterDirectiveClass,
......@@ -893,6 +896,7 @@ enum ZigClangBuiltinTypeKind {
893896 ZigClangBuiltinTypeFloat16,
894897 ZigClangBuiltinTypeBFloat16,
895898 ZigClangBuiltinTypeFloat128,
899 ZigClangBuiltinTypeIbm128,
896900 ZigClangBuiltinTypeNullPtr,
897901 ZigClangBuiltinTypeObjCId,
898902 ZigClangBuiltinTypeObjCClass,
src/zig_llvm.cpp+30-47
......@@ -35,6 +35,8 @@
3535#include <llvm/IR/Verifier.h>
3636#include <llvm/InitializePasses.h>
3737#include <llvm/MC/SubtargetFeature.h>
38#include <llvm/MC/TargetRegistry.h>
39#include <llvm/Passes/OptimizationLevel.h>
3840#include <llvm/Passes/PassBuilder.h>
3941#include <llvm/Passes/StandardInstrumentations.h>
4042#include <llvm/Object/Archive.h>
......@@ -51,7 +53,6 @@
5153#include <llvm/Support/TimeProfiler.h>
5254#include <llvm/Support/Timer.h>
5355#include <llvm/Support/raw_ostream.h>
54#include <llvm/Support/TargetRegistry.h>
5556#include <llvm/Target/TargetMachine.h>
5657#include <llvm/Target/CodeGenCWrappers.h>
5758#include <llvm/Transforms/IPO.h>
......@@ -273,7 +274,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
273274 TargetMachine &target_machine = *reinterpret_cast<TargetMachine*>(targ_machine_ref);
274275 target_machine.setO0WantsFastISel(true);
275276
276 Module &module = *unwrap(module_ref);
277 Module &llvm_module = *unwrap(module_ref);
277278
278279 // Pipeline configurations
279280 PipelineTuningOptions pipeline_opts;
......@@ -290,7 +291,6 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
290291
291292 PassBuilder pass_builder(&target_machine, pipeline_opts,
292293 None, &instr_callbacks);
293 using OptimizationLevel = typename PassBuilder::OptimizationLevel;
294294
295295 LoopAnalysisManager loop_am;
296296 FunctionAnalysisManager function_am;
......@@ -302,7 +302,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
302302 return pass_builder.buildDefaultAAPipeline();
303303 });
304304
305 Triple target_triple(module.getTargetTriple());
305 Triple target_triple(llvm_module.getTargetTriple());
306306 auto tlii = std::make_unique<TargetLibraryInfoImpl>(target_triple);
307307 function_am.registerPass([&] { return TargetLibraryAnalysis(*tlii); });
308308
......@@ -339,9 +339,9 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
339339
340340 // Thread sanitizer
341341 if (tsan) {
342 pass_builder.registerOptimizerLastEPCallback(
343 [](ModulePassManager &module_pm, OptimizationLevel level) {
344 module_pm.addPass(ThreadSanitizerPass());
342 pass_builder.registerOptimizerLastEPCallback([](ModulePassManager &module_pm, OptimizationLevel level) {
343 module_pm.addPass(ModuleThreadSanitizerPass());
344 module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
345345 });
346346 }
347347
......@@ -383,10 +383,10 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
383383 }
384384
385385 // Optimization phase
386 module_pm.run(module, module_am);
386 module_pm.run(llvm_module, module_am);
387387
388388 // Code generation phase
389 codegen_pm.run(module);
389 codegen_pm.run(llvm_module);
390390
391391 if (llvm_ir_filename) {
392392 if (LLVMPrintModuleToFile(module_ref, llvm_ir_filename, error_message)) {
......@@ -395,10 +395,10 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
395395 }
396396
397397 if (dest_bin && lto) {
398 WriteBitcodeToFile(module, *dest_bin);
398 WriteBitcodeToFile(llvm_module, *dest_bin);
399399 }
400400 if (dest_bitcode) {
401 WriteBitcodeToFile(module, *dest_bitcode);
401 WriteBitcodeToFile(llvm_module, *dest_bitcode);
402402 }
403403
404404 if (time_report) {
......@@ -421,7 +421,7 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A
421421 unsigned NumArgs, ZigLLVM_CallingConv CC, ZigLLVM_CallAttr attr, const char *Name)
422422{
423423 Value *V = unwrap(Fn);
424 FunctionType *FnT = cast<FunctionType>(cast<PointerType>(V->getType())->getElementType());
424 FunctionType *FnT = cast<FunctionType>(V->getType()->getNonOpaquePointerElementType());
425425 CallInst *call_inst = CallInst::Create(FnT, V, makeArrayRef(unwrap(Args), NumArgs), Name);
426426 call_inst->setCallingConv(static_cast<CallingConv::ID>(CC));
427427 switch (attr) {
......@@ -431,13 +431,13 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A
431431 call_inst->setTailCallKind(CallInst::TCK_NoTail);
432432 break;
433433 case ZigLLVM_CallAttrNeverInline:
434 call_inst->addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
434 call_inst->addFnAttr(Attribute::NoInline);
435435 break;
436436 case ZigLLVM_CallAttrAlwaysTail:
437437 call_inst->setTailCallKind(CallInst::TCK_MustTail);
438438 break;
439439 case ZigLLVM_CallAttrAlwaysInline:
440 call_inst->addAttribute(AttributeList::FunctionIndex, Attribute::AlwaysInline);
440 call_inst->addFnAttr(Attribute::AlwaysInline);
441441 break;
442442 }
443443 return wrap(unwrap(B)->Insert(call_inst));
......@@ -972,44 +972,28 @@ void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state) {
972972
973973void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val) {
974974 Function *func = unwrap<Function>(fn_ref);
975 const AttributeList attr_set = func->getAttributes();
976 AttrBuilder attr_builder;
975 AttrBuilder attr_builder(func->getContext());
977976 Type *llvm_type = unwrap<Type>(type_val);
978977 attr_builder.addByValAttr(llvm_type);
979 const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(), ArgNo + 1, attr_builder);
980 func->setAttributes(new_attr_set);
978 func->addParamAttrs(ArgNo + 1, attr_builder);
981979}
982980
983981void ZigLLVMAddSretAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val) {
984982 Function *func = unwrap<Function>(fn_ref);
985 const AttributeList attr_set = func->getAttributes();
986 AttrBuilder attr_builder;
983 AttrBuilder attr_builder(func->getContext());
987984 Type *llvm_type = unwrap<Type>(type_val);
988985 attr_builder.addStructRetAttr(llvm_type);
989 const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(), ArgNo + 1, attr_builder);
990 func->setAttributes(new_attr_set);
986 func->addParamAttrs(ArgNo + 1, attr_builder);
991987}
992988
993989void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const char *attr_value) {
994990 Function *func = unwrap<Function>(fn_ref);
995 const AttributeList attr_set = func->getAttributes();
996 AttrBuilder attr_builder;
997 if (attr_value) {
998 attr_builder.addAttribute(attr_name, attr_value);
999 } else {
1000 attr_builder.addAttribute(attr_name);
1001 }
1002 const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(),
1003 AttributeList::FunctionIndex, attr_builder);
1004 func->setAttributes(new_attr_set);
991 func->addFnAttr(attr_name, attr_value);
1005992}
1006993
1007994void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn_ref) {
1008995 Function *func = unwrap<Function>(fn_ref);
1009 const AttributeList attr_set = func->getAttributes();
1010 const AttributeList new_attr_set = attr_set.addAttribute(func->getContext(), AttributeList::FunctionIndex,
1011 Attribute::Cold);
1012 func->setAttributes(new_attr_set);
996 func->addFnAttr(Attribute::Cold);
1013997}
1014998
1015999void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) {
......@@ -1102,12 +1086,9 @@ void ZigLLVMSetTailCall(LLVMValueRef Call) {
11021086}
11031087
11041088void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type) {
1105 const AttributeList attr_set = unwrap<CallInst>(Call)->getAttributes();
1106 AttrBuilder attr_builder;
1089 CallInst *call_inst = unwrap<CallInst>(Call);
11071090 Type *llvm_type = unwrap<Type>(return_type);
1108 attr_builder.addStructRetAttr(llvm_type);
1109 const AttributeList new_attr_set = attr_set.addAttributes(unwrap<CallInst>(Call)->getContext(), 1, attr_builder);
1110 unwrap<CallInst>(Call)->setAttributes(new_attr_set);
1091 call_inst->addParamAttr(1, Attribute::getWithStructRetType(call_inst->getContext(), llvm_type));
11111092}
11121093
11131094void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) {
......@@ -1252,19 +1233,19 @@ bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size
12521233 return false;
12531234}
12541235
1255int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early) {
1236int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early, bool disable_output) {
12561237 std::vector<const char *> args(argv, argv + argc);
1257 return lld::coff::link(args, can_exit_early, llvm::outs(), llvm::errs());
1238 return lld::coff::link(args, llvm::outs(), llvm::errs(), can_exit_early, disable_output);
12581239}
12591240
1260int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early) {
1241int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early, bool disable_output) {
12611242 std::vector<const char *> args(argv, argv + argc);
1262 return lld::elf::link(args, can_exit_early, llvm::outs(), llvm::errs());
1243 return lld::elf::link(args, llvm::outs(), llvm::errs(), can_exit_early, disable_output);
12631244}
12641245
1265int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early) {
1246int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early, bool disable_output) {
12661247 std::vector<const char *> args(argv, argv + argc);
1267 return lld::wasm::link(args, can_exit_early, llvm::outs(), llvm::errs());
1248 return lld::wasm::link(args, llvm::outs(), llvm::errs(), can_exit_early, disable_output);
12681249}
12691250
12701251inline LLVMAttributeRef wrap(Attribute Attr) {
......@@ -1370,6 +1351,8 @@ static_assert((Triple::ArchType)ZigLLVM_hsail == Triple::hsail, "");
13701351static_assert((Triple::ArchType)ZigLLVM_hsail64 == Triple::hsail64, "");
13711352static_assert((Triple::ArchType)ZigLLVM_spir == Triple::spir, "");
13721353static_assert((Triple::ArchType)ZigLLVM_spir64 == Triple::spir64, "");
1354static_assert((Triple::ArchType)ZigLLVM_spirv32 == Triple::spirv32, "");
1355static_assert((Triple::ArchType)ZigLLVM_spirv64 == Triple::spirv64, "");
13731356static_assert((Triple::ArchType)ZigLLVM_kalimba == Triple::kalimba, "");
13741357static_assert((Triple::ArchType)ZigLLVM_shave == Triple::shave, "");
13751358static_assert((Triple::ArchType)ZigLLVM_lanai == Triple::lanai, "");
src/zig_llvm.h+5-3
......@@ -346,6 +346,8 @@ enum ZigLLVM_ArchType {
346346 ZigLLVM_hsail64, // AMD HSAIL with 64-bit pointers
347347 ZigLLVM_spir, // SPIR: standard portable IR for OpenCL 32-bit version
348348 ZigLLVM_spir64, // SPIR: standard portable IR for OpenCL 64-bit version
349 ZigLLVM_spirv32, // SPIR-V with 32-bit pointers
350 ZigLLVM_spirv64, // SPIR-V with 64-bit pointers
349351 ZigLLVM_kalimba, // Kalimba: generic kalimba
350352 ZigLLVM_shave, // SHAVE: Movidius vector VLIW processors
351353 ZigLLVM_lanai, // Lanai: Lanai 32-bit
......@@ -512,9 +514,9 @@ ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor
512514ZIG_EXTERN_C const char *ZigLLVMGetOSTypeName(enum ZigLLVM_OSType os);
513515ZIG_EXTERN_C const char *ZigLLVMGetEnvironmentTypeName(enum ZigLLVM_EnvironmentType abi);
514516
515ZIG_EXTERN_C int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early);
516ZIG_EXTERN_C int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early);
517ZIG_EXTERN_C int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early);
517ZIG_EXTERN_C int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early, bool disable_output);
518ZIG_EXTERN_C int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early, bool disable_output);
519ZIG_EXTERN_C int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early, bool disable_output);
518520
519521ZIG_EXTERN_C bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size_t file_name_count,
520522 enum ZigLLVM_OSType os_type);