| ... | ... | @@ -1910,11 +1910,15 @@ const DeclGen = struct { |
| 1910 | 1910 | return try self.convertToDirect(result_ty, result_id); |
| 1911 | 1911 | } |
| 1912 | 1912 | |
| 1913 | | fn load(self: *DeclGen, value_ty: Type, ptr_id: IdRef, is_volatile: bool) !IdRef { |
| 1913 | const MemoryOptions = struct { |
| 1914 | is_volatile: bool = false, |
| 1915 | }; |
| 1916 | |
| 1917 | fn load(self: *DeclGen, value_ty: Type, ptr_id: IdRef, options: MemoryOptions) !IdRef { |
| 1914 | 1918 | const indirect_value_ty_ref = try self.resolveType(value_ty, .indirect); |
| 1915 | 1919 | const result_id = self.spv.allocId(); |
| 1916 | 1920 | const access = spec.MemoryAccess.Extended{ |
| 1917 | | .Volatile = is_volatile, |
| 1921 | .Volatile = options.is_volatile, |
| 1918 | 1922 | }; |
| 1919 | 1923 | try self.func.body.emit(self.spv.gpa, .OpLoad, .{ |
| 1920 | 1924 | .id_result_type = self.typeId(indirect_value_ty_ref), |
| ... | ... | @@ -1925,10 +1929,10 @@ const DeclGen = struct { |
| 1925 | 1929 | return try self.convertToDirect(value_ty, result_id); |
| 1926 | 1930 | } |
| 1927 | 1931 | |
| 1928 | | fn store(self: *DeclGen, value_ty: Type, ptr_id: IdRef, value_id: IdRef, is_volatile: bool) !void { |
| 1932 | fn store(self: *DeclGen, value_ty: Type, ptr_id: IdRef, value_id: IdRef, options: MemoryOptions) !void { |
| 1929 | 1933 | const indirect_value_id = try self.convertToIndirect(value_ty, value_id); |
| 1930 | 1934 | const access = spec.MemoryAccess.Extended{ |
| 1931 | | .Volatile = is_volatile, |
| 1935 | .Volatile = options.is_volatile, |
| 1932 | 1936 | }; |
| 1933 | 1937 | try self.func.body.emit(self.spv.gpa, .OpStore, .{ |
| 1934 | 1938 | .pointer = ptr_id, |
| ... | ... | @@ -2849,14 +2853,14 @@ const DeclGen = struct { |
| 2849 | 2853 | const dst_ptr_ty_ref = try self.ptrType(dst_ty, .Function); |
| 2850 | 2854 | |
| 2851 | 2855 | const tmp_id = try self.alloc(src_ty, .{ .storage_class = .Function }); |
| 2852 | | try self.store(src_ty, tmp_id, src_id, false); |
| 2856 | try self.store(src_ty, tmp_id, src_id, .{}); |
| 2853 | 2857 | const casted_ptr_id = self.spv.allocId(); |
| 2854 | 2858 | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ |
| 2855 | 2859 | .id_result_type = self.typeId(dst_ptr_ty_ref), |
| 2856 | 2860 | .id_result = casted_ptr_id, |
| 2857 | 2861 | .operand = tmp_id, |
| 2858 | 2862 | }); |
| 2859 | | return try self.load(dst_ty, casted_ptr_id, false); |
| 2863 | return try self.load(dst_ty, casted_ptr_id, .{}); |
| 2860 | 2864 | } |
| 2861 | 2865 | |
| 2862 | 2866 | fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| ... | ... | @@ -3219,7 +3223,7 @@ const DeclGen = struct { |
| 3219 | 3223 | |
| 3220 | 3224 | const slice_ptr = try self.extractField(ptr_ty, slice_id, 0); |
| 3221 | 3225 | const elem_ptr = try self.ptrAccessChain(ptr_ty_ref, slice_ptr, index_id, &.{}); |
| 3222 | | return try self.load(slice_ty.childType(mod), elem_ptr, slice_ty.isVolatilePtr(mod)); |
| 3226 | return try self.load(slice_ty.childType(mod), elem_ptr, .{ .is_volatile = slice_ty.isVolatilePtr(mod) }); |
| 3223 | 3227 | } |
| 3224 | 3228 | |
| 3225 | 3229 | fn ptrElemPtr(self: *DeclGen, ptr_ty: Type, ptr_id: IdRef, index_id: IdRef) !IdRef { |
| ... | ... | @@ -3273,9 +3277,9 @@ const DeclGen = struct { |
| 3273 | 3277 | const elem_ptr_ty_ref = try self.ptrType(elem_ty, .Function); |
| 3274 | 3278 | |
| 3275 | 3279 | const tmp_id = try self.alloc(array_ty, .{ .storage_class = .Function }); |
| 3276 | | try self.store(array_ty, tmp_id, array_id, false); |
| 3280 | try self.store(array_ty, tmp_id, array_id, .{}); |
| 3277 | 3281 | const elem_ptr_id = try self.accessChainId(elem_ptr_ty_ref, tmp_id, &.{index_id}); |
| 3278 | | return try self.load(elem_ty, elem_ptr_id, false); |
| 3282 | return try self.load(elem_ty, elem_ptr_id, .{}); |
| 3279 | 3283 | } |
| 3280 | 3284 | |
| 3281 | 3285 | fn airPtrElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| ... | ... | @@ -3288,7 +3292,7 @@ const DeclGen = struct { |
| 3288 | 3292 | const ptr_id = try self.resolve(bin_op.lhs); |
| 3289 | 3293 | const index_id = try self.resolve(bin_op.rhs); |
| 3290 | 3294 | const elem_ptr_id = try self.ptrElemPtr(ptr_ty, ptr_id, index_id); |
| 3291 | | return try self.load(elem_ty, elem_ptr_id, ptr_ty.isVolatilePtr(mod)); |
| 3295 | return try self.load(elem_ty, elem_ptr_id, .{ .is_volatile = ptr_ty.isVolatilePtr(mod) }); |
| 3292 | 3296 | } |
| 3293 | 3297 | |
| 3294 | 3298 | fn airSetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !void { |
| ... | ... | @@ -3307,10 +3311,10 @@ const DeclGen = struct { |
| 3307 | 3311 | const new_tag_id = try self.resolve(bin_op.rhs); |
| 3308 | 3312 | |
| 3309 | 3313 | if (layout.payload_size == 0) { |
| 3310 | | try self.store(tag_ty, union_ptr_id, new_tag_id, un_ptr_ty.isVolatilePtr(mod)); |
| 3314 | try self.store(tag_ty, union_ptr_id, new_tag_id, .{ .is_volatile = un_ptr_ty.isVolatilePtr(mod) }); |
| 3311 | 3315 | } else { |
| 3312 | 3316 | const ptr_id = try self.accessChain(tag_ptr_ty_ref, union_ptr_id, &.{layout.tag_index}); |
| 3313 | | try self.store(tag_ty, ptr_id, new_tag_id, un_ptr_ty.isVolatilePtr(mod)); |
| 3317 | try self.store(tag_ty, ptr_id, new_tag_id, .{ .is_volatile = un_ptr_ty.isVolatilePtr(mod) }); |
| 3314 | 3318 | } |
| 3315 | 3319 | } |
| 3316 | 3320 | |
| ... | ... | @@ -3384,13 +3388,13 @@ const DeclGen = struct { |
| 3384 | 3388 | const tag_ptr_ty_ref = try self.ptrType(maybe_tag_ty.?, .Function); |
| 3385 | 3389 | const ptr_id = try self.accessChain(tag_ptr_ty_ref, tmp_id, &.{@as(u32, @intCast(layout.tag_index))}); |
| 3386 | 3390 | const tag_id = try self.constInt(tag_ty_ref, tag_int); |
| 3387 | | try self.store(maybe_tag_ty.?, ptr_id, tag_id, false); |
| 3391 | try self.store(maybe_tag_ty.?, ptr_id, tag_id, .{}); |
| 3388 | 3392 | } |
| 3389 | 3393 | |
| 3390 | 3394 | if (layout.active_field_size != 0) { |
| 3391 | 3395 | const active_field_ptr_ty_ref = try self.ptrType(layout.active_field_ty, .Function); |
| 3392 | 3396 | const ptr_id = try self.accessChain(active_field_ptr_ty_ref, tmp_id, &.{@as(u32, @intCast(layout.active_field_index))}); |
| 3393 | | try self.store(layout.active_field_ty, ptr_id, payload.?, false); |
| 3397 | try self.store(layout.active_field_ty, ptr_id, payload.?, .{}); |
| 3394 | 3398 | } else { |
| 3395 | 3399 | assert(payload == null); |
| 3396 | 3400 | } |
| ... | ... | @@ -3468,7 +3472,7 @@ const DeclGen = struct { |
| 3468 | 3472 | .id_result = tmp_id, |
| 3469 | 3473 | .storage_class = .Function, |
| 3470 | 3474 | }); |
| 3471 | | try self.store(object_ty, tmp_id, object_id, false); |
| 3475 | try self.store(object_ty, tmp_id, object_id, .{}); |
| 3472 | 3476 | const casted_tmp_id = self.spv.allocId(); |
| 3473 | 3477 | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ |
| 3474 | 3478 | .id_result_type = self.typeId(un_active_ptr_ty_ref), |
| ... | ... | @@ -3477,7 +3481,7 @@ const DeclGen = struct { |
| 3477 | 3481 | }); |
| 3478 | 3482 | const layout = self.unionLayout(object_ty, field_index); |
| 3479 | 3483 | const field_ptr_id = try self.accessChain(field_ptr_ty_ref, casted_tmp_id, &.{layout.active_field_index}); |
| 3480 | | return try self.load(field_ty, field_ptr_id, false); |
| 3484 | return try self.load(field_ty, field_ptr_id, .{}); |
| 3481 | 3485 | }, |
| 3482 | 3486 | }, |
| 3483 | 3487 | else => unreachable, |
| ... | ... | @@ -3730,7 +3734,7 @@ const DeclGen = struct { |
| 3730 | 3734 | const operand = try self.resolve(ty_op.operand); |
| 3731 | 3735 | if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null; |
| 3732 | 3736 | |
| 3733 | | return try self.load(elem_ty, operand, ptr_ty.isVolatilePtr(mod)); |
| 3737 | return try self.load(elem_ty, operand, .{ .is_volatile = ptr_ty.isVolatilePtr(mod) }); |
| 3734 | 3738 | } |
| 3735 | 3739 | |
| 3736 | 3740 | fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void { |
| ... | ... | @@ -3740,7 +3744,7 @@ const DeclGen = struct { |
| 3740 | 3744 | const ptr = try self.resolve(bin_op.lhs); |
| 3741 | 3745 | const value = try self.resolve(bin_op.rhs); |
| 3742 | 3746 | |
| 3743 | | try self.store(elem_ty, ptr, value, ptr_ty.isVolatilePtr(self.module)); |
| 3747 | try self.store(elem_ty, ptr, value, .{ .is_volatile = ptr_ty.isVolatilePtr(self.module) }); |
| 3744 | 3748 | } |
| 3745 | 3749 | |
| 3746 | 3750 | fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void { |
| ... | ... | @@ -3804,7 +3808,7 @@ const DeclGen = struct { |
| 3804 | 3808 | } |
| 3805 | 3809 | |
| 3806 | 3810 | const ptr = try self.resolve(un_op); |
| 3807 | | const value = try self.load(ret_ty, ptr, ptr_ty.isVolatilePtr(mod)); |
| 3811 | const value = try self.load(ret_ty, ptr, .{ .is_volatile = ptr_ty.isVolatilePtr(mod) }); |
| 3808 | 3812 | try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ |
| 3809 | 3813 | .value = value, |
| 3810 | 3814 | }); |