tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

61 lignes · 2620 octetsBrut · Historique
1#!/usr/bin/env bash
2# PGO for the fast runtime archive (issue #193, step 2): builds
3# liblouise_rt instrumented, trains it on the benchmarks, rebuilds with
4# the profile, and leaves a directory with the result as
5# liblouise_rt-fast.a. Link it with:
6#
7# LOUISE_LIB_DIR=target/pgo/use LOUISE_RUNTIME=fast louise build --release …
8#
9# The recipe's traps, found the hard way:
10# - the *link* needs the driver's `-fprofile-generate` flag, not just the
11# archive: without it the profile writer is never registered and no
12# .profraw is written (any linker, with or without --gc-sections);
13# - the instrumented archive must also be on the link line (it is, as the
14# fast archive);
15# - PGO applies to the `fast` (machine-code) archive; with ThinLTO the
16# runtime is re-laid-out at the program's link, where this profile does
17# not reach.
18#
19# Measured 2026-10-15 (best of 5-8, pinned, interleaved; instructions in
20# parentheses): fanin -25% (-22%), selective -17% (-18%), records -8%
21# (-11%), html ~+2% (careful re-measure; a first pass said +14%, which
22# was run-order noise), the compute benchmarks ~0%. Trained on
23# tests/bench.
24set -euo pipefail
25cd "$(dirname "$0")/.."
26
27out=target/pgo
28raw="$PWD/$out/profraw"
29rm -rf "$out"
30mkdir -p "$raw" "$out/bin" "$out/use"
31
32echo "== instrumented runtime" >&2
33RUSTFLAGS="-Cprofile-generate=$raw" \
34 cargo build --quiet --profile runtime -p louise_rt --no-default-features --features mimalloc,tls,crypto \
35 --target-dir "$out/gen"
36cp "$out/gen/runtime/liblouise_rt.a" "$out/use/liblouise_rt-fast.a"
37
38echo "== instrumented benchmarks" >&2
39# The link needs the driver's flag (see the header); the training builds'
40# own C is instrumented too, harmlessly.
41for program in tests/bench/*.lse; do
42 name="$(basename "$program" .lse)"
43 LOUISE_LIB_DIR="$PWD/$out/use" LOUISE_RUNTIME=fast \
44 LOUISE_CFLAGS="-fprofile-generate=$raw" \
45 ./target/dist/louise build --release "$program" -o "$out/bin/$name" >/dev/null
46done
47
48echo "== training run" >&2
49for bin in "$out"/bin/*; do
50 [ -f "$bin" ] && [ -x "$bin" ] || continue
51 "$bin" >/dev/null
52done
53[ -z "$(ls -A "$raw" 2>/dev/null)" ] && { echo "pgo-runtime: no profiles written (see the header's traps)" >&2; exit 1; }
54llvm-profdata merge -o "$out/rt.profdata" "$raw"/*.profraw
55
56echo "== runtime with the profile" >&2
57RUSTFLAGS="-Cprofile-use=$PWD/$out/rt.profdata" \
58 cargo build --quiet --profile runtime -p louise_rt --no-default-features --features mimalloc,tls,crypto \
59 --target-dir "$out/final"
60cp "$out/final/runtime/liblouise_rt.a" "$out/use/liblouise_rt-fast.a"
61echo "pgo-runtime: $out/use/liblouise_rt-fast.a" >&2