mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-08 08:44:37 +08:00
Optimize the speed runtime units with a committed runtime profile
The LLVM helper's runtime-unit now optimizes a unit itself (--opt-level), with IR instrumentation (--profile-generate) or a profile (--profile-use), through the same pipeline as program code. The Linux x64 pack's speed units are compiled to unoptimized bitcode and optimized there with packages/runtime-pack-common/profiles/linux-x64-gnu.profdata.gz, so one LLVM writes and reads every profile. Release and library flavors are unchanged. The pack manifest records how the profile matched the units. Code the runtime profile finds cold is optimized for speed, not size: a runtime function the training programs rarely call can be hot in another program. scr_message.c is optimized without the profile. scripts/refresh-runtime-profile.mjs trains the profile on the runtime benchmark workloads and, optionally, a tsc-ts checkout, and keeps only the records of functions the instrumented runtime units define (merge-profiles --keep-functions). Tests check that the profile still matches the runtime and names only runtime functions.
This commit is contained in:
@@ -58,6 +58,9 @@ int version(int Argc, char **Argv) {
|
||||
{"supported_targets", std::move(SupportedTargets)},
|
||||
{"default_target", scriptc::DefaultTarget},
|
||||
{"data_layout", Machine->createDataLayout().getStringRepresentation()},
|
||||
// Commands and options added within one protocol version, for callers
|
||||
// that also run against older helpers.
|
||||
{"features", json::Array{"runtime-unit-profile", "profile-functions"}},
|
||||
};
|
||||
outs() << formatv("{0}\n", json::Value(std::move(Response)));
|
||||
return 0;
|
||||
@@ -80,6 +83,8 @@ int main(int Argc, char **Argv) {
|
||||
return scriptc::pruneImport(Argc, Argv);
|
||||
if (Argc >= 2 && StringRef(Argv[1]) == "merge-profiles")
|
||||
return scriptc::mergeProfiles(Argc, Argv);
|
||||
if (Argc >= 2 && StringRef(Argv[1]) == "profile-functions")
|
||||
return scriptc::profileFunctions(Argc, Argv);
|
||||
if (Argc >= 2 && StringRef(Argv[1]) == "emit") {
|
||||
std::optional<scriptc::EmitOptions> Options =
|
||||
scriptc::parseEmitOptions(Argc, Argv);
|
||||
@@ -95,5 +100,6 @@ int main(int Argc, char **Argv) {
|
||||
}
|
||||
return scriptc::reportError("usage",
|
||||
"expected 'version --format=json', 'emit', 'runtime-unit', "
|
||||
"'prune-import', or 'merge-profiles'");
|
||||
"'prune-import', 'merge-profiles', or "
|
||||
"'profile-functions'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user