Avoid allocation of temporary zone lists when inserting representation changes.

Instead of allocating fresh temporary lists for every instruction, reuse
the same instance and reset it between instructions.

This reduces the amount of zone memory used for inserting the HChange
instructions roughly by half.

Review URL: http://codereview.chromium.org/6628079

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7094 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5a768f07
...@@ -1775,15 +1775,18 @@ int CompareConversionUses(HValue* a, ...@@ -1775,15 +1775,18 @@ int CompareConversionUses(HValue* a,
} }
void HGraph::InsertRepresentationChanges(HValue* current) { void HGraph::InsertRepresentationChangesForValue(
HValue* current,
ZoneList<HValue*>* to_convert,
ZoneList<Representation>* to_convert_reps) {
Representation r = current->representation(); Representation r = current->representation();
if (r.IsNone()) return; if (r.IsNone()) return;
if (current->uses()->length() == 0) return; if (current->uses()->length() == 0) return;
// Collect the representation changes in a sorted list. This allows // Collect the representation changes in a sorted list. This allows
// us to avoid duplicate changes without searching the list. // us to avoid duplicate changes without searching the list.
ZoneList<HValue*> to_convert(2); ASSERT(to_convert->is_empty());
ZoneList<Representation> to_convert_reps(2); ASSERT(to_convert_reps->is_empty());
for (int i = 0; i < current->uses()->length(); ++i) { for (int i = 0; i < current->uses()->length(); ++i) {
HValue* use = current->uses()->at(i); HValue* use = current->uses()->at(i);
// The occurrences index means the index within the operand array of "use" // The occurrences index means the index within the operand array of "use"
...@@ -1803,10 +1806,10 @@ void HGraph::InsertRepresentationChanges(HValue* current) { ...@@ -1803,10 +1806,10 @@ void HGraph::InsertRepresentationChanges(HValue* current) {
Representation req = use->RequiredInputRepresentation(operand_index); Representation req = use->RequiredInputRepresentation(operand_index);
if (req.IsNone() || req.Equals(r)) continue; if (req.IsNone() || req.Equals(r)) continue;
int index = 0; int index = 0;
while (to_convert.length() > index && while (index < to_convert->length() &&
CompareConversionUses(to_convert[index], CompareConversionUses(to_convert->at(index),
use, use,
to_convert_reps[index], to_convert_reps->at(index),
req) < 0) { req) < 0) {
++index; ++index;
} }
...@@ -1816,13 +1819,13 @@ void HGraph::InsertRepresentationChanges(HValue* current) { ...@@ -1816,13 +1819,13 @@ void HGraph::InsertRepresentationChanges(HValue* current) {
current->id(), current->id(),
use->id()); use->id());
} }
to_convert.InsertAt(index, use); to_convert->InsertAt(index, use);
to_convert_reps.InsertAt(index, req); to_convert_reps->InsertAt(index, req);
} }
for (int i = 0; i < to_convert.length(); ++i) { for (int i = 0; i < to_convert->length(); ++i) {
HValue* use = to_convert[i]; HValue* use = to_convert->at(i);
Representation r_to = to_convert_reps[i]; Representation r_to = to_convert_reps->at(i);
InsertRepresentationChangeForUse(current, use, r_to); InsertRepresentationChangeForUse(current, use, r_to);
} }
...@@ -1830,6 +1833,8 @@ void HGraph::InsertRepresentationChanges(HValue* current) { ...@@ -1830,6 +1833,8 @@ void HGraph::InsertRepresentationChanges(HValue* current) {
ASSERT(current->IsConstant()); ASSERT(current->IsConstant());
current->Delete(); current->Delete();
} }
to_convert->Rewind(0);
to_convert_reps->Rewind(0);
} }
...@@ -1865,17 +1870,19 @@ void HGraph::InsertRepresentationChanges() { ...@@ -1865,17 +1870,19 @@ void HGraph::InsertRepresentationChanges() {
} }
} }
ZoneList<HValue*> value_list(4);
ZoneList<Representation> rep_list(4);
for (int i = 0; i < blocks_.length(); ++i) { for (int i = 0; i < blocks_.length(); ++i) {
// Process phi instructions first. // Process phi instructions first.
for (int j = 0; j < blocks_[i]->phis()->length(); j++) { for (int j = 0; j < blocks_[i]->phis()->length(); j++) {
HPhi* phi = blocks_[i]->phis()->at(j); HPhi* phi = blocks_[i]->phis()->at(j);
InsertRepresentationChanges(phi); InsertRepresentationChangesForValue(phi, &value_list, &rep_list);
} }
// Process normal instructions. // Process normal instructions.
HInstruction* current = blocks_[i]->first(); HInstruction* current = blocks_[i]->first();
while (current != NULL) { while (current != NULL) {
InsertRepresentationChanges(current); InsertRepresentationChangesForValue(current, &value_list, &rep_list);
current = current->next(); current = current->next();
} }
} }
......
...@@ -296,7 +296,9 @@ class HGraph: public HSubgraph { ...@@ -296,7 +296,9 @@ class HGraph: public HSubgraph {
void InsertRepresentationChangeForUse(HValue* value, void InsertRepresentationChangeForUse(HValue* value,
HValue* use, HValue* use,
Representation to); Representation to);
void InsertRepresentationChanges(HValue* current); void InsertRepresentationChangesForValue(HValue* current,
ZoneList<HValue*>* value_list,
ZoneList<Representation>* rep_list);
void InferTypes(ZoneList<HValue*>* worklist); void InferTypes(ZoneList<HValue*>* worklist);
void InitializeInferredTypes(int from_inclusive, int to_inclusive); void InitializeInferredTypes(int from_inclusive, int to_inclusive);
void CheckForBackEdge(HBasicBlock* block, HBasicBlock* successor); void CheckForBackEdge(HBasicBlock* block, HBasicBlock* successor);
......
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