llvm-project
e89363f9 - [CodeGen] Cache `shouldOptimizeForSize()` when computing spill weights (#214905)

Commit
15 days ago
[CodeGen] Cache `shouldOptimizeForSize()` when computing spill weights (#214905) `VirtRegAuxInfo::weightCalcHelper()` calls LiveIntervals::getSpillWeight() once per use/def operand of every virtual register, and `getSpillWeight()` evaluates `(PSI && llvm::shouldOptimizeForSize(MF, PSI, MBFI))` repeatedly. `shouldOptimizeForSize` is expensive: `O(#operands * #blocks)`. We had a function with 20k blocks, and this inefficient repeated query caused severe delay, the function took 30+ minutes to build. Since the result is the same for every query in this MF, and `VirtRegAuxInfo` already holds `MF`, `PSI` and `MBFI`, all fixed for the lifetime of the object, so the value is provably invariant across every `getSpillWeight()` call it makes. We should cache it.
Author
Parents
Loading