Revision: 15393
Author:   [email protected]
Date:     Fri Jun 28 09:09:54 2013
Log:      First simplistic implementation of escape analysis.

[email protected], [email protected]

Review URL: https://codereview.chromium.org/17914002
http://code.google.com/p/v8/source/detail?r=15393

Added:
 /branches/bleeding_edge/src/hydrogen-escape-analysis.cc
 /branches/bleeding_edge/src/hydrogen-escape-analysis.h
Modified:
 /branches/bleeding_edge/src/flag-definitions.h
 /branches/bleeding_edge/src/hydrogen-instructions.h
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/hydrogen.h
 /branches/bleeding_edge/tools/gyp/v8.gyp

=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/hydrogen-escape-analysis.cc Fri Jun 28 09:09:54 2013
@@ -0,0 +1,72 @@
+// Copyright 2013 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:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "hydrogen-escape-analysis.h"
+
+namespace v8 {
+namespace internal {
+
+
+void HEscapeAnalysis::CollectIfNoEscapingUses(HInstruction* instr) {
+  for (HUseIterator it(instr->uses()); !it.Done(); it.Advance()) {
+    HValue* use = it.value();
+    if (use->HasEscapingOperandAt(it.index())) {
+      if (FLAG_trace_escape_analysis) {
+        PrintF("#%d (%s) escapes through #%d (%s) @%d\n", instr->id(),
+               instr->Mnemonic(), use->id(), use->Mnemonic(), it.index());
+      }
+      return;
+    }
+  }
+  if (FLAG_trace_escape_analysis) {
+    PrintF("#%d (%s) is being captured\n", instr->id(), instr->Mnemonic());
+  }
+  captured_.Add(instr, zone_);
+}
+
+
+void HEscapeAnalysis::CollectCapturedValues() {
+  int block_count = graph_->blocks()->length();
+  for (int i = 0; i < block_count; ++i) {
+    HBasicBlock* block = graph_->blocks()->at(i);
+    for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
+      HInstruction* instr = it.Current();
+      if (instr->IsAllocate() || instr->IsAllocateObject()) {
+        CollectIfNoEscapingUses(instr);
+      }
+    }
+  }
+}
+
+
+void HEscapeAnalysis::Analyze() {
+  HPhase phase("H_Escape analysis", graph_);
+  CollectCapturedValues();
+}
+
+
+} }  // namespace v8::internal
=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/hydrogen-escape-analysis.h Fri Jun 28 09:09:54 2013
@@ -0,0 +1,57 @@
+// Copyright 2013 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:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_HYDROGEN_ESCAPE_ANALYSIS_H_
+#define V8_HYDROGEN_ESCAPE_ANALYSIS_H_
+
+#include "allocation.h"
+#include "hydrogen.h"
+
+namespace v8 {
+namespace internal {
+
+
+class HEscapeAnalysis BASE_EMBEDDED {
+ public:
+  explicit HEscapeAnalysis(HGraph* graph)
+      : graph_(graph), zone_(graph->zone()), captured_(0, zone_) { }
+
+  void Analyze();
+
+ private:
+  void CollectCapturedValues();
+  void CollectIfNoEscapingUses(HInstruction* instr);
+
+  HGraph* graph_;
+  Zone* zone_;
+  ZoneList<HValue*> captured_;
+};
+
+
+} }  // namespace v8::internal
+
+#endif  // V8_HYDROGEN_ESCAPE_ANALYSIS_H_
=======================================
--- /branches/bleeding_edge/src/flag-definitions.h      Wed Jun 26 01:43:27 2013
+++ /branches/bleeding_edge/src/flag-definitions.h      Fri Jun 28 09:09:54 2013
@@ -214,6 +214,7 @@
 DEFINE_bool(use_gvn, true, "use hydrogen global value numbering")
DEFINE_bool(use_canonicalizing, true, "use hydrogen instruction canonicalizing")
 DEFINE_bool(use_inlining, true, "use function inlining")
+DEFINE_bool(use_escape_analysis, false, "use hydrogen escape analysis")
 DEFINE_int(max_inlined_source_size, 600,
            "maximum source size in bytes considered for a single inlining")
 DEFINE_int(max_inlined_nodes, 196,
@@ -234,6 +235,7 @@
 DEFINE_bool(trace_range, false, "trace range analysis")
 DEFINE_bool(trace_gvn, false, "trace global value numbering")
 DEFINE_bool(trace_representation, false, "trace representation types")
+DEFINE_bool(trace_escape_analysis, false, "trace hydrogen escape analysis")
 DEFINE_bool(trace_track_allocation_sites, false,
             "trace the tracking of allocation sites")
 DEFINE_bool(trace_migration, false, "trace object migration")
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Fri Jun 28 06:16:14 2013 +++ /branches/bleeding_edge/src/hydrogen-instructions.h Fri Jun 28 09:09:54 2013
@@ -1061,6 +1061,9 @@
   void AddNewRange(Range* r, Zone* zone);
   void RemoveLastAddedRange();
   void ComputeInitialRange(Zone* zone);
+
+  // Escape analysis helpers.
+  virtual bool HasEscapingOperandAt(int index) { return true; }

   // Representation helpers.
   virtual Representation observed_input_representation(int index) {
@@ -1433,6 +1436,7 @@

   HValue* value() { return OperandAt(0); }

+  virtual bool HasEscapingOperandAt(int index) { return false; }
   virtual Representation RequiredInputRepresentation(int index) {
     return Representation::None();
   }
@@ -1892,6 +1896,7 @@
   virtual int OperandCount() { return values_.length(); }
   virtual HValue* OperandAt(int index) const { return values_[index]; }

+  virtual bool HasEscapingOperandAt(int index) { return false; }
   virtual Representation RequiredInputRepresentation(int index) {
     return Representation::None();
   }
@@ -2801,6 +2806,7 @@
     return check_map;
   }

+  virtual bool HasEscapingOperandAt(int index) { return false; }
   virtual Representation RequiredInputRepresentation(int index) {
     return Representation::Tagged();
   }
@@ -3228,6 +3234,7 @@
   virtual int OperandCount() { return values_.length(); }
   virtual HValue* OperandAt(int index) const { return values_[index]; }

+  virtual bool HasEscapingOperandAt(int index) { return false; }
   virtual Representation RequiredInputRepresentation(int index) {
     return Representation::None();
   }
@@ -5431,6 +5438,7 @@
   HObjectAccess access() const { return access_; }
   Representation field_representation() const { return representation_; }

+  virtual bool HasEscapingOperandAt(int index) { return false; }
   virtual Representation RequiredInputRepresentation(int index) {
     return Representation::Tagged();
   }
@@ -5763,6 +5771,7 @@

   DECLARE_CONCRETE_INSTRUCTION(StoreNamedField)

+  virtual bool HasEscapingOperandAt(int index) { return index == 1; }
   virtual Representation RequiredInputRepresentation(int index) {
     if (FLAG_track_double_fields &&
         index == 1 && field_representation_.IsDouble()) {
@@ -5895,6 +5904,7 @@
     }
   }

+  virtual bool HasEscapingOperandAt(int index) { return index != 0; }
   virtual Representation RequiredInputRepresentation(int index) {
     // kind_fast:       tagged[int32] = tagged
     // kind_double:     tagged[int32] = double
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Fri Jun 28 08:48:38 2013
+++ /branches/bleeding_edge/src/hydrogen.cc     Fri Jun 28 09:09:54 2013
@@ -26,7 +26,6 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 #include "hydrogen.h"
-#include "hydrogen-gvn.h"

 #include <algorithm>

@@ -35,7 +34,9 @@
 #include "full-codegen.h"
 #include "hashmap.h"
 #include "hydrogen-environment-liveness.h"
+#include "hydrogen-escape-analysis.h"
 #include "hydrogen-infer-representation.h"
+#include "hydrogen-gvn.h"
 #include "lithium-allocator.h"
 #include "parser.h"
 #include "scopeinfo.h"
@@ -3825,11 +3826,16 @@

   if (FLAG_use_canonicalizing) Canonicalize();

+  if (FLAG_use_escape_analysis) {
+    HEscapeAnalysis escape_analysis(this);
+    escape_analysis.Analyze();
+  }
+
   if (FLAG_use_gvn) Run<HGlobalValueNumberingPhase>();

   if (FLAG_use_range) {
-    HRangeAnalysis rangeAnalysis(this);
-    rangeAnalysis.Analyze();
+    HRangeAnalysis range_analysis(this);
+    range_analysis.Analyze();
   }
   ComputeMinusZeroChecks();

=======================================
--- /branches/bleeding_edge/src/hydrogen.h      Fri Jun 28 06:16:14 2013
+++ /branches/bleeding_edge/src/hydrogen.h      Fri Jun 28 09:09:54 2013
@@ -230,6 +230,21 @@
 };


+class HInstructionIterator BASE_EMBEDDED {
+ public:
+  explicit HInstructionIterator(HBasicBlock* block)
+      : block_(block), instr_(block->first()) { }
+
+  bool Done() { return instr_ == block_->last(); }
+  HInstruction* Current() { return instr_; }
+  void Advance() { instr_ = instr_->next(); }
+
+ private:
+  HBasicBlock* block_;
+  HInstruction* instr_;
+};
+
+
 class HLoopInformation: public ZoneObject {
  public:
   HLoopInformation(HBasicBlock* loop_header, Zone* zone)
=======================================
--- /branches/bleeding_edge/tools/gyp/v8.gyp    Fri Jun 28 08:22:46 2013
+++ /branches/bleeding_edge/tools/gyp/v8.gyp    Fri Jun 28 09:09:54 2013
@@ -327,6 +327,8 @@
         '../../src/heap.h',
         '../../src/hydrogen-environment-liveness.cc',
         '../../src/hydrogen-environment-liveness.h',
+        '../../src/hydrogen-escape-analysis.cc',
+        '../../src/hydrogen-escape-analysis.h',
         '../../src/hydrogen-instructions.cc',
         '../../src/hydrogen-instructions.h',
         '../../src/hydrogen.cc',

--
--
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