authorgravatar for vesim809@pm.meMaciej 'vesim' Kuliński <vesim809@pm.me> 2022-12-09 22:18:18+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-04 01:26:50+02:00
log2b9478ce12a5556a9ef596d98a14347be8daee4a
treef52142db643c655746ca3950f746e6f5555f5171
parentfd0fb26aba57ba14676dafc4c294bb5d9e75a649

Sema: implement AVR address spaces

Co-authored-by: Veikka Tuominen <git@vexu.eu>

6 files changed, 29 insertions(+), 3 deletions(-)

lib/std/builtin.zig+8
......@@ -174,6 +174,14 @@ pub const AddressSpace = enum {
174174 param,
175175 shared,
176176 local,
177
178 // AVR address spaces.
179 flash,
180 flash1,
181 flash2,
182 flash3,
183 flash4,
184 flash5,
177185};
178186
179187/// This data structure is used by the Zig language code generation and
lib/std/target.zig+2
......@@ -1186,6 +1186,8 @@ pub const Target = struct {
11861186 .fs, .gs, .ss => arch == .x86_64 or arch == .x86,
11871187 .global, .constant, .local, .shared => is_gpu,
11881188 .param => is_nvptx,
1189 // TODO this should also check how many flash banks the cpu has
1190 .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr,
11891191 };
11901192 }
11911193
src/Sema.zig+2
......@@ -31938,6 +31938,8 @@ pub fn analyzeAddressSpace(
3193831938 .param => is_nv,
3193931939 .global, .shared, .local => is_gpu,
3194031940 .constant => is_gpu and (ctx == .constant),
31941 // TODO this should also check how many flash banks the cpu has
31942 .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr,
3194131943 };
3194231944
3194331945 if (!supported) {
src/codegen/llvm.zig+10
......@@ -10241,6 +10241,16 @@ fn toLlvmAddressSpace(address_space: std.builtin.AddressSpace, target: std.Targe
1024110241 .local => llvm.address_space.amdgpu.private,
1024210242 else => unreachable,
1024310243 },
10244 .avr => switch (address_space) {
10245 .generic => llvm.address_space.default,
10246 .flash => llvm.address_space.avr.flash,
10247 .flash1 => llvm.address_space.avr.flash1,
10248 .flash2 => llvm.address_space.avr.flash2,
10249 .flash3 => llvm.address_space.avr.flash3,
10250 .flash4 => llvm.address_space.avr.flash4,
10251 .flash5 => llvm.address_space.avr.flash5,
10252 else => unreachable,
10253 },
1024410254 else => switch (address_space) {
1024510255 .generic => llvm.address_space.default,
1024610256 else => unreachable,
src/codegen/llvm/bindings.zig+6-2
......@@ -1530,8 +1530,12 @@ pub const address_space = struct {
15301530
15311531 // See llvm/lib/Target/AVR/AVR.h
15321532 pub const avr = struct {
1533 pub const data_memory: c_uint = 0;
1534 pub const program_memory: c_uint = 1;
1533 pub const flash: c_uint = 1;
1534 pub const flash1: c_uint = 2;
1535 pub const flash2: c_uint = 3;
1536 pub const flash3: c_uint = 4;
1537 pub const flash4: c_uint = 5;
1538 pub const flash5: c_uint = 6;
15351539 };
15361540
15371541 // See llvm/lib/Target/NVPTX/NVPTX.h
src/codegen/spirv.zig+1-1
......@@ -548,7 +548,7 @@ pub const DeclGen = struct {
548548 .gs, .fs, .ss => unreachable,
549549 .shared => .Workgroup,
550550 .local => .Private,
551 .global, .param, .constant => unreachable,
551 .global, .param, .constant, .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => unreachable,
552552 };
553553 }
554554