summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SpillPlacement.h
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2016-05-19 22:40:37 +0000
committerQuentin Colombet <qcolombet@apple.com>2016-05-19 22:40:37 +0000
commitb926bdac4c18e0f31d827dec482f207856e88e1e (patch)
treefc56892b2d177ef811e811c40abe91dbb6f3f656 /llvm/lib/CodeGen/SpillPlacement.h
parentd9e02c4f3c56b3e1e064566680ed2dfcf60fa5a4 (diff)
downloadbcm5719-llvm-b926bdac4c18e0f31d827dec482f207856e88e1e.tar.gz
bcm5719-llvm-b926bdac4c18e0f31d827dec482f207856e88e1e.zip
Reapply r263460: [SpillPlacement] Fix a quadratic behavior in spill placement.
Using Chandler's words from r265331: This commit was greatly exacerbating PR17409 and effectively regressed build time for lot of (very large) code when compiled with ASan or MSan. PR17409 is fixed by r269249, so this is fine to reapply r263460. Original commit message: 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: 270149
Diffstat (limited to 'llvm/lib/CodeGen/SpillPlacement.h')
-rw-r--r--llvm/lib/CodeGen/SpillPlacement.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SpillPlacement.h b/llvm/lib/CodeGen/SpillPlacement.h
index 03dd58d6e9a..9b9ecccf904 100644
--- a/llvm/lib/CodeGen/SpillPlacement.h
+++ b/llvm/lib/CodeGen/SpillPlacement.h
@@ -29,6 +29,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SparseSet.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/Support/BlockFrequency.h"
@@ -66,6 +67,9 @@ class SpillPlacement : public MachineFunctionPass {
/// its inputs falls in the open interval (-Threshold;Threshold).
BlockFrequency Threshold;
+ /// List of nodes that need to be updated in ::iterate.
+ SparseSet<unsigned> TodoList;
+
public:
static char ID; // Pass identification, replacement for typeid.
@@ -157,6 +161,8 @@ private:
void activate(unsigned);
void setThreshold(const BlockFrequency &Entry);
+
+ bool update(unsigned);
};
} // end namespace llvm
OpenPOWER on IntegriCloud