@@ -58,32 +58,13 @@ namespace internal {
5858
5959namespace {
6060
61- const char * CompilationTargetName (CompilationTarget target) {
62- switch (target) {
63- case CompilationTarget::kTurbofan :
64- return " Turbofan" ;
65- case CompilationTarget::kNativeContextIndependent :
66- return " NativeContextIndependent" ;
67- }
68- UNREACHABLE ();
69- }
70-
71- CompilationTarget CompilationTargetOf (OptimizedCompilationInfo* info) {
72- return info->native_context_independent ()
73- ? CompilationTarget::kNativeContextIndependent
74- : CompilationTarget::kTurbofan ;
75- }
76-
77- bool IsNativeContextIndependent (CompilationTarget target) {
78- return target == CompilationTarget::kNativeContextIndependent ;
79- }
80-
81- bool IsForNativeContextIndependentCachingOnly (CompilationTarget target) {
82- return IsNativeContextIndependent (target) && !FLAG_turbo_nci_as_highest_tier;
61+ bool IsForNativeContextIndependentCachingOnly (CodeKind kind) {
62+ return CodeKindIsNativeContextIndependentJSFunction (kind) &&
63+ !FLAG_turbo_nci_as_highest_tier;
8364}
8465
8566bool IsForNativeContextIndependentCachingOnly (OptimizedCompilationInfo* info) {
86- return IsForNativeContextIndependentCachingOnly (CompilationTargetOf ( info));
67+ return IsForNativeContextIndependentCachingOnly (info-> code_kind ( ));
8768}
8869
8970class CompilerTracer : public AllStatic {
@@ -93,8 +74,7 @@ class CompilerTracer : public AllStatic {
9374 OptimizedCompilationInfo* info) {
9475 PrintF (scope.file (), " [%s " , header);
9576 info->closure ()->ShortPrint (scope.file ());
96- PrintF (scope.file (), " (target %s)" ,
97- CompilationTargetName (CompilationTargetOf (info)));
77+ PrintF (scope.file (), " (target %s)" , CodeKindToString (info->code_kind ()));
9878 }
9979
10080 static void PrintTracePrefix (const CodeTracer::Scope& scope,
@@ -893,8 +873,7 @@ void InsertCodeIntoOptimizedCodeCache(
893873 // Cached NCI code currently does not use the optimization marker field.
894874 if (IsForNativeContextIndependentCachingOnly (compilation_info)) return ;
895875
896- Handle<Code> code = compilation_info->code ();
897- if (code->kind () != Code::OPTIMIZED_FUNCTION) return ; // Nothing to do.
876+ if (!CodeKindIsOptimizedJSFunction (compilation_info->code_kind ())) return ;
898877
899878 // Function context specialization folds-in the function context,
900879 // so no sharing can occur.
@@ -906,6 +885,7 @@ void InsertCodeIntoOptimizedCodeCache(
906885 }
907886
908887 // Cache optimized context-specific code.
888+ Handle<Code> code = compilation_info->code ();
909889 Handle<JSFunction> function = compilation_info->closure ();
910890 Handle<SharedFunctionInfo> shared (function->shared (), function->GetIsolate ());
911891 Handle<NativeContext> native_context (function->context ().native_context (),
@@ -922,15 +902,14 @@ void InsertCodeIntoOptimizedCodeCache(
922902
923903void InsertCodeIntoCompilationCache (Isolate* isolate,
924904 OptimizedCompilationInfo* info) {
925- if (!info->native_context_independent ( )) return ;
905+ if (!CodeKindIsNativeContextIndependentJSFunction ( info->code_kind () )) return ;
926906
927907 // TODO(jgruber,v8:8888): This should turn into a DCHECK once we
928908 // spawn dedicated NCI compile tasks.
929909 if (!info->osr_offset ().IsNone ()) return ;
930910
931911 Handle<Code> code = info->code ();
932912 DCHECK (!info->function_context_specializing ());
933- DCHECK_EQ (code->kind (), Code::OPTIMIZED_FUNCTION);
934913
935914 Handle<SharedFunctionInfo> sfi = info->shared_info ();
936915 CompilationCache* cache = isolate->compilation_cache ();
@@ -1004,10 +983,11 @@ bool GetOptimizedCodeLater(OptimizedCompilationJob* job, Isolate* isolate) {
1004983}
1005984
1006985MaybeHandle<Code> GetOptimizedCode (Handle<JSFunction> function,
1007- ConcurrencyMode mode,
1008- CompilationTarget compilation_target,
986+ ConcurrencyMode mode, CodeKind code_kind,
1009987 BailoutId osr_offset = BailoutId::None(),
1010988 JavaScriptFrame* osr_frame = nullptr) {
989+ DCHECK (CodeKindIsOptimizedJSFunction (code_kind));
990+
1011991 Isolate* isolate = function->GetIsolate ();
1012992 Handle<SharedFunctionInfo> shared (function->shared (), isolate);
1013993
@@ -1038,7 +1018,7 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
10381018 PendingOptimizationTable::FunctionWasOptimized (isolate, function);
10391019 }
10401020
1041- if (!IsForNativeContextIndependentCachingOnly (compilation_target )) {
1021+ if (!IsForNativeContextIndependentCachingOnly (code_kind )) {
10421022 Handle<Code> cached_code;
10431023 if (GetCodeFromOptimizedCodeCache (function, osr_offset)
10441024 .ToHandle (&cached_code)) {
@@ -1051,7 +1031,7 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
10511031 DCHECK (shared->is_compiled ());
10521032 function->feedback_vector ().set_profiler_ticks (0 );
10531033
1054- if (IsNativeContextIndependent (compilation_target )) {
1034+ if (CodeKindIsNativeContextIndependentJSFunction (code_kind )) {
10551035 // We don't generate NCI code for OSR.
10561036 DCHECK_EQ (osr_offset, BailoutId::None ());
10571037 // Don't generate NCI code when we've already done so in the past.
@@ -1074,9 +1054,8 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
10741054 // tolerate the lack of a script without bytecode.
10751055 DCHECK_IMPLIES (!has_script, shared->HasBytecodeArray ());
10761056 std::unique_ptr<OptimizedCompilationJob> job (
1077- compiler::Pipeline::NewCompilationJob (
1078- isolate, function, has_script, osr_offset, osr_frame,
1079- IsNativeContextIndependent (compilation_target)));
1057+ compiler::Pipeline::NewCompilationJob (isolate, function, code_kind,
1058+ has_script, osr_offset, osr_frame));
10801059 OptimizedCompilationInfo* compilation_info = job->compilation_info ();
10811060
10821061 // In case of concurrent recompilation, all handles below this point will be
@@ -1098,7 +1077,7 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
10981077 job.release (); // The background recompile job owns this now.
10991078
11001079 // Set the optimization marker and return a code object which checks it.
1101- if (!IsForNativeContextIndependentCachingOnly (compilation_target )) {
1080+ if (!IsForNativeContextIndependentCachingOnly (code_kind )) {
11021081 // Cached NCI code currently does not use the optimization marker field.
11031082 function->SetOptimizationMarker (
11041083 OptimizationMarker::kInOptimizationQueue );
@@ -1778,7 +1757,7 @@ bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag,
17781757
17791758 Handle<Code> maybe_code;
17801759 if (GetOptimizedCode (function, ConcurrencyMode::kNotConcurrent ,
1781- DefaultCompilationTarget ())
1760+ CodeKindForTopTier ())
17821761 .ToHandle (&maybe_code)) {
17831762 code = maybe_code;
17841763 }
@@ -1839,15 +1818,16 @@ bool Compiler::FinalizeBackgroundCompileTask(
18391818
18401819// static
18411820bool Compiler::CompileOptimized (Handle<JSFunction> function,
1842- ConcurrencyMode mode,
1843- CompilationTarget target) {
1821+ ConcurrencyMode mode, CodeKind code_kind) {
1822+ DCHECK (CodeKindIsOptimizedJSFunction (code_kind));
1823+
18441824 if (function->IsOptimized ()) return true ;
18451825
18461826 Isolate* isolate = function->GetIsolate ();
18471827 DCHECK (AllowCompilation::IsAllowed (isolate));
18481828
18491829 Handle<Code> code;
1850- if (!GetOptimizedCode (function, mode, target ).ToHandle (&code)) {
1830+ if (!GetOptimizedCode (function, mode, code_kind ).ToHandle (&code)) {
18511831 // Optimization failed, get unoptimized code. Unoptimized code must exist
18521832 // already if we are optimizing.
18531833 DCHECK (!isolate->has_pending_exception ());
@@ -1856,7 +1836,7 @@ bool Compiler::CompileOptimized(Handle<JSFunction> function,
18561836 code = BUILTIN_CODE (isolate, InterpreterEntryTrampoline);
18571837 }
18581838
1859- if (!IsForNativeContextIndependentCachingOnly (target )) {
1839+ if (!IsForNativeContextIndependentCachingOnly (code_kind )) {
18601840 function->set_code (*code);
18611841 }
18621842
@@ -2913,7 +2893,7 @@ MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function,
29132893 DCHECK (!osr_offset.IsNone ());
29142894 DCHECK_NOT_NULL (osr_frame);
29152895 return GetOptimizedCode (function, ConcurrencyMode::kNotConcurrent ,
2916- CompilationTarget:: kTurbofan , osr_offset, osr_frame);
2896+ CodeKindForOSR () , osr_offset, osr_frame);
29172897}
29182898
29192899// static
0 commit comments