authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-25 19:35:38+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-25 22:22:16-04:00
logc1098e90367c8965fbf0c65e4967d938986af8b0
tree09e84d44a63c6912ee7c858c0daff33fec29b272
parent600c7fe1dacc1d6fd35275c7abe459b5b56bfa63

stage2 x86_64: remove MCValue.embedded_in_code


1 files changed, 6 insertions(+), 60 deletions(-)

src/arch/x86_64/CodeGen.zig+6-60
...@@ -117,11 +117,6 @@ pub const MCValue = union(enum) {...@@ -117,11 +117,6 @@ pub const MCValue = union(enum) {
117 /// A pointer-sized integer that fits in a register.117 /// A pointer-sized integer that fits in a register.
118 /// If the type is a pointer, this is the pointer address in virtual address space.118 /// If the type is a pointer, this is the pointer address in virtual address space.
119 immediate: u64,119 immediate: u64,
120 /// The constant was emitted into the code, at this offset.
121 /// If the type is a pointer, it means the pointer address is embedded in the code.
122 embedded_in_code: usize,
123 /// The value is a pointer to a constant which was emitted into the code, at this offset.
124 ptr_embedded_in_code: usize,
125 /// The value is in a target-specific register.120 /// The value is in a target-specific register.
126 register: Register,121 register: Register,
127 /// The value is in memory at a hard-coded address.122 /// The value is in memory at a hard-coded address.
...@@ -149,7 +144,7 @@ pub const MCValue = union(enum) {...@@ -149,7 +144,7 @@ pub const MCValue = union(enum) {
149144
150 fn isMemory(mcv: MCValue) bool {145 fn isMemory(mcv: MCValue) bool {
151 return switch (mcv) {146 return switch (mcv) {
152 .embedded_in_code, .memory, .stack_offset => true,147 .memory, .stack_offset => true,
153 else => false,148 else => false,
154 };149 };
155 }150 }
...@@ -168,12 +163,10 @@ pub const MCValue = union(enum) {...@@ -168,12 +163,10 @@ pub const MCValue = union(enum) {
168 .dead => unreachable,163 .dead => unreachable,
169164
170 .immediate,165 .immediate,
171 .embedded_in_code,
172 .memory,166 .memory,
173 .compare_flags_unsigned,167 .compare_flags_unsigned,
174 .compare_flags_signed,168 .compare_flags_signed,
175 .ptr_stack_offset,169 .ptr_stack_offset,
176 .ptr_embedded_in_code,
177 .undef,170 .undef,
178 => false,171 => false,
179172
...@@ -2437,12 +2430,6 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo...@@ -2437,12 +2430,6 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
2437 .ptr_stack_offset => |off| {2430 .ptr_stack_offset => |off| {
2438 try self.setRegOrMem(elem_ty, dst_mcv, .{ .stack_offset = off });2431 try self.setRegOrMem(elem_ty, dst_mcv, .{ .stack_offset = off });
2439 },2432 },
2440 .ptr_embedded_in_code => |off| {
2441 try self.setRegOrMem(elem_ty, dst_mcv, .{ .embedded_in_code = off });
2442 },
2443 .embedded_in_code => {
2444 return self.fail("TODO implement loading from MCValue.embedded_in_code", .{});
2445 },
2446 .register => |reg| {2433 .register => |reg| {
2447 self.register_manager.freezeRegs(&.{reg});2434 self.register_manager.freezeRegs(&.{reg});
2448 defer self.register_manager.unfreezeRegs(&.{reg});2435 defer self.register_manager.unfreezeRegs(&.{reg});
...@@ -2452,7 +2439,6 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo...@@ -2452,7 +2439,6 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
2452 .undef => unreachable,2439 .undef => unreachable,
2453 .compare_flags_unsigned => unreachable,2440 .compare_flags_unsigned => unreachable,
2454 .compare_flags_signed => unreachable,2441 .compare_flags_signed => unreachable,
2455 .embedded_in_code => unreachable,
2456 .register => |dst_reg| {2442 .register => |dst_reg| {
2457 // mov dst_reg, [reg]2443 // mov dst_reg, [reg]
2458 _ = try self.addInst(.{2444 _ = try self.addInst(.{
...@@ -2567,12 +2553,6 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -2567,12 +2553,6 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
2567 .ptr_stack_offset => |off| {2553 .ptr_stack_offset => |off| {
2568 try self.genSetStack(value_ty, off, value, .{});2554 try self.genSetStack(value_ty, off, value, .{});
2569 },2555 },
2570 .ptr_embedded_in_code => |off| {
2571 try self.setRegOrMem(value_ty, .{ .embedded_in_code = off }, value);
2572 },
2573 .embedded_in_code => {
2574 return self.fail("TODO implement storing to MCValue.embedded_in_code", .{});
2575 },
2576 .register => |reg| {2556 .register => |reg| {
2577 self.register_manager.freezeRegs(&.{reg});2557 self.register_manager.freezeRegs(&.{reg});
2578 defer self.register_manager.unfreezeRegs(&.{reg});2558 defer self.register_manager.unfreezeRegs(&.{reg});
...@@ -3025,7 +3005,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3025,7 +3005,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3025 .compare_flags_unsigned => unreachable,3005 .compare_flags_unsigned => unreachable,
3026 .compare_flags_signed => unreachable,3006 .compare_flags_signed => unreachable,
3027 .ptr_stack_offset => unreachable,3007 .ptr_stack_offset => unreachable,
3028 .ptr_embedded_in_code => unreachable,
3029 .register => |dst_reg| {3008 .register => |dst_reg| {
3030 switch (src_mcv) {3009 switch (src_mcv) {
3031 .none => unreachable,3010 .none => unreachable,
...@@ -3037,7 +3016,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3037,7 +3016,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3037 const reg = try self.copyToTmpRegister(dst_ty, src_mcv);3016 const reg = try self.copyToTmpRegister(dst_ty, src_mcv);
3038 return self.genBinMathOpMir(mir_tag, dst_ty, dst_mcv, .{ .register = reg });3017 return self.genBinMathOpMir(mir_tag, dst_ty, dst_mcv, .{ .register = reg });
3039 },3018 },
3040 .ptr_embedded_in_code => unreachable,
3041 .register => |src_reg| {3019 .register => |src_reg| {
3042 _ = try self.addInst(.{3020 _ = try self.addInst(.{
3043 .tag = mir_tag,3021 .tag = mir_tag,
...@@ -3057,7 +3035,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3057,7 +3035,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3057 .data = .{ .imm = @truncate(u32, imm) },3035 .data = .{ .imm = @truncate(u32, imm) },
3058 });3036 });
3059 },3037 },
3060 .embedded_in_code,
3061 .memory,3038 .memory,
3062 .got_load,3039 .got_load,
3063 .direct_load,3040 .direct_load,
...@@ -3099,7 +3076,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3099,7 +3076,6 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3099 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),3076 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),
3100 .dead, .unreach => unreachable,3077 .dead, .unreach => unreachable,
3101 .ptr_stack_offset => unreachable,3078 .ptr_stack_offset => unreachable,
3102 .ptr_embedded_in_code => unreachable,
3103 .register => |src_reg| {3079 .register => |src_reg| {
3104 _ = try self.addInst(.{3080 _ = try self.addInst(.{
3105 .tag = mir_tag,3081 .tag = mir_tag,
...@@ -3141,7 +3117,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3141,7 +3117,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3141 .data = .{ .payload = payload },3117 .data = .{ .payload = payload },
3142 });3118 });
3143 },3119 },
3144 .embedded_in_code, .memory, .stack_offset => {3120 .memory, .stack_offset => {
3145 return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{});3121 return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{});
3146 },3122 },
3147 .got_load, .direct_load => {3123 .got_load, .direct_load => {
...@@ -3155,7 +3131,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3155,7 +3131,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3155 },3131 },
3156 }3132 }
3157 },3133 },
3158 .embedded_in_code, .memory => {3134 .memory => {
3159 return self.fail("TODO implement x86 ADD/SUB/CMP destination memory", .{});3135 return self.fail("TODO implement x86 ADD/SUB/CMP destination memory", .{});
3160 },3136 },
3161 .got_load, .direct_load => {3137 .got_load, .direct_load => {
...@@ -3173,14 +3149,12 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3173,14 +3149,12 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3173 .compare_flags_unsigned => unreachable,3149 .compare_flags_unsigned => unreachable,
3174 .compare_flags_signed => unreachable,3150 .compare_flags_signed => unreachable,
3175 .ptr_stack_offset => unreachable,3151 .ptr_stack_offset => unreachable,
3176 .ptr_embedded_in_code => unreachable,
3177 .register => |dst_reg| {3152 .register => |dst_reg| {
3178 switch (src_mcv) {3153 switch (src_mcv) {
3179 .none => unreachable,3154 .none => unreachable,
3180 .undef => try self.genSetReg(dst_ty, dst_reg, .undef),3155 .undef => try self.genSetReg(dst_ty, dst_reg, .undef),
3181 .dead, .unreach => unreachable,3156 .dead, .unreach => unreachable,
3182 .ptr_stack_offset => unreachable,3157 .ptr_stack_offset => unreachable,
3183 .ptr_embedded_in_code => unreachable,
3184 .register => |src_reg| {3158 .register => |src_reg| {
3185 // register, register3159 // register, register
3186 _ = try self.addInst(.{3160 _ = try self.addInst(.{
...@@ -3222,7 +3196,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3222,7 +3196,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3222 .data = .{ .imm = @bitCast(u32, -off) },3196 .data = .{ .imm = @bitCast(u32, -off) },
3223 });3197 });
3224 },3198 },
3225 .embedded_in_code, .memory => {3199 .memory => {
3226 return self.fail("TODO implement x86 multiply source memory", .{});3200 return self.fail("TODO implement x86 multiply source memory", .{});
3227 },3201 },
3228 .got_load, .direct_load => {3202 .got_load, .direct_load => {
...@@ -3242,7 +3216,6 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3242,7 +3216,6 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3242 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),3216 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),
3243 .dead, .unreach => unreachable,3217 .dead, .unreach => unreachable,
3244 .ptr_stack_offset => unreachable,3218 .ptr_stack_offset => unreachable,
3245 .ptr_embedded_in_code => unreachable,
3246 .register => |src_reg| {3219 .register => |src_reg| {
3247 // copy dst to a register3220 // copy dst to a register
3248 const dst_reg = try self.copyToTmpRegister(dst_ty, dst_mcv);3221 const dst_reg = try self.copyToTmpRegister(dst_ty, dst_mcv);
...@@ -3263,7 +3236,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3263,7 +3236,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3263 _ = imm;3236 _ = imm;
3264 return self.fail("TODO implement x86 multiply source immediate", .{});3237 return self.fail("TODO implement x86 multiply source immediate", .{});
3265 },3238 },
3266 .embedded_in_code, .memory, .stack_offset => {3239 .memory, .stack_offset => {
3267 return self.fail("TODO implement x86 multiply source memory", .{});3240 return self.fail("TODO implement x86 multiply source memory", .{});
3268 },3241 },
3269 .got_load, .direct_load => {3242 .got_load, .direct_load => {
...@@ -3277,7 +3250,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3277,7 +3250,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3277 },3250 },
3278 }3251 }
3279 },3252 },
3280 .embedded_in_code, .memory => {3253 .memory => {
3281 return self.fail("TODO implement x86 multiply destination memory", .{});3254 return self.fail("TODO implement x86 multiply destination memory", .{});
3282 },3255 },
3283 .got_load, .direct_load => {3256 .got_load, .direct_load => {
...@@ -3396,14 +3369,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions....@@ -3396,14 +3369,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
3396 .ptr_stack_offset => {3369 .ptr_stack_offset => {
3397 return self.fail("TODO implement calling with MCValue.ptr_stack_offset arg", .{});3370 return self.fail("TODO implement calling with MCValue.ptr_stack_offset arg", .{});
3398 },3371 },
3399 .ptr_embedded_in_code => {
3400 return self.fail("TODO implement calling with MCValue.ptr_embedded_in_code arg", .{});
3401 },
3402 .undef => unreachable,3372 .undef => unreachable,
3403 .immediate => unreachable,3373 .immediate => unreachable,
3404 .unreach => unreachable,3374 .unreach => unreachable,
3405 .dead => unreachable,3375 .dead => unreachable,
3406 .embedded_in_code => unreachable,
3407 .memory => unreachable,3376 .memory => unreachable,
3408 .got_load => unreachable,3377 .got_load => unreachable,
3409 .direct_load => unreachable,3378 .direct_load => unreachable,
...@@ -4626,7 +4595,6 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE...@@ -4626,7 +4595,6 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
4626 const abi_size = ty.abiSize(self.target.*);4595 const abi_size = ty.abiSize(self.target.*);
4627 switch (mcv) {4596 switch (mcv) {
4628 .dead => unreachable,4597 .dead => unreachable,
4629 .ptr_embedded_in_code => unreachable,
4630 .unreach, .none => return,4598 .unreach, .none => return,
4631 .undef => {4599 .undef => {
4632 if (abi_size <= 8) {4600 if (abi_size <= 8) {
...@@ -4677,13 +4645,6 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE...@@ -4677,13 +4645,6 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
4677 else => return self.fail("TODO implement inputs on stack for {} with abi size > 8", .{mcv}),4645 else => return self.fail("TODO implement inputs on stack for {} with abi size > 8", .{mcv}),
4678 }4646 }
4679 },4647 },
4680 .embedded_in_code => {
4681 if (abi_size <= 8) {
4682 const reg = try self.copyToTmpRegister(ty, mcv);
4683 return self.genSetStackArg(ty, stack_offset, MCValue{ .register = reg });
4684 }
4685 return self.fail("TODO implement inputs on stack for {} with abi size > 8", .{mcv});
4686 },
4687 .memory,4648 .memory,
4688 .direct_load,4649 .direct_load,
4689 .got_load,4650 .got_load,
...@@ -4731,7 +4692,6 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl...@@ -4731,7 +4692,6 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl
4731 const abi_size = ty.abiSize(self.target.*);4692 const abi_size = ty.abiSize(self.target.*);
4732 switch (mcv) {4693 switch (mcv) {
4733 .dead => unreachable,4694 .dead => unreachable,
4734 .ptr_embedded_in_code => unreachable,
4735 .unreach, .none => return, // Nothing to do.4695 .unreach, .none => return, // Nothing to do.
4736 .undef => {4696 .undef => {
4737 if (!self.wantSafety())4697 if (!self.wantSafety())
...@@ -4870,7 +4830,6 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl...@@ -4870,7 +4830,6 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl
4870 }4830 }
4871 },4831 },
4872 .memory,4832 .memory,
4873 .embedded_in_code,
4874 .got_load,4833 .got_load,
4875 .direct_load,4834 .direct_load,
4876 => {4835 => {
...@@ -5222,7 +5181,6 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5222,7 +5181,6 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5222 .data = .{ .imm = @bitCast(u32, -off) },5181 .data = .{ .imm = @bitCast(u32, -off) },
5223 });5182 });
5224 },5183 },
5225 .ptr_embedded_in_code => unreachable,
5226 .unreach, .none => return, // Nothing to do.5184 .unreach, .none => return, // Nothing to do.
5227 .undef => {5185 .undef => {
5228 if (!self.wantSafety())5186 if (!self.wantSafety())
...@@ -5304,18 +5262,6 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5304,18 +5262,6 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5304 .data = .{ .payload = payload },5262 .data = .{ .payload = payload },
5305 });5263 });
5306 },5264 },
5307 .embedded_in_code => |code_offset| {
5308 // We need the offset from RIP in a signed i32 twos complement.
5309 const payload = try self.addExtra(Mir.Imm64.encode(code_offset));
5310 _ = try self.addInst(.{
5311 .tag = .lea,
5312 .ops = (Mir.Ops{
5313 .reg1 = reg,
5314 .flags = 0b01,
5315 }).encode(),
5316 .data = .{ .payload = payload },
5317 });
5318 },
5319 .register => |src_reg| {5265 .register => |src_reg| {
5320 // If the registers are the same, nothing to do.5266 // If the registers are the same, nothing to do.
5321 if (src_reg.id() == reg.id())5267 if (src_reg.id() == reg.id())