authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-19 10:52:59+01:00
committergravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-19 10:52:59+01:00
log956d9f4ce019243ed0bd7f587acdeb1af4b5f61c
tree12cab5adb771b5e3de67318d25fb113e3298c556
parentad5770eba40e0cc425c7a1eab4d37c6f9788d670
signaturelock-open Commit is signed but in an unrecognized format.

stage2 RISCV64: remove MCValue.embedded_in_code


1 files changed, 17 insertions(+), 53 deletions(-)

src/arch/riscv64/CodeGen.zig+17-53
......@@ -111,11 +111,6 @@ const MCValue = union(enum) {
111111 /// A pointer-sized integer that fits in a register.
112112 /// If the type is a pointer, this is the pointer address in virtual address space.
113113 immediate: u64,
114 /// The constant was emitted into the code, at this offset.
115 /// If the type is a pointer, it means the pointer address is embedded in the code.
116 embedded_in_code: usize,
117 /// The value is a pointer to a constant which was emitted into the code, at this offset.
118 ptr_embedded_in_code: usize,
119114 /// The value is in a target-specific register.
120115 register: Register,
121116 /// The value is in memory at a hard-coded address.
......@@ -129,7 +124,7 @@ const MCValue = union(enum) {
129124
130125 fn isMemory(mcv: MCValue) bool {
131126 return switch (mcv) {
132 .embedded_in_code, .memory, .stack_offset => true,
127 .memory, .stack_offset => true,
133128 else => false,
134129 };
135130 }
......@@ -148,10 +143,8 @@ const MCValue = union(enum) {
148143 .dead => unreachable,
149144
150145 .immediate,
151 .embedded_in_code,
152146 .memory,
153147 .ptr_stack_offset,
154 .ptr_embedded_in_code,
155148 .undef,
156149 => false,
157150
......@@ -1279,12 +1272,6 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
12791272 .dead => unreachable,
12801273 .immediate => |imm| try self.setRegOrMem(elem_ty, dst_mcv, .{ .memory = imm }),
12811274 .ptr_stack_offset => |off| try self.setRegOrMem(elem_ty, dst_mcv, .{ .stack_offset = off }),
1282 .ptr_embedded_in_code => |off| {
1283 try self.setRegOrMem(elem_ty, dst_mcv, .{ .embedded_in_code = off });
1284 },
1285 .embedded_in_code => {
1286 return self.fail("TODO implement loading from MCValue.embedded_in_code", .{});
1287 },
12881275 .register => {
12891276 return self.fail("TODO implement loading from MCValue.register", .{});
12901277 },
......@@ -1327,27 +1314,19 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
13271314 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13281315}
13291316
1330fn airStore(self: *Self, inst: Air.Inst.Index) !void {
1331 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1332 const ptr = try self.resolveInst(bin_op.lhs);
1333 const value = try self.resolveInst(bin_op.rhs);
1334 const elem_ty = self.air.typeOf(bin_op.rhs);
1317fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) !void {
1318 _ = ptr_ty;
1319
13351320 switch (ptr) {
13361321 .none => unreachable,
13371322 .undef => unreachable,
13381323 .unreach => unreachable,
13391324 .dead => unreachable,
13401325 .immediate => |imm| {
1341 try self.setRegOrMem(elem_ty, .{ .memory = imm }, value);
1326 try self.setRegOrMem(value_ty, .{ .memory = imm }, value);
13421327 },
13431328 .ptr_stack_offset => |off| {
1344 try self.genSetStack(elem_ty, off, value);
1345 },
1346 .ptr_embedded_in_code => |off| {
1347 try self.setRegOrMem(elem_ty, .{ .embedded_in_code = off }, value);
1348 },
1349 .embedded_in_code => {
1350 return self.fail("TODO implement storing to MCValue.embedded_in_code", .{});
1329 try self.genSetStack(value_ty, off, value);
13511330 },
13521331 .register => {
13531332 return self.fail("TODO implement storing to MCValue.register", .{});
......@@ -1359,6 +1338,17 @@ fn airStore(self: *Self, inst: Air.Inst.Index) !void {
13591338 return self.fail("TODO implement storing to MCValue.stack_offset", .{});
13601339 },
13611340 }
1341}
1342
1343fn airStore(self: *Self, inst: Air.Inst.Index) !void {
1344 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1345 const ptr = try self.resolveInst(bin_op.lhs);
1346 const value = try self.resolveInst(bin_op.rhs);
1347 const ptr_ty = self.air.typeOf(bin_op.lhs);
1348 const value_ty = self.air.typeOf(bin_op.rhs);
1349
1350 try self.store(ptr, value, ptr_ty, value_ty);
1351
13621352 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
13631353}
13641354
......@@ -1504,7 +1494,6 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
15041494 .immediate => unreachable,
15051495 .unreach => unreachable,
15061496 .dead => unreachable,
1507 .embedded_in_code => unreachable,
15081497 .memory => unreachable,
15091498 .register => |reg| {
15101499 try self.register_manager.getReg(reg, null);
......@@ -1516,9 +1505,6 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
15161505 .ptr_stack_offset => {
15171506 return self.fail("TODO implement calling with MCValue.ptr_stack_offset arg", .{});
15181507 },
1519 .ptr_embedded_in_code => {
1520 return self.fail("TODO implement calling with MCValue.ptr_embedded_in_code arg", .{});
1521 },
15221508 }
15231509 }
15241510
......@@ -2043,7 +2029,6 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
20432029 switch (mcv) {
20442030 .dead => unreachable,
20452031 .ptr_stack_offset => unreachable,
2046 .ptr_embedded_in_code => unreachable,
20472032 .unreach, .none => return, // Nothing to do.
20482033 .undef => {
20492034 if (!self.wantSafety())
......@@ -2312,27 +2297,6 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue {
23122297 }
23132298}
23142299
2315/// If the MCValue is an immediate, and it does not fit within this type,
2316/// we put it in a register.
2317/// A potential opportunity for future optimization here would be keeping track
2318/// of the fact that the instruction is available both as an immediate
2319/// and as a register.
2320fn limitImmediateType(self: *Self, operand: Air.Inst.Ref, comptime T: type) !MCValue {
2321 const mcv = try self.resolveInst(operand);
2322 const ti = @typeInfo(T).Int;
2323 switch (mcv) {
2324 .immediate => |imm| {
2325 // This immediate is unsigned.
2326 const U = std.meta.Int(.unsigned, ti.bits - @boolToInt(ti.signedness == .signed));
2327 if (imm >= math.maxInt(U)) {
2328 return MCValue{ .register = try self.copyToTmpRegister(Type.initTag(.usize), mcv) };
2329 }
2330 },
2331 else => {},
2332 }
2333 return mcv;
2334}
2335
23362300fn lowerDeclRef(self: *Self, tv: TypedValue, decl: *Module.Decl) InnerError!MCValue {
23372301 const ptr_bits = self.target.cpu.arch.ptrBitWidth();
23382302 const ptr_bytes: u64 = @divExact(ptr_bits, 8);