| ... | ... | @@ -181,8 +181,7 @@ const Error = error{ CodegenFail, OutOfMemory }; |
| 181 | 181 | |
| 182 | 182 | pub fn genNav(cg: *CodeGen, do_codegen: bool) Error!void { |
| 183 | 183 | const gpa = cg.module.gpa; |
| 184 | | const pt = cg.pt; |
| 185 | | const zcu = pt.zcu; |
| 184 | const zcu = cg.module.zcu; |
| 186 | 185 | const ip = &zcu.intern_pool; |
| 187 | 186 | |
| 188 | 187 | const nav = ip.getNav(cg.owner_nav); |
| ... | ... | @@ -198,7 +197,7 @@ pub fn genNav(cg: *CodeGen, do_codegen: bool) Error!void { |
| 198 | 197 | .func => { |
| 199 | 198 | const fn_info = zcu.typeToFunc(ty).?; |
| 200 | 199 | const return_ty_id = try cg.resolveFnReturnType(.fromInterned(fn_info.return_type)); |
| 201 | | const is_test = cg.pt.zcu.test_functions.contains(cg.owner_nav); |
| 200 | const is_test = zcu.test_functions.contains(cg.owner_nav); |
| 202 | 201 | |
| 203 | 202 | const func_result_id = if (is_test) cg.module.allocId() else result_id; |
| 204 | 203 | const prototype_ty_id = try cg.resolveType(ty, .direct); |
| ... | ... | @@ -354,7 +353,7 @@ pub fn genNav(cg: *CodeGen, do_codegen: bool) Error!void { |
| 354 | 353 | |
| 355 | 354 | pub fn fail(cg: *CodeGen, comptime format: []const u8, args: anytype) Error { |
| 356 | 355 | @branchHint(.cold); |
| 357 | | const zcu = cg.pt.zcu; |
| 356 | const zcu = cg.module.zcu; |
| 358 | 357 | const src_loc = zcu.navSrcLoc(cg.owner_nav); |
| 359 | 358 | assert(cg.error_msg == null); |
| 360 | 359 | cg.error_msg = try Zcu.ErrorMsg.create(zcu.gpa, src_loc, format, args); |
| ... | ... | @@ -368,7 +367,7 @@ pub fn todo(cg: *CodeGen, comptime format: []const u8, args: anytype) Error { |
| 368 | 367 | /// This imports the "default" extended instruction set for the target |
| 369 | 368 | /// For OpenCL, OpenCL.std.100. For Vulkan and OpenGL, GLSL.std.450. |
| 370 | 369 | fn importExtendedSet(cg: *CodeGen) !Id { |
| 371 | | const target = cg.module.target; |
| 370 | const target = cg.module.zcu.getTarget(); |
| 372 | 371 | return switch (target.os.tag) { |
| 373 | 372 | .opencl, .amdhsa => try cg.module.importInstructionSet(.@"OpenCL.std"), |
| 374 | 373 | .vulkan, .opengl => try cg.module.importInstructionSet(.@"GLSL.std.450"), |
| ... | ... | @@ -379,7 +378,7 @@ fn importExtendedSet(cg: *CodeGen) !Id { |
| 379 | 378 | /// Fetch the result-id for a previously generated instruction or constant. |
| 380 | 379 | fn resolve(cg: *CodeGen, inst: Air.Inst.Ref) !Id { |
| 381 | 380 | const pt = cg.pt; |
| 382 | | const zcu = pt.zcu; |
| 381 | const zcu = cg.module.zcu; |
| 383 | 382 | const ip = &zcu.intern_pool; |
| 384 | 383 | if (try cg.air.value(inst, pt)) |val| { |
| 385 | 384 | const ty = cg.typeOf(inst); |
| ... | ... | @@ -405,7 +404,7 @@ fn resolveUav(cg: *CodeGen, val: InternPool.Index) !Id { |
| 405 | 404 | |
| 406 | 405 | // TODO: This cannot be a function at this point, but it should probably be handled anyway. |
| 407 | 406 | |
| 408 | | const zcu = cg.pt.zcu; |
| 407 | const zcu = cg.module.zcu; |
| 409 | 408 | const ty: Type = .fromInterned(zcu.intern_pool.typeOf(val)); |
| 410 | 409 | const decl_ptr_ty_id = try cg.ptrType(ty, cg.module.storageClass(.generic), .indirect); |
| 411 | 410 | |
| ... | ... | @@ -499,7 +498,8 @@ fn resolveUav(cg: *CodeGen, val: InternPool.Index) !Id { |
| 499 | 498 | } |
| 500 | 499 | |
| 501 | 500 | fn addFunctionDep(cg: *CodeGen, decl_index: Module.Decl.Index, storage_class: StorageClass) !void { |
| 502 | | if (cg.module.target.cpu.has(.spirv, .v1_4)) { |
| 501 | const target = cg.module.zcu.getTarget(); |
| 502 | if (target.cpu.has(.spirv, .v1_4)) { |
| 503 | 503 | try cg.decl_deps.put(cg.module.gpa, decl_index, {}); |
| 504 | 504 | } else { |
| 505 | 505 | // Before version 1.4, the interface’s storage classes are limited to the Input and Output |
| ... | ... | @@ -510,7 +510,8 @@ fn addFunctionDep(cg: *CodeGen, decl_index: Module.Decl.Index, storage_class: St |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | fn castToGeneric(cg: *CodeGen, type_id: Id, ptr_id: Id) !Id { |
| 513 | | if (cg.module.target.cpu.has(.spirv, .generic_pointer)) { |
| 513 | const target = cg.module.zcu.getTarget(); |
| 514 | if (target.cpu.has(.spirv, .generic_pointer)) { |
| 514 | 515 | const result_id = cg.module.allocId(); |
| 515 | 516 | try cg.body.emit(cg.module.gpa, .OpPtrCastToGeneric, .{ |
| 516 | 517 | .id_result_type = type_id, |
| ... | ... | @@ -541,10 +542,12 @@ fn beginSpvBlock(cg: *CodeGen, label: Id) !void { |
| 541 | 542 | /// The result is valid to be used with OpTypeInt. |
| 542 | 543 | /// TODO: Should the result of this function be cached? |
| 543 | 544 | fn backingIntBits(cg: *CodeGen, bits: u16) struct { u16, bool } { |
| 545 | const target = cg.module.zcu.getTarget(); |
| 546 | |
| 544 | 547 | // The backend will never be asked to compiler a 0-bit integer, so we won't have to handle those in this function. |
| 545 | 548 | assert(bits != 0); |
| 546 | 549 | |
| 547 | | if (cg.module.target.cpu.has(.spirv, .arbitrary_precision_integers) and bits <= 32) { |
| 550 | if (target.cpu.has(.spirv, .arbitrary_precision_integers) and bits <= 32) { |
| 548 | 551 | return .{ bits, false }; |
| 549 | 552 | } |
| 550 | 553 | |
| ... | ... | @@ -556,7 +559,7 @@ fn backingIntBits(cg: *CodeGen, bits: u16) struct { u16, bool } { |
| 556 | 559 | .{ .bits = 32, .enabled = true }, |
| 557 | 560 | .{ |
| 558 | 561 | .bits = 64, |
| 559 | | .enabled = cg.module.target.cpu.has(.spirv, .int64) or cg.module.target.cpu.arch == .spirv64, |
| 562 | .enabled = target.cpu.has(.spirv, .int64) or target.cpu.arch == .spirv64, |
| 560 | 563 | }, |
| 561 | 564 | }; |
| 562 | 565 | |
| ... | ... | @@ -575,7 +578,8 @@ fn backingIntBits(cg: *CodeGen, bits: u16) struct { u16, bool } { |
| 575 | 578 | /// is no way of knowing whether those are actually supported. |
| 576 | 579 | /// TODO: Maybe this should be cached? |
| 577 | 580 | fn largestSupportedIntBits(cg: *CodeGen) u16 { |
| 578 | | if (cg.module.target.cpu.has(.spirv, .int64) or cg.module.target.cpu.arch == .spirv64) { |
| 581 | const target = cg.module.zcu.getTarget(); |
| 582 | if (target.cpu.has(.spirv, .int64) or target.cpu.arch == .spirv64) { |
| 579 | 583 | return 64; |
| 580 | 584 | } |
| 581 | 585 | return 32; |
| ... | ... | @@ -618,8 +622,8 @@ const ArithmeticTypeInfo = struct { |
| 618 | 622 | }; |
| 619 | 623 | |
| 620 | 624 | fn arithmeticTypeInfo(cg: *CodeGen, ty: Type) ArithmeticTypeInfo { |
| 621 | | const zcu = cg.pt.zcu; |
| 622 | | const target = cg.module.target; |
| 625 | const zcu = cg.module.zcu; |
| 626 | const target = cg.module.zcu.getTarget(); |
| 623 | 627 | var scalar_ty = ty.scalarType(zcu); |
| 624 | 628 | if (scalar_ty.zigTypeTag(zcu) == .@"enum") { |
| 625 | 629 | scalar_ty = scalar_ty.intTagType(zcu); |
| ... | ... | @@ -663,7 +667,8 @@ fn arithmeticTypeInfo(cg: *CodeGen, ty: Type) ArithmeticTypeInfo { |
| 663 | 667 | |
| 664 | 668 | /// Checks whether the type can be directly translated to SPIR-V vectors |
| 665 | 669 | fn isSpvVector(cg: *CodeGen, ty: Type) bool { |
| 666 | | const zcu = cg.pt.zcu; |
| 670 | const zcu = cg.module.zcu; |
| 671 | const target = cg.module.zcu.getTarget(); |
| 667 | 672 | if (ty.zigTypeTag(zcu) != .vector) return false; |
| 668 | 673 | |
| 669 | 674 | // TODO: This check must be expanded for types that can be represented |
| ... | ... | @@ -683,7 +688,7 @@ fn isSpvVector(cg: *CodeGen, ty: Type) bool { |
| 683 | 688 | |
| 684 | 689 | if (elem_ty.isNumeric(zcu) or elem_ty.toIntern() == .bool_type) { |
| 685 | 690 | if (len > 1 and len <= 4) return true; |
| 686 | | if (cg.module.target.cpu.has(.spirv, .vector16)) return (len == 8 or len == 16); |
| 691 | if (target.cpu.has(.spirv, .vector16)) return (len == 8 or len == 16); |
| 687 | 692 | } |
| 688 | 693 | |
| 689 | 694 | return false; |
| ... | ... | @@ -701,7 +706,8 @@ fn constBool(cg: *CodeGen, value: bool, repr: Repr) !Id { |
| 701 | 706 | /// This function, unlike Module.constInt, takes care to bitcast |
| 702 | 707 | /// the value to an unsigned int first for Kernels. |
| 703 | 708 | fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id { |
| 704 | | const zcu = cg.pt.zcu; |
| 709 | const zcu = cg.module.zcu; |
| 710 | const target = cg.module.zcu.getTarget(); |
| 705 | 711 | const scalar_ty = ty.scalarType(zcu); |
| 706 | 712 | const int_info = scalar_ty.intInfo(zcu); |
| 707 | 713 | // Use backing bits so that negatives are sign extended |
| ... | ... | @@ -726,7 +732,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id { |
| 726 | 732 | }); |
| 727 | 733 | } |
| 728 | 734 | |
| 729 | | const final_value: spec.LiteralContextDependentNumber = switch (cg.module.target.os.tag) { |
| 735 | const final_value: spec.LiteralContextDependentNumber = switch (target.os.tag) { |
| 730 | 736 | .opencl, .amdhsa => blk: { |
| 731 | 737 | const value64: u64 = switch (signedness) { |
| 732 | 738 | .signed => @bitCast(@as(i64, @intCast(value))), |
| ... | ... | @@ -773,7 +779,7 @@ pub fn constructComposite(cg: *CodeGen, result_ty_id: Id, constituents: []const |
| 773 | 779 | /// ty must be an aggregate type. |
| 774 | 780 | fn constructCompositeSplat(cg: *CodeGen, ty: Type, constituent: Id) !Id { |
| 775 | 781 | const gpa = cg.module.gpa; |
| 776 | | const zcu = cg.pt.zcu; |
| 782 | const zcu = cg.module.zcu; |
| 777 | 783 | const n: usize = @intCast(ty.arrayLen(zcu)); |
| 778 | 784 | |
| 779 | 785 | const constituents = try gpa.alloc(Id, n); |
| ... | ... | @@ -801,8 +807,8 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id { |
| 801 | 807 | } |
| 802 | 808 | |
| 803 | 809 | const pt = cg.pt; |
| 804 | | const zcu = pt.zcu; |
| 805 | | const target = cg.module.target; |
| 810 | const zcu = cg.module.zcu; |
| 811 | const target = cg.module.zcu.getTarget(); |
| 806 | 812 | const result_ty_id = try cg.resolveType(ty, repr); |
| 807 | 813 | const ip = &zcu.intern_pool; |
| 808 | 814 | |
| ... | ... | @@ -874,39 +880,35 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id { |
| 874 | 880 | .error_union => |error_union| { |
| 875 | 881 | // TODO: Error unions may be constructed with constant instructions if the payload type |
| 876 | 882 | // allows it. For now, just generate it here regardless. |
| 877 | | const err_int_ty = try pt.errorIntType(); |
| 878 | | const err_ty = switch (error_union.val) { |
| 879 | | .err_name => ty.errorUnionSet(zcu), |
| 880 | | .payload => err_int_ty, |
| 881 | | }; |
| 882 | | const err_val = switch (error_union.val) { |
| 883 | | .err_name => |err_name| Value.fromInterned(try pt.intern(.{ .err = .{ |
| 884 | | .ty = ty.errorUnionSet(zcu).toIntern(), |
| 885 | | .name = err_name, |
| 886 | | } })), |
| 887 | | .payload => try pt.intValue(err_int_ty, 0), |
| 888 | | }; |
| 883 | const err_ty = ty.errorUnionSet(zcu); |
| 889 | 884 | const payload_ty = ty.errorUnionPayload(zcu); |
| 885 | const err_val_id = switch (error_union.val) { |
| 886 | .err_name => |err_name| try cg.constInt( |
| 887 | err_ty, |
| 888 | try pt.getErrorValue(err_name), |
| 889 | ), |
| 890 | .payload => try cg.constInt(err_ty, 0), |
| 891 | }; |
| 890 | 892 | const eu_layout = cg.errorUnionLayout(payload_ty); |
| 891 | 893 | if (!eu_layout.payload_has_bits) { |
| 892 | 894 | // We use the error type directly as the type. |
| 893 | | break :cache try cg.constant(err_ty, err_val, .indirect); |
| 895 | break :cache err_val_id; |
| 894 | 896 | } |
| 895 | 897 | |
| 896 | | const payload_val: Value = .fromInterned(switch (error_union.val) { |
| 897 | | .err_name => try pt.intern(.{ .undef = payload_ty.toIntern() }), |
| 898 | | .payload => |payload| payload, |
| 899 | | }); |
| 898 | const payload_val_id = switch (error_union.val) { |
| 899 | .err_name => try cg.constant(payload_ty, .undef, .indirect), |
| 900 | .payload => |p| try cg.constant(payload_ty, .fromInterned(p), .indirect), |
| 901 | }; |
| 900 | 902 | |
| 901 | 903 | var constituents: [2]Id = undefined; |
| 902 | 904 | var types: [2]Type = undefined; |
| 903 | 905 | if (eu_layout.error_first) { |
| 904 | | constituents[0] = try cg.constant(err_ty, err_val, .indirect); |
| 905 | | constituents[1] = try cg.constant(payload_ty, payload_val, .indirect); |
| 906 | constituents[0] = err_val_id; |
| 907 | constituents[1] = payload_val_id; |
| 906 | 908 | types = .{ err_ty, payload_ty }; |
| 907 | 909 | } else { |
| 908 | | constituents[0] = try cg.constant(payload_ty, payload_val, .indirect); |
| 909 | | constituents[1] = try cg.constant(err_ty, err_val, .indirect); |
| 910 | constituents[0] = payload_val_id; |
| 911 | constituents[1] = err_val_id; |
| 910 | 912 | types = .{ payload_ty, err_ty }; |
| 911 | 913 | } |
| 912 | 914 | |
| ... | ... | @@ -1055,10 +1057,11 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id { |
| 1055 | 1057 | |
| 1056 | 1058 | fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id { |
| 1057 | 1059 | const pt = cg.pt; |
| 1060 | const zcu = cg.module.zcu; |
| 1058 | 1061 | const gpa = cg.module.gpa; |
| 1059 | 1062 | |
| 1060 | | if (ptr_val.isUndef(pt.zcu)) { |
| 1061 | | const result_ty = ptr_val.typeOf(pt.zcu); |
| 1063 | if (ptr_val.isUndef(zcu)) { |
| 1064 | const result_ty = ptr_val.typeOf(zcu); |
| 1062 | 1065 | const result_ty_id = try cg.resolveType(result_ty, .direct); |
| 1063 | 1066 | return cg.module.constUndef(result_ty_id); |
| 1064 | 1067 | } |
| ... | ... | @@ -1072,7 +1075,7 @@ fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id { |
| 1072 | 1075 | |
| 1073 | 1076 | fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { |
| 1074 | 1077 | const pt = cg.pt; |
| 1075 | | const zcu = pt.zcu; |
| 1078 | const zcu = cg.module.zcu; |
| 1076 | 1079 | switch (derivation) { |
| 1077 | 1080 | .comptime_alloc_ptr, .comptime_field_ptr => unreachable, |
| 1078 | 1081 | .int => |int| { |
| ... | ... | @@ -1152,8 +1155,7 @@ fn constantUavRef( |
| 1152 | 1155 | ) !Id { |
| 1153 | 1156 | // TODO: Merge this function with constantDeclRef. |
| 1154 | 1157 | |
| 1155 | | const pt = cg.pt; |
| 1156 | | const zcu = pt.zcu; |
| 1158 | const zcu = cg.module.zcu; |
| 1157 | 1159 | const ip = &zcu.intern_pool; |
| 1158 | 1160 | const ty_id = try cg.resolveType(ty, .direct); |
| 1159 | 1161 | const uav_ty: Type = .fromInterned(ip.typeOf(uav.val)); |
| ... | ... | @@ -1190,8 +1192,7 @@ fn constantUavRef( |
| 1190 | 1192 | } |
| 1191 | 1193 | |
| 1192 | 1194 | fn constantNavRef(cg: *CodeGen, ty: Type, nav_index: InternPool.Nav.Index) !Id { |
| 1193 | | const pt = cg.pt; |
| 1194 | | const zcu = pt.zcu; |
| 1195 | const zcu = cg.module.zcu; |
| 1195 | 1196 | const ip = &zcu.intern_pool; |
| 1196 | 1197 | const ty_id = try cg.resolveType(ty, .direct); |
| 1197 | 1198 | const nav = ip.getNav(nav_index); |
| ... | ... | @@ -1264,6 +1265,8 @@ fn resolveTypeName(cg: *CodeGen, ty: Type) ![]const u8 { |
| 1264 | 1265 | /// actual operations (as well as store) a Zig type of a particular number of bits. To create |
| 1265 | 1266 | /// a type with an exact size, use Module.intType. |
| 1266 | 1267 | fn intType(cg: *CodeGen, signedness: std.builtin.Signedness, bits: u16) !Id { |
| 1268 | const target = cg.module.zcu.getTarget(); |
| 1269 | |
| 1267 | 1270 | const backing_bits, const big_int = cg.backingIntBits(bits); |
| 1268 | 1271 | if (big_int) { |
| 1269 | 1272 | if (backing_bits > 64) { |
| ... | ... | @@ -1273,7 +1276,7 @@ fn intType(cg: *CodeGen, signedness: std.builtin.Signedness, bits: u16) !Id { |
| 1273 | 1276 | return cg.arrayType(backing_bits / big_int_bits, int_ty); |
| 1274 | 1277 | } |
| 1275 | 1278 | |
| 1276 | | return switch (cg.module.target.os.tag) { |
| 1279 | return switch (target.os.tag) { |
| 1277 | 1280 | // Kernel only supports unsigned ints. |
| 1278 | 1281 | .opencl, .amdhsa => return cg.module.intType(.unsigned, backing_bits), |
| 1279 | 1282 | else => cg.module.intType(signedness, backing_bits), |
| ... | ... | @@ -1287,9 +1290,12 @@ fn arrayType(cg: *CodeGen, len: u32, child_ty: Id) !Id { |
| 1287 | 1290 | |
| 1288 | 1291 | fn ptrType(cg: *CodeGen, child_ty: Type, storage_class: StorageClass, child_repr: Repr) !Id { |
| 1289 | 1292 | const gpa = cg.module.gpa; |
| 1290 | | const zcu = cg.pt.zcu; |
| 1293 | const zcu = cg.module.zcu; |
| 1291 | 1294 | const ip = &zcu.intern_pool; |
| 1292 | | const key = .{ child_ty.toIntern(), storage_class, child_repr }; |
| 1295 | const target = cg.module.zcu.getTarget(); |
| 1296 | |
| 1297 | const child_ty_id = try cg.resolveType(child_ty, child_repr); |
| 1298 | const key = .{ child_ty_id, storage_class }; |
| 1293 | 1299 | const entry = try cg.module.ptr_types.getOrPut(gpa, key); |
| 1294 | 1300 | if (entry.found_existing) { |
| 1295 | 1301 | const fwd_id = entry.value_ptr.ty_id; |
| ... | ... | @@ -1309,9 +1315,7 @@ fn ptrType(cg: *CodeGen, child_ty: Type, storage_class: StorageClass, child_repr |
| 1309 | 1315 | .fwd_emitted = false, |
| 1310 | 1316 | }; |
| 1311 | 1317 | |
| 1312 | | const child_ty_id = try cg.resolveType(child_ty, child_repr); |
| 1313 | | |
| 1314 | | switch (cg.module.target.os.tag) { |
| 1318 | switch (target.os.tag) { |
| 1315 | 1319 | .vulkan, .opengl => { |
| 1316 | 1320 | if (child_ty.zigTypeTag(zcu) == .@"struct") { |
| 1317 | 1321 | switch (storage_class) { |
| ... | ... | @@ -1374,7 +1378,7 @@ fn functionType(cg: *CodeGen, return_ty: Type, param_types: []const Type) !Id { |
| 1374 | 1378 | /// If any of the fields' size is 0, it will be omitted. |
| 1375 | 1379 | fn resolveUnionType(cg: *CodeGen, ty: Type) !Id { |
| 1376 | 1380 | const gpa = cg.module.gpa; |
| 1377 | | const zcu = cg.pt.zcu; |
| 1381 | const zcu = cg.module.zcu; |
| 1378 | 1382 | const ip = &zcu.intern_pool; |
| 1379 | 1383 | const union_obj = zcu.typeToUnion(ty).?; |
| 1380 | 1384 | |
| ... | ... | @@ -1417,8 +1421,12 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id { |
| 1417 | 1421 | member_names[layout.padding_index] = "(padding)"; |
| 1418 | 1422 | } |
| 1419 | 1423 | |
| 1420 | | const result_id = cg.module.allocId(); |
| 1421 | | try cg.module.structType(result_id, member_types[0..layout.total_fields], member_names[0..layout.total_fields]); |
| 1424 | const result_id = try cg.module.structType( |
| 1425 | member_types[0..layout.total_fields], |
| 1426 | member_names[0..layout.total_fields], |
| 1427 | null, |
| 1428 | .none, |
| 1429 | ); |
| 1422 | 1430 | |
| 1423 | 1431 | const type_name = try cg.resolveTypeName(ty); |
| 1424 | 1432 | defer gpa.free(type_name); |
| ... | ... | @@ -1428,7 +1436,7 @@ fn resolveUnionType(cg: *CodeGen, ty: Type) !Id { |
| 1428 | 1436 | } |
| 1429 | 1437 | |
| 1430 | 1438 | fn resolveFnReturnType(cg: *CodeGen, ret_ty: Type) !Id { |
| 1431 | | const zcu = cg.pt.zcu; |
| 1439 | const zcu = cg.module.zcu; |
| 1432 | 1440 | if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1433 | 1441 | // If the return type is an error set or an error union, then we make this |
| 1434 | 1442 | // anyerror return type instead, so that it can be coerced into a function |
| ... | ... | @@ -1443,28 +1451,14 @@ fn resolveFnReturnType(cg: *CodeGen, ret_ty: Type) !Id { |
| 1443 | 1451 | return try cg.resolveType(ret_ty, .direct); |
| 1444 | 1452 | } |
| 1445 | 1453 | |
| 1446 | | /// Turn a Zig type into a SPIR-V Type, and return a reference to it. |
| 1447 | | fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) !Id { |
| 1448 | | const gpa = cg.module.gpa; |
| 1449 | | |
| 1450 | | if (cg.module.intern_map.get(.{ ty.toIntern(), repr })) |id| { |
| 1451 | | return id; |
| 1452 | | } |
| 1453 | | |
| 1454 | | const id = try cg.resolveTypeInner(ty, repr); |
| 1455 | | try cg.module.intern_map.put(gpa, .{ ty.toIntern(), repr }, id); |
| 1456 | | return id; |
| 1457 | | } |
| 1458 | | |
| 1459 | | fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1454 | fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1460 | 1455 | const gpa = cg.module.gpa; |
| 1461 | 1456 | const pt = cg.pt; |
| 1462 | | const zcu = pt.zcu; |
| 1457 | const zcu = cg.module.zcu; |
| 1463 | 1458 | const ip = &zcu.intern_pool; |
| 1464 | | log.debug("resolveType: ty = {f}", .{ty.fmt(pt)}); |
| 1465 | | const target = cg.module.target; |
| 1459 | const target = cg.module.zcu.getTarget(); |
| 1466 | 1460 | |
| 1467 | | const section = &cg.module.sections.globals; |
| 1461 | log.debug("resolveType: ty = {f}", .{ty.fmt(pt)}); |
| 1468 | 1462 | |
| 1469 | 1463 | switch (ty.zigTypeTag(zcu)) { |
| 1470 | 1464 | .noreturn => { |
| ... | ... | @@ -1472,18 +1466,8 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1472 | 1466 | return try cg.module.voidType(); |
| 1473 | 1467 | }, |
| 1474 | 1468 | .void => switch (repr) { |
| 1475 | | .direct => { |
| 1476 | | return try cg.module.voidType(); |
| 1477 | | }, |
| 1478 | | // Pointers to void |
| 1479 | | .indirect => { |
| 1480 | | const result_id = cg.module.allocId(); |
| 1481 | | try section.emit(cg.module.gpa, .OpTypeOpaque, .{ |
| 1482 | | .id_result = result_id, |
| 1483 | | .literal_string = "void", |
| 1484 | | }); |
| 1485 | | return result_id; |
| 1486 | | }, |
| 1469 | .direct => return try cg.module.voidType(), |
| 1470 | .indirect => return try cg.module.opaqueType("void"), |
| 1487 | 1471 | }, |
| 1488 | 1472 | .bool => switch (repr) { |
| 1489 | 1473 | .direct => return try cg.module.boolType(), |
| ... | ... | @@ -1492,36 +1476,26 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1492 | 1476 | .int => { |
| 1493 | 1477 | const int_info = ty.intInfo(zcu); |
| 1494 | 1478 | if (int_info.bits == 0) { |
| 1495 | | // Some times, the backend will be asked to generate a pointer to i0. OpTypeInt |
| 1496 | | // with 0 bits is invalid, so return an opaque type in this case. |
| 1497 | 1479 | assert(repr == .indirect); |
| 1498 | | const result_id = cg.module.allocId(); |
| 1499 | | try section.emit(cg.module.gpa, .OpTypeOpaque, .{ |
| 1500 | | .id_result = result_id, |
| 1501 | | .literal_string = "u0", |
| 1502 | | }); |
| 1503 | | return result_id; |
| 1480 | return try cg.module.opaqueType("u0"); |
| 1504 | 1481 | } |
| 1505 | 1482 | return try cg.intType(int_info.signedness, int_info.bits); |
| 1506 | 1483 | }, |
| 1507 | | .@"enum" => { |
| 1508 | | const tag_ty = ty.intTagType(zcu); |
| 1509 | | return try cg.resolveType(tag_ty, repr); |
| 1510 | | }, |
| 1484 | .@"enum" => return try cg.resolveType(ty.intTagType(zcu), repr), |
| 1511 | 1485 | .float => { |
| 1512 | | // We can (and want) not really emulate floating points with other floating point types like with the integer types, |
| 1513 | | // so if the float is not supported, just return an error. |
| 1514 | 1486 | const bits = ty.floatBits(target); |
| 1515 | 1487 | const supported = switch (bits) { |
| 1516 | | 16 => cg.module.target.cpu.has(.spirv, .float16), |
| 1517 | | // 32-bit floats are always supported (see spec, 2.16.1, Data rules). |
| 1488 | 16 => target.cpu.has(.spirv, .float16), |
| 1518 | 1489 | 32 => true, |
| 1519 | | 64 => cg.module.target.cpu.has(.spirv, .float64), |
| 1490 | 64 => target.cpu.has(.spirv, .float64), |
| 1520 | 1491 | else => false, |
| 1521 | 1492 | }; |
| 1522 | 1493 | |
| 1523 | 1494 | if (!supported) { |
| 1524 | | return cg.fail("Floating point width of {} bits is not supported for the current SPIR-V feature set", .{bits}); |
| 1495 | return cg.fail( |
| 1496 | "floating point width of {} bits is not supported for the current SPIR-V feature set", |
| 1497 | .{bits}, |
| 1498 | ); |
| 1525 | 1499 | } |
| 1526 | 1500 | |
| 1527 | 1501 | return try cg.module.floatType(bits); |
| ... | ... | @@ -1534,36 +1508,27 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1534 | 1508 | }; |
| 1535 | 1509 | |
| 1536 | 1510 | if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1537 | | // The size of the array would be 0, but that is not allowed in SPIR-V. |
| 1538 | | // This path can be reached when the backend is asked to generate a pointer to |
| 1539 | | // an array of some zero-bit type. This should always be an indirect path. |
| 1540 | 1511 | assert(repr == .indirect); |
| 1541 | | |
| 1542 | | // We cannot use the child type here, so just use an opaque type. |
| 1543 | | const result_id = cg.module.allocId(); |
| 1544 | | try section.emit(cg.module.gpa, .OpTypeOpaque, .{ |
| 1545 | | .id_result = result_id, |
| 1546 | | .literal_string = "zero-sized array", |
| 1547 | | }); |
| 1548 | | return result_id; |
| 1512 | return try cg.module.opaqueType("zero-sized-array"); |
| 1549 | 1513 | } else if (total_len == 0) { |
| 1550 | 1514 | // The size of the array would be 0, but that is not allowed in SPIR-V. |
| 1551 | 1515 | // This path can be reached for example when there is a slicing of a pointer |
| 1552 | 1516 | // that produces a zero-length array. In all cases where this type can be generated, |
| 1553 | 1517 | // this should be an indirect path. |
| 1554 | 1518 | assert(repr == .indirect); |
| 1555 | | |
| 1556 | 1519 | // In this case, we have an array of a non-zero sized type. In this case, |
| 1557 | 1520 | // generate an array of 1 element instead, so that ptr_elem_ptr instructions |
| 1558 | 1521 | // can be lowered to ptrAccessChain instead of manually performing the math. |
| 1559 | 1522 | return try cg.arrayType(1, elem_ty_id); |
| 1560 | 1523 | } else { |
| 1561 | 1524 | const result_id = try cg.arrayType(total_len, elem_ty_id); |
| 1562 | | switch (cg.module.target.os.tag) { |
| 1525 | switch (target.os.tag) { |
| 1563 | 1526 | .vulkan, .opengl => { |
| 1564 | | try cg.module.decorate(result_id, .{ .array_stride = .{ |
| 1565 | | .array_stride = @intCast(elem_ty.abiSize(zcu)), |
| 1566 | | } }); |
| 1527 | try cg.module.decorate(result_id, .{ |
| 1528 | .array_stride = .{ |
| 1529 | .array_stride = @intCast(elem_ty.abiSize(zcu)), |
| 1530 | }, |
| 1531 | }); |
| 1567 | 1532 | }, |
| 1568 | 1533 | else => {}, |
| 1569 | 1534 | } |
| ... | ... | @@ -1574,18 +1539,15 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1574 | 1539 | const elem_ty = ty.childType(zcu); |
| 1575 | 1540 | const elem_ty_id = try cg.resolveType(elem_ty, repr); |
| 1576 | 1541 | const len = ty.vectorLen(zcu); |
| 1577 | | |
| 1578 | | if (cg.isSpvVector(ty)) { |
| 1579 | | return try cg.module.vectorType(len, elem_ty_id); |
| 1580 | | } else { |
| 1581 | | return try cg.arrayType(len, elem_ty_id); |
| 1582 | | } |
| 1542 | if (cg.isSpvVector(ty)) return try cg.module.vectorType(len, elem_ty_id); |
| 1543 | return try cg.arrayType(len, elem_ty_id); |
| 1583 | 1544 | }, |
| 1584 | 1545 | .@"fn" => switch (repr) { |
| 1585 | 1546 | .direct => { |
| 1586 | 1547 | const fn_info = zcu.typeToFunc(ty).?; |
| 1587 | 1548 | |
| 1588 | 1549 | comptime assert(zig_call_abi_ver == 3); |
| 1550 | assert(!fn_info.is_var_args); |
| 1589 | 1551 | switch (fn_info.cc) { |
| 1590 | 1552 | .auto, |
| 1591 | 1553 | .spirv_kernel, |
| ... | ... | @@ -1596,11 +1558,7 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1596 | 1558 | else => unreachable, |
| 1597 | 1559 | } |
| 1598 | 1560 | |
| 1599 | | // Guaranteed by callConvSupportsVarArgs, there are no SPIR-V CCs which support |
| 1600 | | // varargs. |
| 1601 | | assert(!fn_info.is_var_args); |
| 1602 | | |
| 1603 | | // Note: Logic is different from functionType(). |
| 1561 | const return_ty_id = try cg.resolveFnReturnType(.fromInterned(fn_info.return_type)); |
| 1604 | 1562 | const param_ty_ids = try gpa.alloc(Id, fn_info.param_types.len); |
| 1605 | 1563 | defer gpa.free(param_ty_ids); |
| 1606 | 1564 | var param_index: usize = 0; |
| ... | ... | @@ -1612,16 +1570,7 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1612 | 1570 | param_index += 1; |
| 1613 | 1571 | } |
| 1614 | 1572 | |
| 1615 | | const return_ty_id = try cg.resolveFnReturnType(.fromInterned(fn_info.return_type)); |
| 1616 | | |
| 1617 | | const result_id = cg.module.allocId(); |
| 1618 | | try section.emit(cg.module.gpa, .OpTypeFunction, .{ |
| 1619 | | .id_result = result_id, |
| 1620 | | .return_type = return_ty_id, |
| 1621 | | .id_ref_2 = param_ty_ids[0..param_index], |
| 1622 | | }); |
| 1623 | | |
| 1624 | | return result_id; |
| 1573 | return try cg.module.functionType(return_ty_id, param_ty_ids[0..param_index]); |
| 1625 | 1574 | }, |
| 1626 | 1575 | .indirect => { |
| 1627 | 1576 | // TODO: Represent function pointers properly. |
| ... | ... | @@ -1641,13 +1590,12 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1641 | 1590 | } |
| 1642 | 1591 | |
| 1643 | 1592 | const size_ty_id = try cg.resolveType(.usize, .direct); |
| 1644 | | const result_id = cg.module.allocId(); |
| 1645 | | try cg.module.structType( |
| 1646 | | result_id, |
| 1593 | return try cg.module.structType( |
| 1647 | 1594 | &.{ ptr_ty_id, size_ty_id }, |
| 1648 | 1595 | &.{ "ptr", "len" }, |
| 1596 | null, |
| 1597 | .none, |
| 1649 | 1598 | ); |
| 1650 | | return result_id; |
| 1651 | 1599 | }, |
| 1652 | 1600 | .@"struct" => { |
| 1653 | 1601 | const struct_type = switch (ip.indexToKey(ty.toIntern())) { |
| ... | ... | @@ -1663,13 +1611,15 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1663 | 1611 | member_index += 1; |
| 1664 | 1612 | } |
| 1665 | 1613 | |
| 1666 | | const result_id = cg.module.allocId(); |
| 1667 | | try cg.module.structType(result_id, member_types[0..member_index], null); |
| 1668 | | |
| 1614 | const result_id = try cg.module.structType( |
| 1615 | member_types[0..member_index], |
| 1616 | null, |
| 1617 | null, |
| 1618 | .none, |
| 1619 | ); |
| 1669 | 1620 | const type_name = try cg.resolveTypeName(ty); |
| 1670 | 1621 | defer gpa.free(type_name); |
| 1671 | 1622 | try cg.module.debugName(result_id, type_name); |
| 1672 | | |
| 1673 | 1623 | return result_id; |
| 1674 | 1624 | }, |
| 1675 | 1625 | .struct_type => ip.loadStructType(ty.toIntern()), |
| ... | ... | @@ -1686,34 +1636,27 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1686 | 1636 | var member_names = std.ArrayList([]const u8).init(gpa); |
| 1687 | 1637 | defer member_names.deinit(); |
| 1688 | 1638 | |
| 1689 | | var index: u32 = 0; |
| 1639 | var member_offsets = std.ArrayList(u32).init(gpa); |
| 1640 | defer member_offsets.deinit(); |
| 1641 | |
| 1690 | 1642 | var it = struct_type.iterateRuntimeOrder(ip); |
| 1691 | | const result_id = cg.module.allocId(); |
| 1692 | 1643 | while (it.next()) |field_index| { |
| 1693 | 1644 | const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]); |
| 1694 | | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1695 | | // This is a zero-bit field - we only needed it for the alignment. |
| 1696 | | continue; |
| 1697 | | } |
| 1698 | | |
| 1699 | | switch (cg.module.target.os.tag) { |
| 1700 | | .vulkan, .opengl => { |
| 1701 | | try cg.module.decorateMember(result_id, index, .{ .offset = .{ |
| 1702 | | .byte_offset = @intCast(ty.structFieldOffset(field_index, zcu)), |
| 1703 | | } }); |
| 1704 | | }, |
| 1705 | | else => {}, |
| 1706 | | } |
| 1645 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; |
| 1707 | 1646 | |
| 1708 | 1647 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 1709 | 1648 | try ip.getOrPutStringFmt(zcu.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 1710 | 1649 | try member_types.append(try cg.resolveType(field_ty, .indirect)); |
| 1711 | 1650 | try member_names.append(field_name.toSlice(ip)); |
| 1712 | | |
| 1713 | | index += 1; |
| 1651 | try member_offsets.append(@intCast(ty.structFieldOffset(field_index, zcu))); |
| 1714 | 1652 | } |
| 1715 | 1653 | |
| 1716 | | try cg.module.structType(result_id, member_types.items, member_names.items); |
| 1654 | const result_id = try cg.module.structType( |
| 1655 | member_types.items, |
| 1656 | member_names.items, |
| 1657 | member_offsets.items, |
| 1658 | ty.toIntern(), |
| 1659 | ); |
| 1717 | 1660 | |
| 1718 | 1661 | const type_name = try cg.resolveTypeName(ty); |
| 1719 | 1662 | defer gpa.free(type_name); |
| ... | ... | @@ -1738,13 +1681,12 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1738 | 1681 | |
| 1739 | 1682 | const bool_ty_id = try cg.resolveType(.bool, .indirect); |
| 1740 | 1683 | |
| 1741 | | const result_id = cg.module.allocId(); |
| 1742 | | try cg.module.structType( |
| 1743 | | result_id, |
| 1684 | return try cg.module.structType( |
| 1744 | 1685 | &.{ payload_ty_id, bool_ty_id }, |
| 1745 | 1686 | &.{ "payload", "valid" }, |
| 1687 | null, |
| 1688 | .none, |
| 1746 | 1689 | ); |
| 1747 | | return result_id; |
| 1748 | 1690 | }, |
| 1749 | 1691 | .@"union" => return try cg.resolveUnionType(ty), |
| 1750 | 1692 | .error_set => { |
| ... | ... | @@ -1753,7 +1695,8 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1753 | 1695 | }, |
| 1754 | 1696 | .error_union => { |
| 1755 | 1697 | const payload_ty = ty.errorUnionPayload(zcu); |
| 1756 | | const error_ty_id = try cg.resolveType(.anyerror, .indirect); |
| 1698 | const err_ty = ty.errorUnionSet(zcu); |
| 1699 | const error_ty_id = try cg.resolveType(err_ty, .indirect); |
| 1757 | 1700 | |
| 1758 | 1701 | const eu_layout = cg.errorUnionLayout(payload_ty); |
| 1759 | 1702 | if (!eu_layout.payload_has_bits) { |
| ... | ... | @@ -1776,20 +1719,12 @@ fn resolveTypeInner(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1776 | 1719 | // TODO: ABI padding? |
| 1777 | 1720 | } |
| 1778 | 1721 | |
| 1779 | | const result_id = cg.module.allocId(); |
| 1780 | | try cg.module.structType(result_id, &member_types, &member_names); |
| 1781 | | return result_id; |
| 1722 | return try cg.module.structType(&member_types, &member_names, null, .none); |
| 1782 | 1723 | }, |
| 1783 | 1724 | .@"opaque" => { |
| 1784 | 1725 | const type_name = try cg.resolveTypeName(ty); |
| 1785 | 1726 | defer gpa.free(type_name); |
| 1786 | | |
| 1787 | | const result_id = cg.module.allocId(); |
| 1788 | | try section.emit(cg.module.gpa, .OpTypeOpaque, .{ |
| 1789 | | .id_result = result_id, |
| 1790 | | .literal_string = type_name, |
| 1791 | | }); |
| 1792 | | return result_id; |
| 1727 | return try cg.module.opaqueType(type_name); |
| 1793 | 1728 | }, |
| 1794 | 1729 | |
| 1795 | 1730 | .null, |
| ... | ... | @@ -1820,8 +1755,7 @@ const ErrorUnionLayout = struct { |
| 1820 | 1755 | }; |
| 1821 | 1756 | |
| 1822 | 1757 | fn errorUnionLayout(cg: *CodeGen, payload_ty: Type) ErrorUnionLayout { |
| 1823 | | const pt = cg.pt; |
| 1824 | | const zcu = pt.zcu; |
| 1758 | const zcu = cg.module.zcu; |
| 1825 | 1759 | |
| 1826 | 1760 | const error_align = Type.abiAlignment(.anyerror, zcu); |
| 1827 | 1761 | const payload_align = payload_ty.abiAlignment(zcu); |
| ... | ... | @@ -1852,8 +1786,7 @@ const UnionLayout = struct { |
| 1852 | 1786 | }; |
| 1853 | 1787 | |
| 1854 | 1788 | fn unionLayout(cg: *CodeGen, ty: Type) UnionLayout { |
| 1855 | | const pt = cg.pt; |
| 1856 | | const zcu = pt.zcu; |
| 1789 | const zcu = cg.module.zcu; |
| 1857 | 1790 | const ip = &zcu.intern_pool; |
| 1858 | 1791 | const layout = ty.unionGetLayout(zcu); |
| 1859 | 1792 | const union_obj = zcu.typeToUnion(ty).?; |
| ... | ... | @@ -1944,7 +1877,7 @@ const Temporary = struct { |
| 1944 | 1877 | |
| 1945 | 1878 | fn materialize(temp: Temporary, cg: *CodeGen) !Id { |
| 1946 | 1879 | const gpa = cg.module.gpa; |
| 1947 | | const zcu = cg.pt.zcu; |
| 1880 | const zcu = cg.module.zcu; |
| 1948 | 1881 | switch (temp.value) { |
| 1949 | 1882 | .singleton => |id| return id, |
| 1950 | 1883 | .exploded_vector => |range| { |
| ... | ... | @@ -1975,7 +1908,7 @@ const Temporary = struct { |
| 1975 | 1908 | /// 'Explode' a temporary into separate elements. This turns a vector |
| 1976 | 1909 | /// into a bag of elements. |
| 1977 | 1910 | fn explode(temp: Temporary, cg: *CodeGen) !IdRange { |
| 1978 | | const zcu = cg.pt.zcu; |
| 1911 | const zcu = cg.module.zcu; |
| 1979 | 1912 | |
| 1980 | 1913 | // If the value is a scalar, then this is a no-op. |
| 1981 | 1914 | if (!temp.ty.isVector(zcu)) { |
| ... | ... | @@ -2029,7 +1962,7 @@ const Vectorization = union(enum) { |
| 2029 | 1962 | |
| 2030 | 1963 | /// Derive a vectorization from a particular type |
| 2031 | 1964 | fn fromType(ty: Type, cg: *CodeGen) Vectorization { |
| 2032 | | const zcu = cg.pt.zcu; |
| 1965 | const zcu = cg.module.zcu; |
| 2033 | 1966 | if (!ty.isVector(zcu)) return .scalar; |
| 2034 | 1967 | return .{ .unrolled = ty.vectorLen(zcu) }; |
| 2035 | 1968 | } |
| ... | ... | @@ -2063,7 +1996,8 @@ const Vectorization = union(enum) { |
| 2063 | 1996 | /// `ty` may be a scalar or vector, it doesn't matter. |
| 2064 | 1997 | fn resultType(vec: Vectorization, cg: *CodeGen, ty: Type) !Type { |
| 2065 | 1998 | const pt = cg.pt; |
| 2066 | | const scalar_ty = ty.scalarType(pt.zcu); |
| 1999 | const zcu = cg.module.zcu; |
| 2000 | const scalar_ty = ty.scalarType(zcu); |
| 2067 | 2001 | return switch (vec) { |
| 2068 | 2002 | .scalar => scalar_ty, |
| 2069 | 2003 | .unrolled => |n| try pt.vectorType(.{ .len = n, .child = scalar_ty.toIntern() }), |
| ... | ... | @@ -2074,8 +2008,8 @@ const Vectorization = union(enum) { |
| 2074 | 2008 | /// this setup, and returns a new type that holds the relevant information on how to access |
| 2075 | 2009 | /// elements of the input. |
| 2076 | 2010 | fn prepare(vec: Vectorization, cg: *CodeGen, tmp: Temporary) !PreparedOperand { |
| 2077 | | const pt = cg.pt; |
| 2078 | | const is_vector = tmp.ty.isVector(pt.zcu); |
| 2011 | const zcu = cg.module.zcu; |
| 2012 | const is_vector = tmp.ty.isVector(zcu); |
| 2079 | 2013 | const value: PreparedOperand.Value = switch (tmp.value) { |
| 2080 | 2014 | .singleton => |id| switch (vec) { |
| 2081 | 2015 | .scalar => blk: { |
| ... | ... | @@ -2174,7 +2108,7 @@ fn vectorization(cg: *CodeGen, args: anytype) Vectorization { |
| 2174 | 2108 | /// This function builds an OpSConvert of OpUConvert depending on the |
| 2175 | 2109 | /// signedness of the types. |
| 2176 | 2110 | fn buildConvert(cg: *CodeGen, dst_ty: Type, src: Temporary) !Temporary { |
| 2177 | | const zcu = cg.pt.zcu; |
| 2111 | const zcu = cg.module.zcu; |
| 2178 | 2112 | |
| 2179 | 2113 | const dst_ty_id = try cg.resolveType(dst_ty.scalarType(zcu), .direct); |
| 2180 | 2114 | const src_ty_id = try cg.resolveType(src.ty.scalarType(zcu), .direct); |
| ... | ... | @@ -2217,8 +2151,8 @@ fn buildConvert(cg: *CodeGen, dst_ty: Type, src: Temporary) !Temporary { |
| 2217 | 2151 | } |
| 2218 | 2152 | |
| 2219 | 2153 | fn buildFma(cg: *CodeGen, a: Temporary, b: Temporary, c: Temporary) !Temporary { |
| 2220 | | const zcu = cg.pt.zcu; |
| 2221 | | const target = cg.module.target; |
| 2154 | const zcu = cg.module.zcu; |
| 2155 | const target = cg.module.zcu.getTarget(); |
| 2222 | 2156 | |
| 2223 | 2157 | const v = cg.vectorization(.{ a, b, c }); |
| 2224 | 2158 | const ops = v.components(); |
| ... | ... | @@ -2258,7 +2192,7 @@ fn buildFma(cg: *CodeGen, a: Temporary, b: Temporary, c: Temporary) !Temporary { |
| 2258 | 2192 | } |
| 2259 | 2193 | |
| 2260 | 2194 | fn buildSelect(cg: *CodeGen, condition: Temporary, lhs: Temporary, rhs: Temporary) !Temporary { |
| 2261 | | const zcu = cg.pt.zcu; |
| 2195 | const zcu = cg.module.zcu; |
| 2262 | 2196 | |
| 2263 | 2197 | const v = cg.vectorization(.{ condition, lhs, rhs }); |
| 2264 | 2198 | const ops = v.components(); |
| ... | ... | @@ -2377,8 +2311,8 @@ const UnaryOp = enum { |
| 2377 | 2311 | }; |
| 2378 | 2312 | |
| 2379 | 2313 | fn buildUnary(cg: *CodeGen, op: UnaryOp, operand: Temporary) !Temporary { |
| 2380 | | const zcu = cg.pt.zcu; |
| 2381 | | const target = cg.module.target; |
| 2314 | const zcu = cg.module.zcu; |
| 2315 | const target = cg.module.zcu.getTarget(); |
| 2382 | 2316 | const v = cg.vectorization(.{operand}); |
| 2383 | 2317 | const ops = v.components(); |
| 2384 | 2318 | const results = cg.module.allocIds(ops); |
| ... | ... | @@ -2497,8 +2431,8 @@ const BinaryOp = enum { |
| 2497 | 2431 | }; |
| 2498 | 2432 | |
| 2499 | 2433 | fn buildBinary(cg: *CodeGen, op: BinaryOp, lhs: Temporary, rhs: Temporary) !Temporary { |
| 2500 | | const zcu = cg.pt.zcu; |
| 2501 | | const target = cg.module.target; |
| 2434 | const zcu = cg.module.zcu; |
| 2435 | const target = cg.module.zcu.getTarget(); |
| 2502 | 2436 | |
| 2503 | 2437 | const v = cg.vectorization(.{ lhs, rhs }); |
| 2504 | 2438 | const ops = v.components(); |
| ... | ... | @@ -2595,8 +2529,8 @@ fn buildWideMul( |
| 2595 | 2529 | rhs: Temporary, |
| 2596 | 2530 | ) !struct { Temporary, Temporary } { |
| 2597 | 2531 | const pt = cg.pt; |
| 2598 | | const zcu = pt.zcu; |
| 2599 | | const target = cg.module.target; |
| 2532 | const zcu = cg.module.zcu; |
| 2533 | const target = cg.module.zcu.getTarget(); |
| 2600 | 2534 | const ip = &zcu.intern_pool; |
| 2601 | 2535 | |
| 2602 | 2536 | const v = lhs.vectorization(cg).unify(rhs.vectorization(cg)); |
| ... | ... | @@ -2718,8 +2652,8 @@ fn generateTestEntryPoint( |
| 2718 | 2652 | test_id: Id, |
| 2719 | 2653 | ) !void { |
| 2720 | 2654 | const gpa = cg.module.gpa; |
| 2721 | | const zcu = cg.pt.zcu; |
| 2722 | | const target = cg.module.target; |
| 2655 | const zcu = cg.module.zcu; |
| 2656 | const target = cg.module.zcu.getTarget(); |
| 2723 | 2657 | |
| 2724 | 2658 | const anyerror_ty_id = try cg.resolveType(.anyerror, .direct); |
| 2725 | 2659 | const ptr_anyerror_ty = try cg.pt.ptrType(.{ |
| ... | ... | @@ -2762,8 +2696,12 @@ fn generateTestEntryPoint( |
| 2762 | 2696 | const spv_err_decl_index = try cg.module.allocDecl(.global); |
| 2763 | 2697 | try cg.module.declareDeclDeps(spv_err_decl_index, &.{}); |
| 2764 | 2698 | |
| 2765 | | const buffer_struct_ty_id = cg.module.allocId(); |
| 2766 | | try cg.module.structType(buffer_struct_ty_id, &.{anyerror_ty_id}, &.{"error_out"}); |
| 2699 | const buffer_struct_ty_id = try cg.module.structType( |
| 2700 | &.{anyerror_ty_id}, |
| 2701 | &.{"error_out"}, |
| 2702 | null, |
| 2703 | .none, |
| 2704 | ); |
| 2767 | 2705 | try cg.module.decorate(buffer_struct_ty_id, .block); |
| 2768 | 2706 | try cg.module.decorateMember(buffer_struct_ty_id, 0, .{ .offset = .{ .byte_offset = 0 } }); |
| 2769 | 2707 | |
| ... | ... | @@ -2871,14 +2809,14 @@ fn intFromBool2(cg: *CodeGen, value: Temporary, result_ty: Type) !Temporary { |
| 2871 | 2809 | /// This converts the argument type from resolveType(ty, .indirect) to resolveType(ty, .direct). |
| 2872 | 2810 | fn convertToDirect(cg: *CodeGen, ty: Type, operand_id: Id) !Id { |
| 2873 | 2811 | const pt = cg.pt; |
| 2874 | | const zcu = pt.zcu; |
| 2812 | const zcu = cg.module.zcu; |
| 2875 | 2813 | switch (ty.scalarType(zcu).zigTypeTag(zcu)) { |
| 2876 | 2814 | .bool => { |
| 2877 | 2815 | const false_id = try cg.constBool(false, .indirect); |
| 2878 | 2816 | const operand_ty = blk: { |
| 2879 | | if (!ty.isVector(pt.zcu)) break :blk Type.u1; |
| 2817 | if (!ty.isVector(zcu)) break :blk Type.u1; |
| 2880 | 2818 | break :blk try pt.vectorType(.{ |
| 2881 | | .len = ty.vectorLen(pt.zcu), |
| 2819 | .len = ty.vectorLen(zcu), |
| 2882 | 2820 | .child = .u1_type, |
| 2883 | 2821 | }); |
| 2884 | 2822 | }; |
| ... | ... | @@ -2897,7 +2835,7 @@ fn convertToDirect(cg: *CodeGen, ty: Type, operand_id: Id) !Id { |
| 2897 | 2835 | /// Convert representation from direct (in 'register) to direct (in memory) |
| 2898 | 2836 | /// This converts the argument type from resolveType(ty, .direct) to resolveType(ty, .indirect). |
| 2899 | 2837 | fn convertToIndirect(cg: *CodeGen, ty: Type, operand_id: Id) !Id { |
| 2900 | | const zcu = cg.pt.zcu; |
| 2838 | const zcu = cg.module.zcu; |
| 2901 | 2839 | switch (ty.scalarType(zcu).zigTypeTag(zcu)) { |
| 2902 | 2840 | .bool => { |
| 2903 | 2841 | const result = try cg.intFromBool(Temporary.init(ty, operand_id)); |
| ... | ... | @@ -2940,7 +2878,7 @@ const MemoryOptions = struct { |
| 2940 | 2878 | }; |
| 2941 | 2879 | |
| 2942 | 2880 | fn load(cg: *CodeGen, value_ty: Type, ptr_id: Id, options: MemoryOptions) !Id { |
| 2943 | | const zcu = cg.pt.zcu; |
| 2881 | const zcu = cg.module.zcu; |
| 2944 | 2882 | const alignment: u32 = @intCast(value_ty.abiAlignment(zcu).toByteUnits().?); |
| 2945 | 2883 | const indirect_value_ty_id = try cg.resolveType(value_ty, .indirect); |
| 2946 | 2884 | const result_id = cg.module.allocId(); |
| ... | ... | @@ -2975,7 +2913,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) !void { |
| 2975 | 2913 | |
| 2976 | 2914 | fn genInst(cg: *CodeGen, inst: Air.Inst.Index) Error!void { |
| 2977 | 2915 | const gpa = cg.module.gpa; |
| 2978 | | const zcu = cg.pt.zcu; |
| 2916 | const zcu = cg.module.zcu; |
| 2979 | 2917 | const ip = &zcu.intern_pool; |
| 2980 | 2918 | if (cg.liveness.isUnused(inst) and !cg.air.mustLower(inst, ip)) |
| 2981 | 2919 | return; |
| ... | ... | @@ -3159,7 +3097,7 @@ fn airBinOpSimple(cg: *CodeGen, inst: Air.Inst.Index, op: BinaryOp) !?Id { |
| 3159 | 3097 | } |
| 3160 | 3098 | |
| 3161 | 3099 | fn airShift(cg: *CodeGen, inst: Air.Inst.Index, unsigned: BinaryOp, signed: BinaryOp) !?Id { |
| 3162 | | const zcu = cg.pt.zcu; |
| 3100 | const zcu = cg.module.zcu; |
| 3163 | 3101 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3164 | 3102 | |
| 3165 | 3103 | if (cg.typeOf(bin_op.lhs).isVector(zcu) and !cg.typeOf(bin_op.rhs).isVector(zcu)) { |
| ... | ... | @@ -3241,7 +3179,7 @@ fn minMax(cg: *CodeGen, lhs: Temporary, rhs: Temporary, op: MinMax) !Temporary { |
| 3241 | 3179 | /// All other values are returned unmodified (this makes strange integer |
| 3242 | 3180 | /// wrapping easier to use in generic operations). |
| 3243 | 3181 | fn normalize(cg: *CodeGen, value: Temporary, info: ArithmeticTypeInfo) !Temporary { |
| 3244 | | const zcu = cg.pt.zcu; |
| 3182 | const zcu = cg.module.zcu; |
| 3245 | 3183 | const ty = value.ty; |
| 3246 | 3184 | switch (info.class) { |
| 3247 | 3185 | .composite_integer, .integer, .bool, .float => return value, |
| ... | ... | @@ -3391,7 +3329,8 @@ fn airAbs(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3391 | 3329 | } |
| 3392 | 3330 | |
| 3393 | 3331 | fn abs(cg: *CodeGen, result_ty: Type, value: Temporary) !Temporary { |
| 3394 | | const zcu = cg.pt.zcu; |
| 3332 | const zcu = cg.module.zcu; |
| 3333 | const target = cg.module.zcu.getTarget(); |
| 3395 | 3334 | const operand_info = cg.arithmeticTypeInfo(value.ty); |
| 3396 | 3335 | |
| 3397 | 3336 | switch (operand_info.class) { |
| ... | ... | @@ -3399,7 +3338,7 @@ fn abs(cg: *CodeGen, result_ty: Type, value: Temporary) !Temporary { |
| 3399 | 3338 | .integer, .strange_integer => { |
| 3400 | 3339 | const abs_value = try cg.buildUnary(.i_abs, value); |
| 3401 | 3340 | |
| 3402 | | switch (cg.module.target.os.tag) { |
| 3341 | switch (target.os.tag) { |
| 3403 | 3342 | .vulkan, .opengl => { |
| 3404 | 3343 | if (value.ty.intInfo(zcu).signedness == .signed) { |
| 3405 | 3344 | return cg.todo("perform bitcast after @abs", .{}); |
| ... | ... | @@ -3657,7 +3596,7 @@ fn airMulOverflow(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3657 | 3596 | } |
| 3658 | 3597 | |
| 3659 | 3598 | fn airShlOverflow(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3660 | | const zcu = cg.pt.zcu; |
| 3599 | const zcu = cg.module.zcu; |
| 3661 | 3600 | |
| 3662 | 3601 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3663 | 3602 | const extra = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -3716,7 +3655,7 @@ fn airMulAdd(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3716 | 3655 | fn airClzCtz(cg: *CodeGen, inst: Air.Inst.Index, op: UnaryOp) !?Id { |
| 3717 | 3656 | if (cg.liveness.isUnused(inst)) return null; |
| 3718 | 3657 | |
| 3719 | | const zcu = cg.pt.zcu; |
| 3658 | const zcu = cg.module.zcu; |
| 3720 | 3659 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3721 | 3660 | const operand = try cg.temporary(ty_op.operand); |
| 3722 | 3661 | |
| ... | ... | @@ -3759,7 +3698,7 @@ fn airSplat(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3759 | 3698 | } |
| 3760 | 3699 | |
| 3761 | 3700 | fn airReduce(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3762 | | const zcu = cg.pt.zcu; |
| 3701 | const zcu = cg.module.zcu; |
| 3763 | 3702 | const reduce = cg.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| 3764 | 3703 | const operand = try cg.resolve(reduce.operand); |
| 3765 | 3704 | const operand_ty = cg.typeOf(reduce.operand); |
| ... | ... | @@ -3831,8 +3770,7 @@ fn airReduce(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3831 | 3770 | } |
| 3832 | 3771 | |
| 3833 | 3772 | fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3834 | | const pt = cg.pt; |
| 3835 | | const zcu = pt.zcu; |
| 3773 | const zcu = cg.module.zcu; |
| 3836 | 3774 | const gpa = zcu.gpa; |
| 3837 | 3775 | |
| 3838 | 3776 | const unwrapped = cg.air.unwrapShuffleOne(zcu, inst); |
| ... | ... | @@ -3856,8 +3794,7 @@ fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3856 | 3794 | } |
| 3857 | 3795 | |
| 3858 | 3796 | fn airShuffleTwo(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 3859 | | const pt = cg.pt; |
| 3860 | | const zcu = pt.zcu; |
| 3797 | const zcu = cg.module.zcu; |
| 3861 | 3798 | const gpa = zcu.gpa; |
| 3862 | 3799 | |
| 3863 | 3800 | const unwrapped = cg.air.unwrapShuffleTwo(zcu, inst); |
| ... | ... | @@ -3934,11 +3871,12 @@ fn ptrAccessChain( |
| 3934 | 3871 | indices: []const u32, |
| 3935 | 3872 | ) !Id { |
| 3936 | 3873 | const gpa = cg.module.gpa; |
| 3874 | const target = cg.module.zcu.getTarget(); |
| 3937 | 3875 | const ids = try cg.indicesToIds(indices); |
| 3938 | 3876 | defer gpa.free(ids); |
| 3939 | 3877 | |
| 3940 | 3878 | const result_id = cg.module.allocId(); |
| 3941 | | switch (cg.module.target.os.tag) { |
| 3879 | switch (target.os.tag) { |
| 3942 | 3880 | .opencl, .amdhsa => { |
| 3943 | 3881 | try cg.body.emit(cg.module.gpa, .OpInBoundsPtrAccessChain, .{ |
| 3944 | 3882 | .id_result_type = result_ty_id, |
| ... | ... | @@ -3962,7 +3900,7 @@ fn ptrAccessChain( |
| 3962 | 3900 | } |
| 3963 | 3901 | |
| 3964 | 3902 | fn ptrAdd(cg: *CodeGen, result_ty: Type, ptr_ty: Type, ptr_id: Id, offset_id: Id) !Id { |
| 3965 | | const zcu = cg.pt.zcu; |
| 3903 | const zcu = cg.module.zcu; |
| 3966 | 3904 | const result_ty_id = try cg.resolveType(result_ty, .direct); |
| 3967 | 3905 | |
| 3968 | 3906 | switch (ptr_ty.ptrSize(zcu)) { |
| ... | ... | @@ -4019,7 +3957,7 @@ fn cmp( |
| 4019 | 3957 | rhs: Temporary, |
| 4020 | 3958 | ) !Temporary { |
| 4021 | 3959 | const pt = cg.pt; |
| 4022 | | const zcu = pt.zcu; |
| 3960 | const zcu = cg.module.zcu; |
| 4023 | 3961 | const ip = &zcu.intern_pool; |
| 4024 | 3962 | const scalar_ty = lhs.ty.scalarType(zcu); |
| 4025 | 3963 | const is_vector = lhs.ty.isVector(zcu); |
| ... | ... | @@ -4216,7 +4154,7 @@ fn bitCast( |
| 4216 | 4154 | src_ty: Type, |
| 4217 | 4155 | src_id: Id, |
| 4218 | 4156 | ) !Id { |
| 4219 | | const zcu = cg.pt.zcu; |
| 4157 | const zcu = cg.module.zcu; |
| 4220 | 4158 | const src_ty_id = try cg.resolveType(src_ty, .direct); |
| 4221 | 4159 | const dst_ty_id = try cg.resolveType(dst_ty, .direct); |
| 4222 | 4160 | |
| ... | ... | @@ -4408,8 +4346,7 @@ fn airNot(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4408 | 4346 | } |
| 4409 | 4347 | |
| 4410 | 4348 | fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4411 | | const pt = cg.pt; |
| 4412 | | const zcu = pt.zcu; |
| 4349 | const zcu = cg.module.zcu; |
| 4413 | 4350 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4414 | 4351 | const array_ptr_ty = cg.typeOf(ty_op.operand); |
| 4415 | 4352 | const array_ty = array_ptr_ty.childType(zcu); |
| ... | ... | @@ -4445,8 +4382,9 @@ fn airSlice(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4445 | 4382 | fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4446 | 4383 | const gpa = cg.module.gpa; |
| 4447 | 4384 | const pt = cg.pt; |
| 4448 | | const zcu = pt.zcu; |
| 4385 | const zcu = cg.module.zcu; |
| 4449 | 4386 | const ip = &zcu.intern_pool; |
| 4387 | const target = cg.module.zcu.getTarget(); |
| 4450 | 4388 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4451 | 4389 | const result_ty = cg.typeOfIndex(inst); |
| 4452 | 4390 | const len: usize = @intCast(result_ty.arrayLen(zcu)); |
| ... | ... | @@ -4467,7 +4405,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4467 | 4405 | const field_int_ty = try cg.pt.intType(.unsigned, ty_bit_size); |
| 4468 | 4406 | const field_int_id = blk: { |
| 4469 | 4407 | if (field_ty.isPtrAtRuntime(zcu)) { |
| 4470 | | assert(cg.module.target.cpu.arch == .spirv64 and |
| 4408 | assert(target.cpu.arch == .spirv64 and |
| 4471 | 4409 | field_ty.ptrAddressSpace(zcu) == .storage_buffer); |
| 4472 | 4410 | break :blk try cg.intFromPtr(field_id); |
| 4473 | 4411 | } |
| ... | ... | @@ -4567,8 +4505,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4567 | 4505 | } |
| 4568 | 4506 | |
| 4569 | 4507 | fn sliceOrArrayLen(cg: *CodeGen, operand_id: Id, ty: Type) !Id { |
| 4570 | | const pt = cg.pt; |
| 4571 | | const zcu = pt.zcu; |
| 4508 | const zcu = cg.module.zcu; |
| 4572 | 4509 | switch (ty.ptrSize(zcu)) { |
| 4573 | 4510 | .slice => return cg.extractField(.usize, operand_id, 1), |
| 4574 | 4511 | .one => { |
| ... | ... | @@ -4583,7 +4520,7 @@ fn sliceOrArrayLen(cg: *CodeGen, operand_id: Id, ty: Type) !Id { |
| 4583 | 4520 | } |
| 4584 | 4521 | |
| 4585 | 4522 | fn sliceOrArrayPtr(cg: *CodeGen, operand_id: Id, ty: Type) !Id { |
| 4586 | | const zcu = cg.pt.zcu; |
| 4523 | const zcu = cg.module.zcu; |
| 4587 | 4524 | if (ty.isSlice(zcu)) { |
| 4588 | 4525 | const ptr_ty = ty.slicePtrFieldType(zcu); |
| 4589 | 4526 | return cg.extractField(ptr_ty, operand_id, 0); |
| ... | ... | @@ -4620,7 +4557,7 @@ fn airSliceField(cg: *CodeGen, inst: Air.Inst.Index, field: u32) !?Id { |
| 4620 | 4557 | } |
| 4621 | 4558 | |
| 4622 | 4559 | fn airSliceElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4623 | | const zcu = cg.pt.zcu; |
| 4560 | const zcu = cg.module.zcu; |
| 4624 | 4561 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4625 | 4562 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4626 | 4563 | const slice_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -4637,7 +4574,7 @@ fn airSliceElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4637 | 4574 | } |
| 4638 | 4575 | |
| 4639 | 4576 | fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4640 | | const zcu = cg.pt.zcu; |
| 4577 | const zcu = cg.module.zcu; |
| 4641 | 4578 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4642 | 4579 | const slice_ty = cg.typeOf(bin_op.lhs); |
| 4643 | 4580 | if (!slice_ty.isVolatilePtr(zcu) and cg.liveness.isUnused(inst)) return null; |
| ... | ... | @@ -4654,7 +4591,7 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4654 | 4591 | } |
| 4655 | 4592 | |
| 4656 | 4593 | fn ptrElemPtr(cg: *CodeGen, ptr_ty: Type, ptr_id: Id, index_id: Id) !Id { |
| 4657 | | const zcu = cg.pt.zcu; |
| 4594 | const zcu = cg.module.zcu; |
| 4658 | 4595 | // Construct new pointer type for the resulting pointer |
| 4659 | 4596 | const elem_ty = ptr_ty.elemType2(zcu); // use elemType() so that we get T for *[N]T. |
| 4660 | 4597 | const elem_ptr_ty_id = try cg.ptrType(elem_ty, cg.module.storageClass(ptr_ty.ptrAddressSpace(zcu)), .indirect); |
| ... | ... | @@ -4669,8 +4606,7 @@ fn ptrElemPtr(cg: *CodeGen, ptr_ty: Type, ptr_id: Id, index_id: Id) !Id { |
| 4669 | 4606 | } |
| 4670 | 4607 | |
| 4671 | 4608 | fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4672 | | const pt = cg.pt; |
| 4673 | | const zcu = pt.zcu; |
| 4609 | const zcu = cg.module.zcu; |
| 4674 | 4610 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4675 | 4611 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4676 | 4612 | const src_ptr_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -4687,7 +4623,7 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4687 | 4623 | } |
| 4688 | 4624 | |
| 4689 | 4625 | fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4690 | | const zcu = cg.pt.zcu; |
| 4626 | const zcu = cg.module.zcu; |
| 4691 | 4627 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4692 | 4628 | const array_ty = cg.typeOf(bin_op.lhs); |
| 4693 | 4629 | const elem_ty = array_ty.childType(zcu); |
| ... | ... | @@ -4737,7 +4673,7 @@ fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4737 | 4673 | } |
| 4738 | 4674 | |
| 4739 | 4675 | fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4740 | | const zcu = cg.pt.zcu; |
| 4676 | const zcu = cg.module.zcu; |
| 4741 | 4677 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4742 | 4678 | const ptr_ty = cg.typeOf(bin_op.lhs); |
| 4743 | 4679 | const elem_ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -4748,7 +4684,7 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4748 | 4684 | } |
| 4749 | 4685 | |
| 4750 | 4686 | fn airVectorStoreElem(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 4751 | | const zcu = cg.pt.zcu; |
| 4687 | const zcu = cg.module.zcu; |
| 4752 | 4688 | const data = cg.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; |
| 4753 | 4689 | const extra = cg.air.extraData(Air.Bin, data.payload).data; |
| 4754 | 4690 | |
| ... | ... | @@ -4770,7 +4706,7 @@ fn airVectorStoreElem(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 4770 | 4706 | } |
| 4771 | 4707 | |
| 4772 | 4708 | fn airSetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 4773 | | const zcu = cg.pt.zcu; |
| 4709 | const zcu = cg.module.zcu; |
| 4774 | 4710 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4775 | 4711 | const un_ptr_ty = cg.typeOf(bin_op.lhs); |
| 4776 | 4712 | const un_ty = un_ptr_ty.childType(zcu); |
| ... | ... | @@ -4796,7 +4732,7 @@ fn airGetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4796 | 4732 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4797 | 4733 | const un_ty = cg.typeOf(ty_op.operand); |
| 4798 | 4734 | |
| 4799 | | const zcu = cg.pt.zcu; |
| 4735 | const zcu = cg.module.zcu; |
| 4800 | 4736 | const layout = cg.unionLayout(un_ty); |
| 4801 | 4737 | if (layout.tag_size == 0) return null; |
| 4802 | 4738 | |
| ... | ... | @@ -4820,7 +4756,7 @@ fn unionInit( |
| 4820 | 4756 | // Note: The result here is not cached, because it generates runtime code. |
| 4821 | 4757 | |
| 4822 | 4758 | const pt = cg.pt; |
| 4823 | | const zcu = pt.zcu; |
| 4759 | const zcu = cg.module.zcu; |
| 4824 | 4760 | const ip = &zcu.intern_pool; |
| 4825 | 4761 | const union_ty = zcu.typeToUnion(ty).?; |
| 4826 | 4762 | const tag_ty: Type = .fromInterned(union_ty.enum_tag_ty); |
| ... | ... | @@ -4898,8 +4834,7 @@ fn unionInit( |
| 4898 | 4834 | } |
| 4899 | 4835 | |
| 4900 | 4836 | fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4901 | | const pt = cg.pt; |
| 4902 | | const zcu = pt.zcu; |
| 4837 | const zcu = cg.module.zcu; |
| 4903 | 4838 | const ip = &zcu.intern_pool; |
| 4904 | 4839 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4905 | 4840 | const extra = cg.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| ... | ... | @@ -4916,7 +4851,7 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4916 | 4851 | |
| 4917 | 4852 | fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 4918 | 4853 | const pt = cg.pt; |
| 4919 | | const zcu = pt.zcu; |
| 4854 | const zcu = cg.module.zcu; |
| 4920 | 4855 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4921 | 4856 | const struct_field = cg.air.extraData(Air.StructField, ty_pl.payload).data; |
| 4922 | 4857 | |
| ... | ... | @@ -5000,8 +4935,7 @@ fn airStructFieldVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5000 | 4935 | } |
| 5001 | 4936 | |
| 5002 | 4937 | fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5003 | | const pt = cg.pt; |
| 5004 | | const zcu = pt.zcu; |
| 4938 | const zcu = cg.module.zcu; |
| 5005 | 4939 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 5006 | 4940 | const extra = cg.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 5007 | 4941 | |
| ... | ... | @@ -5041,7 +4975,7 @@ fn structFieldPtr( |
| 5041 | 4975 | ) !Id { |
| 5042 | 4976 | const result_ty_id = try cg.resolveType(result_ptr_ty, .direct); |
| 5043 | 4977 | |
| 5044 | | const zcu = cg.pt.zcu; |
| 4978 | const zcu = cg.module.zcu; |
| 5045 | 4979 | const object_ty = object_ptr_ty.childType(zcu); |
| 5046 | 4980 | switch (object_ty.zigTypeTag(zcu)) { |
| 5047 | 4981 | .pointer => { |
| ... | ... | @@ -5106,6 +5040,7 @@ fn alloc( |
| 5106 | 5040 | ty: Type, |
| 5107 | 5041 | options: AllocOptions, |
| 5108 | 5042 | ) !Id { |
| 5043 | const target = cg.module.zcu.getTarget(); |
| 5109 | 5044 | const ptr_fn_ty_id = try cg.ptrType(ty, .function, .indirect); |
| 5110 | 5045 | |
| 5111 | 5046 | // SPIR-V requires that OpVariable declarations for locals go into the first block, so we are just going to |
| ... | ... | @@ -5118,7 +5053,7 @@ fn alloc( |
| 5118 | 5053 | .initializer = options.initializer, |
| 5119 | 5054 | }); |
| 5120 | 5055 | |
| 5121 | | switch (cg.module.target.os.tag) { |
| 5056 | switch (target.os.tag) { |
| 5122 | 5057 | .vulkan, .opengl => return var_id, |
| 5123 | 5058 | else => {}, |
| 5124 | 5059 | } |
| ... | ... | @@ -5135,7 +5070,7 @@ fn alloc( |
| 5135 | 5070 | } |
| 5136 | 5071 | |
| 5137 | 5072 | fn airAlloc(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5138 | | const zcu = cg.pt.zcu; |
| 5073 | const zcu = cg.module.zcu; |
| 5139 | 5074 | const ptr_ty = cg.typeOfIndex(inst); |
| 5140 | 5075 | const child_ty = ptr_ty.childType(zcu); |
| 5141 | 5076 | return try cg.alloc(child_ty, .{ |
| ... | ... | @@ -5314,8 +5249,7 @@ fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, body: []const Air.Inst.Index) |
| 5314 | 5249 | // ir.Block in a different SPIR-V block. |
| 5315 | 5250 | |
| 5316 | 5251 | const gpa = cg.module.gpa; |
| 5317 | | const pt = cg.pt; |
| 5318 | | const zcu = pt.zcu; |
| 5252 | const zcu = cg.module.zcu; |
| 5319 | 5253 | const ty = cg.typeOfIndex(inst); |
| 5320 | 5254 | const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu); |
| 5321 | 5255 | |
| ... | ... | @@ -5448,7 +5382,7 @@ fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, body: []const Air.Inst.Index) |
| 5448 | 5382 | |
| 5449 | 5383 | fn airBr(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5450 | 5384 | const gpa = cg.module.gpa; |
| 5451 | | const zcu = cg.pt.zcu; |
| 5385 | const zcu = cg.module.zcu; |
| 5452 | 5386 | const br = cg.air.instructions.items(.data)[@intFromEnum(inst)].br; |
| 5453 | 5387 | const operand_ty = cg.typeOf(br.operand); |
| 5454 | 5388 | |
| ... | ... | @@ -5592,7 +5526,7 @@ fn airLoop(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5592 | 5526 | } |
| 5593 | 5527 | |
| 5594 | 5528 | fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5595 | | const zcu = cg.pt.zcu; |
| 5529 | const zcu = cg.module.zcu; |
| 5596 | 5530 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5597 | 5531 | const ptr_ty = cg.typeOf(ty_op.operand); |
| 5598 | 5532 | const elem_ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -5603,7 +5537,7 @@ fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5603 | 5537 | } |
| 5604 | 5538 | |
| 5605 | 5539 | fn airStore(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5606 | | const zcu = cg.pt.zcu; |
| 5540 | const zcu = cg.module.zcu; |
| 5607 | 5541 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 5608 | 5542 | const ptr_ty = cg.typeOf(bin_op.lhs); |
| 5609 | 5543 | const elem_ty = ptr_ty.childType(zcu); |
| ... | ... | @@ -5614,8 +5548,7 @@ fn airStore(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5614 | 5548 | } |
| 5615 | 5549 | |
| 5616 | 5550 | fn airRet(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5617 | | const pt = cg.pt; |
| 5618 | | const zcu = pt.zcu; |
| 5551 | const zcu = cg.module.zcu; |
| 5619 | 5552 | const operand = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5620 | 5553 | const ret_ty = cg.typeOf(operand); |
| 5621 | 5554 | if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| ... | ... | @@ -5636,8 +5569,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5636 | 5569 | } |
| 5637 | 5570 | |
| 5638 | 5571 | fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5639 | | const pt = cg.pt; |
| 5640 | | const zcu = pt.zcu; |
| 5572 | const zcu = cg.module.zcu; |
| 5641 | 5573 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5642 | 5574 | const ptr_ty = cg.typeOf(un_op); |
| 5643 | 5575 | const ret_ty = ptr_ty.childType(zcu); |
| ... | ... | @@ -5663,7 +5595,7 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5663 | 5595 | } |
| 5664 | 5596 | |
| 5665 | 5597 | fn airTry(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5666 | | const zcu = cg.pt.zcu; |
| 5598 | const zcu = cg.module.zcu; |
| 5667 | 5599 | const pl_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 5668 | 5600 | const err_union_id = try cg.resolve(pl_op.operand); |
| 5669 | 5601 | const extra = cg.air.extraData(Air.Try, pl_op.payload); |
| ... | ... | @@ -5733,7 +5665,7 @@ fn airTry(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5733 | 5665 | } |
| 5734 | 5666 | |
| 5735 | 5667 | fn airErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5736 | | const zcu = cg.pt.zcu; |
| 5668 | const zcu = cg.module.zcu; |
| 5737 | 5669 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5738 | 5670 | const operand_id = try cg.resolve(ty_op.operand); |
| 5739 | 5671 | const err_union_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -5769,7 +5701,7 @@ fn airErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5769 | 5701 | } |
| 5770 | 5702 | |
| 5771 | 5703 | fn airWrapErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5772 | | const zcu = cg.pt.zcu; |
| 5704 | const zcu = cg.module.zcu; |
| 5773 | 5705 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5774 | 5706 | const err_union_ty = cg.typeOfIndex(inst); |
| 5775 | 5707 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| ... | ... | @@ -5818,8 +5750,7 @@ fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5818 | 5750 | } |
| 5819 | 5751 | |
| 5820 | 5752 | fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum { is_null, is_non_null }) !?Id { |
| 5821 | | const pt = cg.pt; |
| 5822 | | const zcu = pt.zcu; |
| 5753 | const zcu = cg.module.zcu; |
| 5823 | 5754 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5824 | 5755 | const operand_id = try cg.resolve(un_op); |
| 5825 | 5756 | const operand_ty = cg.typeOf(un_op); |
| ... | ... | @@ -5895,7 +5826,7 @@ fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum { |
| 5895 | 5826 | } |
| 5896 | 5827 | |
| 5897 | 5828 | fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, pred: enum { is_err, is_non_err }) !?Id { |
| 5898 | | const zcu = cg.pt.zcu; |
| 5829 | const zcu = cg.module.zcu; |
| 5899 | 5830 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5900 | 5831 | const operand_id = try cg.resolve(un_op); |
| 5901 | 5832 | const err_union_ty = cg.typeOf(un_op); |
| ... | ... | @@ -5933,8 +5864,7 @@ fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, pred: enum { is_err, is_non_err |
| 5933 | 5864 | } |
| 5934 | 5865 | |
| 5935 | 5866 | fn airUnwrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5936 | | const pt = cg.pt; |
| 5937 | | const zcu = pt.zcu; |
| 5867 | const zcu = cg.module.zcu; |
| 5938 | 5868 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5939 | 5869 | const operand_id = try cg.resolve(ty_op.operand); |
| 5940 | 5870 | const optional_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -5950,8 +5880,7 @@ fn airUnwrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5950 | 5880 | } |
| 5951 | 5881 | |
| 5952 | 5882 | fn airUnwrapOptionalPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5953 | | const pt = cg.pt; |
| 5954 | | const zcu = pt.zcu; |
| 5883 | const zcu = cg.module.zcu; |
| 5955 | 5884 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5956 | 5885 | const operand_id = try cg.resolve(ty_op.operand); |
| 5957 | 5886 | const operand_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -5975,8 +5904,7 @@ fn airUnwrapOptionalPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5975 | 5904 | } |
| 5976 | 5905 | |
| 5977 | 5906 | fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 5978 | | const pt = cg.pt; |
| 5979 | | const zcu = pt.zcu; |
| 5907 | const zcu = cg.module.zcu; |
| 5980 | 5908 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5981 | 5909 | const payload_ty = cg.typeOf(ty_op.operand); |
| 5982 | 5910 | |
| ... | ... | @@ -6000,8 +5928,8 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 6000 | 5928 | fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 6001 | 5929 | const gpa = cg.module.gpa; |
| 6002 | 5930 | const pt = cg.pt; |
| 6003 | | const zcu = pt.zcu; |
| 6004 | | const target = cg.module.target; |
| 5931 | const zcu = cg.module.zcu; |
| 5932 | const target = cg.module.zcu.getTarget(); |
| 6005 | 5933 | const switch_br = cg.air.unwrapSwitch(inst); |
| 6006 | 5934 | const cond_ty = cg.typeOf(switch_br.operand); |
| 6007 | 5935 | const cond = try cg.resolve(switch_br.operand); |
| ... | ... | @@ -6157,29 +6085,21 @@ fn airUnreach(cg: *CodeGen) !void { |
| 6157 | 6085 | } |
| 6158 | 6086 | |
| 6159 | 6087 | fn airDbgStmt(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 6160 | | const gpa = cg.module.gpa; |
| 6161 | | const pt = cg.pt; |
| 6162 | | const zcu = pt.zcu; |
| 6088 | const zcu = cg.module.zcu; |
| 6163 | 6089 | const dbg_stmt = cg.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 6164 | 6090 | const path = zcu.navFileScope(cg.owner_nav).sub_file_path; |
| 6165 | 6091 | |
| 6166 | | if (cg.file_path_id == .none) { |
| 6167 | | cg.file_path_id = cg.module.allocId(); |
| 6168 | | try cg.module.sections.debug_strings.emit(gpa, .OpString, .{ |
| 6169 | | .id_result = cg.file_path_id, |
| 6170 | | .string = path, |
| 6171 | | }); |
| 6172 | | } |
| 6092 | if (zcu.comp.config.root_strip) return; |
| 6173 | 6093 | |
| 6174 | 6094 | try cg.body.emit(cg.module.gpa, .OpLine, .{ |
| 6175 | | .file = cg.file_path_id, |
| 6095 | .file = try cg.module.debugString(path), |
| 6176 | 6096 | .line = cg.base_line + dbg_stmt.line + 1, |
| 6177 | 6097 | .column = dbg_stmt.column + 1, |
| 6178 | 6098 | }); |
| 6179 | 6099 | } |
| 6180 | 6100 | |
| 6181 | 6101 | fn airDbgInlineBlock(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 6182 | | const zcu = cg.pt.zcu; |
| 6102 | const zcu = cg.module.zcu; |
| 6183 | 6103 | const inst_datas = cg.air.instructions.items(.data); |
| 6184 | 6104 | const extra = cg.air.extraData(Air.DbgInlineBlock, inst_datas[@intFromEnum(inst)].ty_pl.payload); |
| 6185 | 6105 | const old_base_line = cg.base_line; |
| ... | ... | @@ -6197,7 +6117,7 @@ fn airDbgVar(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 6197 | 6117 | |
| 6198 | 6118 | fn airAssembly(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 6199 | 6119 | const gpa = cg.module.gpa; |
| 6200 | | const zcu = cg.pt.zcu; |
| 6120 | const zcu = cg.module.zcu; |
| 6201 | 6121 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6202 | 6122 | const extra = cg.air.extraData(Air.Asm, ty_pl.payload); |
| 6203 | 6123 | |
| ... | ... | @@ -6360,8 +6280,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie |
| 6360 | 6280 | _ = modifier; |
| 6361 | 6281 | |
| 6362 | 6282 | const gpa = cg.module.gpa; |
| 6363 | | const pt = cg.pt; |
| 6364 | | const zcu = pt.zcu; |
| 6283 | const zcu = cg.module.zcu; |
| 6365 | 6284 | const pl_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 6366 | 6285 | const extra = cg.air.extraData(Air.Call, pl_op.payload); |
| 6367 | 6286 | const args: []const Air.Inst.Ref = @ptrCast(cg.air.extra.items[extra.end..][0..extra.data.args_len]); |
| ... | ... | @@ -6455,11 +6374,11 @@ fn airWorkGroupId(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 6455 | 6374 | } |
| 6456 | 6375 | |
| 6457 | 6376 | fn typeOf(cg: *CodeGen, inst: Air.Inst.Ref) Type { |
| 6458 | | const zcu = cg.pt.zcu; |
| 6377 | const zcu = cg.module.zcu; |
| 6459 | 6378 | return cg.air.typeOf(inst, &zcu.intern_pool); |
| 6460 | 6379 | } |
| 6461 | 6380 | |
| 6462 | 6381 | fn typeOfIndex(cg: *CodeGen, inst: Air.Inst.Index) Type { |
| 6463 | | const zcu = cg.pt.zcu; |
| 6382 | const zcu = cg.module.zcu; |
| 6464 | 6383 | return cg.air.typeOfIndex(inst, &zcu.intern_pool); |
| 6465 | 6384 | } |