summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-07-17 11:06:50 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-07-17 11:13:01 -0700
commit0c7476b4e1e1d6312c2c56021eb31cb12fbe350e (patch)
tree557c911bef4bd9d1a3b14f6eab4ade32acdb1318 /src
parent52497a2f34cb3cf98afe706f57e9a60d8ab4990d (diff)
downloadbinaryen-0c7476b4e1e1d6312c2c56021eb31cb12fbe350e.tar.gz
binaryen-0c7476b4e1e1d6312c2c56021eb31cb12fbe350e.tar.bz2
binaryen-0c7476b4e1e1d6312c2c56021eb31cb12fbe350e.zip
try natural and reverse order in coalese-locals
Diffstat (limited to 'src')
-rw-r--r--src/passes/CoalesceLocals.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp
index 56bee17d9..c1c7611c2 100644
--- a/src/passes/CoalesceLocals.cpp
+++ b/src/passes/CoalesceLocals.cpp
@@ -441,14 +441,32 @@ void CoalesceLocals::pickIndicesFromOrder(std::vector<Index>& order, std::vector
}
void CoalesceLocals::pickIndices(std::vector<Index>& indices) {
- // use the natural order. this is less arbitrary than it seems, as the program
+ if (numLocals == 0) return;
+ if (numLocals == 1) {
+ indices.push_back(0);
+ return;
+ }
+ // first try the natural order. this is less arbitrary than it seems, as the program
// may have a natural order of locals inherent in it.
std::vector<Index> order;
order.resize(numLocals);
- for (size_t i = 0; i < numLocals; i++) {
+ for (Index i = 0; i < numLocals; i++) {
order[i] = i;
}
pickIndicesFromOrder(order, indices);
+ auto maxIndex = *std::max_element(indices.begin(), indices.end());
+ // next try the reverse order. this both gives us anothe chance at something good,
+ // and also the very naturalness of the simple order may be quite suboptimal
+ auto numParams = getFunction()->getNumParams();
+ for (Index i = numParams; i < numLocals; i++) {
+ order[i] = numParams + numLocals - 1 - i;
+ }
+ std::vector<Index> reverseIndices;
+ pickIndicesFromOrder(order, reverseIndices);
+ auto reverseMaxIndex = *std::max_element(reverseIndices.begin(), reverseIndices.end());
+ if (reverseMaxIndex < maxIndex) {
+ indices.swap(reverseIndices);
+ }
}
void CoalesceLocals::applyIndices(std::vector<Index>& indices, Expression* root) {