OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 } | 1322 } |
1323 if (instr->IsSoftDeoptimize()) { | 1323 if (instr->IsSoftDeoptimize()) { |
1324 ASSERT(block->IsDeoptimizing()); | 1324 ASSERT(block->IsDeoptimizing()); |
1325 nullify = true; | 1325 nullify = true; |
1326 } | 1326 } |
1327 } | 1327 } |
1328 } | 1328 } |
1329 } | 1329 } |
1330 | 1330 |
1331 | 1331 |
| 1332 // Replace all phis consisting of a single non-loop operand plus any number of |
| 1333 // loop operands by that single non-loop operand. |
1332 void HGraph::EliminateRedundantPhis() { | 1334 void HGraph::EliminateRedundantPhis() { |
1333 HPhase phase("H_Redundant phi elimination", this); | 1335 HPhase phase("H_Redundant phi elimination", this); |
1334 | 1336 |
1335 // Worklist of phis that can potentially be eliminated. Initialized with | 1337 // We do a simple fixed point iteration without any work list, because |
1336 // all phi nodes. When elimination of a phi node modifies another phi node | 1338 // machine-generated JavaScript can lead to a very dense Hydrogen graph with |
1337 // the modified phi node is added to the worklist. | 1339 // an enormous work list and will consequently result in OOM. Experiments |
1338 ZoneList<HPhi*> worklist(blocks_.length(), zone()); | 1340 // showed that this simple algorithm is good enough, and even e.g. tracking |
| 1341 // the set or range of blocks to consider is not a real improvement. |
| 1342 bool need_another_iteration; |
| 1343 ZoneList<HPhi*> redundant_phis(blocks_.length(), zone()); |
| 1344 do { |
| 1345 need_another_iteration = false; |
| 1346 for (int i = 0; i < blocks_.length(); ++i) { |
| 1347 HBasicBlock* block = blocks_[i]; |
| 1348 for (int j = 0; j < block->phis()->length(); j++) { |
| 1349 HPhi* phi = block->phis()->at(j); |
| 1350 HValue* replacement = phi->GetRedundantReplacement(); |
| 1351 if (replacement != NULL) { |
| 1352 // Remember phi to avoid concurrent modification of the block's phis. |
| 1353 redundant_phis.Add(phi, zone()); |
| 1354 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { |
| 1355 HValue* value = it.value(); |
| 1356 value->SetOperandAt(it.index(), replacement); |
| 1357 need_another_iteration |= value->IsPhi(); |
| 1358 } |
| 1359 } |
| 1360 } |
| 1361 for (int i = 0; i < redundant_phis.length(); i++) { |
| 1362 block->RemovePhi(redundant_phis[i]); |
| 1363 } |
| 1364 redundant_phis.Clear(); |
| 1365 } |
| 1366 } while (need_another_iteration); |
| 1367 |
| 1368 #if DEBUG |
| 1369 // Make sure that we *really* removed all redundant phis. |
1339 for (int i = 0; i < blocks_.length(); ++i) { | 1370 for (int i = 0; i < blocks_.length(); ++i) { |
1340 worklist.AddAll(*blocks_[i]->phis(), zone()); | 1371 for (int j = 0; j < blocks_[i]->phis()->length(); j++) { |
1341 } | 1372 ASSERT(blocks_[i]->phis()->at(j)->GetRedundantReplacement() == NULL); |
1342 | |
1343 while (!worklist.is_empty()) { | |
1344 HPhi* phi = worklist.RemoveLast(); | |
1345 HBasicBlock* block = phi->block(); | |
1346 | |
1347 // Skip phi node if it was already replaced. | |
1348 if (block == NULL) continue; | |
1349 | |
1350 // Get replacement value if phi is redundant. | |
1351 HValue* replacement = phi->GetRedundantReplacement(); | |
1352 | |
1353 if (replacement != NULL) { | |
1354 // Iterate through the uses and replace them all. | |
1355 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { | |
1356 HValue* value = it.value(); | |
1357 value->SetOperandAt(it.index(), replacement); | |
1358 if (value->IsPhi()) worklist.Add(HPhi::cast(value), zone()); | |
1359 } | |
1360 block->RemovePhi(phi); | |
1361 } | 1373 } |
1362 } | 1374 } |
| 1375 #endif |
1363 } | 1376 } |
1364 | 1377 |
1365 | 1378 |
1366 void HGraph::EliminateUnreachablePhis() { | 1379 void HGraph::EliminateUnreachablePhis() { |
1367 HPhase phase("H_Unreachable phi elimination", this); | 1380 HPhase phase("H_Unreachable phi elimination", this); |
1368 | 1381 |
1369 // Initialize worklist. | 1382 // Initialize worklist. |
1370 ZoneList<HPhi*> phi_list(blocks_.length(), zone()); | 1383 ZoneList<HPhi*> phi_list(blocks_.length(), zone()); |
1371 ZoneList<HPhi*> worklist(blocks_.length(), zone()); | 1384 ZoneList<HPhi*> worklist(blocks_.length(), zone()); |
1372 for (int i = 0; i < blocks_.length(); ++i) { | 1385 for (int i = 0; i < blocks_.length(); ++i) { |
(...skipping 8938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10311 } | 10324 } |
10312 } | 10325 } |
10313 | 10326 |
10314 #ifdef DEBUG | 10327 #ifdef DEBUG |
10315 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 10328 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
10316 if (allocator_ != NULL) allocator_->Verify(); | 10329 if (allocator_ != NULL) allocator_->Verify(); |
10317 #endif | 10330 #endif |
10318 } | 10331 } |
10319 | 10332 |
10320 } } // namespace v8::internal | 10333 } } // namespace v8::internal |
OLD | NEW |