Commit 84876fec58

Robin Voetter <robin@voetter.nl>
2021-10-21 14:12:54
stage2: remove ptr_ptr_elem_val and ptr_slice_elem_val
1 parent 1d33822
src/arch/aarch64/CodeGen.zig
@@ -500,10 +500,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
 
                     .array_elem_val      => try self.airArrayElemVal(inst),
                     .slice_elem_val      => try self.airSliceElemVal(inst),
-                    .ptr_slice_elem_val  => try self.airPtrSliceElemVal(inst),
                     .ptr_elem_val        => try self.airPtrElemVal(inst),
                     .ptr_elem_ptr        => try self.airPtrElemPtr(inst),
-                    .ptr_ptr_elem_val    => try self.airPtrPtrElemVal(inst),
 
                     .constant => unreachable, // excluded from function bodies
                     .const_ty => unreachable, // excluded from function bodies
@@ -1092,13 +1090,6 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
     return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
 }
 
-fn airPtrSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
-    const is_volatile = false; // TODO
-    const bin_op = self.air.instructions.items(.data)[inst].bin_op;
-    const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_elem_val for {}", .{self.target.cpu.arch});
-    return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
-}
-
 fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
     const is_volatile = false; // TODO
     const bin_op = self.air.instructions.items(.data)[inst].bin_op;
@@ -1113,13 +1104,6 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
     return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
 }
 
-fn airPtrPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
-    const is_volatile = false; // TODO
-    const bin_op = self.air.instructions.items(.data)[inst].bin_op;
-    const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_ptr_elem_val for {}", .{self.target.cpu.arch});
-    return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
-}
-
 fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
     const bin_op = self.air.instructions.items(.data)[inst].bin_op;
     _ = bin_op;
src/codegen/c.zig
@@ -1081,10 +1081,8 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
             .ptr_slice_ptr_ptr => try airPtrSliceFieldPtr(f, inst, ".ptr;\n"),
 
             .ptr_elem_val       => try airPtrElemVal(f, inst, "["),
-            .ptr_ptr_elem_val   => try airPtrElemVal(f, inst, "[0]["),
             .ptr_elem_ptr       => try airPtrElemPtr(f, inst),
             .slice_elem_val     => try airSliceElemVal(f, inst, "["),
-            .ptr_slice_elem_val => try airSliceElemVal(f, inst, "[0]["),
             .array_elem_val     => try airArrayElemVal(f, inst),
 
             .unwrap_errunion_payload     => try airUnwrapErrUnionPay(f, inst),
src/codegen/llvm.zig
@@ -1760,10 +1760,8 @@ pub const FuncGen = struct {
 
                 .array_elem_val     => try self.airArrayElemVal(inst),
                 .slice_elem_val     => try self.airSliceElemVal(inst),
-                .ptr_slice_elem_val => try self.airPtrSliceElemVal(inst),
                 .ptr_elem_val       => try self.airPtrElemVal(inst),
                 .ptr_elem_ptr       => try self.airPtrElemPtr(inst),
-                .ptr_ptr_elem_val   => try self.airPtrPtrElemVal(inst),
 
                 .optional_payload     => try self.airOptionalPayload(inst, false),
                 .optional_payload_ptr => try self.airOptionalPayload(inst, true),
@@ -2165,24 +2163,6 @@ pub const FuncGen = struct {
         return self.load(ptr, slice_ty);
     }
 
-    fn airPtrSliceElemVal(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
-        const bin_op = self.air.instructions.items(.data)[inst].bin_op;
-        const slice_ty = self.air.typeOf(bin_op.lhs).childType();
-        if (!slice_ty.isVolatilePtr() and self.liveness.isUnused(inst)) return null;
-
-        const lhs = try self.resolveInst(bin_op.lhs);
-        const rhs = try self.resolveInst(bin_op.rhs);
-
-        const base_ptr = ptr: {
-            const ptr_field_ptr = self.builder.buildStructGEP(lhs, 0, "");
-            break :ptr self.builder.buildLoad(ptr_field_ptr, "");
-        };
-
-        const indices: [1]*const llvm.Value = .{rhs};
-        const ptr = self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, "");
-        return self.load(ptr, slice_ty);
-    }
-
     fn airArrayElemVal(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
         if (self.liveness.isUnused(inst)) return null;
 
@@ -2240,19 +2220,6 @@ pub const FuncGen = struct {
         }
     }
 
