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 07:17:50-07:00
log95845ba2ac81625507e9cb0c060e1a5b3903e102
tree020b80c5d90175ed5f4b464a54e561d8849f7877
parent4a09703f6274f41c3408a8012b6d20cbfaf2f092

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

Closes #19942

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

doc/langref.html.in+2-2
...@@ -9040,7 +9040,7 @@ test "integer cast panic" {...@@ -9040,7 +9040,7 @@ test "integer cast panic" {
9040 {#header_close#}9040 {#header_close#}
90419041
9042 {#header_open|@wasmMemorySize#}9042 {#header_open|@wasmMemorySize#}
9043 <pre>{#syntax#}@wasmMemorySize(index: u32) u32{#endsyntax#}</pre>9043 <pre>{#syntax#}@wasmMemorySize(index: u32) usize{#endsyntax#}</pre>
9044 <p>9044 <p>
9045 This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as9045 This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as
9046 an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size.9046 an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size.
...@@ -9054,7 +9054,7 @@ test "integer cast panic" {...@@ -9054,7 +9054,7 @@ test "integer cast panic" {
9054 {#header_close#}9054 {#header_close#}
90559055
9056 {#header_open|@wasmMemoryGrow#}9056 {#header_open|@wasmMemoryGrow#}
9057 <pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: u32) i32{#endsyntax#}</pre>9057 <pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: usize) isize{#endsyntax#}</pre>
9058 <p>9058 <p>
9059 This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by9059 This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by
9060 {#syntax#}delta{#endsyntax#} in units of unsigned number of Wasm pages. Note that each Wasm page9060 {#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
...@@ -26238,7 +26238,7 @@ fn zirWasmMemoryGrow(...@@ -26238,7 +26238,7 @@ fn zirWasmMemoryGrow(
26238 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{26238 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{
26239 .needed_comptime_reason = "wasm memory size index must be comptime-known",26239 .needed_comptime_reason = "wasm memory size index must be comptime-known",
26240 }));26240 }));
26241 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);26241 const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src);
2624226242
26243 try sema.requireRuntimeBlock(block, builtin_src, null);26243 try sema.requireRuntimeBlock(block, builtin_src, null);
26244 return block.addInst(.{26244 return block.addInst(.{
src/codegen/llvm.zig+4-2
...@@ -7499,7 +7499,8 @@ pub const FuncGen = struct {...@@ -7499,7 +7499,8 @@ pub const FuncGen = struct {
7499 const o = self.dg.object;7499 const o = self.dg.object;
7500 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;7500 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7501 const index = pl_op.payload;7501 const index = pl_op.payload;
7502 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{7502 const llvm_usize = try o.lowerType(Type.usize);
7503 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
7503 try o.builder.intValue(.i32, index),7504 try o.builder.intValue(.i32, index),
7504 }, "");7505 }, "");
7505 }7506 }
...@@ -7508,7 +7509,8 @@ pub const FuncGen = struct {...@@ -7508,7 +7509,8 @@ pub const FuncGen = struct {
7508 const o = self.dg.object;7509 const o = self.dg.object;
7509 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;7510 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7510 const index = pl_op.payload;7511 const index = pl_op.payload;
7511 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{7512 const llvm_isize = try o.lowerType(Type.isize);
7513 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
7512 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),7514 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
7513 }, "");7515 }, "");
7514 }7516 }