Clang/LLVM static analyzer that detects microarchitectural hazards
2 days ago
- #static-analysis
- #C++
- #performance
- lshaz is a Clang/LLVM-based static analysis tool for detecting microarchitectural latency hazards in C++ code at compile time.
- The tool aims to move the performance feedback loop earlier in the development process, from production profiling to code writing.
- lshaz analyzes struct field geometry, atomic ordering choices, thread escape, and NUMA placement using runtime-relevant information like byte offsets and cache line boundaries.
- When run against Abseil-C++, lshaz produced 256 diagnostics, highlighting potential performance issues.
- Key findings include the ThreadIdentity struct, which has deliberate hardware trade-offs involving cache line sharing and atomic fields.
- ThreadIdentity triggers a Compound Hazard Amplification due to multiple co-occurring hazards like cache spanning and false sharing.
- Another significant finding is HashtablezInfo, a sampling struct with high atomic field density across cache lines.
- The 256 diagnostics are categorized into Proven, Likely, and Speculative tiers based on evidence strength.
- lshaz uniquely generates formal hypotheses and experiment bundles for validating its predictions using hardware performance counters.
- The tool is available on GitHub and integrates with CI systems via SARIF output for GitHub Code Scanning.