Skip to content

Commit d83a26f

Browse files
committed
stage2 llvm: keep track of inlined functions
1 parent 0343811 commit d83a26f

File tree

14 files changed

+132
-46
lines changed

14 files changed

+132
-46
lines changed

src/Air.zig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,12 @@ pub const Inst = struct {
326326
/// Result type is always void.
327327
/// Uses the `dbg_stmt` field.
328328
dbg_stmt,
329-
/// Marks change of source function. Emitted around an inline call.
329+
/// Marks the start of an inline call.
330330
/// Uses `ty_pl` with the payload being the index of a Value.Function in air.values.
331-
dbg_func,
331+
dbg_inline_begin,
332+
/// Marks the end of an inline call.
333+
/// Uses `ty_pl` with the payload being the index of a Value.Function in air.values.
334+
dbg_inline_end,
332335
/// Marks the beginning of a local variable. The operand is a pointer pointing
333336
/// to the storage for the variable. The local may be a const or a var.
334337
/// Result type is always void.
@@ -973,7 +976,8 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
973976

974977
.breakpoint,
975978
.dbg_stmt,
976-
.dbg_func,
979+
.dbg_inline_begin,
980+
.dbg_inline_end,
977981
.dbg_var_ptr,
978982
.dbg_var_val,
979983
.store,

src/Liveness.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ fn analyzeInst(
314314
.const_ty,
315315
.breakpoint,
316316
.dbg_stmt,
317-
.dbg_func,
317+
.dbg_inline_begin,
318+
.dbg_inline_end,
318319
.unreach,
319320
.fence,
320321
.ret_addr,

src/Sema.zig

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4765,7 +4765,9 @@ fn analyzeCall(
47654765
}
47664766

47674767
const new_func_resolved_ty = try Type.Tag.function.create(sema.arena, new_fn_info);
4768-
if (!is_comptime_call) try sema.emitDbgFunc(block, parent_func.?, module_fn, new_func_resolved_ty);
4768+
if (!is_comptime_call) {
4769+
try sema.emitDbgInline(block, parent_func.?, module_fn, new_func_resolved_ty, .dbg_inline_begin);
4770+
}
47694771

47704772
const result = result: {
47714773
sema.analyzeBody(&child_block, fn_info.body) catch |err| switch (err) {
@@ -4781,7 +4783,9 @@ fn analyzeCall(
47814783
break :result try sema.analyzeBlockBody(block, call_src, &child_block, merges);
47824784
};
47834785

4784-
if (!is_comptime_call) try sema.emitDbgFunc(block, module_fn, parent_func.?, parent_func.?.owner_decl.ty);
4786+
if (!is_comptime_call) {
4787+
try sema.emitDbgInline(block, module_fn, parent_func.?, parent_func.?.owner_decl.ty, .dbg_inline_end);
4788+
}
47854789

47864790
if (should_memoize and is_comptime_call) {
47874791
const result_val = try sema.resolveConstMaybeUndefVal(block, call_src, result);
@@ -5187,19 +5191,20 @@ fn instantiateGenericCall(
51875191
return func_inst;
51885192
}
51895193

5190-
fn emitDbgFunc(
5194+
fn emitDbgInline(
51915195
sema: *Sema,
51925196
block: *Block,
51935197
old_func: *Module.Fn,
51945198
new_func: *Module.Fn,
51955199
new_func_ty: Type,
5200+
tag: Air.Inst.Tag,
51965201
) CompileError!void {
5197-
// No change of file; no dbg_func needed.
5202+
// No change of file; no dbg_inline needed.
51985203
if (old_func == new_func) return;
51995204

52005205
try sema.air_values.append(sema.gpa, try Value.Tag.function.create(sema.arena, new_func));
52015206
_ = try block.addInst(.{
5202-
.tag = .dbg_func,
5207+
.tag = tag,
52035208
.data = .{ .ty_pl = .{
52045209
.ty = try sema.addType(new_func_ty),
52055210
.payload = @intCast(u32, sema.air_values.items.len - 1),

src/arch/aarch64/CodeGen.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
598598
.fence => try self.airFence(),
599599
.cond_br => try self.airCondBr(inst),
600600
.dbg_stmt => try self.airDbgStmt(inst),
601-
.dbg_func => try self.airDbgFunc(inst),
602601
.fptrunc => try self.airFptrunc(inst),
603602
.fpext => try self.airFpext(inst),
604603
.intcast => try self.airIntCast(inst),
@@ -650,6 +649,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
650649
.dbg_var_val,
651650
=> try self.airDbgVar(inst),
652651

652+
.dbg_inline_begin,
653+
.dbg_inline_end,
654+
=> try self.airDbgInline(inst),
655+
653656
.call => try self.airCall(inst, .auto),
654657
.call_always_tail => try self.airCall(inst, .always_tail),
655658
.call_never_tail => try self.airCall(inst, .never_tail),
@@ -2716,7 +2719,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
27162719
return self.finishAirBookkeeping();
27172720
}
27182721

2719-
fn airDbgFunc(self: *Self, inst: Air.Inst.Index) !void {
2722+
fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
27202723
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
27212724
const function = self.air.values[ty_pl.payload].castTag(.function).?.data;
27222725
// TODO emit debug info for function change

src/arch/arm/CodeGen.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
595595
.fence => try self.airFence(),
596596
.cond_br => try self.airCondBr(inst),
597597
.dbg_stmt => try self.airDbgStmt(inst),
598-
.dbg_func => try self.airDbgFunc(inst),
599598
.fptrunc => try self.airFptrunc(inst),
600599
.fpext => try self.airFpext(inst),
601600
.intcast => try self.airIntCast(inst),
@@ -647,6 +646,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
647646
.dbg_var_val,
648647
=> try self.airDbgVar(inst),
649648

649+
.dbg_inline_begin,
650+
.dbg_inline_end,
651+
=> try self.airDbgInline(inst),
652+
650653
.call => try self.airCall(inst, .auto),
651654
.call_always_tail => try self.airCall(inst, .always_tail),
652655
.call_never_tail => try self.airCall(inst, .never_tail),
@@ -2836,7 +2839,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
28362839
return self.finishAirBookkeeping();
28372840
}
28382841

2839-
fn airDbgFunc(self: *Self, inst: Air.Inst.Index) !void {
2842+
fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
28402843
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
28412844
const function = self.air.values[ty_pl.payload].castTag(.function).?.data;
28422845
// TODO emit debug info for function change

src/arch/riscv64/CodeGen.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
562562
.fence => try self.airFence(),
563563
.cond_br => try self.airCondBr(inst),
564564
.dbg_stmt => try self.airDbgStmt(inst),
565-
.dbg_func => try self.airDbgFunc(inst),
566565
.fptrunc => try self.airFptrunc(inst),
567566
.fpext => try self.airFpext(inst),
568567
.intcast => try self.airIntCast(inst),
@@ -614,6 +613,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
614613
.dbg_var_val,
615614
=> try self.airDbgVar(inst),
616615

616+
.dbg_inline_begin,
617+
.dbg_inline_end,
618+
=> try self.airDbgInline(inst),
619+
617620
.call => try self.airCall(inst, .auto),
618621
.call_always_tail => try self.airCall(inst, .always_tail),
619622
.call_never_tail => try self.airCall(inst, .never_tail),
@@ -1641,7 +1644,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
16411644
return self.finishAirBookkeeping();
16421645
}
16431646

1644-
fn airDbgFunc(self: *Self, inst: Air.Inst.Index) !void {
1647+
fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
16451648
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
16461649
const function = self.air.values[ty_pl.payload].castTag(.function).?.data;
16471650
// TODO emit debug info for function change

src/arch/wasm/CodeGen.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,8 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
12271227

12281228
// TODO
12291229
.dbg_stmt,
1230-
.dbg_func,
1230+
.dbg_inline_begin,
1231+
.dbg_inline_end,
12311232
.dbg_var_ptr,
12321233
.dbg_var_val,
12331234
=> WValue.none,

src/arch/x86_64/CodeGen.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
679679
.fence => try self.airFence(),
680680
.cond_br => try self.airCondBr(inst),
681681
.dbg_stmt => try self.airDbgStmt(inst),
682-
.dbg_func => try self.airDbgFunc(inst),
683682
.fptrunc => try self.airFptrunc(inst),
684683
.fpext => try self.airFpext(inst),
685684
.intcast => try self.airIntCast(inst),
@@ -731,6 +730,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
731730
.dbg_var_val,
732731
=> try self.airDbgVar(inst),
733732

733+
.dbg_inline_begin,
734+
.dbg_inline_end,
735+
=> try self.airDbgInline(inst),
736+
734737
.call => try self.airCall(inst, .auto),
735738
.call_always_tail => try self.airCall(inst, .always_tail),
736739
.call_never_tail => try self.airCall(inst, .never_tail),
@@ -3671,7 +3674,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
36713674
return self.finishAirBookkeeping();
36723675
}
36733676

3674-
fn airDbgFunc(self: *Self, inst: Air.Inst.Index) !void {
3677+
fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
36753678
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
36763679
const function = self.air.values[ty_pl.payload].castTag(.function).?.data;
36773680
// TODO emit debug info for function change

src/codegen/c.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,6 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
16871687
.block => try airBlock(f, inst),
16881688
.bitcast => try airBitcast(f, inst),
16891689
.dbg_stmt => try airDbgStmt(f, inst),
1690-
.dbg_func => try airDbgFunc(f, inst),
16911690
.intcast => try airIntCast(f, inst),
16921691
.trunc => try airTrunc(f, inst),
16931692
.bool_to_int => try airBoolToInt(f, inst),
@@ -1727,6 +1726,10 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
17271726
.dbg_var_val,
17281727
=> try airDbgVar(f, inst),
17291728

1729+
.dbg_inline_begin,
1730+
.dbg_inline_end,
1731+
=> try airDbgInline(f, inst),
1732+
17301733
.call => try airCall(f, inst, .auto),
17311734
.call_always_tail => try airCall(f, inst, .always_tail),
17321735
.call_never_tail => try airCall(f, inst, .never_tail),
@@ -2661,7 +2664,7 @@ fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue {
26612664
return CValue.none;
26622665
}
26632666

2664-
fn airDbgFunc(f: *Function, inst: Air.Inst.Index) !CValue {
2667+
fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {
26652668
const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
26662669
const writer = f.object.writer();
26672670
const function = f.air.values[ty_pl.payload].castTag(.function).?.data;

0 commit comments

Comments
 (0)