aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 252d449fc2..368a67f4b4 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -2314,6 +2314,9 @@ pub const FuncGen = struct {
.wrap_errunion_payload => try self.airWrapErrUnionPayload(inst),
.wrap_errunion_err => try self.airWrapErrUnionErr(inst),
+ .wasm_memory_size => try self.airWasmMemorySize(inst),
+ .wasm_memory_grow => try self.airWasmMemoryGrow(inst),
+
.constant => unreachable,
.const_ty => unreachable,
.unreach => self.airUnreach(inst),
@@ -3474,6 +3477,30 @@ pub const FuncGen = struct {
return partial;
}
+ fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ if (self.liveness.isUnused(inst)) return null;
+
+ const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+ const index = pl_op.payload;
+ const llvm_u32 = self.context.intType(32);
+ const llvm_fn = self.getIntrinsic("llvm.wasm.memory.size.i32", &.{llvm_u32});
+ const args: [1]*const llvm.Value = .{llvm_u32.constInt(index, .False)};
+ return self.builder.buildCall(llvm_fn, &args, args.len, .Fast, .Auto, "");
+ }
+
+ fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+ const index = pl_op.payload;
+ const operand = try self.resolveInst(pl_op.operand);
+ const llvm_u32 = self.context.intType(32);
+ const llvm_fn = self.getIntrinsic("llvm.wasm.memory.grow.i32", &.{ llvm_u32, llvm_u32 });
+ const args: [2]*const llvm.Value = .{
+ llvm_u32.constInt(index, .False),
+ operand,
+ };
+ return self.builder.buildCall(llvm_fn, &args, args.len, .Fast, .Auto, "");
+ }
+
fn airMin(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
if (self.liveness.isUnused(inst)) return null;