authorgravatar for gwenzek@users.noreply.github.comGuillaume Wenzek <gwenzek@users.noreply.github.com> 2022-09-16 22:21:14+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-15 10:39:19-07:00
logaad983cf40dad209ccc79b1e5ef4531e1b4d4ca7
treefc56b5007f1a66e8b1e693e33518a9c937140435
parent92a857b76c9a6ff7b885b623ae86844ca77ed646

sanitize qualified name for nvptx backend


4 files changed, 26 insertions(+), 23 deletions(-)

lib/std/target.zig+7
......@@ -951,6 +951,13 @@ pub const Target = struct {
951951 };
952952 }
953953
954 pub fn isNvptx(arch: Arch) bool {
955 return switch (arch) {
956 .nvptx, .nvptx64 => true,
957 else => false,
958 };
959 }
960
954961 pub fn parseCpuModel(arch: Arch, cpu_name: []const u8) !*const Cpu.Model {
955962 for (arch.allCpuModels()) |cpu| {
956963 if (mem.eql(u8, cpu_name, cpu.name)) {
src/Module.zig+9
......@@ -720,6 +720,15 @@ pub const Decl = struct {
720720 var buffer = std.ArrayList(u8).init(mod.gpa);
721721 defer buffer.deinit();
722722 try decl.renderFullyQualifiedName(mod, buffer.writer());
723
724 // Sanitize the name for nvptx which is more restrictive.
725 if (mod.comp.bin_file.options.target.cpu.arch.isNvptx()) {
726 for (buffer.items) |*byte| switch (byte.*) {
727 '{', '}', '*', '[', ']', '(', ')', ',', ' ', '\'' => byte.* = '_',
728 else => {},
729 };
730 }
731
723732 return buffer.toOwnedSliceSentinel(0);
724733 }
725734
src/link/NvPtx.zig+4-16
......@@ -28,10 +28,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
2828 if (!build_options.have_llvm) return error.PtxArchNotSupported;
2929 if (!options.use_llvm) return error.PtxArchNotSupported;
3030
31 switch (options.target.cpu.arch) {
32 .nvptx, .nvptx64 => {},
33 else => return error.PtxArchNotSupported,
34 }
31 if (!options.target.cpu.arch.isNvptx()) return error.PtxArchNotSupported;
3532
3633 switch (options.target.os.tag) {
3734 // TODO: does it also work with nvcl ?
......@@ -59,9 +56,8 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
5956 if (!options.use_llvm) return error.PtxArchNotSupported;
6057 assert(options.target.ofmt == .nvptx);
6158
62 const nvptx = try createEmpty(allocator, options);
63 log.info("Opening .ptx target file {s}", .{sub_path});
64 return nvptx;
59 log.debug("Opening .ptx target file {s}", .{sub_path});
60 return createEmpty(allocator, options);
6561}
6662
6763pub fn deinit(self: *NvPtx) void {
......@@ -76,15 +72,7 @@ pub fn updateFunc(self: *NvPtx, module: *Module, func: *Module.Fn, air: Air, liv
7672
7773pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {
7874 if (!build_options.have_llvm) return;
79 const decl = module.declPtr(decl_index);
80 log.info("updating {s}", .{decl.name});
8175 return self.llvm_object.updateDecl(module, decl_index);
82 // const decl_index = func.owner_decl;
83 // const decl = module.declPtr(decl_index);
84
85 // try mod.decl_exports.ensureUnusedCapacity(gpa, 1);
86 // try mod.export_owners.ensureUnusedCapacity(gpa, 1);
87 // mod.decl_exports.getOrPutAssumeCapacity(exported_decl_index);
8876}
8977
9078pub fn updateDeclExports(
......@@ -118,7 +106,7 @@ pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.No
118106 defer tracy.end();
119107
120108 const outfile = comp.bin_file.options.emit.?;
121 // !!! We modify 'comp' before passing it to LLVM, but restore value afterwards
109 // We modify 'comp' before passing it to LLVM, but restore value afterwards.
122110 // We tell LLVM to not try to build a .o, only an "assembly" file.
123111 // This is required by the LLVM PTX backend.
124112 comp.bin_file.options.emit = null;
src/target.zig+6-7
......@@ -411,13 +411,12 @@ pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerR
411411}
412412
413413pub fn hasDebugInfo(target: std.Target) bool {
414 return switch (target.cpu.arch) {
415 .nvptx, .nvptx64 => {
416 // TODO: not sure to test "ptx >= 7.5" with featureset
417 return std.Target.nvptx.featureSetHas(target.cpu.features, .ptx75);
418 },
419 else => true
420 };
414 if (target.cpu.arch.isNvptx()) {
415 // TODO: not sure how to test "ptx >= 7.5" with featureset
416 return std.Target.nvptx.featureSetHas(target.cpu.features, .ptx75);
417 }
418
419 return true;
421420}
422421
423422pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.Mode {