Version 6.4.158.1 (cherry-pick)

Merged f585415ab0b3af4d11153790a419b8ac7690b914

Revert "[TurboFan] Remove maximum inlining levels check from inlining heuristics"

Tbr: mythria@chromium.org
Bug: chromium:779509
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I20fbf8efbb090013325dfba8fb7c043d6cc883f6
Reviewed-on: https://chromium-review.googlesource.com/744562
Reviewed-by: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/6.4.158@{#2}
Cr-Branched-From: 317cf32131bbb73c30faa25fc6923a38c874e081-refs/heads/master@{#49013}
diff --git a/include/v8-version.h b/include/v8-version.h
index d3b34c6..4606c1b 100644
--- a/include/v8-version.h
+++ b/include/v8-version.h
@@ -11,7 +11,7 @@
 #define V8_MAJOR_VERSION 6
 #define V8_MINOR_VERSION 4
 #define V8_BUILD_NUMBER 158
-#define V8_PATCH_LEVEL 0
+#define V8_PATCH_LEVEL 1
 
 // Use 1 for candidates and 0 otherwise.
 // (Boolean macro values are not supported by all preprocessors.)
diff --git a/src/compiler/js-inlining-heuristic.cc b/src/compiler/js-inlining-heuristic.cc
index 6c44341..b784c6e 100644
--- a/src/compiler/js-inlining-heuristic.cc
+++ b/src/compiler/js-inlining-heuristic.cc
@@ -139,6 +139,24 @@
   }
   if (!can_inline) return NoChange();
 
+  // Stop inlining once the maximum allowed level is reached.
+  int level = 0;
+  for (Node* frame_state = NodeProperties::GetFrameStateInput(node);
+       frame_state->opcode() == IrOpcode::kFrameState;
+       frame_state = NodeProperties::GetFrameStateInput(frame_state)) {
+    FrameStateInfo const& frame_info = OpParameter<FrameStateInfo>(frame_state);
+    if (FrameStateFunctionInfo::IsJSFunctionType(frame_info.type())) {
+      if (++level > FLAG_max_inlining_levels) {
+        TRACE(
+            "Not considering call site #%d:%s, because inlining depth "
+            "%d exceeds maximum allowed level %d\n",
+            node->id(), node->op()->mnemonic(), level,
+            FLAG_max_inlining_levels);
+        return NoChange();
+      }
+    }
+  }
+
   // Gather feedback on how often this call site has been hit before.
   if (node->opcode() == IrOpcode::kJSCall) {
     CallParameters const p = CallParametersOf(node->op());
diff --git a/src/debug/debug-frames.cc b/src/debug/debug-frames.cc
index 805fcc7..75f5cb6 100644
--- a/src/debug/debug-frames.cc
+++ b/src/debug/debug-frames.cc
@@ -236,6 +236,7 @@
   int count = -1;
   for (; !it->done(); it->Advance()) {
     std::vector<FrameSummary> frames;
+    frames.reserve(FLAG_max_inlining_levels + 1);
     it->frame()->Summarize(&frames);
     for (size_t i = frames.size(); i != 0; i--) {
       // Omit functions from native and extension scripts.
diff --git a/src/debug/debug-stack-trace-iterator.cc b/src/debug/debug-stack-trace-iterator.cc
index 7b0c169..d71bca1 100644
--- a/src/debug/debug-stack-trace-iterator.cc
+++ b/src/debug/debug-stack-trace-iterator.cc
@@ -29,6 +29,7 @@
       is_top_frame_(true) {
   if (iterator_.done()) return;
   std::vector<FrameSummary> frames;
+  frames.reserve(FLAG_max_inlining_levels + 1);
   iterator_.frame()->Summarize(&frames);
   inlined_frame_index_ = static_cast<int>(frames.size());
   Advance();
@@ -60,6 +61,7 @@
     iterator_.Advance();
     if (iterator_.done()) break;
     std::vector<FrameSummary> frames;
+    frames.reserve(FLAG_max_inlining_levels + 1);
     iterator_.frame()->Summarize(&frames);
     inlined_frame_index_ = static_cast<int>(frames.size());
   }
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index e1d9928..e11c66f 100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -414,6 +414,7 @@
 DEFINE_BOOL(function_context_specialization, false,
             "enable function context specialization in TurboFan")
 DEFINE_BOOL(turbo_inlining, true, "enable inlining in TurboFan")
+DEFINE_INT(max_inlining_levels, 5, "maximum number of inlining levels")
 DEFINE_INT(max_inlined_bytecode_size, 500,
            "maximum size of bytecode for a single inlining")
 DEFINE_INT(max_inlined_bytecode_size_cumulative, 1000,
@@ -426,6 +427,7 @@
 DEFINE_BOOL(polymorphic_inlining, true, "polymorphic inlining")
 DEFINE_BOOL(stress_inline, false,
             "set high thresholds for inlining to inline as much as possible")
+DEFINE_VALUE_IMPLICATION(stress_inline, max_inlining_levels, 999999)
 DEFINE_VALUE_IMPLICATION(stress_inline, max_inlined_bytecode_size, 999999)
 DEFINE_VALUE_IMPLICATION(stress_inline, max_inlined_bytecode_size_cumulative,
                          999999)
diff --git a/src/frames.cc b/src/frames.cc
index adabfdc..a92ae1a 100644
--- a/src/frames.cc
+++ b/src/frames.cc
@@ -1268,6 +1268,7 @@
 
 FrameSummary FrameSummary::GetTop(const StandardFrame* frame) {
   std::vector<FrameSummary> frames;
+  frames.reserve(FLAG_max_inlining_levels + 1);
   frame->Summarize(&frames);
   DCHECK_LT(0, frames.size());
   return frames.back();
@@ -1287,6 +1288,7 @@
 FrameSummary FrameSummary::Get(const StandardFrame* frame, int index) {
   DCHECK_LE(0, index);
   std::vector<FrameSummary> frames;
+  frames.reserve(FLAG_max_inlining_levels + 1);
   frame->Summarize(&frames);
   DCHECK_GT(frames.size(), index);
   return frames[index];
diff --git a/src/isolate.cc b/src/isolate.cc
index 1bf882b..dac7079 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -390,6 +390,7 @@
 
   void AppendStandardFrame(StandardFrame* frame) {
     std::vector<FrameSummary> frames;
+    frames.reserve(FLAG_max_inlining_levels + 1);
     frame->Summarize(&frames);
     // A standard frame may include many summarized frames (due to inlining).
     for (size_t i = frames.size(); i != 0 && !full(); i--) {
@@ -801,6 +802,7 @@
     // Set initial size to the maximum inlining level + 1 for the outermost
     // function.
     std::vector<FrameSummary> frames;
+    frames.reserve(FLAG_max_inlining_levels + 1);
     frame->Summarize(&frames);
     for (size_t i = frames.size(); i != 0 && frames_seen < limit; i--) {
       FrameSummary& frame = frames[i - 1];
@@ -1599,6 +1601,7 @@
   // baseline code. For optimized code this will use the deoptimization
   // information to get canonical location information.
   std::vector<FrameSummary> frames;
+  frames.reserve(FLAG_max_inlining_levels + 1);
   frame->Summarize(&frames);
   FrameSummary& summary = frames.back();
   int pos = summary.SourcePosition();
diff --git a/src/runtime/runtime-debug.cc b/src/runtime/runtime-debug.cc
index 9faa1bb..97e400e 100644
--- a/src/runtime/runtime-debug.cc
+++ b/src/runtime/runtime-debug.cc
@@ -434,6 +434,7 @@
   }
 
   std::vector<FrameSummary> frames;
+  frames.reserve(FLAG_max_inlining_levels + 1);
   for (StackTraceFrameIterator it(isolate, id); !it.done(); it.Advance()) {
     frames.clear();
     it.frame()->Summarize(&frames);
diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc
index b503695..9fff5cd 100644
--- a/src/runtime/runtime-internal.cc
+++ b/src/runtime/runtime-internal.cc
@@ -370,6 +370,7 @@
     // baseline code. For optimized code this will use the deoptimization
     // information to get canonical location information.
     std::vector<FrameSummary> frames;
+    frames.reserve(FLAG_max_inlining_levels + 1);
     it.frame()->Summarize(&frames);
     auto& summary = frames.back().AsJavaScript();
     Handle<SharedFunctionInfo> shared(summary.function()->shared());