authorgravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-10-31 14:29:49+00:00
committergravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-10-31 14:29:49+00:00
log8a3a6a98aadcaf8fd13dd02e5efe9752326ce306
tree8dc0905d9430ffc206ae41ef0df976a67d46a937
parent49d8723408233ac1c8942eca0a52ca12188040ce

use named frames to mark the stages of compilation


1 files changed, 104 insertions(+), 17 deletions(-)

src/Compilation.zig+104-17
......@@ -13,7 +13,8 @@ const Type = @import("type.zig").Type;
1313const target_util = @import("target.zig");
1414const Package = @import("Package.zig");
1515const link = @import("link.zig");
16const trace = @import("tracy.zig").trace;
16const tracy = @import("tracy.zig");
17const trace = tracy.trace;
1718const Liveness = @import("Liveness.zig");
1819const build_options = @import("build_options");
1920const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
......@@ -1726,8 +1727,8 @@ pub fn getTarget(self: Compilation) Target {
17261727
17271728/// Detect changes to source files, perform semantic analysis, and update the output files.
17281729pub fn update(self: *Compilation) !void {
1729 const tracy = trace(@src());
1730 defer tracy.end();
1730 const t = trace(@src());
1731 defer t.end();
17311732
17321733 self.clearMiscFailures();
17331734
......@@ -2111,6 +2112,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
21112112 defer self.work_queue_wait_group.wait();
21122113
21132114 {
2115 const astgen_frame = tracy.namedFrame("astgen");
2116 defer astgen_frame.end();
2117
21142118 self.astgen_wait_group.reset();
21152119 defer self.astgen_wait_group.wait();
21162120
......@@ -2138,6 +2142,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
21382142
21392143 const use_stage1 = build_options.is_stage1 and self.bin_file.options.use_stage1;
21402144 if (!use_stage1) {
2145 const outdated_and_deleted_decls_frame = tracy.namedFrame("outdated_and_deleted_decls");
2146 defer outdated_and_deleted_decls_frame.end();
2147
21412148 // Iterate over all the files and look for outdated and deleted declarations.
21422149 if (self.bin_file.options.module) |mod| {
21432150 try mod.processOutdatedAndDeletedDecls();
......@@ -2181,6 +2188,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
21812188 => return,
21822189
21832190 .complete, .codegen_failure_retryable => {
2191 const named_frame = tracy.namedFrame("codegen_decl");
2192 defer named_frame.end();
2193
21842194 if (build_options.omit_stage2)
21852195 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
21862196
......@@ -2230,6 +2240,10 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
22302240 defer tmp_arena.deinit();
22312241 const sema_arena = &tmp_arena.allocator;
22322242
2243 const sema_frame = tracy.namedFrame("sema");
2244 var sema_frame_ended = false;
2245 errdefer if (!sema_frame_ended) sema_frame.end();
2246
22332247 var air = module.analyzeFnBody(decl, func, sema_arena) catch |err| switch (err) {
22342248 error.AnalysisFail => {
22352249 assert(func.state != .in_progress);
......@@ -2239,16 +2253,29 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
22392253 };
22402254 defer air.deinit(gpa);
22412255
2256 sema_frame.end();
2257 sema_frame_ended = true;
2258
2259 const liveness_frame = tracy.namedFrame("liveness");
2260 var liveness_frame_ended = false;
2261 errdefer if (!liveness_frame_ended) liveness_frame.end();
2262
22422263 log.debug("analyze liveness of {s}", .{decl.name});
22432264 var liveness = try Liveness.analyze(gpa, air, decl.getFileScope().zir);
22442265 defer liveness.deinit(gpa);
22452266
2267 liveness_frame.end();
2268 liveness_frame_ended = true;
2269
22462270 if (builtin.mode == .Debug and comp.verbose_air) {
22472271 std.debug.print("# Begin Function AIR: {s}:\n", .{decl.name});
22482272 @import("print_air.zig").dump(gpa, air, decl.getFileScope().zir, liveness);
22492273 std.debug.print("# End Function AIR: {s}\n\n", .{decl.name});
22502274 }
22512275
2276 const named_frame = tracy.namedFrame("codegen");
2277 defer named_frame.end();
2278
22522279 comp.bin_file.updateFunc(module, func, air, liveness) catch |err| switch (err) {
22532280 error.OutOfMemory => return error.OutOfMemory,
22542281 error.AnalysisFail => {
......@@ -2284,6 +2311,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
22842311 // emit-h only requires semantic analysis of the Decl to be complete,
22852312 // it does not depend on machine code generation to succeed.
22862313 .codegen_failure, .codegen_failure_retryable, .complete => {
2314 const named_frame = tracy.namedFrame("emit_h_decl");
2315 defer named_frame.end();
2316
22872317 if (build_options.omit_stage2)
22882318 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
22892319 const gpa = comp.gpa;
......@@ -2321,6 +2351,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23212351 },
23222352 },
23232353 .analyze_decl => |decl| {
2354 const named_frame = tracy.namedFrame("analyze_decl");
2355 defer named_frame.end();
2356
23242357 if (build_options.omit_stage2)
23252358 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
23262359 const module = comp.bin_file.options.module.?;
......@@ -2330,6 +2363,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23302363 };
23312364 },
23322365 .update_embed_file => |embed_file| {
2366 const named_frame = tracy.namedFrame("update_embed_file");
2367 defer named_frame.end();
2368
23332369 if (build_options.omit_stage2)
23342370 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
23352371 const module = comp.bin_file.options.module.?;
......@@ -2339,6 +2375,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23392375 };
23402376 },
23412377 .update_line_number => |decl| {
2378 const named_frame = tracy.namedFrame("update_line_number");
2379 defer named_frame.end();
2380
23422381 if (build_options.omit_stage2)
23432382 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
23442383 const gpa = comp.gpa;
......@@ -2355,6 +2394,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23552394 };
23562395 },
23572396 .analyze_pkg => |pkg| {
2397 const named_frame = tracy.namedFrame("analyze_pkg");
2398 defer named_frame.end();
2399
23582400 if (build_options.omit_stage2)
23592401 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
23602402 const module = comp.bin_file.options.module.?;
......@@ -2371,6 +2413,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23712413 };
23722414 },
23732415 .glibc_crt_file => |crt_file| {
2416 const named_frame = tracy.namedFrame("glibc_crt_file");
2417 defer named_frame.end();
2418
23742419 glibc.buildCRTFile(comp, crt_file) catch |err| {
23752420 // TODO Surface more error details.
23762421 try comp.setMiscFailure(.glibc_crt_file, "unable to build glibc CRT file: {s}", .{
......@@ -2379,6 +2424,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23792424 };
23802425 },
23812426 .glibc_shared_objects => {
2427 const named_frame = tracy.namedFrame("glibc_shared_objects");
2428 defer named_frame.end();
2429
23822430 glibc.buildSharedObjects(comp) catch |err| {
23832431 // TODO Surface more error details.
23842432 try comp.setMiscFailure(
......@@ -2389,6 +2437,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23892437 };
23902438 },
23912439 .musl_crt_file => |crt_file| {
2440 const named_frame = tracy.namedFrame("musl_crt_file");
2441 defer named_frame.end();
2442
23922443 musl.buildCRTFile(comp, crt_file) catch |err| {
23932444 // TODO Surface more error details.
23942445 try comp.setMiscFailure(
......@@ -2399,6 +2450,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
23992450 };
24002451 },
24012452 .mingw_crt_file => |crt_file| {
2453 const named_frame = tracy.namedFrame("mingw_crt_file");
2454 defer named_frame.end();
2455
24022456 mingw.buildCRTFile(comp, crt_file) catch |err| {
24032457 // TODO Surface more error details.
24042458 try comp.setMiscFailure(
......@@ -2409,6 +2463,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24092463 };
24102464 },
24112465 .windows_import_lib => |index| {
2466 const named_frame = tracy.namedFrame("windows_import_lib");
2467 defer named_frame.end();
2468
24122469 const link_lib = comp.bin_file.options.system_libs.keys()[index];
24132470 mingw.buildImportLib(comp, link_lib) catch |err| {
24142471 // TODO Surface more error details.
......@@ -2420,6 +2477,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24202477 };
24212478 },
24222479 .libunwind => {
2480 const named_frame = tracy.namedFrame("libunwind");
2481 defer named_frame.end();
2482
24232483 libunwind.buildStaticLib(comp) catch |err| {
24242484 // TODO Surface more error details.
24252485 try comp.setMiscFailure(
......@@ -2430,6 +2490,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24302490 };
24312491 },
24322492 .libcxx => {
2493 const named_frame = tracy.namedFrame("libcxx");
2494 defer named_frame.end();
2495
24332496 libcxx.buildLibCXX(comp) catch |err| {
24342497 // TODO Surface more error details.
24352498 try comp.setMiscFailure(
......@@ -2440,6 +2503,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24402503 };
24412504 },
24422505 .libcxxabi => {
2506 const named_frame = tracy.namedFrame("libcxxabi");
2507 defer named_frame.end();
2508
24432509 libcxx.buildLibCXXABI(comp) catch |err| {
24442510 // TODO Surface more error details.
24452511 try comp.setMiscFailure(
......@@ -2450,6 +2516,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24502516 };
24512517 },
24522518 .libtsan => {
2519 const named_frame = tracy.namedFrame("libtsan");
2520 defer named_frame.end();
2521
24532522 libtsan.buildTsan(comp) catch |err| {
24542523 // TODO Surface more error details.
24552524 try comp.setMiscFailure(
......@@ -2460,6 +2529,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24602529 };
24612530 },
24622531 .wasi_libc_crt_file => |crt_file| {
2532 const named_frame = tracy.namedFrame("wasi_libc_crt_file");
2533 defer named_frame.end();
2534
24632535 wasi_libc.buildCRTFile(comp, crt_file) catch |err| {
24642536 // TODO Surface more error details.
24652537 try comp.setMiscFailure(
......@@ -2470,6 +2542,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24702542 };
24712543 },
24722544 .compiler_rt_lib => {
2545 const named_frame = tracy.namedFrame("compiler_rt_lib");
2546 defer named_frame.end();
2547
24732548 comp.buildOutputFromZig(
24742549 "compiler_rt.zig",
24752550 .Lib,
......@@ -2486,6 +2561,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
24862561 };
24872562 },
24882563 .compiler_rt_obj => {
2564 const named_frame = tracy.namedFrame("compiler_rt_obj");
2565 defer named_frame.end();
2566
24892567 comp.buildOutputFromZig(
24902568 "compiler_rt.zig",
24912569 .Obj,
......@@ -2502,6 +2580,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
25022580 };
25032581 },
25042582 .libssp => {
2583 const named_frame = tracy.namedFrame("libssp");
2584 defer named_frame.end();
2585
25052586 comp.buildOutputFromZig(
25062587 "ssp.zig",
25072588 .Lib,
......@@ -2518,6 +2599,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
25182599 };
25192600 },
25202601 .zig_libc => {
2602 const named_frame = tracy.namedFrame("zig_libc");
2603 defer named_frame.end();
2604
25212605 comp.buildOutputFromZig(
25222606 "c.zig",
25232607 .Lib,
......@@ -2534,6 +2618,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress
25342618 };
25352619 },
25362620 .stage1_module => {
2621 const named_frame = tracy.namedFrame("stage1_module");
2622 defer named_frame.end();
2623
25372624 if (!build_options.is_stage1)
25382625 unreachable;
25392626
......@@ -2674,8 +2761,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
26742761 if (!build_options.have_llvm)
26752762 return error.ZigCompilerNotBuiltWithLLVMExtensions;
26762763
2677 const tracy = trace(@src());
2678 defer tracy.end();
2764 const t = trace(@src());
2765 defer t.end();
26792766
26802767 const cimport_zig_basename = "cimport.zig";
26812768
......@@ -2929,8 +3016,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
29293016 const self_exe_path = comp.self_exe_path orelse
29303017 return comp.failCObj(c_object, "clang compilation disabled", .{});
29313018
2932 const tracy = trace(@src());
2933 defer tracy.end();
3019 const t = trace(@src());
3020 defer t.end();
29343021
29353022 log.debug("updating C object: {s}", .{c_object.src.src_path});
29363023
......@@ -3828,8 +3915,8 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool {
38283915}
38293916
38303917fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void {
3831 const tracy = trace(@src());
3832 defer tracy.end();
3918 const t = trace(@src());
3919 defer t.end();
38333920
38343921 const source = try comp.generateBuiltinZigSource(comp.gpa);
38353922 defer comp.gpa.free(source);
......@@ -3866,8 +3953,8 @@ pub fn dump_argv(argv: []const []const u8) void {
38663953}
38673954
38683955pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Allocator.Error![]u8 {
3869 const tracy = trace(@src());
3870 defer tracy.end();
3956 const t = trace(@src());
3957 defer t.end();
38713958
38723959 var buffer = std.ArrayList(u8).init(allocator);
38733960 defer buffer.deinit();
......@@ -4112,8 +4199,8 @@ fn buildOutputFromZig(
41124199 out: *?CRTFile,
41134200 misc_task_tag: MiscTask,
41144201) !void {
4115 const tracy = trace(@src());
4116 defer tracy.end();
4202 const t = trace(@src());
4203 defer t.end();
41174204
41184205 std.debug.assert(output_mode != .Exe);
41194206 const special_sub = "std" ++ std.fs.path.sep_str ++ "special";
......@@ -4211,8 +4298,8 @@ fn buildOutputFromZig(
42114298}
42124299
42134300fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node) !void {
4214 const tracy = trace(@src());
4215 defer tracy.end();
4301 const t = trace(@src());
4302 defer t.end();
42164303
42174304 var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);
42184305 defer arena_allocator.deinit();
......@@ -4564,8 +4651,8 @@ pub fn build_crt_file(
45644651 output_mode: std.builtin.OutputMode,
45654652 c_source_files: []const Compilation.CSourceFile,
45664653) !void {
4567 const tracy = trace(@src());
4568 defer tracy.end();
4654 const t = trace(@src());
4655 defer t.end();
45694656
45704657 const target = comp.getTarget();
45714658 const basename = try std.zig.binNameAlloc(comp.gpa, .{