llvm-project
9cff8cc6 - [analyzer][NFC] Memoize inferred symbol ranges per ProgramState (#246900)

Commit
4 days ago
[analyzer][NFC] Memoize inferred symbol ranges per ProgramState (#246900) The inferred range of a symbol is a pure function of the ProgramState, yet simplifying an SVal queries the range of every sub-expression again and again against the same state. Memoize the ranges for the most recently queried state in RangeConstraintManager (a DenseMap<SymbolRef, RangeSet> plus the state it belongs to; it is cleared when a different state is queried). SymbolicRangeInferrer takes the cache as an optional, nullable pointer; the static inferRange() call sites pass none (a stack-local cache there never got a lookup: 0 hits over 76406 instances on the corpus below). Why this is safe: the cache holds a ProgramStateRef, so the state stays alive and its address cannot be recycled for a different state while it is the cache key. To make that hold at destruction time, ConstraintMgr is now declared last in ProgramStateManager and is destroyed first, while the state set, the allocator and the GDM contexts are still alive. Measurements (base = origin/main 2e6a92abfd76, which is the parent of this change up to an NFC; both binaries built with the same config). Metric: user-space instructions retired from `/usr/bin/time -l`, median of 3 runs, base and head interleaved. Same checkers everywhere: core,deadcode,alpha.core,unix,nullability,alpha.security,optin,alpha.unix,core.builtin with unroll-loops=true and eagerly-assume=true. Run-to-run spread of identical binaries is <= 0.5% (<= 1.5% on a few runs), so only differences above ~0.7% are meaningful. (1) Reproducers from llvm/llvm-project#105512, `clang -cc1 -analyze` -triple x86_64-unknown-linux-gnu, ON = defaults, OFF = -analyzer-config graph-trim-interval=0 (instructions, millions): file mode before after change linux-topro.c ON 61074 48508 -20.6% linux-topro.c OFF 61491 49056 -20.2% ruby-unicode.c ON 22644 21935 -3.1% ruby-unicode.c OFF 23897 23225 -2.8% MSP430ISelDAGToDAG.cpp ON 26272 26169 -0.4% MSP430ISelDAGToDAG.cpp OFF 26725 26653 -0.3% Assisted-by: Claude Code
Author
Parents
Loading