Reviewers: fschneider,

Description:
Disable aggressive optimizations on the last optimization attempt.

Only has effect on the loop invariant code motion and Check instructions
for now.

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

Affected files:
  M src/compiler.cc
  M src/hydrogen-instructions.h
  M src/hydrogen.h
  M src/hydrogen.cc
  M src/v8globals.h


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 0bd973045a1aaf3dc1c476c910cbd9e97cb22930..84fd607433fc36771c98d03e0c24c59adfa9749d 100755
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -207,7 +207,8 @@ static bool MakeCrankshaftCode(CompilationInfo* info) {

   // Limit the number of times we re-compile a functions with
   // the optimizing compiler.
-  const int kMaxOptCount = FLAG_deopt_every_n_times == 0 ? 10 : 1000;
+  const int kMaxOptCount =
+      FLAG_deopt_every_n_times == 0 ? kDefaultMaxOptCount : 1000;
   if (info->shared_info()->opt_count() > kMaxOptCount) {
     AbortAndDisable(info);
     // True indicates the compilation pipeline is still going, not
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index 4a23f2a327ef4d41e19481c84c6279ee779a1907..de003477315395d95cfb9d24bf244cf5461e4833 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -773,6 +773,10 @@ class HInstruction: public HValue {
   virtual void Verify() const;
 #endif

+  // Conservative indication of whether the instruction can
+  // deoptimize. Allowed to have false positives.
+  virtual bool CanDeoptimize() const { return false; }
+
   DECLARE_INSTRUCTION(Instruction)

  protected:
@@ -1504,6 +1508,8 @@ class HCheckMap: public HUnaryOperation {
     SetFlag(kDependsOnMaps);
   }

+  virtual bool CanDeoptimize() const { return true; }
+
   virtual Representation RequiredInputRepresentation(int index) const {
     return Representation::Tagged();
   }
@@ -1537,6 +1543,8 @@ class HCheckFunction: public HUnaryOperation {
     SetFlag(kUseGVN);
   }

+  virtual bool CanDeoptimize() const { return true; }
+
   virtual Representation RequiredInputRepresentation(int index) const {
     return Representation::Tagged();
   }
@@ -1573,6 +1581,8 @@ class HCheckInstanceType: public HUnaryOperation {
     SetFlag(kUseGVN);
   }

+  virtual bool CanDeoptimize() const { return true; }
+
   virtual Representation RequiredInputRepresentation(int index) const {
     return Representation::Tagged();
   }
@@ -1610,6 +1620,8 @@ class HCheckNonSmi: public HUnaryOperation {
     SetFlag(kUseGVN);
   }

+  virtual bool CanDeoptimize() const { return true; }
+
   virtual Representation RequiredInputRepresentation(int index) const {
     return Representation::Tagged();
   }
@@ -1632,6 +1644,8 @@ class HCheckPrototypeMaps: public HInstruction {
     SetFlag(kDependsOnMaps);
   }

+  virtual bool CanDeoptimize() const { return true; }
+
 #ifdef DEBUG
   virtual void Verify() const;
 #endif
@@ -1668,6 +1682,8 @@ class HCheckSmi: public HUnaryOperation {
     SetFlag(kUseGVN);
   }

+  virtual bool CanDeoptimize() const { return true; }
+
   virtual Representation RequiredInputRepresentation(int index) const {
     return Representation::Tagged();
   }
@@ -1996,6 +2012,8 @@ class HBoundsCheck: public HBinaryOperation {
     SetFlag(kUseGVN);
   }

+  virtual bool CanDeoptimize() const { return true; }
+
   virtual Representation RequiredInputRepresentation(int index) const {
     return Representation::Integer32();
   }
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 7aa66fd619c1f48a774d54feab2f1b829c67f332..59d962bc82ca33261cf6929a0708d06939aac577 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -687,6 +687,11 @@ HGraph::HGraph(CompilationInfo* info)
 }


+bool HGraph::AllowAggressiveOptimizations() const {
+  return info()->shared_info()->opt_count() + 1 < kDefaultMaxOptCount;
+}
+
+
 Handle<Code> HGraph::Compile() {
   int values = GetMaximumValueID();
   if (values > LAllocator::max_initial_value_ids()) {
@@ -1453,8 +1458,11 @@ void HGlobalValueNumberer::ProcessLoopBlock(HBasicBlock* block,
 // about code that was never executed.
 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr,
                                       HBasicBlock* loop_header) {
-  if (!instr->IsChange() &&
-      FLAG_aggressive_loop_invariant_motion) return true;
+  if (FLAG_aggressive_loop_invariant_motion &&
+      !instr->IsChange() &&
+ (!instr->CanDeoptimize() || graph_->AllowAggressiveOptimizations())) {
+    return true;
+  }
   HBasicBlock* block = instr->block();
   bool result = true;
   if (block != loop_header) {
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index 35165ae97aea4a37b75ed41270bc1a4a5d0d7528..19f898381f02ab63c235ff45d329b5e7e78141a4 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -296,6 +296,9 @@ class HGraph: public HSubgraph {
   explicit HGraph(CompilationInfo* info);

   CompilationInfo* info() const { return info_; }
+
+  bool AllowAggressiveOptimizations() const;
+
   const ZoneList<HBasicBlock*>* blocks() const { return &blocks_; }
   const ZoneList<HPhi*>* phi_list() const { return phi_list_; }
Handle<String> debug_name() const { return info_->function()->debug_name(); }
Index: src/v8globals.h
diff --git a/src/v8globals.h b/src/v8globals.h
index 3f27114beccfdfb43073e53e358c917d1265bf6c..3e6442a2affe08031d82ec3f6147dabfdfc428ed 100644
--- a/src/v8globals.h
+++ b/src/v8globals.h
@@ -105,6 +105,10 @@ const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);

+// Default maximum number of function optimization attempts before we
+// give up.
+const int kDefaultMaxOptCount = 10;
+

// -----------------------------------------------------------------------------
 // Forward declarations for frequently used classes


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

Reply via email to