| Index: src/hydrogen-dehoist.cc
|
| diff --git a/src/hydrogen-redundant-phi.cc b/src/hydrogen-dehoist.cc
|
| similarity index 51%
|
| copy from src/hydrogen-redundant-phi.cc
|
| copy to src/hydrogen-dehoist.cc
|
| index 9c38200577d4994e79f5e1925039ca10a8c8a8c2..696d22c608e5b707635b13229cf0046dda4c3e03 100644
|
| --- a/src/hydrogen-redundant-phi.cc
|
| +++ b/src/hydrogen-dehoist.cc
|
| @@ -25,52 +25,56 @@
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -#include "hydrogen-redundant-phi.h"
|
| +#include "hydrogen-dehoist.h"
|
|
|
| namespace v8 {
|
| namespace internal {
|
|
|
| -void HRedundantPhiEliminationPhase::Run() {
|
| - // We do a simple fixed point iteration without any work list, because
|
| - // machine-generated JavaScript can lead to a very dense Hydrogen graph with
|
| - // an enormous work list and will consequently result in OOM. Experiments
|
| - // showed that this simple algorithm is good enough, and even e.g. tracking
|
| - // the set or range of blocks to consider is not a real improvement.
|
| - bool need_another_iteration;
|
| - const ZoneList<HBasicBlock*>* blocks(graph()->blocks());
|
| - ZoneList<HPhi*> redundant_phis(blocks->length(), zone());
|
| - do {
|
| - need_another_iteration = false;
|
| - for (int i = 0; i < blocks->length(); ++i) {
|
| - HBasicBlock* block = blocks->at(i);
|
| - for (int j = 0; j < block->phis()->length(); j++) {
|
| - HPhi* phi = block->phis()->at(j);
|
| - HValue* replacement = phi->GetRedundantReplacement();
|
| - if (replacement != NULL) {
|
| - // Remember phi to avoid concurrent modification of the block's phis.
|
| - redundant_phis.Add(phi, zone());
|
| - for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) {
|
| - HValue* value = it.value();
|
| - value->SetOperandAt(it.index(), replacement);
|
| - need_another_iteration |= value->IsPhi();
|
| - }
|
| - }
|
| - }
|
| - for (int i = 0; i < redundant_phis.length(); i++) {
|
| - block->RemovePhi(redundant_phis[i]);
|
| - }
|
| - redundant_phis.Clear();
|
| - }
|
| - } while (need_another_iteration);
|
| +static void DehoistArrayIndex(ArrayInstructionInterface* array_operation) {
|
| + HValue* index = array_operation->GetKey()->ActualValue();
|
| + if (!index->representation().IsSmiOrInteger32()) return;
|
| + if (!index->IsAdd() && !index->IsSub()) return;
|
| +
|
| + HConstant* constant;
|
| + HValue* subexpression;
|
| + HBinaryOperation* binary_operation = HBinaryOperation::cast(index);
|
| + if (binary_operation->left()->IsConstant()) {
|
| + subexpression = binary_operation->right();
|
| + constant = HConstant::cast(binary_operation->left());
|
| + } else if (binary_operation->right()->IsConstant()) {
|
| + subexpression = binary_operation->left();
|
| + constant = HConstant::cast(binary_operation->right());
|
| + } else {
|
| + return;
|
| + }
|
|
|
| -#if DEBUG
|
| - // Make sure that we *really* removed all redundant phis.
|
| + if (!constant->HasInteger32Value()) return;
|
| + int32_t sign = binary_operation->IsSub() ? -1 : 1;
|
| + int32_t value = constant->Integer32Value() * sign;
|
| + // We limit offset values to 30 bits because we want to avoid the risk of
|
| + // overflows when the offset is added to the object header size.
|
| + if (value >= 1 << 30 || value < 0) return;
|
| + array_operation->SetKey(subexpression);
|
| + if (binary_operation->HasNoUses()) {
|
| + binary_operation->DeleteAndReplaceWith(NULL);
|
| + }
|
| + array_operation->SetIndexOffset(static_cast<uint32_t>(value));
|
| + array_operation->SetDehoisted(true);
|
| +}
|
| +
|
| +
|
| +void HDehoistIndexComputationsPhase::Run() {
|
| + const ZoneList<HBasicBlock*>* blocks(graph()->blocks());
|
| for (int i = 0; i < blocks->length(); ++i) {
|
| - for (int j = 0; j < blocks->at(i)->phis()->length(); j++) {
|
| - ASSERT(blocks->at(i)->phis()->at(j)->GetRedundantReplacement() == NULL);
|
| + for (HInstructionIterator it(blocks->at(i)); !it.Done(); it.Advance()) {
|
| + HInstruction* instr = it.Current();
|
| + if (instr->IsLoadKeyed()) {
|
| + DehoistArrayIndex(HLoadKeyed::cast(instr));
|
| + } else if (instr->IsStoreKeyed()) {
|
| + DehoistArrayIndex(HStoreKeyed::cast(instr));
|
| + }
|
| }
|
| }
|
| -#endif
|
| }
|
|
|
| } } // namespace v8::internal
|
|
|