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...@@ -1208,14 +1208,16 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
1208 .register => {1208 .register => {
1209 return self.fail("TODO implement loading from MCValue.register", .{});1209 return self.fail("TODO implement loading from MCValue.register", .{});
1210 },1210 },
1211 .memory => |addr| {1211 .memory,
1212 .stack_offset,
1213 => {
1212 const reg = try self.register_manager.allocReg(null, &.{});1214 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);
1214 try self.load(dst_mcv, .{ .register = reg }, ptr_ty);1219 try self.load(dst_mcv, .{ .register = reg }, ptr_ty);
1215 },1220 },
1216 .stack_offset => {
1217 return self.fail("TODO implement loading from MCValue.stack_offset", .{});
1218 },
1219 }1221 }
1220}1222}
12211223
src/arch/riscv64/bits.zig+22-28
...@@ -71,9 +71,9 @@ pub const Instruction = union(enum) {...@@ -71,9 +71,9 @@ pub const Instruction = union(enum) {
71 .opcode = op,71 .opcode = op,
72 .funct3 = fn3,72 .funct3 = fn3,
73 .funct7 = fn7,73 .funct7 = fn7,
74 .rd = @enumToInt(rd),74 .rd = rd.id(),
75 .rs1 = @enumToInt(r1),75 .rs1 = r1.id(),
76 .rs2 = @enumToInt(r2),76 .rs2 = r2.id(),
77 },77 },
78 };78 };
79 }79 }
...@@ -86,8 +86,8 @@ pub const Instruction = union(enum) {...@@ -86,8 +86,8 @@ pub const Instruction = union(enum) {
86 .I = .{86 .I = .{
87 .opcode = op,87 .opcode = op,
88 .funct3 = fn3,88 .funct3 = fn3,
89 .rd = @enumToInt(rd),89 .rd = rd.id(),
90 .rs1 = @enumToInt(r1),90 .rs1 = r1.id(),
91 .imm0_11 = umm,91 .imm0_11 = umm,
92 },92 },
93 };93 };
...@@ -100,8 +100,8 @@ pub const Instruction = union(enum) {...@@ -100,8 +100,8 @@ pub const Instruction = union(enum) {
100 .S = .{100 .S = .{
101 .opcode = op,101 .opcode = op,
102 .funct3 = fn3,102 .funct3 = fn3,
103 .rs1 = @enumToInt(r1),103 .rs1 = r1.id(),
104 .rs2 = @enumToInt(r2),104 .rs2 = r2.id(),
105 .imm0_4 = @truncate(u5, umm),105 .imm0_4 = @truncate(u5, umm),
106 .imm5_11 = @truncate(u7, umm >> 5),106 .imm5_11 = @truncate(u7, umm >> 5),
107 },107 },
...@@ -118,8 +118,8 @@ pub const Instruction = union(enum) {...@@ -118,8 +118,8 @@ pub const Instruction = union(enum) {
118 .B = .{118 .B = .{
119 .opcode = op,119 .opcode = op,
120 .funct3 = fn3,120 .funct3 = fn3,
121 .rs1 = @enumToInt(r1),121 .rs1 = r1.id(),
122 .rs2 = @enumToInt(r2),122 .rs2 = r2.id(),
123 .imm1_4 = @truncate(u4, umm >> 1),123 .imm1_4 = @truncate(u4, umm >> 1),
124 .imm5_10 = @truncate(u6, umm >> 5),124 .imm5_10 = @truncate(u6, umm >> 5),
125 .imm11 = @truncate(u1, umm >> 11),125 .imm11 = @truncate(u1, umm >> 11),
...@@ -135,7 +135,7 @@ pub const Instruction = union(enum) {...@@ -135,7 +135,7 @@ pub const Instruction = union(enum) {
135 return Instruction{135 return Instruction{
136 .U = .{136 .U = .{
137 .opcode = op,137 .opcode = op,
138 .rd = @enumToInt(rd),138 .rd = rd.id(),
139 .imm12_31 = umm,139 .imm12_31 = umm,
140 },140 },
141 };141 };
...@@ -148,7 +148,7 @@ pub const Instruction = union(enum) {...@@ -148,7 +148,7 @@ pub const Instruction = union(enum) {
148 return Instruction{148 return Instruction{
149 .J = .{149 .J = .{
150 .opcode = op,150 .opcode = op,
151 .rd = @enumToInt(rd),151 .rd = rd.id(),
152 .imm1_10 = @truncate(u10, umm >> 1),152 .imm1_10 = @truncate(u10, umm >> 1),
153 .imm11 = @truncate(u1, umm >> 11),153 .imm11 = @truncate(u1, umm >> 11),
154 .imm12_19 = @truncate(u8, umm >> 12),154 .imm12_19 = @truncate(u8, umm >> 12),
...@@ -382,20 +382,13 @@ pub const Instruction = union(enum) {...@@ -382,20 +382,13 @@ pub const Instruction = union(enum) {
382 pub const ebreak = iType(0b1110011, 0b000, .zero, .zero, 0x001);382 pub const ebreak = iType(0b1110011, 0b000, .zero, .zero, 0x001);
383};383};
384384
385// zig fmt: off385pub const Register = enum(u6) {
386pub const RawRegister = enum(u5) {386 // zig fmt: off
387 x0, x1, x2, x3, x4, x5, x6, x7,387 x0, x1, x2, x3, x4, x5, x6, x7,
388 x8, x9, x10, x11, x12, x13, x14, x15,388 x8, x9, x10, x11, x12, x13, x14, x15,
389 x16, x17, x18, x19, x20, x21, x22, x23,389 x16, x17, x18, x19, x20, x21, x22, x23,
390 x24, x25, x26, x27, x28, x29, x30, x31,390 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
399 zero, // zero392 zero, // zero
400 ra, // return address. caller saved393 ra, // return address. caller saved
401 sp, // stack pointer. callee saved.394 sp, // stack pointer. callee saved.
...@@ -408,23 +401,24 @@ pub const Register = enum(u5) {...@@ -408,23 +401,24 @@ pub const Register = enum(u5) {
408 a2, a3, a4, a5, a6, a7, // fn args. caller saved.401 a2, a3, a4, a5, a6, a7, // fn args. caller saved.
409 s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, // saved registers. callee saved.402 s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, // saved registers. callee saved.
410 t3, t4, t5, t6, // caller saved403 t3, t4, t5, t6, // caller saved
411 404 // zig fmt: on
412 pub fn parseRegName(name: []const u8) ?Register {405
413 if(std.meta.stringToEnum(Register, name)) |reg| return reg;406 /// Returns the unique 4-bit ID of this register which is used in
414 if(std.meta.stringToEnum(RawRegister, name)) |rawreg| return @intToEnum(Register, @enumToInt(rawreg));407 /// the machine code
415 return null;408 pub fn id(self: Register) u5 {
409 return @truncate(u5, @enumToInt(self));
416 }410 }
417411
418 /// Returns the index into `callee_preserved_regs`.412 /// Returns the index into `callee_preserved_regs`.
419 pub fn allocIndex(self: Register) ?u4 {413 pub fn allocIndex(self: Register) ?u4 {
420 inline for(callee_preserved_regs) |cpreg, i| {414 inline for (callee_preserved_regs) |cpreg, i| {
421 if(self == cpreg) return i;415 if (self.id() == cpreg.id()) return i;
422 }416 }
423 return null;417 return null;
424 }418 }
425419
426 pub fn dwarfLocOp(reg: Register) u8 {420 pub fn dwarfLocOp(reg: Register) u8 {
427 return @as(u8, @enumToInt(reg)) + DW.OP.reg0;421 return @as(u8, reg.id()) + DW.OP.reg0;
428 }422 }
429};423};
430424