aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-02-28 13:38:33 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-02-28 13:38:33 -0700
commitd5100dc81555f0e8197d5f189b1432070e8d72dd (patch)
tree96de992b22f7cfc4bcb672892c64fb2cdf621913 /src/codegen/llvm.zig
parent90bce11f62aa2f246b9bce5bc49069a3faf7ec9a (diff)
downloadzig-d5100dc81555f0e8197d5f189b1432070e8d72dd.tar.gz
zig-d5100dc81555f0e8197d5f189b1432070e8d72dd.zip
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.
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig36
1 files changed, 19 insertions, 17 deletions
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, &params, 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, &params, 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 {