From ab607d455e47c35b980c3281ef5c3fb433a770a7 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Sun, 17 Jan 2021 16:18:00 +0100 Subject: SPIR-V: Initial architecture definitions and setup --- lib/std/target.zig | 23 +++++++++++++++++++++++ lib/std/zig.zig | 1 + lib/std/zig/cross_target.zig | 2 ++ src/link.zig | 8 ++++++++ src/type.zig | 1 + 5 files changed, 35 insertions(+) diff --git a/lib/std/target.zig b/lib/std/target.zig index 155ba046d2..b3e0f8afdd 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -57,6 +57,7 @@ pub const Target = struct { wasi, emscripten, uefi, + opencl, // SPIR-V on OpenCL other, pub fn isDarwin(tag: Tag) bool { @@ -248,6 +249,7 @@ pub const Target = struct { .wasi, .emscripten, .uefi, + .opencl, .other, => return .{ .none = {} }, @@ -403,6 +405,7 @@ pub const Target = struct { .wasi, .emscripten, .uefi, + .opencl, .other, => false, }; @@ -421,6 +424,7 @@ pub const Target = struct { pub const powerpc = @import("target/powerpc.zig"); pub const riscv = @import("target/riscv.zig"); pub const sparc = @import("target/sparc.zig"); + pub const spirv = @import("target/spirv.zig"); pub const systemz = @import("target/systemz.zig"); pub const wasm = @import("target/wasm.zig"); pub const x86 = @import("target/x86.zig"); @@ -493,6 +497,8 @@ pub const Target = struct { .wasi, .emscripten, => return .musl, + .opencl, // TODO: Where should this go? + => return .none, } } @@ -528,6 +534,7 @@ pub const Target = struct { macho, wasm, c, + spirv, hex, raw, }; @@ -744,6 +751,8 @@ pub const Target = struct { // Stage1 currently assumes that architectures above this comment // map one-to-one with the ZigLLVM_ArchType enum. spu_2, + spirv32, + spirv64, pub fn isARM(arch: Arch) bool { return switch (arch) { @@ -857,6 +866,8 @@ pub const Target = struct { .s390x => ._S390, .ve => ._NONE, .spu_2 => ._SPU_2, + .spirv32 => ._NONE, + .spirv64 => ._NONE, }; } @@ -914,6 +925,8 @@ pub const Target = struct { .s390x => .Unknown, .ve => .Unknown, .spu_2 => .Unknown, + .spirv32 => .Unknown, + .spirv64 => .Unknown, }; } @@ -957,6 +970,9 @@ pub const Target = struct { .shave, .ve, .spu_2, + // GPU bitness is opaque. For now, assume little endian. + .spirv32, + .spirv64, => .Little, .arc, @@ -1012,6 +1028,7 @@ pub const Target = struct { .wasm32, .renderscript32, .aarch64_32, + .spirv32, => return 32, .aarch64, @@ -1035,6 +1052,7 @@ pub const Target = struct { .sparcv9, .s390x, .ve, + .spirv64, => return 64, } } @@ -1057,6 +1075,7 @@ pub const Target = struct { .i386, .x86_64 => "x86", .nvptx, .nvptx64 => "nvptx", .wasm32, .wasm64 => "wasm", + .spirv32, .spirv64 => "spir-v", else => @tagName(arch), }; } @@ -1347,6 +1366,7 @@ pub const Target = struct { .uefi, .windows, .emscripten, + .opencl, .other, => return false, else => return true, @@ -1482,6 +1502,8 @@ pub const Target = struct { .nvptx64, .spu_2, .avr, + .spirv32, + .spirv64, => return result, // TODO go over each item in this list and either move it to the above list, or @@ -1524,6 +1546,7 @@ pub const Target = struct { .windows, .emscripten, .wasi, + .opencl, .other, => return result, diff --git a/lib/std/zig.zig b/lib/std/zig.zig index c39eb6b05f..dd75b81597 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -141,6 +141,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro .Lib => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}), }, .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}), + .spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}), .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}), .raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}), } diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index f0849f9a03..1e9066b90b 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -130,6 +130,7 @@ pub const CrossTarget = struct { .wasi, .emscripten, .uefi, + .opencl, .other, => { self.os_version_min = .{ .none = {} }; @@ -730,6 +731,7 @@ pub const CrossTarget = struct { .wasi, .emscripten, .uefi, + .opencl, .other, => return error.InvalidOperatingSystemVersion, diff --git a/src/link.zig b/src/link.zig index 6914131bea..fdbb7efd4b 100644 --- a/src/link.zig +++ b/src/link.zig @@ -133,6 +133,7 @@ pub const File = struct { macho: MachO.TextBlock, c: C.DeclBlock, wasm: void, + spirv: void, }; pub const LinkFn = union { @@ -141,6 +142,7 @@ pub const File = struct { macho: MachO.SrcFn, c: C.FnBlock, wasm: ?Wasm.FnData, + spirv: void, }; pub const Export = union { @@ -149,6 +151,7 @@ pub const File = struct { macho: MachO.Export, c: void, wasm: void, + spirv: void, }; /// For DWARF .debug_info. @@ -177,6 +180,7 @@ pub const File = struct { .macho => &(try MachO.createEmpty(allocator, options)).base, .wasm => &(try Wasm.createEmpty(allocator, options)).base, .c => unreachable, // Reported error earlier. + .spirv => return error.SpirVObjectFormatUnimplemented, .hex => return error.HexObjectFormatUnimplemented, .raw => return error.RawObjectFormatUnimplemented, }; @@ -192,6 +196,7 @@ pub const File = struct { .macho => &(try MachO.createEmpty(allocator, options)).base, .wasm => &(try Wasm.createEmpty(allocator, options)).base, .c => unreachable, // Reported error earlier. + .spirv => return error.SpirVObjectFormatUnimplemented, .hex => return error.HexObjectFormatUnimplemented, .raw => return error.RawObjectFormatUnimplemented, }; @@ -207,6 +212,7 @@ pub const File = struct { .macho => &(try MachO.openPath(allocator, sub_path, options)).base, .wasm => &(try Wasm.openPath(allocator, sub_path, options)).base, .c => &(try C.openPath(allocator, sub_path, options)).base, + .spirv => return error.SpirVObjectFormatUnimplemented, .hex => return error.HexObjectFormatUnimplemented, .raw => return error.RawObjectFormatUnimplemented, }; @@ -595,6 +601,7 @@ pub const File = struct { macho, c, wasm, + spirv, }; pub const ErrorFlags = struct { @@ -605,6 +612,7 @@ pub const File = struct { pub const Coff = @import("link/Coff.zig"); pub const Elf = @import("link/Elf.zig"); pub const MachO = @import("link/MachO.zig"); + pub const SpirV = @import("link/SpirV.zig"); pub const Wasm = @import("link/Wasm.zig"); }; diff --git a/src/type.zig b/src/type.zig index be61f57c1d..cb2448aa1a 100644 --- a/src/type.zig +++ b/src/type.zig @@ -3597,6 +3597,7 @@ pub const CType = enum { .amdpal, .hermit, .hurd, + .opencl, => @panic("TODO specify the C integer and float type sizes for this OS"), } } -- cgit v1.2.3