Reviewers: fschneider,

Message:
This simple change cuts zone allocation for Lithium code generation on the
benchmarks from 7.2 MB to 2.3 MB.

Description:
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.

Please review this at http://codereview.chromium.org/6128007/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge/build/ia32

Affected files:
  M src/arm/lithium-codegen-arm.h
  M src/arm/lithium-codegen-arm.cc
  M src/ia32/lithium-codegen-ia32.h
  M src/ia32/lithium-codegen-ia32.cc
  M src/lithium.h
  M src/lithium.cc


Index: src/arm/lithium-codegen-arm.cc
diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc
index f53cebbb3b10703b2fb521560dd700cc48218a8f..d782cc6908ee12bb2f1f51602e9f9885cf516857 100644
--- a/src/arm/lithium-codegen-arm.cc
+++ b/src/arm/lithium-codegen-arm.cc
@@ -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
 // modification, are permitted provided that the following conditions are
 // met:
@@ -601,8 +601,8 @@ void LCodeGen::DoParallelMove(LParallelMove* move) {
   Register core_scratch = scratch0();
   bool destroys_core_scratch = false;

-  LGapResolver resolver(move->move_operands(), &marker_operand);
-  const ZoneList<LMoveOperands>* moves = resolver.ResolveInReverseOrder();
+  const ZoneList<LMoveOperands>* moves =
+      resolver_.Resolve(move->move_operands(), &marker_operand);
   for (int i = moves->length() - 1; i >= 0; --i) {
     LMoveOperands move = moves->at(i);
     LOperand* from = move.from();
Index: src/arm/lithium-codegen-arm.h
diff --git a/src/arm/lithium-codegen-arm.h b/src/arm/lithium-codegen-arm.h
index 608efa9e0dff59864d57bf9b7c211e8e66c7e0ac..c368d3c2010ac2c841d24f43e2ec11434f22086b 100644
--- a/src/arm/lithium-codegen-arm.h
+++ b/src/arm/lithium-codegen-arm.h
@@ -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
 // modification, are permitted provided that the following conditions are
 // met:
@@ -239,6 +239,9 @@ class LCodeGen BASE_EMBEDDED {
   // itself is emitted at the end of the generated code.
   SafepointTableBuilder safepoints_;

+  // Compiler from a set of parallel moves to a sequential list of moves.
+  LGapResolver resolver_;
+
   friend class LDeferredCode;
   friend class LEnvironment;
   friend class SafepointGenerator;
Index: src/ia32/lithium-codegen-ia32.cc
diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index d32f95d3098cd8ed3a3c0153d3adae19acc7ad08..50b9acc0ef9cbe92bece3a8bcc471a7a0b168c93 100644
--- a/src/ia32/lithium-codegen-ia32.cc
+++ b/src/ia32/lithium-codegen-ia32.cc
@@ -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
 // modification, are permitted provided that the following conditions are
 // met:
@@ -564,8 +564,8 @@ void LCodeGen::DoParallelMove(LParallelMove* move) {
   Register cpu_scratch = esi;
   bool destroys_cpu_scratch = false;

-  LGapResolver resolver(move->move_operands(), &marker_operand);
-  const ZoneList<LMoveOperands>* moves = resolver.ResolveInReverseOrder();
+  const ZoneList<LMoveOperands>* moves =
+      resolver_.Resolve(move->move_operands(), &marker_operand);
   for (int i = moves->length() - 1; i >= 0; --i) {
     LMoveOperands move = moves->at(i);
     LOperand* from = move.from();
Index: src/ia32/lithium-codegen-ia32.h
diff --git a/src/ia32/lithium-codegen-ia32.h b/src/ia32/lithium-codegen-ia32.h index 41ac39a44eff561ed26e7eed7ee81be4faf56394..68ffb8d0331d26f25553e396e994e7b91a867703 100644
--- a/src/ia32/lithium-codegen-ia32.h
+++ b/src/ia32/lithium-codegen-ia32.h
@@ -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
 // modification, are permitted provided that the following conditions are
 // met:
@@ -230,6 +230,9 @@ class LCodeGen BASE_EMBEDDED {
   // itself is emitted at the end of the generated code.
   SafepointTableBuilder safepoints_;

+  // Compiler from a set of parallel moves to a sequential list of moves.
+  LGapResolver resolver_;
+
   friend class LDeferredCode;
   friend class LEnvironment;
   friend class SafepointGenerator;
Index: src/lithium.cc
diff --git a/src/lithium.cc b/src/lithium.cc
index a65b091e762ba55e43185c36fa929b031ede03cd..7a7518cf61e1ecb6cc3fef71900e973feb7194fa 100644
--- a/src/lithium.cc
+++ b/src/lithium.cc
@@ -60,23 +60,29 @@ class LGapNode: public ZoneObject {
 };


-LGapResolver::LGapResolver(const ZoneList<LMoveOperands>* moves,
-                           LOperand* marker_operand)
-    : nodes_(4),
+LGapResolver::LGapResolver()
+    : nodes_(32),
       identified_cycles_(4),
-      result_(4),
-      marker_operand_(marker_operand),
+      result_(16),
       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) {
     LMoveOperands move = moves->at(i);
     if (!move.IsRedundant()) RegisterMove(move);
   }
-}
-

-const ZoneList<LMoveOperands>* LGapResolver::ResolveInReverseOrder() {
   for (int i = 0; i < identified_cycles_.length(); ++i) {
-    ResolveCycle(identified_cycles_[i]);
+    ResolveCycle(identified_cycles_[i], marker_operand);
   }

   int unresolved_nodes;
@@ -105,20 +111,20 @@ void LGapResolver::AddResultMove(LOperand* from, LOperand* to) {
 }


-void LGapResolver::ResolveCycle(LGapNode* start) {
-  ZoneList<LOperand*> circle_operands(8);
-  circle_operands.Add(marker_operand_);
+void LGapResolver::ResolveCycle(LGapNode* start, LOperand* marker_operand) {
+  ZoneList<LOperand*> cycle_operands(8);
+  cycle_operands.Add(marker_operand);
   LGapNode* cur = start;
   do {
     cur->MarkResolved();
-    circle_operands.Add(cur->operand());
+    cycle_operands.Add(cur->operand());
     cur = cur->assigned_from();
   } while (cur != start);
-  circle_operands.Add(marker_operand_);
+  cycle_operands.Add(marker_operand);

-  for (int i = circle_operands.length() - 1; i > 0; --i) {
-    LOperand* from = circle_operands[i];
-    LOperand* to = circle_operands[i - 1];
+  for (int i = cycle_operands.length() - 1; i > 0; --i) {
+    LOperand* from = cycle_operands[i];
+    LOperand* to = cycle_operands[i - 1];
     AddResultMove(from, to);
   }
 }
@@ -156,7 +162,7 @@ void LGapResolver::RegisterMove(LMoveOperands move) {
     }
     ASSERT(!to->IsAssigned());
     if (CanReach(from, to)) {
-      // This introduces a circle. Save.
+      // This introduces a cycle. Save.
       identified_cycles_.Add(from);
     }
     to->set_assigned_from(from);
Index: src/lithium.h
diff --git a/src/lithium.h b/src/lithium.h
index 1fe8b613b2d533e07af2fb744d0058885203ef3d..1596f30af9cc716f9697141533dbd880da56ae01 100644
--- a/src/lithium.h
+++ b/src/lithium.h
@@ -37,8 +37,9 @@ class LGapNode;

 class LGapResolver BASE_EMBEDDED {
  public:
- LGapResolver(const ZoneList<LMoveOperands>* moves, LOperand* marker_operand);
-  const ZoneList<LMoveOperands>* ResolveInReverseOrder();
+  LGapResolver();
+ const ZoneList<LMoveOperands>* Resolve(const ZoneList<LMoveOperands>* moves,
+                                         LOperand* marker_operand);

  private:
   LGapNode* LookupNode(LOperand* operand);
@@ -47,14 +48,12 @@ class LGapResolver BASE_EMBEDDED {
   void RegisterMove(LMoveOperands move);
   void AddResultMove(LOperand* from, LOperand* to);
   void AddResultMove(LGapNode* from, LGapNode* to);
-  void ResolveCycle(LGapNode* start);
+  void ResolveCycle(LGapNode* start, LOperand* marker_operand);

   ZoneList<LGapNode*> nodes_;
   ZoneList<LGapNode*> identified_cycles_;
   ZoneList<LMoveOperands> result_;
-  LOperand* marker_operand_;
   int next_visited_id_;
-  int bailout_after_ast_id_;
 };




--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to