Skip to content

Commit

Permalink
introduces Gpu address spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenzek committed Feb 17, 2022
1 parent 5aa35f6 commit 632e147
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ pub const AddressSpace = enum {
gs,
fs,
ss,
// GPU address spaces
global,
constant,
param,
shared,
local,
};

/// This data structure is used by the Zig language code generation and
Expand Down
4 changes: 3 additions & 1 deletion src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17747,10 +17747,13 @@ pub fn analyzeAddrspace(
const address_space = addrspace_tv.val.toEnum(std.builtin.AddressSpace);
const target = sema.mod.getTarget();
const arch = target.cpu.arch;
const is_gpu = arch == .nvptx or arch == .nvptx64;

const supported = switch (address_space) {
.generic => true,
.gs, .fs, .ss => (arch == .i386 or arch == .x86_64) and ctx == .pointer,
.global, .param, .shared, .local => is_gpu,
.constant => is_gpu and (ctx == .constant),
};

if (!supported) {
Expand All @@ -17761,7 +17764,6 @@ pub fn analyzeAddrspace(
.constant => "constant values",
.pointer => "pointers",
};

return sema.fail(
block,
src,
Expand Down
10 changes: 10 additions & 0 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,16 @@ pub const DeclGen = struct {
.gs => llvm.address_space.x86.gs,
.fs => llvm.address_space.x86.fs,
.ss => llvm.address_space.x86.ss,
else => unreachable,
},
.nvptx, .nvptx64 => switch (address_space) {
.generic => llvm.address_space.default,
.global => llvm.address_space.nvptx.global,
.constant => llvm.address_space.nvptx.constant,
.param => llvm.address_space.nvptx.param,
.shared => llvm.address_space.nvptx.shared,
.local => llvm.address_space.nvptx.local,
else => unreachable,
},
else => switch (address_space) {
.generic => llvm.address_space.default,
Expand Down

0 comments on commit 632e147

Please sign in to comment.