Profile-guided optimization script (#321)

This commit is contained in:
Jakub Nabaglo 2021-10-23 11:55:49 -07:00 committed by GitHub
parent 806641d13f
commit 7a8e12b8f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/target
Cargo.lock
/tmp
pgo-data.profdata

31
pgo-profile.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
rm -rf tmp/pgo
if !(rustup help >/dev/null); then
echo "Rustup not found; ensure rustup is on PATH" 1>&2
exit 1
fi
if !(rustup component add llvm-tools-preview); then
echo "Could not install llvm-tools-preview" 1>&2
exit 1
fi
TOOLCHAIN_BASE=$(dirname $(dirname $(rustup which cargo)))
TOOLCHAIN_NAME=$(basename $TOOLCHAIN_BASE)
TARGET_TRIPLE=${TOOLCHAIN_NAME#*"-"} # e.g. nightly-x86_64-apple-darwin -> x86_64-apple-darwin
PROFDATA_PATH=$TOOLCHAIN_BASE/lib/rustlib/$TARGET_TRIPLE/bin/llvm-profdata
if !(RUSTFLAGS="$RUSTFLAGS -Cprofile-generate=$(pwd)/tmp/pgo/data -Ctarget-cpu=native" cargo test --target-dir tmp/pgo/target --release test_recursive_recursive_verifier -- --ignored); then
echo "Build failed" 1>&2
exit 1
fi
if !($PROFDATA_PATH merge -o pgo-data.profdata tmp/pgo/data); then
echo "Could not create .profdata file" 1>&2
exit 1
fi
rm -rf tmp/pgo
echo '.profdata file successfully created. Add "-Cprofile-use=$(pwd)/pgo-data.profdata" to RUSTFLAGS to use it.' 1>&2