authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2025-06-17 09:21:33+03:30
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-23 06:03:03+02:00
log1df79ab895a5740611b57fb091d0487ec21a762d
tree0485e74f1fa2cad32235078542e6de3c39d83329
parentc71bb0f2b66f72122e25400c97a1213d59e4ad73

remove `spirv` cpu arch


19 files changed, 169 insertions(+), 247 deletions(-)

lib/compiler/aro/aro/target.zig-3
......@@ -486,7 +486,6 @@ pub fn get32BitArchVariant(target: std.Target) ?std.Target {
486486 .kalimba,
487487 .lanai,
488488 .wasm32,
489 .spirv,
490489 .spirv32,
491490 .loongarch32,
492491 .xtensa,
......@@ -554,7 +553,6 @@ pub fn get64BitArchVariant(target: std.Target) ?std.Target {
554553 .powerpcle => copy.cpu.arch = .powerpc64le,
555554 .riscv32 => copy.cpu.arch = .riscv64,
556555 .sparc => copy.cpu.arch = .sparc64,
557 .spirv => copy.cpu.arch = .spirv64,
558556 .spirv32 => copy.cpu.arch = .spirv64,
559557 .thumb => copy.cpu.arch = .aarch64,
560558 .thumbeb => copy.cpu.arch = .aarch64_be,
......@@ -609,7 +607,6 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
609607 .xtensa => "xtensa",
610608 .nvptx => "nvptx",
611609 .nvptx64 => "nvptx64",
612 .spirv => "spirv",
613610 .spirv32 => "spirv32",
614611 .spirv64 => "spirv64",
615612 .kalimba => "kalimba",
lib/compiler_rt/common.zig-1
......@@ -120,7 +120,6 @@ pub fn F16T(comptime OtherType: type) type {
120120 .nvptx64,
121121 .riscv32,
122122 .riscv64,
123 .spirv,
124123 .spirv32,
125124 .spirv64,
126125 => f16,
lib/std/Target.zig+5-13
......@@ -1066,7 +1066,7 @@ pub const ObjectFormat = enum {
10661066 .uefi, .windows => .coff,
10671067 .zos => .goff,
10681068 else => switch (arch) {
1069 .spirv, .spirv32, .spirv64 => .spirv,
1069 .spirv32, .spirv64 => .spirv,
10701070 .wasm32, .wasm64 => .wasm,
10711071 else => .elf,
10721072 },
......@@ -1106,7 +1106,6 @@ pub fn toElfMachine(target: *const Target) std.elf.EM {
11061106
11071107 .nvptx,
11081108 .nvptx64,
1109 .spirv,
11101109 .spirv32,
11111110 .spirv64,
11121111 .wasm32,
......@@ -1155,7 +1154,6 @@ pub fn toCoffMachine(target: *const Target) std.coff.MachineType {
11551154 .s390x,
11561155 .sparc,
11571156 .sparc64,
1158 .spirv,
11591157 .spirv32,
11601158 .spirv64,
11611159 .ve,
......@@ -1368,7 +1366,6 @@ pub const Cpu = struct {
13681366 s390x,
13691367 sparc,
13701368 sparc64,
1371 spirv,
13721369 spirv32,
13731370 spirv64,
13741371 ve,
......@@ -1454,7 +1451,7 @@ pub const Cpu = struct {
14541451 .riscv32, .riscv64 => .riscv,
14551452 .s390x => .s390x,
14561453 .sparc, .sparc64 => .sparc,
1457 .spirv, .spirv32, .spirv64 => .spirv,
1454 .spirv32, .spirv64 => .spirv,
14581455 .ve => .ve,
14591456 .wasm32, .wasm64 => .wasm,
14601457 .x86, .x86_64 => .x86,
......@@ -1558,7 +1555,7 @@ pub const Cpu = struct {
15581555
15591556 pub inline fn isSpirV(arch: Arch) bool {
15601557 return switch (arch) {
1561 .spirv, .spirv32, .spirv64 => true,
1558 .spirv32, .spirv64 => true,
15621559 else => false,
15631560 };
15641561 }
......@@ -1614,7 +1611,6 @@ pub const Cpu = struct {
16141611 .thumb,
16151612 .ve,
16161613 // GPU bitness is opaque. For now, assume little endian.
1617 .spirv,
16181614 .spirv32,
16191615 .spirv64,
16201616 .loongarch32,
......@@ -1843,7 +1839,7 @@ pub const Cpu = struct {
18431839 .spirv_kernel,
18441840 .spirv_fragment,
18451841 .spirv_vertex,
1846 => &.{ .spirv, .spirv32, .spirv64 },
1842 => &.{ .spirv32, .spirv64 },
18471843 };
18481844 }
18491845 };
......@@ -2638,7 +2634,6 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
26382634 .sparc64,
26392635 .s390x,
26402636 .ve,
2641 .spirv,
26422637 .spirv64,
26432638 .loongarch64,
26442639 => 64,
......@@ -3157,7 +3152,6 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
31573152 .riscv32,
31583153 .riscv64,
31593154 .sparc64,
3160 .spirv,
31613155 .spirv32,
31623156 .spirv64,
31633157 .x86_64,
......@@ -3250,7 +3244,6 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
32503244 .riscv32,
32513245 .riscv64,
32523246 .sparc64,
3253 .spirv,
32543247 .spirv32,
32553248 .spirv64,
32563249 .x86_64,
......@@ -3319,7 +3312,6 @@ pub fn cMaxIntAlignment(target: *const Target) u16 {
33193312 .loongarch32,
33203313 .loongarch64,
33213314 .m68k,
3322 .spirv,
33233315 .spirv32,
33243316 .spirv64,
33253317 .ve,
......@@ -3389,7 +3381,7 @@ pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention
33893381 .xtensa => .{ .xtensa_call0 = .{} },
33903382 .amdgcn => .{ .amdgcn_device = .{} },
33913383 .nvptx, .nvptx64 => .nvptx_device,
3392 .spirv, .spirv32, .spirv64 => .spirv_device,
3384 .spirv32, .spirv64 => .spirv_device,
33933385 };
33943386}
33953387
lib/std/Target/spirv.zig+2-45
......@@ -5,16 +5,11 @@ const CpuFeature = std.Target.Cpu.Feature;
55const CpuModel = std.Target.Cpu.Model;
66
77pub const Feature = enum {
8 addresses,
98 arbitrary_precision_integers,
109 float16,
1110 float64,
1211 generic_pointer,
1312 int64,
14 kernel,
15 matrix,
16 physical_storage_buffer,
17 shader,
1813 storage_push_constant16,
1914 v1_0,
2015 v1_1,
......@@ -37,13 +32,6 @@ pub const all_features = blk: {
3732 const len = @typeInfo(Feature).@"enum".fields.len;
3833 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
3934 var result: [len]CpuFeature = undefined;
40 result[@intFromEnum(Feature.addresses)] = .{
41 .llvm_name = null,
42 .description = "Enable Addresses capability",
43 .dependencies = featureSet(&[_]Feature{
44 .v1_0,
45 }),
46 };
4735 result[@intFromEnum(Feature.arbitrary_precision_integers)] = .{
4836 .llvm_name = null,
4937 .description = "Enable SPV_INTEL_arbitrary_precision_integers extension and the ArbitraryPrecisionIntegersINTEL capability",
......@@ -69,7 +57,7 @@ pub const all_features = blk: {
6957 .llvm_name = null,
7058 .description = "Enable GenericPointer capability",
7159 .dependencies = featureSet(&[_]Feature{
72 .addresses,
60 .v1_0,
7361 }),
7462 };
7563 result[@intFromEnum(Feature.int64)] = .{
......@@ -79,34 +67,6 @@ pub const all_features = blk: {
7967 .v1_0,
8068 }),
8169 };
82 result[@intFromEnum(Feature.kernel)] = .{
83 .llvm_name = null,
84 .description = "Enable Kernel capability",
85 .dependencies = featureSet(&[_]Feature{
86 .v1_0,
87 }),
88 };
89 result[@intFromEnum(Feature.matrix)] = .{
90 .llvm_name = null,
91 .description = "Enable Matrix capability",
92 .dependencies = featureSet(&[_]Feature{
93 .v1_0,
94 }),
95 };
96 result[@intFromEnum(Feature.physical_storage_buffer)] = .{
97 .llvm_name = null,
98 .description = "Enable SPV_KHR_variable_pointers extension and the (VariablePointers, VariablePointersStorageBuffer) capabilities",
99 .dependencies = featureSet(&[_]Feature{
100 .v1_0,
101 }),
102 };
103 result[@intFromEnum(Feature.shader)] = .{
104 .llvm_name = null,
105 .description = "Enable Shader capability",
106 .dependencies = featureSet(&[_]Feature{
107 .matrix,
108 }),
109 };
11070 result[@intFromEnum(Feature.storage_push_constant16)] = .{
11171 .llvm_name = null,
11272 .description = "Enable SPV_KHR_16bit_storage extension and the StoragePushConstant16 capability",
......@@ -172,7 +132,7 @@ pub const all_features = blk: {
172132 .llvm_name = null,
173133 .description = "Enable Vector16 capability",
174134 .dependencies = featureSet(&[_]Feature{
175 .kernel,
135 .v1_0,
176136 }),
177137 };
178138 const ti = @typeInfo(Feature);
......@@ -193,8 +153,6 @@ pub const cpu = struct {
193153 .name = "opencl_v2",
194154 .llvm_name = null,
195155 .features = featureSet(&[_]Feature{
196 .generic_pointer,
197 .kernel,
198156 .v1_2,
199157 }),
200158 };
......@@ -202,7 +160,6 @@ pub const cpu = struct {
202160 .name = "vulkan_v1_2",
203161 .llvm_name = null,
204162 .features = featureSet(&[_]Feature{
205 .shader,
206163 .v1_5,
207164 }),
208165 };
lib/std/builtin.zig+1-1
......@@ -189,7 +189,7 @@ pub const CallingConvention = union(enum(u8)) {
189189 pub const kernel: CallingConvention = switch (builtin.target.cpu.arch) {
190190 .amdgcn => .amdgcn_kernel,
191191 .nvptx, .nvptx64 => .nvptx_kernel,
192 .spirv, .spirv32, .spirv64 => .spirv_kernel,
192 .spirv32, .spirv64 => .spirv_kernel,
193193 else => unreachable,
194194 };
195195
lib/std/debug/Dwarf/abi.zig-1
......@@ -14,7 +14,6 @@ pub fn supportsUnwinding(target: *const std.Target) bool {
1414 .amdgcn,
1515 .nvptx,
1616 .nvptx64,
17 .spirv,
1817 .spirv32,
1918 .spirv64,
2019 => false,
src/Sema.zig+1-1
......@@ -26289,7 +26289,7 @@ fn zirWorkItem(
2628926289
2629026290 switch (target.cpu.arch) {
2629126291 // TODO: Allow for other GPU targets.
26292 .amdgcn, .spirv, .spirv64, .spirv32, .nvptx, .nvptx64 => {},
26292 .amdgcn, .spirv64, .spirv32, .nvptx, .nvptx64 => {},
2629326293 else => {
2629426294 return sema.fail(block, builtin_src, "builtin only available on GPU targets; targeted architecture is {s}", .{@tagName(target.cpu.arch)});
2629526295 },
src/Zcu.zig-1
......@@ -3935,7 +3935,6 @@ pub fn atomicPtrAlignment(
39353935 .s390x,
39363936 .wasm64,
39373937 .ve,
3938 .spirv,
39393938 .spirv64,
39403939 .loongarch64,
39413940 => 64,
src/codegen.zig+1-1
......@@ -37,7 +37,7 @@ fn devFeatureForBackend(backend: std.builtin.CompilerBackend) dev.Feature {
3737 .stage2_powerpc => .powerpc_backend,
3838 .stage2_riscv64 => .riscv64_backend,
3939 .stage2_sparc64 => .sparc64_backend,
40 .stage2_spirv => .spirv64_backend,
40 .stage2_spirv => .spirv_backend,
4141 .stage2_wasm => .wasm_backend,
4242 .stage2_x86 => .x86_backend,
4343 .stage2_x86_64 => .x86_64_backend,
src/codegen/llvm.zig+8-8
......@@ -93,8 +93,10 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
9393 .xtensa => "xtensa",
9494 .nvptx => "nvptx",
9595 .nvptx64 => "nvptx64",
96 .spirv => "spirv",
97 .spirv32 => "spirv32",
96 .spirv32 => switch (target.os.tag) {
97 .vulkan, .opengl => "spirv",
98 else => "spirv32",
99 },
98100 .spirv64 => "spirv64",
99101 .lanai => "lanai",
100102 .wasm32 => "wasm32",
......@@ -150,9 +152,6 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
150152 .powerpc => subArchName(target, .powerpc, .{
151153 .{ .spe, "spe" },
152154 }),
153 .spirv => subArchName(target, .spirv, .{
154 .{ .v1_5, "1.5" },
155 }),
156155 .spirv32, .spirv64 => subArchName(target, .spirv, .{
157156 .{ .v1_5, "1.5" },
158157 .{ .v1_4, "1.4" },
......@@ -441,8 +440,10 @@ pub fn dataLayout(target: *const std.Target) []const u8 {
441440 else
442441 "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
443442 },
444 .spirv => "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
445 .spirv32 => "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
443 .spirv32 => switch (target.os.tag) {
444 .vulkan, .opengl => "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
445 else => "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
446 },
446447 .spirv64 => "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
447448 .wasm32 => if (target.os.tag == .emscripten)
448449 "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-S128-ni:1:10:20"
......@@ -13129,7 +13130,6 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
1312913130 llvm.LLVMInitializeLoongArchAsmPrinter();
1313013131 llvm.LLVMInitializeLoongArchAsmParser();
1313113132 },
13132 .spirv,
1313313133 .spirv32,
1313413134 .spirv64,
1313513135 => {
src/codegen/spirv.zig+92-74
......@@ -439,7 +439,7 @@ const NavGen = struct {
439439 fn importExtendedSet(self: *NavGen) !IdResult {
440440 const target = self.spv.target;
441441 return switch (target.os.tag) {
442 .opencl => try self.spv.importInstructionSet(.@"OpenCL.std"),
442 .opencl, .amdhsa => try self.spv.importInstructionSet(.@"OpenCL.std"),
443443 .vulkan, .opengl => try self.spv.importInstructionSet(.@"GLSL.std.450"),
444444 else => unreachable,
445445 };
......@@ -561,7 +561,7 @@ const NavGen = struct {
561561 }
562562
563563 fn castToGeneric(self: *NavGen, type_id: IdRef, ptr_id: IdRef) !IdRef {
564 if (self.spv.hasFeature(.kernel)) {
564 if (self.spv.hasFeature(.generic_pointer)) {
565565 const result_id = self.spv.allocId();
566566 try self.func.body.emit(self.spv.gpa, .OpPtrCastToGeneric, .{
567567 .id_result_type = type_id,
......@@ -601,16 +601,18 @@ const NavGen = struct {
601601
602602 // We require Int8 and Int16 capabilities and benefit Int64 when available.
603603 // 32-bit integers are always supported (see spec, 2.16.1, Data rules).
604 const ints = [_]struct { bits: u16, feature: ?Target.spirv.Feature }{
605 .{ .bits = 8, .feature = null },
606 .{ .bits = 16, .feature = null },
607 .{ .bits = 32, .feature = null },
608 .{ .bits = 64, .feature = .int64 },
604 const ints = [_]struct { bits: u16, enabled: bool }{
605 .{ .bits = 8, .enabled = true },
606 .{ .bits = 16, .enabled = true },
607 .{ .bits = 32, .enabled = true },
608 .{
609 .bits = 64,
610 .enabled = self.spv.hasFeature(.int64) or self.spv.target.cpu.arch == .spirv64,
611 },
609612 };
610613
611614 for (ints) |int| {
612 const has_feature = if (int.feature) |feature| self.spv.hasFeature(feature) else true;
613 if (bits <= int.bits and has_feature) return .{ int.bits, false };
615 if (bits <= int.bits and int.enabled) return .{ int.bits, false };
614616 }
615617
616618 // Big int
......@@ -624,7 +626,10 @@ const NavGen = struct {
624626 /// is no way of knowing whether those are actually supported.
625627 /// TODO: Maybe this should be cached?
626628 fn largestSupportedIntBits(self: *NavGen) u16 {
627 return if (self.spv.hasFeature(.int64)) 64 else 32;
629 if (self.spv.hasFeature(.int64) or self.spv.target.cpu.arch == .spirv64) {
630 return 64;
631 }
632 return 32;
628633 }
629634
630635 fn arithmeticTypeInfo(self: *NavGen, ty: Type) ArithmeticTypeInfo {
......@@ -736,8 +741,8 @@ const NavGen = struct {
736741 });
737742 }
738743
739 const final_value: spec.LiteralContextDependentNumber = blk: {
740 if (self.spv.hasFeature(.kernel)) {
744 const final_value: spec.LiteralContextDependentNumber = switch (self.spv.target.os.tag) {
745 .opencl, .amdhsa => blk: {
741746 const value64: u64 = switch (signedness) {
742747 .signed => @bitCast(@as(i64, @intCast(value))),
743748 .unsigned => @as(u64, @intCast(value)),
......@@ -754,13 +759,12 @@ const NavGen = struct {
754759 33...64 => .{ .uint64 = truncated_value },
755760 else => unreachable,
756761 };
757 }
758
759 break :blk switch (backing_bits) {
762 },
763 else => switch (backing_bits) {
760764 1...32 => if (signedness == .signed) .{ .int32 = @intCast(value) } else .{ .uint32 = @intCast(value) },
761765 33...64 => if (signedness == .signed) .{ .int64 = value } else .{ .uint64 = value },
762766 else => unreachable,
763 };
767 },
764768 };
765769
766770 const result_id = try self.spv.constant(result_ty_id, final_value);
......@@ -1276,12 +1280,11 @@ const NavGen = struct {
12761280 return self.arrayType(backing_bits / big_int_bits, int_ty);
12771281 }
12781282
1279 // Kernel only supports unsigned ints.
1280 if (self.spv.hasFeature(.kernel)) {
1281 return self.spv.intType(.unsigned, backing_bits);
1282 }
1283
1284 return self.spv.intType(signedness, backing_bits);
1283 return switch (self.spv.target.os.tag) {
1284 // Kernel only supports unsigned ints.
1285 .opencl, .amdhsa => return self.spv.intType(.unsigned, backing_bits),
1286 else => self.spv.intType(signedness, backing_bits),
1287 };
12851288 }
12861289
12871290 fn arrayType(self: *NavGen, len: u32, child_ty: IdRef) !IdRef {
......@@ -1314,20 +1317,23 @@ const NavGen = struct {
13141317
13151318 const child_ty_id = try self.resolveType(child_ty, child_repr);
13161319
1317 if (self.spv.hasFeature(.shader)) {
1318 if (child_ty.zigTypeTag(zcu) == .@"struct") {
1319 switch (storage_class) {
1320 .Uniform, .PushConstant => try self.spv.decorate(child_ty_id, .Block),
1321 else => {},
1320 switch (self.spv.target.os.tag) {
1321 .vulkan, .opengl => {
1322 if (child_ty.zigTypeTag(zcu) == .@"struct") {
1323 switch (storage_class) {
1324 .Uniform, .PushConstant => try self.spv.decorate(child_ty_id, .Block),
1325 else => {},
1326 }
13221327 }
1323 }
13241328
1325 switch (ip.indexToKey(child_ty.toIntern())) {
1326 .func_type, .opaque_type => {},
1327 else => {
1328 try self.spv.decorate(result_id, .{ .ArrayStride = .{ .array_stride = @intCast(child_ty.abiSize(zcu)) } });
1329 },
1330 }
1329 switch (ip.indexToKey(child_ty.toIntern())) {
1330 .func_type, .opaque_type => {},
1331 else => {
1332 try self.spv.decorate(result_id, .{ .ArrayStride = .{ .array_stride = @intCast(child_ty.abiSize(zcu)) } });
1333 },
1334 }
1335 },
1336 else => {},
13311337 }
13321338
13331339 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpTypePointer, .{
......@@ -1554,10 +1560,13 @@ const NavGen = struct {
15541560 return try self.arrayType(1, elem_ty_id);
15551561 } else {
15561562 const result_id = try self.arrayType(total_len, elem_ty_id);
1557 if (self.spv.hasFeature(.shader)) {
1558 try self.spv.decorate(result_id, .{ .ArrayStride = .{
1559 .array_stride = @intCast(elem_ty.abiSize(zcu)),
1560 } });
1563 switch (self.spv.target.os.tag) {
1564 .vulkan, .opengl => {
1565 try self.spv.decorate(result_id, .{ .ArrayStride = .{
1566 .array_stride = @intCast(elem_ty.abiSize(zcu)),
1567 } });
1568 },
1569 else => {},
15611570 }
15621571 return result_id;
15631572 }
......@@ -1688,11 +1697,15 @@ const NavGen = struct {
16881697 continue;
16891698 }
16901699
1691 if (self.spv.hasFeature(.shader)) {
1692 try self.spv.decorateMember(result_id, index, .{ .Offset = .{
1693 .byte_offset = @intCast(ty.structFieldOffset(field_index, zcu)),
1694 } });
1700 switch (self.spv.target.os.tag) {
1701 .vulkan, .opengl => {
1702 try self.spv.decorateMember(result_id, index, .{ .Offset = .{
1703 .byte_offset = @intCast(ty.structFieldOffset(field_index, zcu)),
1704 } });
1705 },
1706 else => {},
16951707 }
1708
16961709 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
16971710 try ip.getOrPutStringFmt(zcu.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
16981711 try member_types.append(try self.resolveType(field_ty, .indirect));
......@@ -1795,28 +1808,23 @@ const NavGen = struct {
17951808 fn spvStorageClass(self: *NavGen, as: std.builtin.AddressSpace) StorageClass {
17961809 return switch (as) {
17971810 .generic => if (self.spv.hasFeature(.generic_pointer)) .Generic else .Function,
1798 .global => {
1799 if (self.spv.hasFeature(.kernel)) return .CrossWorkgroup;
1800 return .StorageBuffer;
1811 .global => switch (self.spv.target.os.tag) {
1812 .opencl, .amdhsa => .CrossWorkgroup,
1813 else => .StorageBuffer,
18011814 },
18021815 .push_constant => {
1803 assert(self.spv.hasFeature(.shader));
18041816 return .PushConstant;
18051817 },
18061818 .output => {
1807 assert(self.spv.hasFeature(.shader));
18081819 return .Output;
18091820 },
18101821 .uniform => {
1811 assert(self.spv.hasFeature(.shader));
18121822 return .Uniform;
18131823 },
18141824 .storage_buffer => {
1815 assert(self.spv.hasFeature(.shader));
18161825 return .StorageBuffer;
18171826 },
18181827 .physical_storage_buffer => {
1819 assert(self.spv.hasFeature(.physical_storage_buffer));
18201828 return .PhysicalStorageBuffer;
18211829 },
18221830 .constant => .UniformConstant,
......@@ -2768,7 +2776,7 @@ const NavGen = struct {
27682776
27692777 const p_error_id = self.spv.allocId();
27702778 switch (target.os.tag) {
2771 .opencl => {
2779 .opencl, .amdhsa => {
27722780 const kernel_proto_ty_id = try self.functionType(Type.void, &.{ptr_anyerror_ty});
27732781
27742782 try section.emit(self.spv.gpa, .OpFunction, .{
......@@ -2876,7 +2884,7 @@ const NavGen = struct {
28762884
28772885 const execution_mode: spec.ExecutionModel = switch (target.os.tag) {
28782886 .vulkan, .opengl => .GLCompute,
2879 .opencl => .Kernel,
2887 .opencl, .amdhsa => .Kernel,
28802888 else => unreachable,
28812889 };
28822890
......@@ -3630,8 +3638,13 @@ const NavGen = struct {
36303638 .integer, .strange_integer => {
36313639 const abs_value = try self.buildUnary(.i_abs, value);
36323640
3633 if (value.ty.intInfo(zcu).signedness == .signed and self.spv.hasFeature(.shader)) {
3634 return self.todo("perform bitcast after @abs", .{});
3641 switch (self.spv.target.os.tag) {
3642 .vulkan, .opengl => {
3643 if (value.ty.intInfo(zcu).signedness == .signed) {
3644 return self.todo("perform bitcast after @abs", .{});
3645 }
3646 },
3647 else => {},
36353648 }
36363649
36373650 return try self.normalize(abs_value, self.arithmeticTypeInfo(result_ty));
......@@ -4156,22 +4169,25 @@ const NavGen = struct {
41564169 defer self.gpa.free(ids);
41574170
41584171 const result_id = self.spv.allocId();
4159 if (self.spv.hasFeature(.addresses)) {
4160 try self.func.body.emit(self.spv.gpa, .OpInBoundsPtrAccessChain, .{
4161 .id_result_type = result_ty_id,
4162 .id_result = result_id,
4163 .base = base,
4164 .element = element,
4165 .indexes = ids,
4166 });
4167 } else {
4168 try self.func.body.emit(self.spv.gpa, .OpPtrAccessChain, .{
4169 .id_result_type = result_ty_id,
4170 .id_result = result_id,
4171 .base = base,
4172 .element = element,
4173 .indexes = ids,
4174 });
4172 switch (self.spv.target.os.tag) {
4173 .opencl, .amdhsa => {
4174 try self.func.body.emit(self.spv.gpa, .OpInBoundsPtrAccessChain, .{
4175 .id_result_type = result_ty_id,
4176 .id_result = result_id,
4177 .base = base,
4178 .element = element,
4179 .indexes = ids,
4180 });
4181 },
4182 else => {
4183 try self.func.body.emit(self.spv.gpa, .OpPtrAccessChain, .{
4184 .id_result_type = result_ty_id,
4185 .id_result = result_id,
4186 .base = base,
4187 .element = element,
4188 .indexes = ids,
4189 });
4190 },
41754191 }
41764192 return result_id;
41774193 }
......@@ -4681,9 +4697,8 @@ const NavGen = struct {
46814697 const field_int_ty = try self.pt.intType(.unsigned, ty_bit_size);
46824698 const field_int_id = blk: {
46834699 if (field_ty.isPtrAtRuntime(zcu)) {
4684 assert(self.spv.hasFeature(.addresses) or
4685 (self.spv.hasFeature(.physical_storage_buffer) and
4686 field_ty.ptrAddressSpace(zcu) == .storage_buffer));
4700 assert(self.spv.target.cpu.arch == .spirv64 and
4701 field_ty.ptrAddressSpace(zcu) == .storage_buffer);
46874702 break :blk try self.intFromPtr(field_id);
46884703 }
46894704 break :blk try self.bitCast(field_int_ty, field_ty, field_id);
......@@ -5333,7 +5348,10 @@ const NavGen = struct {
53335348 .initializer = options.initializer,
53345349 });
53355350
5336 if (self.spv.hasFeature(.shader)) return var_id;
5351 switch (self.spv.target.os.tag) {
5352 .vulkan, .opengl => return var_id,
5353 else => {},
5354 }
53375355
53385356 switch (options.storage_class) {
53395357 .Generic => {
src/codegen/spirv/Module.zig+42-52
......@@ -336,65 +336,55 @@ fn entryPoints(self: *Module) !Section {
336336
337337pub fn finalize(self: *Module, a: Allocator) ![]Word {
338338 // Emit capabilities and extensions
339 for (std.Target.spirv.all_features) |feature| {
340 if (self.target.cpu.features.isEnabled(feature.index)) {
341 const feature_tag: std.Target.spirv.Feature = @enumFromInt(feature.index);
342 switch (feature_tag) {
343 // Versions
344 .v1_0, .v1_1, .v1_2, .v1_3, .v1_4, .v1_5, .v1_6 => {},
345 // Features with no dependencies
346 .int64 => try self.addCapability(.Int64),
347 .float16 => try self.addCapability(.Float16),
348 .float64 => try self.addCapability(.Float64),
349 .matrix => try self.addCapability(.Matrix),
350 .storage_push_constant16 => {
351 try self.addExtension("SPV_KHR_16bit_storage");
352 try self.addCapability(.StoragePushConstant16);
353 },
354 .arbitrary_precision_integers => {
355 try self.addExtension("SPV_INTEL_arbitrary_precision_integers");
356 try self.addCapability(.ArbitraryPrecisionIntegersINTEL);
357 },
358 .addresses => try self.addCapability(.Addresses),
359 // Kernel
360 .kernel => try self.addCapability(.Kernel),
361 .generic_pointer => try self.addCapability(.GenericPointer),
362 .vector16 => try self.addCapability(.Vector16),
363 // Shader
364 .shader => try self.addCapability(.Shader),
365 .variable_pointers => {
366 try self.addExtension("SPV_KHR_variable_pointers");
367 try self.addCapability(.VariablePointersStorageBuffer);
368 try self.addCapability(.VariablePointers);
369 },
370 .physical_storage_buffer => {
371 try self.addExtension("SPV_KHR_physical_storage_buffer");
372 try self.addCapability(.PhysicalStorageBufferAddresses);
373 },
339 switch (self.target.os.tag) {
340 .opengl => {
341 try self.addCapability(.Shader);
342 try self.addCapability(.Matrix);
343 },
344 .vulkan => {
345 try self.addCapability(.Shader);
346 try self.addCapability(.Matrix);
347 if (self.target.cpu.arch == .spirv64) {
348 try self.addExtension("SPV_KHR_physical_storage_buffer");
349 try self.addCapability(.PhysicalStorageBufferAddresses);
374350 }
375 }
351 },
352 .opencl, .amdhsa => {
353 try self.addCapability(.Kernel);
354 try self.addCapability(.Addresses);
355 },
356 else => unreachable,
357 }
358 if (self.target.cpu.arch == .spirv64) try self.addCapability(.Int64);
359 if (self.target.cpu.has(.spirv, .int64)) try self.addCapability(.Int64);
360 if (self.target.cpu.has(.spirv, .float16)) try self.addCapability(.Float16);
361 if (self.target.cpu.has(.spirv, .float64)) try self.addCapability(.Float64);
362 if (self.target.cpu.has(.spirv, .generic_pointer)) try self.addCapability(.GenericPointer);
363 if (self.target.cpu.has(.spirv, .vector16)) try self.addCapability(.Vector16);
364 if (self.target.cpu.has(.spirv, .storage_push_constant16)) {
365 try self.addExtension("SPV_KHR_16bit_storage");
366 try self.addCapability(.StoragePushConstant16);
367 }
368 if (self.target.cpu.has(.spirv, .arbitrary_precision_integers)) {
369 try self.addExtension("SPV_INTEL_arbitrary_precision_integers");
370 try self.addCapability(.ArbitraryPrecisionIntegersINTEL);
371 }
372 if (self.target.cpu.has(.spirv, .variable_pointers)) {
373 try self.addExtension("SPV_KHR_variable_pointers");
374 try self.addCapability(.VariablePointersStorageBuffer);
375 try self.addCapability(.VariablePointers);
376376 }
377377 // These are well supported
378378 try self.addCapability(.Int8);
379379 try self.addCapability(.Int16);
380380
381381 // Emit memory model
382 const addressing_model: spec.AddressingModel = blk: {
383 if (self.hasFeature(.shader)) {
384 if (self.hasFeature(.physical_storage_buffer)) {
385 assert(self.target.cpu.arch == .spirv64);
386 break :blk .PhysicalStorageBuffer64;
387 }
388 assert(self.target.cpu.arch == .spirv);
389 break :blk .Logical;
390 }
391
392 assert(self.hasFeature(.kernel));
393 break :blk switch (self.target.cpu.arch) {
394 .spirv32 => .Physical32,
395 .spirv64 => .Physical64,
396 else => unreachable,
397 };
382 const addressing_model: spec.AddressingModel = switch (self.target.os.tag) {
383 .opengl => .Logical,
384 .vulkan => if (self.target.cpu.arch == .spirv32) .Logical else .PhysicalStorageBuffer64,
385 .opencl => if (self.target.cpu.arch == .spirv32) .Physical32 else .Physical64,
386 .amdhsa => .Physical64,
387 else => unreachable,
398388 };
399389 try self.sections.memory_model.emit(self.gpa, .OpMemoryModel, .{
400390 .addressing_model = addressing_model,
src/dev.zig+3-3
......@@ -88,7 +88,7 @@ pub const Env = enum {
8888 .powerpc_backend,
8989 .riscv64_backend,
9090 .sparc64_backend,
91 .spirv64_backend,
91 .spirv_backend,
9292 .lld_linker,
9393 .coff_linker,
9494 .elf_linker,
......@@ -183,7 +183,7 @@ pub const Env = enum {
183183 else => Env.sema.supports(feature),
184184 },
185185 .spirv => switch (feature) {
186 .spirv64_backend,
186 .spirv_backend,
187187 .spirv_linker,
188188 => true,
189189 else => Env.sema.supports(feature),
......@@ -258,7 +258,7 @@ pub const Feature = enum {
258258 powerpc_backend,
259259 riscv64_backend,
260260 sparc64_backend,
261 spirv64_backend,
261 spirv_backend,
262262
263263 lld_linker,
264264 coff_linker,
src/link/SpirV.zig+1-1
......@@ -64,7 +64,7 @@ pub fn createEmpty(
6464 assert(!comp.config.use_llvm); // Caught by Compilation.Config.resolve
6565 assert(target.ofmt == .spirv); // Caught by Compilation.Config.resolve
6666 switch (target.cpu.arch) {
67 .spirv, .spirv32, .spirv64 => {},
67 .spirv32, .spirv64 => {},
6868 else => unreachable, // Caught by Compilation.Config.resolve.
6969 }
7070 switch (target.os.tag) {
src/target.zig+6-9
......@@ -179,7 +179,6 @@ pub fn hasLlvmSupport(target: *const std.Target, ofmt: std.Target.ObjectFormat)
179179 .riscv64,
180180 .sparc,
181181 .sparc64,
182 .spirv,
183182 .spirv32,
184183 .spirv64,
185184 .s390x,
......@@ -241,7 +240,7 @@ pub fn supportsStackProtector(target: *const std.Target, backend: std.builtin.Co
241240 else => {},
242241 }
243242 switch (target.cpu.arch) {
244 .spirv, .spirv32, .spirv64 => return false,
243 .spirv32, .spirv64 => return false,
245244 else => {},
246245 }
247246 return switch (backend) {
......@@ -252,7 +251,7 @@ pub fn supportsStackProtector(target: *const std.Target, backend: std.builtin.Co
252251
253252pub fn clangSupportsStackProtector(target: *const std.Target) bool {
254253 return switch (target.cpu.arch) {
255 .spirv, .spirv32, .spirv64 => return false,
254 .spirv32, .spirv64 => return false,
256255 else => true,
257256 };
258257}
......@@ -270,7 +269,7 @@ pub fn supportsReturnAddress(target: *const std.Target, optimize: std.builtin.Op
270269 // overhead that we would prefer to avoid in release builds.
271270 .wasm32, .wasm64 => target.os.tag == .emscripten and optimize == .Debug,
272271 .bpfel, .bpfeb => false,
273 .spirv, .spirv32, .spirv64 => false,
272 .spirv32, .spirv64 => false,
274273 else => true,
275274 };
276275}
......@@ -335,7 +334,7 @@ pub fn canBuildLibCompilerRt(target: *const std.Target, use_llvm: bool, have_llv
335334 else => {},
336335 }
337336 switch (target.cpu.arch) {
338 .spirv, .spirv32, .spirv64 => return false,
337 .spirv32, .spirv64 => return false,
339338 // Remove this once https://github.com/ziglang/zig/issues/23714 is fixed
340339 .amdgcn => return false,
341340 else => {},
......@@ -352,7 +351,7 @@ pub fn canBuildLibCompilerRt(target: *const std.Target, use_llvm: bool, have_llv
352351
353352pub fn canBuildLibUbsanRt(target: *const std.Target) bool {
354353 switch (target.cpu.arch) {
355 .spirv, .spirv32, .spirv64 => return false,
354 .spirv32, .spirv64 => return false,
356355 // Remove this once https://github.com/ziglang/zig/issues/23715 is fixed
357356 .nvptx, .nvptx64 => return false,
358357 else => return true,
......@@ -719,7 +718,6 @@ pub fn supportsFunctionAlignment(target: *const std.Target) bool {
719718 return switch (target.cpu.arch) {
720719 .nvptx,
721720 .nvptx64,
722 .spirv,
723721 .spirv32,
724722 .spirv64,
725723 .wasm32,
......@@ -816,8 +814,7 @@ pub fn zigBackend(target: *const std.Target, use_llvm: bool) std.builtin.Compile
816814 .powerpc, .powerpcle, .powerpc64, .powerpc64le => .stage2_powerpc,
817815 .riscv64 => .stage2_riscv64,
818816 .sparc64 => .stage2_sparc64,
819 .spirv32 => if (target.os.tag == .opencl) .stage2_spirv else .other,
820 .spirv, .spirv64 => .stage2_spirv,
817 .spirv32, .spirv64 => .stage2_spirv,
821818 .wasm32, .wasm64 => .stage2_wasm,
822819 .x86 => .stage2_x86,
823820 .x86_64 => .stage2_x86_64,
test/behavior/type_info.zig-1
......@@ -389,7 +389,6 @@ fn testFunction() !void {
389389
390390 // Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment.
391391 switch (builtin.target.cpu.arch) {
392 .spirv,
393392 .spirv32,
394393 .spirv64,
395394 .wasm32,
test/cases/compile_errors/function_alignment_on_unsupported_target.zig+1-1
......@@ -2,6 +2,6 @@ export fn entry() align(64) void {}
22
33// error
44// backend=stage2
5// target=nvptx-cuda,nvptx64-cuda,spirv-vulkan,spirv32-opencl,spirv64-opencl,wasm32-freestanding,wasm64-freestanding
5// target=nvptx-cuda,nvptx64-cuda,spirv32-opengl,spirv32-vulkan,spirv32-opencl,spirv64-opencl,spirv64-amdhsa,wasm32-freestanding,wasm64-freestanding
66//
77// :1:25: error: target does not support function alignment
test/tests.zig+2-2
......@@ -1440,7 +1440,7 @@ const test_targets = blk: {
14401440 .{
14411441 .target = std.Target.Query.parse(.{
14421442 .arch_os_abi = "spirv64-vulkan",
1443 .cpu_features = "vulkan_v1_2+physical_storage_buffer+int64+float16+float64",
1443 .cpu_features = "vulkan_v1_2+float16+float64",
14441444 }) catch unreachable,
14451445 .use_llvm = false,
14461446 .use_lld = false,
......@@ -2527,7 +2527,7 @@ fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: Optimiz
25272527 const cpu_arch = query.cpu_arch orelse builtin.cpu.arch;
25282528 switch (cpu_arch) {
25292529 .x86_64 => if (std.Target.ptrBitWidth_arch_abi(cpu_arch, query.abi orelse .none) != 64) return true,
2530 .spirv, .spirv32, .spirv64 => return false,
2530 .spirv32, .spirv64 => return false,
25312531 else => return true,
25322532 }
25332533 return false;
tools/update_cpu_features.zig+4-29
......@@ -1105,11 +1105,6 @@ const targets = [_]ArchTarget{
11051105 .desc = "Enable Float64 capability",
11061106 .deps = &.{"v1_0"},
11071107 },
1108 .{
1109 .zig_name = "matrix",
1110 .desc = "Enable Matrix capability",
1111 .deps = &.{"v1_0"},
1112 },
11131108 .{
11141109 .zig_name = "storage_push_constant16",
11151110 .desc = "Enable SPV_KHR_16bit_storage extension and the StoragePushConstant16 capability",
......@@ -1120,52 +1115,32 @@ const targets = [_]ArchTarget{
11201115 .desc = "Enable SPV_INTEL_arbitrary_precision_integers extension and the ArbitraryPrecisionIntegersINTEL capability",
11211116 .deps = &.{"v1_5"},
11221117 },
1123 .{
1124 .zig_name = "kernel",
1125 .desc = "Enable Kernel capability",
1126 .deps = &.{"v1_0"},
1127 },
1128 .{
1129 .zig_name = "addresses",
1130 .desc = "Enable Addresses capability",
1131 .deps = &.{"v1_0"},
1132 },
11331118 .{
11341119 .zig_name = "generic_pointer",
11351120 .desc = "Enable GenericPointer capability",
1136 .deps = &.{ "v1_0", "addresses" },
1121 .deps = &.{"v1_0"},
11371122 },
11381123 .{
11391124 .zig_name = "vector16",
11401125 .desc = "Enable Vector16 capability",
1141 .deps = &.{ "v1_0", "kernel" },
1142 },
1143 .{
1144 .zig_name = "shader",
1145 .desc = "Enable Shader capability",
1146 .deps = &.{ "v1_0", "matrix" },
1126 .deps = &.{"v1_0"},
11471127 },
11481128 .{
11491129 .zig_name = "variable_pointers",
11501130 .desc = "Enable SPV_KHR_physical_storage_buffer extension and the PhysicalStorageBufferAddresses capability",
11511131 .deps = &.{"v1_0"},
11521132 },
1153 .{
1154 .zig_name = "physical_storage_buffer",
1155 .desc = "Enable SPV_KHR_variable_pointers extension and the (VariablePointers, VariablePointersStorageBuffer) capabilities",
1156 .deps = &.{"v1_0"},
1157 },
11581133 },
11591134 .extra_cpus = &.{
11601135 .{
11611136 .llvm_name = null,
11621137 .zig_name = "vulkan_v1_2",
1163 .features = &.{ "v1_5", "shader" },
1138 .features = &.{"v1_5"},
11641139 },
11651140 .{
11661141 .llvm_name = null,
11671142 .zig_name = "opencl_v2",
1168 .features = &.{ "v1_2", "kernel", "addresses", "generic_pointer" },
1143 .features = &.{"v1_2"},
11691144 },
11701145 },
11711146 },