From d5100dc81555f0e8197d5f189b1432070e8d72dd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 28 Feb 2022 13:38:33 -0700 Subject: stage2: fix frame_address AIR instruction Various places were assuming different union tags. Now it is consistently a no-op instruction, just like the similar instruction ret_addr. --- src/codegen/llvm.zig | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/codegen/llvm.zig') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 6f2cc9bbd0..ddd6e7c06b 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2135,6 +2135,7 @@ pub const FuncGen = struct { .switch_br => try self.airSwitchBr(inst), .breakpoint => try self.airBreakpoint(inst), .ret_addr => try self.airRetAddr(inst), + .frame_addr => try self.airFrameAddress(inst), .call => try self.airCall(inst), .cond_br => try self.airCondBr(inst), .intcast => try self.airIntCast(inst), @@ -2214,8 +2215,6 @@ pub const FuncGen = struct { .wrap_errunion_payload => try self.airWrapErrUnionPayload(inst), .wrap_errunion_err => try self.airWrapErrUnionErr(inst), - .frame_address => try self.airFrameAddress(inst), - .constant => unreachable, .const_ty => unreachable, .unreach => self.airUnreach(inst), @@ -3341,16 +3340,6 @@ pub const FuncGen = struct { return partial; } - fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { - if (self.liveness.isUnused(inst)) return null; - - const llvm_i32 = try self.dg.llvmType(Type.initTag(.i32)); - const llvm_fn = self.getIntrinsic("llvm.frameaddress", &.{llvm_i32}); - const ptr_val = self.builder.buildCall(llvm_fn, &[_]*const llvm.Value{llvm_i32.constNull()}, 1, .Fast, .Auto, ""); - const llvm_usize = try self.dg.llvmType(Type.usize); - return self.builder.buildPtrToInt(ptr_val, llvm_usize, ""); - } - fn airMin(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { if (self.liveness.isUnused(inst)) return null; @@ -4112,12 +4101,25 @@ pub const FuncGen = struct { } fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { - _ = inst; - const i32_zero = self.context.intType(32).constNull(); - const usize_llvm_ty = try self.dg.llvmType(Type.usize); + if (self.liveness.isUnused(inst)) return null; + + const llvm_i32 = self.context.intType(32); const llvm_fn = self.getIntrinsic("llvm.returnaddress", &.{}); - const ptr_val = self.builder.buildCall(llvm_fn, &[_]*const llvm.Value{i32_zero}, 1, .Fast, .Auto, ""); - return self.builder.buildPtrToInt(ptr_val, usize_llvm_ty, ""); + const params = [_]*const llvm.Value{llvm_i32.constNull()}; + const ptr_val = self.builder.buildCall(llvm_fn, ¶ms, params.len, .Fast, .Auto, ""); + const llvm_usize = try self.dg.llvmType(Type.usize); + return self.builder.buildPtrToInt(ptr_val, llvm_usize, ""); + } + + fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { + if (self.liveness.isUnused(inst)) return null; + + const llvm_i32 = self.context.intType(32); + const llvm_fn = self.getIntrinsic("llvm.frameaddress", &.{llvm_i32}); + const params = [_]*const llvm.Value{llvm_i32.constNull()}; + const ptr_val = self.builder.buildCall(llvm_fn, ¶ms, params.len, .Fast, .Auto, ""); + const llvm_usize = try self.dg.llvmType(Type.usize); + return self.builder.buildPtrToInt(ptr_val, llvm_usize, ""); } fn airFence(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { -- cgit v1.2.3