authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-30 19:41:35-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-01-30 19:41:35-05:00
log227968d78c4d0c6eaa92ecae4649bfc757af2c28
tree7517564e4e734d195dc452224567e506f04dd2f9
parentb2338de7fde695d755b4c33600fc98c408a09ebe
parent1fd41af356da74e35a9facf8f3c5d665887f8a1e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10723 from joachimschmidt557/stage2-riscv

stage2 RISCV64: Move to new regalloc freeze API

2 files changed, 29 insertions(+), 33 deletions(-)

src/arch/riscv64/CodeGen.zig+7-5
......@@ -1208,14 +1208,16 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
12081208 .register => {
12091209 return self.fail("TODO implement loading from MCValue.register", .{});
12101210 },
1211 .memory => |addr| {
1211 .memory,
1212 .stack_offset,
1213 => {
12121214 const reg = try self.register_manager.allocReg(null, &.{});
1213 try self.genSetReg(ptr_ty, reg, .{ .memory = addr });
1215 self.register_manager.freezeRegs(&.{reg});
1216 defer self.register_manager.unfreezeRegs(&.{reg});
1217
1218 try self.genSetReg(ptr_ty, reg, ptr);
12141219 try self.load(dst_mcv, .{ .register = reg }, ptr_ty);
12151220 },
1216 .stack_offset => {
1217 return self.fail("TODO implement loading from MCValue.stack_offset", .{});
1218 },
12191221 }
12201222}
12211223
src/arch/riscv64/bits.zig+22-28
......@@ -71,9 +71,9 @@ pub const Instruction = union(enum) {
7171 .opcode = op,
7272 .funct3 = fn3,
7373 .funct7 = fn7,
74 .rd = @enumToInt(rd),
75 .rs1 = @enumToInt(r1),
76 .rs2 = @enumToInt(r2),
74 .rd = rd.id(),
75 .rs1 = r1.id(),
76 .rs2 = r2.id(),
7777 },
7878 };
7979 }
......@@ -86,8 +86,8 @@ pub const Instruction = union(enum) {
8686 .I = .{
8787 .opcode = op,
8888 .funct3 = fn3,
89 .rd = @enumToInt(rd),
90 .rs1 = @enumToInt(r1),
89 .rd = rd.id(),
90 .rs1 = r1.id(),
9191 .imm0_11 = umm,
9292 },
9393 };
......@@ -100,8 +100,8 @@ pub const Instruction = union(enum) {
100100 .S = .{
101101 .opcode = op,
102102 .funct3 = fn3,
103 .rs1 = @enumToInt(r1),
104 .rs2 = @enumToInt(r2),
103 .rs1 = r1.id(),
104 .rs2 = r2.id(),
105105 .imm0_4 = @truncate(u5, umm),
106106 .imm5_11 = @truncate(u7, umm >> 5),
107107 },
......@@ -118,8 +118,8 @@ pub const Instruction = union(enum) {
118118 .B = .{
119119 .opcode = op,
120120 .funct3 = fn3,
121 .rs1 = @enumToInt(r1),
122 .rs2 = @enumToInt(r2),
121 .rs1 = r1.id(),
122 .rs2 = r2.id(),
123123 .imm1_4 = @truncate(u4, umm >> 1),
124124 .imm5_10 = @truncate(u6, umm >> 5),
125125 .imm11 = @truncate(u1, umm >> 11),
......@@ -135,7 +135,7 @@ pub const Instruction = union(enum) {
135135 return Instruction{
136136 .U = .{
137137 .opcode = op,
138 .rd = @enumToInt(rd),
138 .rd = rd.id(),
139139 .imm12_31 = umm,
140140 },
141141 };
......@@ -148,7 +148,7 @@ pub const Instruction = union(enum) {
148148 return Instruction{
149149 .J = .{
150150 .opcode = op,
151 .rd = @enumToInt(rd),
151 .rd = rd.id(),
152152 .imm1_10 = @truncate(u10, umm >> 1),
153153 .imm11 = @truncate(u1, umm >> 11),
154154 .imm12_19 = @truncate(u8, umm >> 12),
......@@ -382,20 +382,13 @@ pub const Instruction = union(enum) {
382382 pub const ebreak = iType(0b1110011, 0b000, .zero, .zero, 0x001);
383383};
384384
385// zig fmt: off
386pub const RawRegister = enum(u5) {
385pub const Register = enum(u6) {
386 // zig fmt: off
387387 x0, x1, x2, x3, x4, x5, x6, x7,
388388 x8, x9, x10, x11, x12, x13, x14, x15,
389389 x16, x17, x18, x19, x20, x21, x22, x23,
390390 x24, x25, x26, x27, x28, x29, x30, x31,
391391
392 pub fn dwarfLocOp(reg: RawRegister) u8 {
393 return @enumToInt(reg) + DW.OP.reg0;
394 }
395};
396
397pub const Register = enum(u5) {
398 // 64 bit registers
399392 zero, // zero
400393 ra, // return address. caller saved
401394 sp, // stack pointer. callee saved.
......@@ -408,23 +401,24 @@ pub const Register = enum(u5) {
408401 a2, a3, a4, a5, a6, a7, // fn args. caller saved.
409402 s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, // saved registers. callee saved.
410403 t3, t4, t5, t6, // caller saved
411
412 pub fn parseRegName(name: []const u8) ?Register {
413 if(std.meta.stringToEnum(Register, name)) |reg| return reg;
414 if(std.meta.stringToEnum(RawRegister, name)) |rawreg| return @intToEnum(Register, @enumToInt(rawreg));
415 return null;
404 // zig fmt: on
405
406 /// Returns the unique 4-bit ID of this register which is used in
407 /// the machine code
408 pub fn id(self: Register) u5 {
409 return @truncate(u5, @enumToInt(self));
416410 }
417411
418412 /// Returns the index into `callee_preserved_regs`.
419413 pub fn allocIndex(self: Register) ?u4 {
420 inline for(callee_preserved_regs) |cpreg, i| {
421 if(self == cpreg) return i;
414 inline for (callee_preserved_regs) |cpreg, i| {
415 if (self.id() == cpreg.id()) return i;
422416 }
423417 return null;
424418 }
425419
426420 pub fn dwarfLocOp(reg: Register) u8 {
427 return @as(u8, @enumToInt(reg)) + DW.OP.reg0;
421 return @as(u8, reg.id()) + DW.OP.reg0;
428422 }
429423};
430424