Unify use-sites of EnsureDeoptimizationSupport.
authormstarzinger@chromium.org <mstarzinger@chromium.org>
Thu, 18 Sep 2014 09:02:36 +0000 (09:02 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org>
Thu, 18 Sep 2014 09:02:36 +0000 (09:02 +0000)
R=sigurds@chromium.org

Review URL: https://codereview.chromium.org/563123004

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24024 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/compiler.cc
src/compiler.h
src/compiler/js-inlining.cc
src/hydrogen.cc
test/cctest/compiler/function-tester.h
test/cctest/compiler/test-codegen-deopt.cc

index ac8d83e..6cad144 100644 (file)
@@ -397,21 +397,8 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
     if (FLAG_hydrogen_stats) {
       timer.Start();
     }
-    CompilationInfoWithZone unoptimized(info()->shared_info());
-    // Note that we use the same AST that we will use for generating the
-    // optimized code.
-    unoptimized.SetFunction(info()->function());
-    unoptimized.PrepareForCompilation(info()->scope());
-    unoptimized.SetContext(info()->context());
-    if (should_recompile) unoptimized.EnableDeoptimizationSupport();
-    bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
-    if (should_recompile) {
-      if (!succeeded) return SetLastStatus(FAILED);
-      Handle<SharedFunctionInfo> shared = info()->shared_info();
-      shared->EnableDeoptimizationSupport(*unoptimized.code());
-      // The existing unoptimized code was replaced with the new one.
-      Compiler::RecordFunctionCompilation(
-          Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
+    if (!Compiler::EnsureDeoptimizationSupport(info())) {
+      return SetLastStatus(FAILED);
     }
     if (FLAG_hydrogen_stats) {
       isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed());
@@ -773,6 +760,38 @@ bool Compiler::EnsureCompiled(Handle<JSFunction> function,
 }
 
 
+// TODO(turbofan): In the future, unoptimized code with deopt support could
+// be generated lazily once deopt is triggered.
+bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
+  if (!info->shared_info()->has_deoptimization_support()) {
+    CompilationInfoWithZone unoptimized(info->shared_info());
+    // Note that we use the same AST that we will use for generating the
+    // optimized code.
+    unoptimized.SetFunction(info->function());
+    unoptimized.PrepareForCompilation(info->scope());
+    unoptimized.SetContext(info->context());
+    unoptimized.EnableDeoptimizationSupport();
+    if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
+
+    Handle<SharedFunctionInfo> shared = info->shared_info();
+    shared->EnableDeoptimizationSupport(*unoptimized.code());
+    shared->set_feedback_vector(*unoptimized.feedback_vector());
+
+    // The scope info might not have been set if a lazily compiled
+    // function is inlined before being called for the first time.
+    if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) {
+      Handle<ScopeInfo> target_scope_info =
+          ScopeInfo::Create(info->scope(), info->zone());
+      shared->set_scope_info(*target_scope_info);
+    }
+
+    // The existing unoptimized code was replaced with the new one.
+    RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
+  }
+  return true;
+}
+
+
 // Compile full code for debugging. This code will have debug break slots
 // and deoptimization information. Deoptimization information is required
 // in case that an optimized version of this function is still activated on
index 51c8daa..500cfa4 100644 (file)
@@ -663,11 +663,14 @@ class Compiler : public AllStatic {
       Handle<JSFunction> function);
   MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCode(
       Handle<SharedFunctionInfo> shared);
-  static bool EnsureCompiled(Handle<JSFunction> function,
-                             ClearExceptionFlag flag);
   MUST_USE_RESULT static MaybeHandle<Code> GetDebugCode(
       Handle<JSFunction> function);
 
+  static bool EnsureCompiled(Handle<JSFunction> function,
+                             ClearExceptionFlag flag);
+
+  static bool EnsureDeoptimizationSupport(CompilationInfo* info);
+
   static void CompileForLiveEdit(Handle<Script> script);
 
   // Compile a String source within a context for eval.
index 4166ace..af02145 100644 (file)
@@ -57,9 +57,7 @@ static void Parse(Handle<JSFunction> function, CompilationInfoWithZone* info) {
   CHECK(Parser::Parse(info));
   CHECK(Rewriter::Rewrite(info));
   CHECK(Scope::Analyze(info));
-  CHECK_NE(NULL, info->scope());
-  Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone());
-  info->shared_info()->set_scope_info(*scope_info);
+  CHECK(Compiler::EnsureDeoptimizationSupport(info));
 }
 
 
