4461 {
4462 GrowableArray<Instruction*>
worklist;
4463 BitVector live(flow_graph->zone(), flow_graph->current_ssa_temp_index());
4464
4465
4466 for (BlockIterator block_it = flow_graph->reverse_postorder_iterator();
4467 !block_it.Done(); block_it.Advance()) {
4468 BlockEntryInstr* block = block_it.Current();
4469 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
4470 Instruction* current = it.Current();
4471 ASSERT(!current->IsMoveArgument());
4472
4473
4474 if (!current->CanEliminate(block)) {
4476 if (Definition* def = current->AsDefinition()) {
4477 if (def->HasSSATemp()) {
4478 live.Add(def->ssa_temp_index());
4479 }
4480 }
4481 }
4482 }
4483 }
4484
4485
4487 Instruction* current =
worklist.RemoveLast();
4488 for (intptr_t i = 0, n = current->InputCount(); i < n; ++i) {
4489 Definition* input = current->InputAt(i)->definition();
4490 ASSERT(input->HasSSATemp());
4491 if (!live.Contains(input->ssa_temp_index())) {
4493 live.Add(input->ssa_temp_index());
4494 }
4495 }
4496 for (intptr_t i = 0, n = current->ArgumentCount(); i < n; ++i) {
4497 Definition* input = current->ArgumentAt(i);
4498 ASSERT(input->HasSSATemp());
4499 if (!live.Contains(input->ssa_temp_index())) {
4501 live.Add(input->ssa_temp_index());
4502 }
4503 }
4504 if (current->env() != nullptr) {
4505 for (Environment::DeepIterator it(current->env()); !it.Done();
4506 it.Advance()) {
4507 Definition* input = it.CurrentValue()->definition();
4508 ASSERT(!input->IsMoveArgument());
4509 if (input->HasSSATemp() && !live.Contains(input->ssa_temp_index())) {
4511 live.Add(input->ssa_temp_index());
4512 }
4513 }
4514 }
4515 }
4516
4517
4518 for (BlockIterator block_it = flow_graph->reverse_postorder_iterator();
4519 !block_it.Done(); block_it.Advance()) {
4520 BlockEntryInstr* block = block_it.Current();
4521 if (JoinEntryInstr* join = block->AsJoinEntry()) {
4522 for (PhiIterator it(join); !it.Done(); it.Advance()) {
4523 PhiInstr* current = it.Current();
4524 if (!live.Contains(current->ssa_temp_index())) {
4525 it.RemoveCurrentFromGraph();
4526 }
4527 }
4528 }
4529 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
4530 Instruction* current = it.Current();
4531 if (!current->CanEliminate(block)) {
4532 continue;
4533 }
4534 ASSERT(!current->IsMoveArgument());
4535 ASSERT((current->ArgumentCount() == 0) || !current->HasMoveArguments());
4536 if (Definition* def = current->AsDefinition()) {
4537 if (def->HasSSATemp() && live.Contains(def->ssa_temp_index())) {
4538 continue;
4539 }
4540 }
4541 it.RemoveCurrentFromGraph();
4542 }
4543 }
4544}