Reuse the gap move resolver.

Rather than allocating a fresh gap move resolver for every parallel
move, use a single one per Lithium code generator.  This avoids always
reallocating the temporary zone-allocated lists used by the gap move
resolver.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6270 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
kmillikin@chromium.org 2011-01-11 13:50:12 +00:00
parent 404fbb5b0b
commit a7c743d3ac
6 changed files with 42 additions and 31 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2010 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
@ -601,8 +601,8 @@ void LCodeGen::DoParallelMove(LParallelMove* move) {
Register core_scratch = scratch0(); Register core_scratch = scratch0();
bool destroys_core_scratch = false; bool destroys_core_scratch = false;
LGapResolver resolver(move->move_operands(), &marker_operand); const ZoneList<LMoveOperands>* moves =
const ZoneList<LMoveOperands>* moves = resolver.ResolveInReverseOrder(); resolver_.Resolve(move->move_operands(), &marker_operand);
for (int i = moves->length() - 1; i >= 0; --i) { for (int i = moves->length() - 1; i >= 0; --i) {
LMoveOperands move = moves->at(i); LMoveOperands move = moves->at(i);
LOperand* from = move.from(); LOperand* from = move.from();

View File

@ -1,4 +1,4 @@
// Copyright 2010 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
@ -239,6 +239,9 @@ class LCodeGen BASE_EMBEDDED {
// itself is emitted at the end of the generated code. // itself is emitted at the end of the generated code.
SafepointTableBuilder safepoints_; SafepointTableBuilder safepoints_;
// Compiler from a set of parallel moves to a sequential list of moves.
LGapResolver resolver_;
friend class LDeferredCode; friend class LDeferredCode;
friend class LEnvironment; friend class LEnvironment;
friend class SafepointGenerator; friend class SafepointGenerator;

View File

@ -1,4 +1,4 @@
// Copyright 2010 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
@ -564,8 +564,8 @@ void LCodeGen::DoParallelMove(LParallelMove* move) {
Register cpu_scratch = esi; Register cpu_scratch = esi;
bool destroys_cpu_scratch = false; bool destroys_cpu_scratch = false;
LGapResolver resolver(move->move_operands(), &marker_operand); const ZoneList<LMoveOperands>* moves =
const ZoneList<LMoveOperands>* moves = resolver.ResolveInReverseOrder(); resolver_.Resolve(move->move_operands(), &marker_operand);
for (int i = moves->length() - 1; i >= 0; --i) { for (int i = moves->length() - 1; i >= 0; --i) {
LMoveOperands move = moves->at(i); LMoveOperands move = moves->at(i);
LOperand* from = move.from(); LOperand* from = move.from();

View File

@ -1,4 +1,4 @@
// Copyright 2010 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
@ -230,6 +230,9 @@ class LCodeGen BASE_EMBEDDED {
// itself is emitted at the end of the generated code. // itself is emitted at the end of the generated code.
SafepointTableBuilder safepoints_; SafepointTableBuilder safepoints_;
// Compiler from a set of parallel moves to a sequential list of moves.
LGapResolver resolver_;
friend class LDeferredCode; friend class LDeferredCode;
friend class LEnvironment; friend class LEnvironment;
friend class SafepointGenerator; friend class SafepointGenerator;

View File

@ -60,23 +60,29 @@ class LGapNode: public ZoneObject {
}; };
LGapResolver::LGapResolver(const ZoneList<LMoveOperands>* moves, LGapResolver::LGapResolver()
LOperand* marker_operand) : nodes_(32),
: nodes_(4),
identified_cycles_(4), identified_cycles_(4),
result_(4), result_(16),
marker_operand_(marker_operand),
next_visited_id_(0) { next_visited_id_(0) {
}
const ZoneList<LMoveOperands>* LGapResolver::Resolve(
const ZoneList<LMoveOperands>* moves,
LOperand* marker_operand) {
nodes_.Rewind(0);
identified_cycles_.Rewind(0);
result_.Rewind(0);
next_visited_id_ = 0;
for (int i = 0; i < moves->length(); ++i) { for (int i = 0; i < moves->length(); ++i) {
LMoveOperands move = moves->at(i); LMoveOperands move = moves->at(i);
if (!move.IsRedundant()) RegisterMove(move); if (!move.IsRedundant()) RegisterMove(move);
} }
}
const ZoneList<LMoveOperands>* LGapResolver::ResolveInReverseOrder() {
for (int i = 0; i < identified_cycles_.length(); ++i) { for (int i = 0; i < identified_cycles_.length(); ++i) {
ResolveCycle(identified_cycles_[i]); ResolveCycle(identified_cycles_[i], marker_operand);
} }
int unresolved_nodes; int unresolved_nodes;
@ -105,20 +111,20 @@ void LGapResolver::AddResultMove(LOperand* from, LOperand* to) {
} }
void LGapResolver::ResolveCycle(LGapNode* start) { void LGapResolver::ResolveCycle(LGapNode* start, LOperand* marker_operand) {
ZoneList<LOperand*> circle_operands(8); ZoneList<LOperand*> cycle_operands(8);
circle_operands.Add(marker_operand_); cycle_operands.Add(marker_operand);
LGapNode* cur = start; LGapNode* cur = start;
do { do {
cur->MarkResolved(); cur->MarkResolved();
circle_operands.Add(cur->operand()); cycle_operands.Add(cur->operand());
cur = cur->assigned_from(); cur = cur->assigned_from();
} while (cur != start); } while (cur != start);
circle_operands.Add(marker_operand_); cycle_operands.Add(marker_operand);
for (int i = circle_operands.length() - 1; i > 0; --i) { for (int i = cycle_operands.length() - 1; i > 0; --i) {
LOperand* from = circle_operands[i]; LOperand* from = cycle_operands[i];
LOperand* to = circle_operands[i - 1]; LOperand* to = cycle_operands[i - 1];
AddResultMove(from, to); AddResultMove(from, to);
} }
} }
@ -156,7 +162,7 @@ void LGapResolver::RegisterMove(LMoveOperands move) {
} }
ASSERT(!to->IsAssigned()); ASSERT(!to->IsAssigned());
if (CanReach(from, to)) { if (CanReach(from, to)) {
// This introduces a circle. Save. // This introduces a cycle. Save.
identified_cycles_.Add(from); identified_cycles_.Add(from);
} }
to->set_assigned_from(from); to->set_assigned_from(from);

View File

@ -37,8 +37,9 @@ class LGapNode;
class LGapResolver BASE_EMBEDDED { class LGapResolver BASE_EMBEDDED {
public: public:
LGapResolver(const ZoneList<LMoveOperands>* moves, LOperand* marker_operand); LGapResolver();
const ZoneList<LMoveOperands>* ResolveInReverseOrder(); const ZoneList<LMoveOperands>* Resolve(const ZoneList<LMoveOperands>* moves,
LOperand* marker_operand);
private: private:
LGapNode* LookupNode(LOperand* operand); LGapNode* LookupNode(LOperand* operand);
@ -47,14 +48,12 @@ class LGapResolver BASE_EMBEDDED {
void RegisterMove(LMoveOperands move); void RegisterMove(LMoveOperands move);
void AddResultMove(LOperand* from, LOperand* to); void AddResultMove(LOperand* from, LOperand* to);
void AddResultMove(LGapNode* from, LGapNode* to); void AddResultMove(LGapNode* from, LGapNode* to);
void ResolveCycle(LGapNode* start); void ResolveCycle(LGapNode* start, LOperand* marker_operand);
ZoneList<LGapNode*> nodes_; ZoneList<LGapNode*> nodes_;
ZoneList<LGapNode*> identified_cycles_; ZoneList<LGapNode*> identified_cycles_;
ZoneList<LMoveOperands> result_; ZoneList<LMoveOperands> result_;
LOperand* marker_operand_;
int next_visited_id_; int next_visited_id_;
int bailout_after_ast_id_;
}; };