Skip to content

Commit

Permalink
all: Handle spirv in addition to spirv(32,64) where applicable.
Browse files Browse the repository at this point in the history
Some of this is arbitrary since spirv (as opposed to spirv32/spirv64) refers to
the version with logical memory layout, i.e. no 'real' pointers. This change at
least matches what clang does.
  • Loading branch information
alexrp committed Aug 12, 2024
1 parent 25096ed commit 442d04e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
14 changes: 7 additions & 7 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ pub const Cpu = struct {

pub inline fn isSpirV(arch: Arch) bool {
return switch (arch) {
.spirv32, .spirv64 => true,
.spirv, .spirv32, .spirv64 => true,
else => false,
};
}
Expand Down Expand Up @@ -1349,8 +1349,8 @@ pub const Cpu = struct {

/// Returns whether this architecture supports the address space
pub fn supportsAddressSpace(arch: Arch, address_space: std.builtin.AddressSpace) bool {
const is_nvptx = arch == .nvptx or arch == .nvptx64;
const is_spirv = arch == .spirv32 or arch == .spirv64;
const is_nvptx = arch.isNvptx();
const is_spirv = arch.isSpirV();
const is_gpu = is_nvptx or is_spirv or arch == .amdgcn;
return switch (address_space) {
.generic => true,
Expand Down Expand Up @@ -1379,7 +1379,7 @@ pub const Cpu = struct {
.x86, .x86_64 => "x86",
.nvptx, .nvptx64 => "nvptx",
.wasm32, .wasm64 => "wasm",
.spirv32, .spirv64 => "spirv",
.spirv, .spirv32, .spirv64 => "spirv",
else => @tagName(arch),
};
}
Expand All @@ -1402,7 +1402,7 @@ pub const Cpu = struct {
.amdgcn => &amdgpu.all_features,
.riscv32, .riscv64 => &riscv.all_features,
.sparc, .sparc64 => &sparc.all_features,
.spirv32, .spirv64 => &spirv.all_features,
.spirv, .spirv32, .spirv64 => &spirv.all_features,
.s390x => &s390x.all_features,
.x86, .x86_64 => &x86.all_features,
.xtensa => &xtensa.all_features,
Expand Down Expand Up @@ -1432,7 +1432,7 @@ pub const Cpu = struct {
.amdgcn => comptime allCpusFromDecls(amdgpu.cpu),
.riscv32, .riscv64 => comptime allCpusFromDecls(riscv.cpu),
.sparc, .sparc64 => comptime allCpusFromDecls(sparc.cpu),
.spirv32, .spirv64 => comptime allCpusFromDecls(spirv.cpu),
.spirv, .spirv32, .spirv64 => comptime allCpusFromDecls(spirv.cpu),
.s390x => comptime allCpusFromDecls(s390x.cpu),
.x86, .x86_64 => comptime allCpusFromDecls(x86.cpu),
.xtensa => comptime allCpusFromDecls(xtensa.cpu),
Expand Down Expand Up @@ -1522,7 +1522,7 @@ pub const Cpu = struct {
.amdgcn => &amdgpu.cpu.generic,
.riscv32 => &riscv.cpu.generic_rv32,
.riscv64 => &riscv.cpu.generic_rv64,
.spirv32, .spirv64 => &spirv.cpu.generic,
.spirv, .spirv32, .spirv64 => &spirv.cpu.generic,
.sparc => &sparc.cpu.generic,
.sparc64 => &sparc.cpu.v9, // 64-bit SPARC needs v9 as the baseline
.s390x => &s390x.cpu.generic,
Expand Down
4 changes: 2 additions & 2 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6266,7 +6266,7 @@ fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool) bool {
else => {},
}
switch (target.cpu.arch) {
.spirv32, .spirv64 => return false,
.spirv, .spirv32, .spirv64 => return false,
else => {},
}
return switch (target_util.zigBackend(target, use_llvm)) {
Expand All @@ -6284,7 +6284,7 @@ fn canBuildZigLibC(target: std.Target, use_llvm: bool) bool {
else => {},
}
switch (target.cpu.arch) {
.spirv32, .spirv64 => return false,
.spirv, .spirv32, .spirv64 => return false,
else => {},
}
return switch (target_util.zigBackend(target, use_llvm)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10038,11 +10038,11 @@ fn finishFunc(
else => "x86_64",
},
.Kernel => switch (arch) {
.nvptx, .nvptx64, .amdgcn, .spirv32, .spirv64 => null,
.nvptx, .nvptx64, .amdgcn, .spirv, .spirv32, .spirv64 => null,
else => "nvptx, amdgcn and SPIR-V",
},
.Fragment, .Vertex => switch (arch) {
.spirv32, .spirv64 => null,
.spirv, .spirv32, .spirv64 => null,
else => "SPIR-V",
},
})) |allowed_platform| {
Expand Down Expand Up @@ -26703,7 +26703,7 @@ fn zirWorkItem(

switch (target.cpu.arch) {
// TODO: Allow for other GPU targets.
.amdgcn, .spirv64, .spirv32 => {},
.amdgcn, .spirv, .spirv64, .spirv32 => {},
else => {
return sema.fail(block, builtin_src, "builtin only available on GPU targets; targeted architecture is {s}", .{@tagName(target.cpu.arch)});
},
Expand Down Expand Up @@ -37323,9 +37323,9 @@ pub fn analyzeAsAddressSpace(
const target = pt.zcu.getTarget();
const arch = target.cpu.arch;

const is_nv = arch == .nvptx or arch == .nvptx64;
const is_nv = arch.isNvptx();
const is_amd = arch == .amdgcn;
const is_spirv = arch == .spirv32 or arch == .spirv64;
const is_spirv = arch.isSpirV();
const is_gpu = is_nv or is_amd or is_spirv;

const supported = switch (address_space) {
Expand Down
3 changes: 1 addition & 2 deletions src/Zcu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2910,6 +2910,7 @@ pub fn atomicPtrAlignment(
.s390x,
.wasm64,
.ve,
.spirv,
.spirv64,
.loongarch64,
=> 64,
Expand All @@ -2919,8 +2920,6 @@ pub fn atomicPtrAlignment(
=> 128,

.x86_64 => if (std.Target.x86.featureSetHas(target.cpu.features, .cx16)) 128 else 64,

.spirv => @panic("TODO what should this value be?"),
};

if (ty.toIntern() == .bool_type) return .none;
Expand Down
2 changes: 1 addition & 1 deletion src/link/SpirV.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn createEmpty(
errdefer self.deinit();

switch (target.cpu.arch) {
.spirv32, .spirv64 => {},
.spirv, .spirv32, .spirv64 => {},
else => unreachable, // Caught by Compilation.Config.resolve.
}

Expand Down
6 changes: 3 additions & 3 deletions src/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerB
else => {},
}
switch (target.cpu.arch) {
.spirv32, .spirv64 => return false,
.spirv, .spirv32, .spirv64 => return false,
else => {},
}
return switch (backend) {
Expand All @@ -207,7 +207,7 @@ pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerB

pub fn clangSupportsStackProtector(target: std.Target) bool {
return switch (target.cpu.arch) {
.spirv32, .spirv64 => return false,
.spirv, .spirv32, .spirv64 => return false,
else => true,
};
}
Expand All @@ -220,7 +220,7 @@ pub fn supportsReturnAddress(target: std.Target) bool {
return switch (target.cpu.arch) {
.wasm32, .wasm64 => target.os.tag == .emscripten,
.bpfel, .bpfeb => false,
.spirv32, .spirv64 => false,
.spirv, .spirv32, .spirv64 => false,
else => true,
};
}
Expand Down

0 comments on commit 442d04e

Please sign in to comment.