Commit 63305af0 authored by titzer@chromium.org's avatar titzer@chromium.org

Reduce queue size in dead code elimination by eagerly processing live instructions.

BUG=
R=rmcilroy@chromium.org

Review URL: https://codereview.chromium.org/27178002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17196 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9fadd295
...@@ -31,56 +31,60 @@ ...@@ -31,56 +31,60 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
bool HDeadCodeEliminationPhase::MarkLive(HValue* ref, HValue* instr) { void HDeadCodeEliminationPhase::MarkLive(
if (instr->CheckFlag(HValue::kIsLive)) return false; HValue* instr, ZoneList<HValue*>* worklist) {
instr->SetFlag(HValue::kIsLive); if (instr->CheckFlag(HValue::kIsLive)) return; // Already live.
if (FLAG_trace_dead_code_elimination) { if (FLAG_trace_dead_code_elimination) PrintLive(NULL, instr);
HeapStringAllocator allocator;
StringStream stream(&allocator); // Transitively mark all inputs of live instructions live.
if (ref != NULL) { worklist->Add(instr, zone());
ref->PrintTo(&stream); while (!worklist->is_empty()) {
} else { HValue* instr = worklist->RemoveLast();
stream.Add("root "); instr->SetFlag(HValue::kIsLive);
for (int i = 0; i < instr->OperandCount(); ++i) {
HValue* input = instr->OperandAt(i);
if (!input->CheckFlag(HValue::kIsLive)) {
input->SetFlag(HValue::kIsLive);
worklist->Add(input, zone());
if (FLAG_trace_dead_code_elimination) PrintLive(instr, input);
}
} }
stream.Add(" -> ");
instr->PrintTo(&stream);
PrintF("[MarkLive %s]\n", *stream.ToCString());
} }
}
return true; void HDeadCodeEliminationPhase::PrintLive(HValue* ref, HValue* instr) {
HeapStringAllocator allocator;
StringStream stream(&allocator);
if (ref != NULL) {
ref->PrintTo(&stream);
} else {
stream.Add("root ");
}
stream.Add(" -> ");
instr->PrintTo(&stream);
PrintF("[MarkLive %s]\n", *stream.ToCString());
} }
void HDeadCodeEliminationPhase::MarkLiveInstructions() { void HDeadCodeEliminationPhase::MarkLiveInstructions() {
ZoneList<HValue*> worklist(graph()->blocks()->length(), zone()); ZoneList<HValue*> worklist(10, zone());
// Mark initial root instructions for dead code elimination. // Transitively mark all live instructions, starting from roots.
for (int i = 0; i < graph()->blocks()->length(); ++i) { for (int i = 0; i < graph()->blocks()->length(); ++i) {
HBasicBlock* block = graph()->blocks()->at(i); HBasicBlock* block = graph()->blocks()->at(i);
for (HInstructionIterator it(block); !it.Done(); it.Advance()) { for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
HInstruction* instr = it.Current(); HInstruction* instr = it.Current();
if (instr->CannotBeEliminated() && MarkLive(NULL, instr)) { if (instr->CannotBeEliminated()) MarkLive(instr, &worklist);
worklist.Add(instr, zone());
}
} }
for (int j = 0; j < block->phis()->length(); j++) { for (int j = 0; j < block->phis()->length(); j++) {
HPhi* phi = block->phis()->at(j); HPhi* phi = block->phis()->at(j);
if (phi->CannotBeEliminated() && MarkLive(NULL, phi)) { if (phi->CannotBeEliminated()) MarkLive(phi, &worklist);
worklist.Add(phi, zone());
}
} }
} }
// Transitively mark all inputs of live instructions live. ASSERT(worklist.is_empty()); // Should have processed everything.
while (!worklist.is_empty()) {
HValue* instr = worklist.RemoveLast();
for (int i = 0; i < instr->OperandCount(); ++i) {
if (MarkLive(instr, instr->OperandAt(i))) {
worklist.Add(instr->OperandAt(i), zone());
}
}
}
} }
......
...@@ -45,7 +45,8 @@ class HDeadCodeEliminationPhase : public HPhase { ...@@ -45,7 +45,8 @@ class HDeadCodeEliminationPhase : public HPhase {
} }
private: private:
bool MarkLive(HValue* ref, HValue* instr); void MarkLive(HValue* instr, ZoneList<HValue*>* worklist);
void PrintLive(HValue* ref, HValue* instr);
void MarkLiveInstructions(); void MarkLiveInstructions();
void RemoveDeadInstructions(); void RemoveDeadInstructions();
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment