| Index: src/hydrogen.cc
|
| diff --git a/src/hydrogen.cc b/src/hydrogen.cc
|
| index 1afa6603aaa31a308969e9f7a15ba92e67e7d61f..628d987a3408b28bca85d250c57d8dfaf710692e 100644
|
| --- a/src/hydrogen.cc
|
| +++ b/src/hydrogen.cc
|
| @@ -3358,6 +3358,7 @@ bool HGraph::Optimize(SmartArrayPointer<char>* bailout_reason) {
|
|
|
| EliminateRedundantBoundsChecks();
|
| DehoistSimpleArrayIndexComputations();
|
| + if (FLAG_dead_code_elimination) DeadCodeElimination();
|
|
|
| return true;
|
| }
|
| @@ -3787,6 +3788,36 @@ void HGraph::DehoistSimpleArrayIndexComputations() {
|
| }
|
|
|
|
|
| +void HGraph::DeadCodeElimination() {
|
| + HPhase phase("H_Dead code elimination", this);
|
| + ZoneList<HInstruction*> worklist(blocks_.length(), zone());
|
| + for (int i = 0; i < blocks()->length(); ++i) {
|
| + for (HInstruction* instr = blocks()->at(i)->first();
|
| + instr != NULL;
|
| + instr = instr->next()) {
|
| + if (instr->IsDead()) worklist.Add(instr, zone());
|
| + }
|
| + }
|
| +
|
| + while (!worklist.is_empty()) {
|
| + HInstruction* instr = worklist.RemoveLast();
|
| + if (FLAG_trace_dead_code_elimination) {
|
| + HeapStringAllocator allocator;
|
| + StringStream stream(&allocator);
|
| + instr->PrintNameTo(&stream);
|
| + stream.Add(" = ");
|
| + instr->PrintTo(&stream);
|
| + PrintF("[removing dead instruction %s]\n", *stream.ToCString());
|
| + }
|
| + instr->DeleteAndReplaceWith(NULL);
|
| + for (int i = 0; i < instr->OperandCount(); ++i) {
|
| + HValue* operand = instr->OperandAt(i);
|
| + if (operand->IsDead()) worklist.Add(HInstruction::cast(operand), zone());
|
| + }
|
| + }
|
| +}
|
| +
|
| +
|
| HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) {
|
| ASSERT(current_block() != NULL);
|
| current_block()->AddInstruction(instr);
|
|
|