Reviewers: titzer,

Message:
Note that this also fixes a bug in the materialization of heap numbers that this
implementation uncovered. I can move that into a separate CL if you think it
should be in separate changes.

Description:
Implement fixpoint iteration for escape analysis.

[email protected]

Please review this at https://codereview.chromium.org/23533003/

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

Affected files:
  M src/deoptimizer.cc
  M src/hydrogen-escape-analysis.h
  M src/hydrogen-escape-analysis.cc
  M src/hydrogen-instructions.h
  M src/hydrogen-instructions.cc


Index: src/deoptimizer.cc
diff --git a/src/deoptimizer.cc b/src/deoptimizer.cc
index dc9ffc51186be1c5535297c6adf77f9efbf922b1..f104e87f56b3e142676be25c635971727e60c8df 100644
--- a/src/deoptimizer.cc
+++ b/src/deoptimizer.cc
@@ -1683,9 +1683,10 @@ Handle<Object> Deoptimizer::MaterializeNextHeapObject() {
     Handle<Map> map = Handle<Map>::cast(MaterializeNextValue());
     switch (map->instance_type()) {
       case HEAP_NUMBER_TYPE: {
-        Handle<HeapNumber> number =
-            Handle<HeapNumber>::cast(MaterializeNextValue());
-        materialized_objects_->Add(number);
+ Handle<HeapNumber> object = isolate_->factory()->NewHeapNumber(0.0);
+        materialized_objects_->Add(object);
+        Handle<Object> number = MaterializeNextValue();
+        object->set_value(number->Number());
         materialization_value_index_ += kDoubleSize / kPointerSize - 1;
         break;
       }
Index: src/hydrogen-escape-analysis.cc
diff --git a/src/hydrogen-escape-analysis.cc b/src/hydrogen-escape-analysis.cc index 311091b6d993ddf78f7b373309d60b6869a249e7..de29266c25f3eafa35d547724dec3ac062450cf0 100644
--- a/src/hydrogen-escape-analysis.cc
+++ b/src/hydrogen-escape-analysis.cc
@@ -259,6 +259,7 @@ void HEscapeAnalysisPhase::AnalyzeDataFlow(HInstruction* allocate) {


 void HEscapeAnalysisPhase::PerformScalarReplacement() {
+  bool maybe_more_work = false;
   for (int i = 0; i < captured_.length(); i++) {
     HAllocate* allocate = HAllocate::cast(captured_.at(i));

@@ -269,13 +270,18 @@ void HEscapeAnalysisPhase::PerformScalarReplacement() {
     number_of_objects_++;
     block_states_.Clear();

-    // Perform actual analysis steps.
+    // Perform actual analysis step.
     AnalyzeDataFlow(allocate);

+    maybe_more_work = true;
     cumulative_values_ += number_of_values_;
     ASSERT(allocate->HasNoUses());
     ASSERT(!allocate->IsLinked());
   }
+
+  // Clear captured objects.
+  maybe_more_work_ = maybe_more_work;
+  captured_.Clear();
 }


Index: src/hydrogen-escape-analysis.h
diff --git a/src/hydrogen-escape-analysis.h b/src/hydrogen-escape-analysis.h
index 2d425e2ecd692e4831cd2c802fd0e597881b3f7c..ff796866a8475baa3ef80f457998cb460d9810b2 100644
--- a/src/hydrogen-escape-analysis.h
+++ b/src/hydrogen-escape-analysis.h
@@ -40,14 +40,17 @@ class HEscapeAnalysisPhase : public HPhase {
   explicit HEscapeAnalysisPhase(HGraph* graph)
       : HPhase("H_Escape analysis", graph),
         captured_(0, zone()),
+        maybe_more_work_(true),
         number_of_objects_(0),
         number_of_values_(0),
         cumulative_values_(0),
         block_states_(graph->blocks()->length(), zone()) { }

   void Run() {
-    CollectCapturedValues();
-    PerformScalarReplacement();
+ for (int i = 0; i < kMaxFixpointIterationCount && maybe_more_work_; i++) {
+      CollectCapturedValues();
+      PerformScalarReplacement();
+    }
   }

  private:
@@ -71,9 +74,15 @@ class HEscapeAnalysisPhase : public HPhase {
     block_states_.Set(block->block_id(), state);
   }

+  // Maximum number of escape analysis iterations.
+  static const int kMaxFixpointIterationCount = 2;
+
   // List of allocations captured during collection phase.
   ZoneList<HInstruction*> captured_;

+  // Indicates another iteration might discover new captured objects.
+  bool maybe_more_work_;
+
   // Number of captured objects on which scalar replacement was done.
   int number_of_objects_;

Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index 07e78f3368e251ea89cd57d81d6045a8e873f4b7..5730623ceffe8105ce677dbfa4d73e0ed2221a02 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -2321,6 +2321,12 @@ void HCapturedObject::ReplayEnvironment(HEnvironment* env) {
 }


+void HCapturedObject::PrintDataTo(StringStream* stream) {
+  stream->Add("#%d ", capture_id());
+  HDematerializedObject::PrintDataTo(stream);
+}
+
+
 void HEnterInlined::RegisterReturnTarget(HBasicBlock* return_target,
                                          Zone* zone) {
   ASSERT(return_target->IsInlineReturnTarget());
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index 8668793c8a3e4844783ca40d1ad1a1cc054f6829..a06f25dc1c0f2dcb8ec8a958ca26ff532176a0f0 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -3227,6 +3227,8 @@ class HCapturedObject V8_FINAL : public HDematerializedObject {
   // Replay effects of this instruction on the given environment.
   void ReplayEnvironment(HEnvironment* env);

+  virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE;
+
   DECLARE_CONCRETE_INSTRUCTION(CapturedObject)

  private:


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to