Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/scripts/compare-llvm-lines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
#
# Compare two cargo-llvm-lines output files and produce a markdown regression report.
#
# Usage:
# ./compare-llvm-lines.sh <baseline.txt> <current.txt>

set -euo pipefail

if [ $# -lt 2 ]; then
echo "Usage: $0 <baseline.txt> <current.txt>" >&2
exit 1
fi

baseline_file="$1"
current_file="$2"

baseline_total=$(awk '/\(TOTAL\)/{print $1}' "$baseline_file")
current_total=$(awk '/\(TOTAL\)/{print $1}' "$current_file")

if [ "$baseline_total" -eq 0 ]; then
echo "Error: baseline total is 0, cannot compute growth." >&2
exit 1
fi

delta_total=$(( current_total - baseline_total ))

# Parse llvm-lines output into "lines\tfunction_name" format.
# Skip header (3 lines) and TOTAL row. Extract the first number (lines count)
# and the function name (everything after the second parenthesized group).
parse() {
awk 'NR>3 && !/TOTAL/{
lines = $1
sub(/^[^)]*\)[^)]*\) */, "")
print lines "\t" $0
}' "$1" | sort -t$'\t' -k2
}

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
baseline_parsed_file="$tmpdir/llvm_baseline_parsed.txt"
current_parsed_file="$tmpdir/llvm_current_parsed.txt"

parse "$baseline_file" > "$baseline_parsed_file"
parse "$current_file" > "$current_parsed_file"

echo "| Delta | Current | Baseline | Function |"
echo "|-------|---------|----------|----------|"
printf "| %+d | %s | %s | (TOTAL) |\n" "$delta_total" "$current_total" "$baseline_total"
join -t$'\t' -j 2 -a1 -a2 -e 0 -o 0,1.1,2.1 \
"$current_parsed_file" "$baseline_parsed_file" | \
awk -F'\t' '{delta=$2-$3; printf "%d\t%s\t%s\t%s\n", delta, $2, $3, $1}' | \
sort -t$'\t' -k1,1rn -k2,2rn | \
awk -F'\t' '{printf "| %+d | %s | %s | %s |\n", $1, $2, $3, $4}'
echo ""
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,59 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# LLVM IR bloat check: compare monomorphization cost against baseline.
# This job is not part of the required CI gate, so it won't block PR merges.
llvm-lines:
Comment thread
harsha-simhadri marked this conversation as resolved.
if: github.event_name == 'pull_request'
needs: basics
name: LLVM Lines Regression Check
runs-on: ubuntu-latest
env:
LLVM_LINES_GROWTH_THRESHOLD: 5
steps:
- name: Checkout current branch
uses: actions/checkout@v4
with:
path: pr

- name: Checkout base ref
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
path: baseline

- name: Install Rust
shell: bash
run: rustup show
working-directory: pr

- name: Install cargo-llvm-lines
run: cargo install cargo-llvm-lines --locked

- uses: Swatinem/rust-cache@v2
with:
workspaces: |
pr -> target
baseline -> target

- name: Generate baseline LLVM lines
working-directory: baseline
run: cargo llvm-lines --package diskann-benchmark --all-features --release | head -100 | tee ../baseline-llvm-lines.txt

- name: Generate current LLVM lines
working-directory: pr
run: cargo llvm-lines --package diskann-benchmark --all-features --release | head -100 | tee ../current-llvm-lines.txt

- name: Compare LLVM lines
run: bash pr/.github/scripts/compare-llvm-lines.sh baseline-llvm-lines.txt current-llvm-lines.txt

- name: Check LLVM lines growth threshold
run: |
baseline_total=$(awk '/\(TOTAL\)/{print $1}' baseline-llvm-lines.txt)
current_total=$(awk '/\(TOTAL\)/{print $1}' current-llvm-lines.txt)
growth=$(( (current_total - baseline_total) * 100 / baseline_total ))

if [ "$growth" -gt "$LLVM_LINES_GROWTH_THRESHOLD" ]; then
echo "::error::LLVM IR grew ${growth}% ($baseline_total → $current_total lines), threshold is ${LLVM_LINES_GROWTH_THRESHOLD}%"
exit 1
fi
Loading