authorgravatar for gwenzek@users.noreply.github.comGuillaume Wenzek <gwenzek@users.noreply.github.com> 2022-11-16 10:50:35+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 14:17:29-07:00
log91b8d9e370f0dfc62f7bf7297ce9a7e22bae9f67
tree38b4646e8ddbb1d014554f29def1eb08d185d51f
parent6064477928421c748c01db5e84401c4f9e220125

fix Nvptx backend outputing files at the top level of zig-cache


2 files changed, 7 insertions(+), 3 deletions(-)

lib/std/zig.zig+1-1
...@@ -193,7 +193,7 @@ pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error...@@ -193,7 +193,7 @@ pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error
193 target.libPrefix(), root_name,193 target.libPrefix(), root_name,
194 }),194 }),
195 },195 },
196 .nvptx => return std.fmt.allocPrint(allocator, "{s}", .{root_name}),196 .nvptx => return std.fmt.allocPrint(allocator, "{s}.ptx", .{root_name}),
197 .dxcontainer => @panic("TODO what's the file extension for these?"),197 .dxcontainer => @panic("TODO what's the file extension for these?"),
198 }198 }
199}199}
src/link/NvPtx.zig+6-2
...@@ -23,6 +23,7 @@ const LlvmObject = @import("../codegen/llvm.zig").Object;...@@ -23,6 +23,7 @@ const LlvmObject = @import("../codegen/llvm.zig").Object;
2323
24base: link.File,24base: link.File,
25llvm_object: *LlvmObject,25llvm_object: *LlvmObject,
26ptx_file_name: []const u8,
2627
27pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {28pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
28 if (!build_options.have_llvm) return error.PtxArchNotSupported;29 if (!build_options.have_llvm) return error.PtxArchNotSupported;
...@@ -46,6 +47,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {...@@ -46,6 +47,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
46 .allocator = gpa,47 .allocator = gpa,
47 },48 },
48 .llvm_object = llvm_object,49 .llvm_object = llvm_object,
50 .ptx_file_name = try std.mem.join(gpa, "", &[_][]const u8{ options.root_name, ".ptx" }),
49 };51 };
5052
51 return nvptx;53 return nvptx;
...@@ -63,6 +65,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -63,6 +65,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
63pub fn deinit(self: *NvPtx) void {65pub fn deinit(self: *NvPtx) void {
64 if (!build_options.have_llvm) return;66 if (!build_options.have_llvm) return;
65 self.llvm_object.destroy(self.base.allocator);67 self.llvm_object.destroy(self.base.allocator);
68 self.base.allocator.free(self.ptx_file_name);
66}69}
6770
68pub fn updateFunc(self: *NvPtx, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {71pub fn updateFunc(self: *NvPtx, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
...@@ -111,8 +114,9 @@ pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.No...@@ -111,8 +114,9 @@ pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.No
111 // This is required by the LLVM PTX backend.114 // This is required by the LLVM PTX backend.
112 comp.bin_file.options.emit = null;115 comp.bin_file.options.emit = null;
113 comp.emit_asm = .{116 comp.emit_asm = .{
114 .directory = outfile.directory,117 // 'null' means using the default cache dir: zig-cache/o/...
115 .basename = comp.bin_file.intermediary_basename.?,118 .directory = null,
119 .basename = self.ptx_file_name,
116 };120 };
117 defer {121 defer {
118 comp.bin_file.options.emit = outfile;122 comp.bin_file.options.emit = outfile;