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