-    fn airPtrPtrElemVal(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
-        const bin_op = self.air.instructions.items(.data)[inst].bin_op;
-        const ptr_ty = self.air.typeOf(bin_op.lhs).childType();
-        if (!ptr_ty.isVolatilePtr() and self.liveness.isUnused(inst)) return null;
-
-        const lhs = try self.resolveInst(bin_op.lhs);
-        const rhs = try self.resolveInst(bin_op.rhs);
-        const base_ptr = self.builder.buildLoad(lhs, "");
-        const indices: [1]*const llvm.Value = .{rhs};
-        const ptr = self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, "");
-        return self.load(ptr, ptr_ty);
-    }
-
     fn airStructFieldPtr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
         if (self.liveness.isUnused(inst))
             return null;
src/Air.zig
@@ -384,10 +384,6 @@ pub const Inst = struct {
         /// Result type is the element type of the slice operand.
         /// Uses the `bin_op` field.
         slice_elem_val,
-        /// Given a pointer to a slice, and element index, return the element value at that index.
-        /// Result type is the element type of the slice operand (2 element type operations).
-        /// Uses the `bin_op` field.
-        ptr_slice_elem_val,
         /// Given a pointer value, and element index, return the element value at that index.
         /// Result type is the element type of the pointer operand.
         /// Uses the `bin_op` field.
@@ -396,11 +392,6 @@ pub const Inst = struct {
         /// Result type is pointer to the element type of the pointer operand.
         /// Uses the `ty_pl` field with payload `Bin`.
         ptr_elem_ptr,
-        /// Given a pointer to a pointer, and element index, return the element value of the inner
-        /// pointer at that index.
-        /// Result type is the element type of the inner pointer operand.
-        /// Uses the `bin_op` field.
-        ptr_ptr_elem_val,
         /// Given a pointer to an array, return a slice.
         /// Uses the `ty_op` field.
         array_to_slice,
@@ -772,11 +763,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
             const ptr_ty = air.typeOf(datas[inst].bin_op.lhs);
             return ptr_ty.elemType();
         },
-        .ptr_slice_elem_val, .ptr_ptr_elem_val => {
-            const outer_ptr_ty = air.typeOf(datas[inst].bin_op.lhs);
-            const inner_ptr_ty = outer_ptr_ty.elemType();
-            return inner_ptr_ty.elemType();
-        },
         .atomic_load => {
             const ptr_ty = air.typeOf(datas[inst].atomic_load.ptr);
             return ptr_ty.elemType();
src/codegen.zig
@@ -848,10 +848,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
 
                     .array_elem_val      => try self.airArrayElemVal(inst),
                     .slice_elem_val      => try self.airSliceElemVal(inst),
-                    .ptr_slice_elem_val  => try self.airPtrSliceElemVal(inst),
                     .ptr_elem_val        => try self.airPtrElemVal(inst),
                     .ptr_elem_ptr        => try self.airPtrElemPtr(inst),
-                    .ptr_ptr_elem_val    => try self.airPtrPtrElemVal(inst),
 
                     .constant => unreachable, // excluded from function bodies
                     .const_ty => unreachable, // excluded from function bodies
@@ -1543,15 +1541,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
             return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
         }
 
-        fn airPtrSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
-            const is_volatile = false; // TODO
-            const bin_op = self.air.instructions.items(.data)[inst].bin_op;
-            const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else switch (arch) {
-                else => return self.fail("TODO implement ptr_slice_elem_val for {}", .{self.target.cpu.arch}),
-            };
-            return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
-        }
-
         fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
             const is_volatile = false; // TODO
             const bin_op = self.air.instructions.items(.data)[inst].bin_op;
@@ -1570,15 +1559,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
             return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
         }
 
-        fn airPtrPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
-            const is_volatile = false; // TODO
-            const bin_op = self.air.instructions.items(.data)[inst].bin_op;
-            const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else switch (arch) {
-                else => return self.fail("TODO implement ptr_ptr_elem_val for {}", .{self.target.cpu.arch}),
-            };
-            return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
-        }
-
         fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
             const bin_op = self.air.instructions.items(.data)[inst].bin_op;
             const result: MCValue = switch (arch) {
src/Liveness.zig
@@ -252,9 +252,7 @@ fn analyzeInst(
         .store,
         .array_elem_val,
         .slice_elem_val,
-        .ptr_slice_elem_val,
         .ptr_elem_val,
-        .ptr_ptr_elem_val,
         .shl,
         .shl_exact,
         .shl_sat,
src/print_air.zig
@@ -130,9 +130,7 @@ const Writer = struct {
             .store,
             .array_elem_val,
             .slice_elem_val,
-            .ptr_slice_elem_val,
             .ptr_elem_val,
-            .ptr_ptr_elem_val,
             .shl,
             .shl_exact,
             .shl_sat,