aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Wenzek <gwenzek@users.noreply.github.com>2022-09-16 22:21:14 +0200
committerAndrew Kelley <andrew@ziglang.org>2022-10-15 10:39:19 -0700
commitaad983cf40dad209ccc79b1e5ef4531e1b4d4ca7 (patch)
treefc56b5007f1a66e8b1e693e33518a9c937140435 /src
parent92a857b76c9a6ff7b885b623ae86844ca77ed646 (diff)
downloadzig-aad983cf40dad209ccc79b1e5ef4531e1b4d4ca7.tar.gz
zig-aad983cf40dad209ccc79b1e5ef4531e1b4d4ca7.zip
sanitize qualified name for nvptx backend
Diffstat (limited to 'src')
-rw-r--r--src/Module.zig9
-rw-r--r--src/link/NvPtx.zig20
-rw-r--r--src/target.zig13
3 files changed, 19 insertions, 23 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 7d87bdba53..fd5cf29516 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -720,6 +720,15 @@ pub const Decl = struct {
var buffer = std.ArrayList(u8).init(mod.gpa);
defer buffer.deinit();
try decl.renderFullyQualifiedName(mod, buffer.writer());
+
+ // Sanitize the name for nvptx which is more restrictive.
+ if (mod.comp.bin_file.options.target.cpu.arch.isNvptx()) {
+ for (buffer.items) |*byte| switch (byte.*) {
+ '{', '}', '*', '[', ']', '(', ')', ',', ' ', '\'' => byte.* = '_',
+ else => {},
+ };
+ }
+
return buffer.toOwnedSliceSentinel(0);
}
diff --git a/src/link/NvPtx.zig b/src/link/NvPtx.zig
index 501575fafb..4873511d55 100644
--- a/src/link/NvPtx.zig
+++ b/src/link/NvPtx.zig
@@ -28,10 +28,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
if (!build_options.have_llvm) return error.PtxArchNotSupported;
if (!options.use_llvm) return error.PtxArchNotSupported;
- switch (options.target.cpu.arch) {
- .nvptx, .nvptx64 => {},
- else => return error.PtxArchNotSupported,
- }
+ if (!options.target.cpu.arch.isNvptx()) return error.PtxArchNotSupported;
switch (options.target.os.tag) {
// TODO: does it also work with nvcl ?
@@ -59,9 +56,8 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
if (!options.use_llvm) return error.PtxArchNotSupported;
assert(options.target.ofmt == .nvptx);
- const nvptx = try createEmpty(allocator, options);
- log.info("Opening .ptx target file {s}", .{sub_path});
- return nvptx;
+ log.debug("Opening .ptx target file {s}", .{sub_path});
+ return createEmpty(allocator, options);
}
pub fn deinit(self: *NvPtx) void {
@@ -76,15 +72,7 @@ pub fn updateFunc(self: *NvPtx, module: *Module, func: *Module.Fn, air: Air, liv
pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {
if (!build_options.have_llvm) return;
- const decl = module.declPtr(decl_index);
- log.info("updating {s}", .{decl.name});
return self.llvm_object.updateDecl(module, decl_index);
- // const decl_index = func.owner_decl;
- // const decl = module.declPtr(decl_index);
-
- // try mod.decl_exports.ensureUnusedCapacity(gpa, 1);
- // try mod.export_owners.ensureUnusedCapacity(gpa, 1);
- // mod.decl_exports.getOrPutAssumeCapacity(exported_decl_index);
}
pub fn updateDeclExports(
@@ -118,7 +106,7 @@ pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.No
defer tracy.end();
const outfile = comp.bin_file.options.emit.?;
- // !!! We modify 'comp' before passing it to LLVM, but restore value afterwards
+ // We modify 'comp' before passing it to LLVM, but restore value afterwards.
// We tell LLVM to not try to build a .o, only an "assembly" file.
// This is required by the LLVM PTX backend.
comp.bin_file.options.emit = null;
diff --git a/src/target.zig b/src/target.zig
index 2c05a80258..01db8555da 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -411,13 +411,12 @@ pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerR
}
pub fn hasDebugInfo(target: std.Target) bool {
- return switch (target.cpu.arch) {
- .nvptx, .nvptx64 => {
- // TODO: not sure to test "ptx >= 7.5" with featureset
- return std.Target.nvptx.featureSetHas(target.cpu.features, .ptx75);
- },
- else => true
- };
+ if (target.cpu.arch.isNvptx()) {
+ // TODO: not sure how to test "ptx >= 7.5" with featureset
+ return std.Target.nvptx.featureSetHas(target.cpu.features, .ptx75);
+ }
+
+ return true;
}
pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.Mode {