@@ -393,18 +391,6 @@ void JSInliner::TryInlineCall(Node* call_node) {
   CompilationInfoWithZone info(function);
   Parse(function, &info);
 
-  if (!function->shared()->has_deoptimization_support()) {
-    // TODO(turbofan) In the future, unoptimized code with deopt support could
-    // be generated lazily once deopt is triggered.
-    info.EnableDeoptimizationSupport();
-    if (!FullCodeGenerator::MakeCode(&info)) {
-      DCHECK(false);
-      return;
-    }
-    function->shared()->EnableDeoptimizationSupport(*info.code());
-    function->shared()->set_feedback_vector(*info.feedback_vector());
-  }
-
   if (info.scope()->arguments() != NULL) {
     // For now do not inline functions that use their arguments array.
     SmartArrayPointer<char> name = function->shared()->DebugName()->ToCString();
index 3c0705c..675b611 100644 (file)
@@ -7835,26 +7835,9 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
 
   // Generate the deoptimization data for the unoptimized version of
   // the target function if we don't already have it.
-  if (!target_shared->has_deoptimization_support()) {
-    // Note that we compile here using the same AST that we will use for
-    // generating the optimized inline code.
-    target_info.EnableDeoptimizationSupport();
-    if (!FullCodeGenerator::MakeCode(&target_info)) {
-      TraceInline(target, caller, "could not generate deoptimization info");
-      return false;
-    }
-    if (target_shared->scope_info() == ScopeInfo::Empty(isolate())) {
-      // The scope info might not have been set if a lazily compiled
-      // function is inlined before being called for the first time.
-      Handle<ScopeInfo> target_scope_info =
-          ScopeInfo::Create(target_info.scope(), zone());
-      target_shared->set_scope_info(*target_scope_info);
-    }
-    target_shared->EnableDeoptimizationSupport(*target_info.code());
-    target_shared->set_feedback_vector(*target_info.feedback_vector());
-    Compiler::RecordFunctionCompilation(Logger::FUNCTION_TAG,
-                                        &target_info,
-                                        target_shared);
+  if (!Compiler::EnsureDeoptimizationSupport(&target_info)) {
+    TraceInline(target, caller, "could not generate deoptimization info");
+    return false;
   }
 
   // ----------------------------------------------------------------
index 2ef46eb..c869f00 100644 (file)
@@ -57,11 +57,7 @@ class FunctionTester : public InitializedHandleScope {
     }
     CHECK(Rewriter::Rewrite(&info));
     CHECK(Scope::Analyze(&info));
-    CHECK_NE(NULL, info.scope());
-    Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), info.zone());
-    info.shared_info()->set_scope_info(*scope_info);
-
-    EnsureDeoptimizationSupport(&info);
+    CHECK(Compiler::EnsureDeoptimizationSupport(&info));
 
     Pipeline pipeline(&info);
     Handle<Code> code = pipeline.GenerateCode();
@@ -87,23 +83,6 @@ class FunctionTester : public InitializedHandleScope {
     return function;
   }
 
-  static void EnsureDeoptimizationSupport(CompilationInfo* info) {
-    bool should_recompile = !info->shared_info()->has_deoptimization_support();
-    if (should_recompile) {
-      CompilationInfoWithZone unoptimized(info->shared_info());
-      // Note that we use the same AST that we will use for generating the
-      // optimized code.
-      unoptimized.SetFunction(info->function());
-      unoptimized.PrepareForCompilation(info->scope());
-      unoptimized.SetContext(info->context());
-      if (should_recompile) unoptimized.EnableDeoptimizationSupport();
-      bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
-      CHECK(succeeded);
-      Handle<SharedFunctionInfo> shared = info->shared_info();
-      shared->EnableDeoptimizationSupport(*unoptimized.code());
-    }
-  }
-
   MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) {
     Handle<Object> args[] = {a, b};
     return Execution::Call(isolate, function, undefined(), 2, args, false);
index 5b6c358..8217229 100644 (file)
@@ -48,11 +48,7 @@ class DeoptCodegenTester {
     info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code()));
     CHECK(Rewriter::Rewrite(&info));
     CHECK(Scope::Analyze(&info));
-    CHECK_NE(NULL, info.scope());
-    Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), info.zone());
-    info.shared_info()->set_scope_info(*scope_info);
-
-    FunctionTester::EnsureDeoptimizationSupport(&info);
+    CHECK(Compiler::EnsureDeoptimizationSupport(&info));
 
     DCHECK(info.shared_info()->has_deoptimization_support());