mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
A profile annotates a function only while its control flow hashes as it did when the profile was collected, so compiler and source changes leave the changed functions without counts. A --profile-use build now reads a block-count file beside the profile (app.blocks beside app.profdata). Right after the annotation before inlining, the helper aligns each uncounted function's blocks with its recorded blocks by label kind and successor count. Paired blocks take their recorded counts and their edges the recorded edge counts, by target or, between targets whose labels changed, by position. LLVM's flow inference fills in the rest, avoiding the edges the function's own llvm.expect weights make unlikely. The helper then sets the entry count, branch weights and hot or cold attribute as the profile annotation does. SCRIPTC_RECORD_PROFILE_BLOCKS names the file a --profile-use build writes for the functions its profile annotates; such a build reuses no cached artifacts. The block file keys every cache, the build report counts the functions it annotated, and the staleness warning counts only the functions left without counts. A single-module build with a context-sensitive profile no longer counts annotated, mismatched and missing functions a second time after inlining. scripts/refresh-cli-profile.mjs records the file in the second phase and build-native-cli.mts reads it beside the profile.