authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-27 17:36:43-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-28 19:04:53-07:00
logc429bb5d2feb36f83e33ef95a25dd5bb7455f16c
treef5cb0a986c3a7792867f88e0985d356d99802da2
parent26b03ca823e36b213b0e1c1d4cddda13d9207eb3

llvm/cbe: support slice in `@prefetch`

Closes #16967

3 files changed, 21 insertions(+), 15 deletions(-)

src/codegen/c.zig+6-1
......@@ -6951,8 +6951,10 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
69516951}
69526952
69536953fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
6954 const mod = f.object.dg.module;
69546955 const prefetch = f.air.instructions.items(.data)[inst].prefetch;
69556956
6957 const ptr_ty = f.typeOf(prefetch.ptr);
69566958 const ptr = try f.resolveInst(prefetch.ptr);
69576959 try reap(f, inst, &.{prefetch.ptr});
69586960
......@@ -6960,7 +6962,10 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
69606962 switch (prefetch.cache) {
69616963 .data => {
69626964 try writer.writeAll("zig_prefetch(");
6963 try f.writeCValue(writer, ptr, .FunctionArgument);
6965 if (ptr_ty.isSlice(mod))
6966 try f.writeCValueMember(writer, ptr, .{ .identifier = "ptr" })
6967 else
6968 try f.writeCValue(writer, ptr, .FunctionArgument);
69646969 try writer.print(", {d}, {d});\n", .{ @intFromEnum(prefetch.rw), prefetch.locality });
69656970 },
69666971 // The available prefetch intrinsics do not accept a cache argument; only
src/codegen/llvm.zig+1-1
......@@ -9837,7 +9837,7 @@ pub const FuncGen = struct {
98379837 }
98389838
98399839 _ = try self.wip.callIntrinsic(.normal, .none, .prefetch, &.{.ptr}, &.{
9840 try self.resolveInst(prefetch.ptr),
9840 try self.sliceOrArrayPtr(try self.resolveInst(prefetch.ptr), self.typeOf(prefetch.ptr)),
98419841 try o.builder.intValue(.i32, prefetch.rw),
98429842 try o.builder.intValue(.i32, prefetch.locality),
98439843 try o.builder.intValue(.i32, prefetch.cache),
test/behavior/prefetch.zig+14-13
......@@ -4,27 +4,28 @@ const std = @import("std");
44test "@prefetch()" {
55 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
66
7 var a: u32 = 42;
7 var a: [2]u32 = .{ 42, 42 };
8 var a_len = a.len;
89
910 @prefetch(&a, .{});
1011
11 @prefetch(&a, .{ .rw = .read, .locality = 3, .cache = .data });
12 @prefetch(&a[0], .{ .rw = .read, .locality = 3, .cache = .data });
1213 @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .data });
13 @prefetch(&a, .{ .rw = .read, .locality = 1, .cache = .data });
14 @prefetch(&a, .{ .rw = .read, .locality = 0, .cache = .data });
14 @prefetch(a[0..].ptr, .{ .rw = .read, .locality = 1, .cache = .data });
15 @prefetch(a[0..a_len], .{ .rw = .read, .locality = 0, .cache = .data });
1516
16 @prefetch(&a, .{ .rw = .write, .locality = 3, .cache = .data });
17 @prefetch(&a[0], .{ .rw = .write, .locality = 3, .cache = .data });
1718 @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .data });
18 @prefetch(&a, .{ .rw = .write, .locality = 1, .cache = .data });
19 @prefetch(&a, .{ .rw = .write, .locality = 0, .cache = .data });
19 @prefetch(a[0..].ptr, .{ .rw = .write, .locality = 1, .cache = .data });
20 @prefetch(a[0..a_len], .{ .rw = .write, .locality = 0, .cache = .data });
2021
21 @prefetch(&a, .{ .rw = .read, .locality = 3, .cache = .instruction });
22 @prefetch(&a[0], .{ .rw = .read, .locality = 3, .cache = .instruction });
2223 @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .instruction });
23 @prefetch(&a, .{ .rw = .read, .locality = 1, .cache = .instruction });
24 @prefetch(&a, .{ .rw = .read, .locality = 0, .cache = .instruction });
24 @prefetch(a[0..].ptr, .{ .rw = .read, .locality = 1, .cache = .instruction });
25 @prefetch(a[0..a_len], .{ .rw = .read, .locality = 0, .cache = .instruction });
2526
26 @prefetch(&a, .{ .rw = .write, .locality = 3, .cache = .instruction });
27 @prefetch(&a[0], .{ .rw = .write, .locality = 3, .cache = .instruction });
2728 @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .instruction });
28 @prefetch(&a, .{ .rw = .write, .locality = 1, .cache = .instruction });
29 @prefetch(&a, .{ .rw = .write, .locality = 0, .cache = .instruction });
29 @prefetch(a[0..].ptr, .{ .rw = .write, .locality = 1, .cache = .instruction });
30 @prefetch(a[0..a_len], .{ .rw = .write, .locality = 0, .cache = .instruction });
3031}