llvm-project/llvm/lib
Quentin Colombet 40ce25b68b [SpillPlacement] Fix a quadratic behavior in spill placement.
The bad behavior happens when we have a function with a long linear chain of
basic blocks, and have a live range spanning most of this chain, but with very
few uses.
Let say we have only 2 uses.
The Hopfield network is only seeded with two active blocks where the uses are,
and each iteration of the outer loop in `RAGreedy::growRegion()` only adds two
new nodes to the network due to the completely linear shape of the CFG.
Meanwhile, `SpillPlacer->iterate()` visits the whole set of discovered nodes,
which adds up to a quadratic algorithm.

This is an historical accident effect from r129188.

When the Hopfield network is expanding, most of the action is happening on the
frontier where new nodes are being added. The internal nodes in the network are
not likely to be flip-flopping much, or they will at least settle down very
quickly. This means that while `SpillPlacer->iterate()` is recomputing all the
nodes in the network, it is probably only the two frontier nodes that are
changing their output.

Instead of recomputing the whole network on each iteration, we can maintain a
SparseSet of nodes that need to be updated:

- `SpillPlacement::activate()` adds the node to the todo list.
- When a node changes value (i.e., `update()` returns true), its neighbors are
  added to the todo list.
- `SpillPlacement::iterate()` only updates the nodes in the list.

The result of Hopfield iterations is not necessarily exact. It should converge
to a local minimum, but there is no guarantee that it will find a global
minimum. It is possible that updating nodes in a different order will cause us
to switch to a different local minimum. In other words, this is not NFC, but
although I saw a few runtime improvements and regressions when I benchmarked
this change, those were side effects and actually the performance change is in
the noise as expected.

Huge thanks to Jakob Stoklund Olesen <stoklund@2pi.dk> for his feedbacks,
guidance and time for the review.

llvm-svn: 263460
2016-03-14 18:21:25 +00:00
..
Analysis ConstantFoldInstruction: avoid wasted calls to ConstantFoldConstantExpression 2016-03-13 05:36:15 +00:00
AsmParser Add a flag to the LLVMContext to disable name for Value other than GlobalValue 2016-03-10 01:28:54 +00:00
Bitcode [Bitcode] Make writeComdats less strange 2016-03-13 08:01:03 +00:00
CodeGen [SpillPlacement] Fix a quadratic behavior in spill placement. 2016-03-14 18:21:25 +00:00
DebugInfo [DebugInfo] Dump CIE augmentation data as a list of hex bytes 2016-03-01 18:38:05 +00:00
ExecutionEngine ExecutionEngine: tweak debug log 2016-03-05 20:00:41 +00:00
Fuzzer [libFuzzer] try to use max_len based on the items of the corpus instead of blindly defaulting to 64 bytes. 2016-03-12 01:57:04 +00:00
IR Add facility to add/remove/check attribute on function and arguments. 2016-03-14 01:37:29 +00:00
IRReader Remove autoconf support 2016-01-26 21:29:08 +00:00
LTO [ThinLTO] Support for reference graph in per-module and combined summary. 2016-03-11 18:52:24 +00:00
LibDriver Remove autoconf support 2016-01-26 21:29:08 +00:00
LineEditor Remove autoconf support 2016-01-26 21:29:08 +00:00
Linker Minor cleanup and documentation to IRMover (NFC) 2016-03-11 22:19:06 +00:00
MC Don't crash when compiling inline assembler containing .file directives. 2016-03-09 17:32:56 +00:00
Object [ThinLTO] Support for reference graph in per-module and combined summary. 2016-03-11 18:52:24 +00:00
ObjectYAML [AMDGPU] add AMDGPU target support to ELFObjectFile.h header 2016-03-09 17:08:19 +00:00
Option Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith r259192 post commit comment. 2016-01-29 20:50:44 +00:00
Passes [PM] Rename the CRTP mixin base classes for the new pass manager to 2016-03-11 10:33:22 +00:00
ProfileData Use LineLocation instead of CallsiteLocation to index callsite profile. 2016-03-03 18:09:32 +00:00
Support APFloat: Fix ilogb for denormals 2016-03-13 05:12:32 +00:00
TableGen [TableGen] Fix typos in comments. NFC 2016-02-26 06:50:27 +00:00
Target [AArch64] Break the dependency between FP and SP when possible. 2016-03-14 18:17:41 +00:00
Transforms [CVP] Replace nonnegative with positive, per Philip's request. NFC. 2016-03-14 13:48:00 +00:00
CMakeLists.txt Move ObjectYAML code to a new library. 2016-03-01 19:15:06 +00:00
LLVMBuild.txt Add LLVMBuild for ObjectYAML. 2016-03-01 21:29:33 +00:00