authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-05-20 14:38:59+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-22 09:48:52-04:00
log0fb2015fd3422fc1df364995f9782dfe7255eccd
treed0e54ff758f3d391b1de6323b36ba2c64a2511fb
parentd78968c1b589811c970ac57a4be52361cca2b5b1

llvm: fix `@wasmMemory{Size,Grow}` for wasm64

Closes #19942

5 files changed, 12 insertions(+), 10 deletions(-)

doc/langref.html.in+2-2
...@@ -5056,7 +5056,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5056,7 +5056,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5056 {#header_close#}5056 {#header_close#}
50575057
5058 {#header_open|@wasmMemorySize#}5058 {#header_open|@wasmMemorySize#}
5059 <pre>{#syntax#}@wasmMemorySize(index: u32) u32{#endsyntax#}</pre>5059 <pre>{#syntax#}@wasmMemorySize(index: u32) usize{#endsyntax#}</pre>
5060 <p>5060 <p>
5061 This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as5061 This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as
5062 an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size.5062 an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size.
...@@ -5070,7 +5070,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5070,7 +5070,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5070 {#header_close#}5070 {#header_close#}
50715071
5072 {#header_open|@wasmMemoryGrow#}5072 {#header_open|@wasmMemoryGrow#}
5073 <pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: u32) i32{#endsyntax#}</pre>5073 <pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: usize) isize{#endsyntax#}</pre>
5074 <p>5074 <p>
5075 This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by5075 This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by
5076 {#syntax#}delta{#endsyntax#} in units of unsigned number of Wasm pages. Note that each Wasm page5076 {#syntax#}delta{#endsyntax#} in units of unsigned number of Wasm pages. Note that each Wasm page
lib/std/zig/AstGen.zig+1-1
...@@ -9461,7 +9461,7 @@ fn builtinCall(...@@ -9461,7 +9461,7 @@ fn builtinCall(
9461 },9461 },
9462 .wasm_memory_grow => {9462 .wasm_memory_grow => {
9463 const index_arg = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);9463 const index_arg = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);
9464 const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[1]);9464 const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, params[1]);
9465 const result = try gz.addExtendedPayload(.wasm_memory_grow, Zir.Inst.BinNode{9465 const result = try gz.addExtendedPayload(.wasm_memory_grow, Zir.Inst.BinNode{
9466 .node = gz.nodeIndexToRelative(node),9466 .node = gz.nodeIndexToRelative(node),
9467 .lhs = index_arg,9467 .lhs = index_arg,
src/Air.zig+4-4
...@@ -782,13 +782,13 @@ pub const Inst = struct {...@@ -782,13 +782,13 @@ pub const Inst = struct {
782 field_parent_ptr,782 field_parent_ptr,
783783
784 /// Implements @wasmMemorySize builtin.784 /// Implements @wasmMemorySize builtin.
785 /// Result type is always `u32`,785 /// Result type is always `usize`,
786 /// Uses the `pl_op` field, payload represents the index of the target memory.786 /// Uses the `pl_op` field, payload represents the index of the target memory.
787 /// The operand is unused and always set to `Ref.none`.787 /// The operand is unused and always set to `Ref.none`.
788 wasm_memory_size,788 wasm_memory_size,
789789
790 /// Implements @wasmMemoryGrow builtin.790 /// Implements @wasmMemoryGrow builtin.
791 /// Result type is always `i32`,791 /// Result type is always `isize`,
792 /// Uses the `pl_op` field, payload represents the index of the target memory.792 /// Uses the `pl_op` field, payload represents the index of the target memory.
793 wasm_memory_grow,793 wasm_memory_grow,
794794
...@@ -1471,8 +1471,8 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1471,8 +1471,8 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1471 .save_err_return_trace_index,1471 .save_err_return_trace_index,
1472 => return Type.usize,1472 => return Type.usize,
14731473
1474 .wasm_memory_grow => return Type.i32,1474 .wasm_memory_grow => return Type.isize,
1475 .wasm_memory_size => return Type.u32,1475 .wasm_memory_size => return Type.usize,
14761476
1477 .int_from_bool => return Type.u1,1477 .int_from_bool => return Type.u1,
14781478
src/Sema.zig+1-1
...@@ -26253,7 +26253,7 @@ fn zirWasmMemoryGrow(...@@ -26253,7 +26253,7 @@ fn zirWasmMemoryGrow(
26253 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{26253 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{
26254 .needed_comptime_reason = "wasm memory size index must be comptime-known",26254 .needed_comptime_reason = "wasm memory size index must be comptime-known",
26255 }));26255 }));
26256 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);26256 const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src);
2625726257
26258 try sema.requireRuntimeBlock(block, builtin_src, null);26258 try sema.requireRuntimeBlock(block, builtin_src, null);
26259 return block.addInst(.{26259 return block.addInst(.{
src/codegen/llvm.zig+4-2
...@@ -7625,7 +7625,8 @@ pub const FuncGen = struct {...@@ -7625,7 +7625,8 @@ pub const FuncGen = struct {
7625 const o = self.dg.object;7625 const o = self.dg.object;
7626 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;7626 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7627 const index = pl_op.payload;7627 const index = pl_op.payload;
7628 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{7628 const llvm_usize = try o.lowerType(Type.usize);
7629 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
7629 try o.builder.intValue(.i32, index),7630 try o.builder.intValue(.i32, index),
7630 }, "");7631 }, "");
7631 }7632 }
...@@ -7634,7 +7635,8 @@ pub const FuncGen = struct {...@@ -7634,7 +7635,8 @@ pub const FuncGen = struct {
7634 const o = self.dg.object;7635 const o = self.dg.object;
7635 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;7636 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7636 const index = pl_op.payload;7637 const index = pl_op.payload;
7637 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{7638 const llvm_isize = try o.lowerType(Type.isize);
7639 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
7638 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),7640 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
7639 }, "");7641 }, "");
7640 }7642 }