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

Closes #19942
This commit is contained in:
Veikka Tuominen 2024-05-20 14:38:59 +03:00 committed by Andrew Kelley
parent d78968c1b5
commit 0fb2015fd3
5 changed files with 12 additions and 10 deletions

View File

@ -5056,7 +5056,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_close#} {#header_close#}
{#header_open|@wasmMemorySize#} {#header_open|@wasmMemorySize#}
<pre>{#syntax#}@wasmMemorySize(index: u32) u32{#endsyntax#}</pre> <pre>{#syntax#}@wasmMemorySize(index: u32) usize{#endsyntax#}</pre>
<p> <p>
This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as
an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. 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
{#header_close#} {#header_close#}
{#header_open|@wasmMemoryGrow#} {#header_open|@wasmMemoryGrow#}
<pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: u32) i32{#endsyntax#}</pre> <pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: usize) isize{#endsyntax#}</pre>
<p> <p>
This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by
{#syntax#}delta{#endsyntax#} in units of unsigned number of Wasm pages. Note that each Wasm page {#syntax#}delta{#endsyntax#} in units of unsigned number of Wasm pages. Note that each Wasm page

View File

@ -9461,7 +9461,7 @@ fn builtinCall(
}, },
.wasm_memory_grow => { .wasm_memory_grow => {
const index_arg = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]); const index_arg = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);
const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[1]); const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, params[1]);
const result = try gz.addExtendedPayload(.wasm_memory_grow, Zir.Inst.BinNode{ const result = try gz.addExtendedPayload(.wasm_memory_grow, Zir.Inst.BinNode{
.node = gz.nodeIndexToRelative(node), .node = gz.nodeIndexToRelative(node),
.lhs = index_arg, .lhs = index_arg,

View File

@ -782,13 +782,13 @@ pub const Inst = struct {
field_parent_ptr, field_parent_ptr,
/// Implements @wasmMemorySize builtin. /// Implements @wasmMemorySize builtin.
/// Result type is always `u32`, /// Result type is always `usize`,
/// Uses the `pl_op` field, payload represents the index of the target memory. /// Uses the `pl_op` field, payload represents the index of the target memory.
/// The operand is unused and always set to `Ref.none`. /// The operand is unused and always set to `Ref.none`.
wasm_memory_size, wasm_memory_size,
/// Implements @wasmMemoryGrow builtin. /// Implements @wasmMemoryGrow builtin.
/// Result type is always `i32`, /// Result type is always `isize`,
/// Uses the `pl_op` field, payload represents the index of the target memory. /// Uses the `pl_op` field, payload represents the index of the target memory.
wasm_memory_grow, wasm_memory_grow,
@ -1471,8 +1471,8 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
.save_err_return_trace_index, .save_err_return_trace_index,
=> return Type.usize, => return Type.usize,
.wasm_memory_grow => return Type.i32, .wasm_memory_grow => return Type.isize,
.wasm_memory_size => return Type.u32, .wasm_memory_size => return Type.usize,
.int_from_bool => return Type.u1, .int_from_bool => return Type.u1,

View File

@ -26253,7 +26253,7 @@ fn zirWasmMemoryGrow(
const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{
.needed_comptime_reason = "wasm memory size index must be comptime-known", .needed_comptime_reason = "wasm memory size index must be comptime-known",
})); }));
const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src);
try sema.requireRuntimeBlock(block, builtin_src, null); try sema.requireRuntimeBlock(block, builtin_src, null);
return block.addInst(.{ return block.addInst(.{

View File

@ -7625,7 +7625,8 @@ pub const FuncGen = struct {
const o = self.dg.object; const o = self.dg.object;
const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
const index = pl_op.payload; const index = pl_op.payload;
return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{ const llvm_usize = try o.lowerType(Type.usize);
return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
try o.builder.intValue(.i32, index), try o.builder.intValue(.i32, index),
}, ""); }, "");
} }
@ -7634,7 +7635,8 @@ pub const FuncGen = struct {
const o = self.dg.object; const o = self.dg.object;
const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
const index = pl_op.payload; const index = pl_op.payload;
return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{ const llvm_isize = try o.lowerType(Type.isize);
return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
}, ""); }, "");
} }