From 4ac37eb484737e98269e198b31b81ee8e929b4f1 Mon Sep 17 00:00:00 2001 From: Jacob G-W Date: Mon, 16 Aug 2021 23:11:55 -0400 Subject: stage2 Air: add struct_field_ptr_index_{0..3} Since these are very common, it will save memory. --- src/codegen/llvm.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/codegen/llvm.zig') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index b80dcf0feb..d7aa2d45b3 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1037,6 +1037,11 @@ pub const FuncGen = struct { .struct_field_ptr => try self.airStructFieldPtr(inst), .struct_field_val => try self.airStructFieldVal(inst), + .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0), + .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1), + .struct_field_ptr_index_2 => try self.airStructFieldPtrIndex(inst, 2), + .struct_field_ptr_index_3 => try self.airStructFieldPtrIndex(inst, 3), + .slice_elem_val => try self.airSliceElemVal(inst), .ptr_slice_elem_val => try self.airPtrSliceElemVal(inst), .ptr_elem_val => try self.airPtrElemVal(inst), @@ -1350,6 +1355,15 @@ pub const FuncGen = struct { return self.builder.buildStructGEP(struct_ptr, field_index, ""); } + fn airStructFieldPtrIndex(self: *FuncGen, inst: Air.Inst.Index, field_index: c_uint) !?*const llvm.Value { + if (self.liveness.isUnused(inst)) + return null; + + const ty_op = self.air.instructions.items(.data)[inst].ty_op; + const struct_ptr = try self.resolveInst(ty_op.operand); + return self.builder.buildStructGEP(struct_ptr, field_index, ""); + } + fn airStructFieldVal(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { if (self.liveness.isUnused(inst)) return null; -- cgit v1.2.3