| ... | @@ -825,6 +825,11 @@ pub const DeclGen = struct { | ... | @@ -825,6 +825,11 @@ pub const DeclGen = struct { |
| 825 | // - Underaligned pointers. These need to be packed into the word array by using a mixture of | 825 | // - Underaligned pointers. These need to be packed into the word array by using a mixture of |
| 826 | // OpSpecConstantOp instructions such as OpConvertPtrToU, OpBitcast, OpShift, etc. | 826 | // OpSpecConstantOp instructions such as OpConvertPtrToU, OpBitcast, OpShift, etc. |
| 827 | | 827 | |
| | 828 | // TODO: Implement alignment here. |
| | 829 | // This is hoing to require some hacks because there is no real way to |
| | 830 | // set an OpVariable's alignment. |
| | 831 | _ = alignment; |
| | 832 | |
| 828 | assert(storage_class != .Generic and storage_class != .Function); | 833 | assert(storage_class != .Generic and storage_class != .Function); |
| 829 | | 834 | |
| 830 | log.debug("lowerIndirectConstant: ty = {}, val = {}", .{ ty.fmt(self.module), val.fmtDebug() }); | 835 | log.debug("lowerIndirectConstant: ty = {}, val = {}", .{ ty.fmt(self.module), val.fmtDebug() }); |
| ... | @@ -832,7 +837,7 @@ pub const DeclGen = struct { | ... | @@ -832,7 +837,7 @@ pub const DeclGen = struct { |
| 832 | const section = &self.spv.globals.section; | 837 | const section = &self.spv.globals.section; |
| 833 | | 838 | |
| 834 | const ty_ref = try self.resolveType(ty, .indirect); | 839 | const ty_ref = try self.resolveType(ty, .indirect); |
| 835 | const ptr_ty_ref = try self.spv.ptrType(ty_ref, storage_class, alignment); | 840 | const ptr_ty_ref = try self.spv.ptrType(ty_ref, storage_class, 0); |
| 836 | | 841 | |
| 837 | // const target = self.getTarget(); | 842 | // const target = self.getTarget(); |
| 838 | | 843 | |
| ... | @@ -874,7 +879,7 @@ pub const DeclGen = struct { | ... | @@ -874,7 +879,7 @@ pub const DeclGen = struct { |
| 874 | try icl.flush(); | 879 | try icl.flush(); |
| 875 | | 880 | |
| 876 | const constant_struct_ty_ref = try self.spv.simpleStructType(icl.members.items); | 881 | const constant_struct_ty_ref = try self.spv.simpleStructType(icl.members.items); |
| 877 | const ptr_constant_struct_ty_ref = try self.spv.ptrType(constant_struct_ty_ref, storage_class, alignment); | 882 | const ptr_constant_struct_ty_ref = try self.spv.ptrType(constant_struct_ty_ref, storage_class, 0); |
| 878 | | 883 | |
| 879 | const constant_struct_id = self.spv.allocId(); | 884 | const constant_struct_id = self.spv.allocId(); |
| 880 | try section.emit(self.spv.gpa, .OpSpecConstantComposite, .{ | 885 | try section.emit(self.spv.gpa, .OpSpecConstantComposite, .{ |
| ... | @@ -909,7 +914,7 @@ pub const DeclGen = struct { | ... | @@ -909,7 +914,7 @@ pub const DeclGen = struct { |
| 909 | }); | 914 | }); |
| 910 | | 915 | |
| 911 | if (cast_to_generic) { | 916 | if (cast_to_generic) { |
| 912 | const generic_ptr_ty_ref = try self.spv.ptrType(ty_ref, .Generic, alignment); | 917 | const generic_ptr_ty_ref = try self.spv.ptrType(ty_ref, .Generic, 0); |
| 913 | try section.emitSpecConstantOp(self.spv.gpa, .OpPtrCastToGeneric, .{ | 918 | try section.emitSpecConstantOp(self.spv.gpa, .OpPtrCastToGeneric, .{ |
| 914 | .id_result_type = self.typeId(generic_ptr_ty_ref), | 919 | .id_result_type = self.typeId(generic_ptr_ty_ref), |
| 915 | .id_result = result_id, | 920 | .id_result = result_id, |
| ... | @@ -1165,21 +1170,16 @@ pub const DeclGen = struct { | ... | @@ -1165,21 +1170,16 @@ pub const DeclGen = struct { |
| 1165 | .Pointer => { | 1170 | .Pointer => { |
| 1166 | const ptr_info = ty.ptrInfo().data; | 1171 | const ptr_info = ty.ptrInfo().data; |
| 1167 | | 1172 | |
| 1168 | const ptr_payload = try self.spv.arena.create(SpvType.Payload.Pointer); | 1173 | const storage_class = spvStorageClass(ptr_info.@"addrspace"); |
| 1169 | ptr_payload.* = .{ | 1174 | const child_ty_ref = try self.resolveType(ptr_info.pointee_type, .indirect); |
| 1170 | .storage_class = spvStorageClass(ptr_info.@"addrspace"), | 1175 | const ptr_ty_ref = try self.spv.ptrType(child_ty_ref, storage_class, 0); |
| 1171 | .child_type = try self.resolveType(ptr_info.pointee_type, .indirect), | | |
| 1172 | // Note: only available in Kernels! | | |
| 1173 | .alignment = ty.ptrAlignment(target) * 8, | | |
| 1174 | }; | | |
| 1175 | const ptr_ty_id = try self.spv.resolveType(SpvType.initPayload(&ptr_payload.base)); | | |
| 1176 | | 1176 | |
| 1177 | if (ptr_info.size != .Slice) { | 1177 | if (ptr_info.size != .Slice) { |
| 1178 | return ptr_ty_id; | 1178 | return ptr_ty_ref; |
| 1179 | } | 1179 | } |
| 1180 | | 1180 | |
| 1181 | return try self.spv.simpleStructType(&.{ | 1181 | return try self.spv.simpleStructType(&.{ |
| 1182 | .{ .ty = ptr_ty_id, .name = "ptr" }, | 1182 | .{ .ty = ptr_ty_ref, .name = "ptr" }, |
| 1183 | .{ .ty = try self.sizeType(), .name = "len" }, | 1183 | .{ .ty = try self.sizeType(), .name = "len" }, |
| 1184 | }); | 1184 | }); |
| 1185 | }, | 1185 | }, |
| ... | @@ -1356,7 +1356,7 @@ pub const DeclGen = struct { | ... | @@ -1356,7 +1356,7 @@ pub const DeclGen = struct { |
| 1356 | /// the name of an error in the text executor. | 1356 | /// the name of an error in the text executor. |
| 1357 | fn generateTestEntryPoint(self: *DeclGen, name: []const u8, spv_test_decl_index: SpvModule.Decl.Index) !void { | 1357 | fn generateTestEntryPoint(self: *DeclGen, name: []const u8, spv_test_decl_index: SpvModule.Decl.Index) !void { |
| 1358 | const anyerror_ty_ref = try self.resolveType(Type.anyerror, .direct); | 1358 | const anyerror_ty_ref = try self.resolveType(Type.anyerror, .direct); |
| 1359 | const ptr_anyerror_ty_ref = try self.spv.ptrType(anyerror_ty_ref, .CrossWorkgroup, null); | 1359 | const ptr_anyerror_ty_ref = try self.spv.ptrType(anyerror_ty_ref, .CrossWorkgroup, 0); |
| 1360 | const void_ty_ref = try self.resolveType(Type.void, .direct); | 1360 | const void_ty_ref = try self.resolveType(Type.void, .direct); |
| 1361 | | 1361 | |
| 1362 | const kernel_proto_ty_ref = blk: { | 1362 | const kernel_proto_ty_ref = blk: { |
| ... | @@ -1497,19 +1497,6 @@ pub const DeclGen = struct { | ... | @@ -1497,19 +1497,6 @@ pub const DeclGen = struct { |
| 1497 | final_storage_class == .Generic, | 1497 | final_storage_class == .Generic, |
| 1498 | decl.@"align", | 1498 | decl.@"align", |
| 1499 | ); | 1499 | ); |
| 1500 | | | |
| 1501 | // if (storage_class == .Generic) { | | |
| 1502 | // const section = &self.spv.globals.section; | | |
| 1503 | // const ty_ref = try self.resolveType(decl.ty, .indirect); | | |
| 1504 | // const ptr_ty_ref = try self.spv.ptrType(ty_ref, storage_class, decl.@"align"); | | |
| 1505 | // // TODO: Can we eliminate this cast? | | |
| 1506 | // // TODO: Const-wash pointer? | | |
| 1507 | // try section.emitSpecConstantOp(self.spv.gpa, .OpPtrCastToGeneric, .{ | | |
| 1508 | // .id_result_type = self.typeId(ptr_ty_ref), | | |
| 1509 | // .id_result = global_result_id, | | |
| 1510 | // .pointer = casted_result_id, | | |
| 1511 | // }); | | |
| 1512 | // } | | |
| 1513 | } | 1500 | } |
| 1514 | } | 1501 | } |
| 1515 | | 1502 | |