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 {...@@ -6951,8 +6951,10 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
6951}6951}
69526952
6953fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {6953fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
6954 const mod = f.object.dg.module;
6954 const prefetch = f.air.instructions.items(.data)[inst].prefetch;6955 const prefetch = f.air.instructions.items(.data)[inst].prefetch;
69556956
6957 const ptr_ty = f.typeOf(prefetch.ptr);
6956 const ptr = try f.resolveInst(prefetch.ptr);6958 const ptr = try f.resolveInst(prefetch.ptr);
6957 try reap(f, inst, &.{prefetch.ptr});6959 try reap(f, inst, &.{prefetch.ptr});
69586960
...@@ -6960,7 +6962,10 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6960,7 +6962,10 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
6960 switch (prefetch.cache) {6962 switch (prefetch.cache) {
6961 .data => {6963 .data => {
6962 try writer.writeAll("zig_prefetch(");6964 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);
6964 try writer.print(", {d}, {d});\n", .{ @intFromEnum(prefetch.rw), prefetch.locality });6969 try writer.print(", {d}, {d});\n", .{ @intFromEnum(prefetch.rw), prefetch.locality });
6965 },6970 },
6966 // The available prefetch intrinsics do not accept a cache argument; only6971 // 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 {...@@ -9837,7 +9837,7 @@ pub const FuncGen = struct {
9837 }9837 }
98389838
9839 _ = try self.wip.callIntrinsic(.normal, .none, .prefetch, &.{.ptr}, &.{9839 _ = 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)),
9841 try o.builder.intValue(.i32, prefetch.rw),9841 try o.builder.intValue(.i32, prefetch.rw),
9842 try o.builder.intValue(.i32, prefetch.locality),9842 try o.builder.intValue(.i32, prefetch.locality),
9843 try o.builder.intValue(.i32, prefetch.cache),9843 try o.builder.intValue(.i32, prefetch.cache),
test/behavior/prefetch.zig+14-13
...@@ -4,27 +4,28 @@ const std = @import("std");...@@ -4,27 +4,28 @@ const std = @import("std");
4test "@prefetch()" {4test "@prefetch()" {
5 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;5 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
9 @prefetch(&a, .{});10 @prefetch(&a, .{});
1011
11 @prefetch(&a, .{ .rw = .read, .locality = 3, .cache = .data });12 @prefetch(&a[0], .{ .rw = .read, .locality = 3, .cache = .data });
12 @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .data });13 @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .data });
13 @prefetch(&a, .{ .rw = .read, .locality = 1, .cache = .data });14 @prefetch(a[0..].ptr, .{ .rw = .read, .locality = 1, .cache = .data });
14 @prefetch(&a, .{ .rw = .read, .locality = 0, .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 });
17 @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .data });18 @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .data });
18 @prefetch(&a, .{ .rw = .write, .locality = 1, .cache = .data });19 @prefetch(a[0..].ptr, .{ .rw = .write, .locality = 1, .cache = .data });
19 @prefetch(&a, .{ .rw = .write, .locality = 0, .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 });
22 @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .instruction });23 @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .instruction });
23 @prefetch(&a, .{ .rw = .read, .locality = 1, .cache = .instruction });24 @prefetch(a[0..].ptr, .{ .rw = .read, .locality = 1, .cache = .instruction });
24 @prefetch(&a, .{ .rw = .read, .locality = 0, .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 });
27 @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .instruction });28 @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .instruction });
28 @prefetch(&a, .{ .rw = .write, .locality = 1, .cache = .instruction });29 @prefetch(a[0..].ptr, .{ .rw = .write, .locality = 1, .cache = .instruction });
29 @prefetch(&a, .{ .rw = .write, .locality = 0, .cache = .instruction });30 @prefetch(a[0..a_len], .{ .rw = .write, .locality = 0, .cache = .instruction });
30}31}