Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Side by Side Diff: src/compilation-info.cc

Issue 2284313003: Separate CompilationInfo into its own file. (Closed)
Patch Set: fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compilation-info.h ('k') | src/compiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compilation-info.h"
6
7 #include "src/api.h"
8 #include "src/ast/scopes.h"
9 #include "src/isolate.h"
10 #include "src/parsing/parse-info.h"
11
12 namespace v8 {
13 namespace internal {
14
15 #define PARSE_INFO_GETTER(type, name) \
16 type CompilationInfo::name() const { \
17 CHECK(parse_info()); \
18 return parse_info()->name(); \
19 }
20
21 #define PARSE_INFO_GETTER_WITH_DEFAULT(type, name, def) \
22 type CompilationInfo::name() const { \
23 return parse_info() ? parse_info()->name() : def; \
24 }
25
26 PARSE_INFO_GETTER(Handle<Script>, script)
27 PARSE_INFO_GETTER(FunctionLiteral*, literal)
28 PARSE_INFO_GETTER_WITH_DEFAULT(DeclarationScope*, scope, nullptr)
29 PARSE_INFO_GETTER_WITH_DEFAULT(Handle<Context>, context,
30 Handle<Context>::null())
31 PARSE_INFO_GETTER(Handle<SharedFunctionInfo>, shared_info)
32
33 #undef PARSE_INFO_GETTER
34 #undef PARSE_INFO_GETTER_WITH_DEFAULT
35
36 bool CompilationInfo::has_shared_info() const {
37 return parse_info_ && !parse_info_->shared_info().is_null();
38 }
39
40 CompilationInfo::CompilationInfo(ParseInfo* parse_info,
41 Handle<JSFunction> closure)
42 : CompilationInfo(parse_info, {}, Code::ComputeFlags(Code::FUNCTION), BASE,
43 parse_info->isolate(), parse_info->zone()) {
44 closure_ = closure;
45
46 // Compiling for the snapshot typically results in different code than
47 // compiling later on. This means that code recompiled with deoptimization
48 // support won't be "equivalent" (as defined by SharedFunctionInfo::
49 // EnableDeoptimizationSupport), so it will replace the old code and all
50 // its type feedback. To avoid this, always compile functions in the snapshot
51 // with deoptimization support.
52 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport();
53
54 if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing();
55 if (FLAG_turbo_inlining) MarkAsInliningEnabled();
56 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled();
57 if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
58 }
59
60 CompilationInfo::CompilationInfo(Vector<const char> debug_name,
61 Isolate* isolate, Zone* zone,
62 Code::Flags code_flags)
63 : CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {}
64
65 CompilationInfo::CompilationInfo(ParseInfo* parse_info,
66 Vector<const char> debug_name,
67 Code::Flags code_flags, Mode mode,
68 Isolate* isolate, Zone* zone)
69 : parse_info_(parse_info),
70 isolate_(isolate),
71 flags_(0),
72 code_flags_(code_flags),
73 mode_(mode),
74 osr_ast_id_(BailoutId::None()),
75 zone_(zone),
76 deferred_handles_(nullptr),
77 dependencies_(isolate, zone),
78 bailout_reason_(kNoReason),
79 prologue_offset_(Code::kPrologueOffsetNotSet),
80 track_positions_(FLAG_hydrogen_track_positions ||
81 isolate->is_profiling()),
82 parameter_count_(0),
83 optimization_id_(-1),
84 osr_expr_stack_height_(0),
85 debug_name_(debug_name) {}
86
87 CompilationInfo::~CompilationInfo() {
88 if (GetFlag(kDisableFutureOptimization) && has_shared_info()) {
89 shared_info()->DisableOptimization(bailout_reason());
90 }
91 dependencies()->Rollback();
92 delete deferred_handles_;
93 }
94
95 int CompilationInfo::num_parameters() const {
96 return !IsStub() ? scope()->num_parameters() : parameter_count_;
97 }
98
99 int CompilationInfo::num_parameters_including_this() const {
100 return num_parameters() + (is_this_defined() ? 1 : 0);
101 }
102
103 bool CompilationInfo::is_this_defined() const { return !IsStub(); }
104
105 // Primitive functions are unlikely to be picked up by the stack-walking
106 // profiler, so they trigger their own optimization when they're called
107 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time.
108 bool CompilationInfo::ShouldSelfOptimize() {
109 return FLAG_crankshaft &&
110 !(literal()->flags() & AstProperties::kDontSelfOptimize) &&
111 !literal()->dont_optimize() &&
112 literal()->scope()->AllowsLazyCompilation() &&
113 !shared_info()->optimization_disabled();
114 }
115
116 void CompilationInfo::ReopenHandlesInNewHandleScope() {
117 closure_ = Handle<JSFunction>(*closure_);
118 }
119
120 bool CompilationInfo::has_simple_parameters() {
121 return scope()->has_simple_parameters();
122 }
123
124 std::unique_ptr<char[]> CompilationInfo::GetDebugName() const {
125 if (parse_info() && parse_info()->literal()) {
126 AllowHandleDereference allow_deref;
127 return parse_info()->literal()->debug_name()->ToCString();
128 }
129 if (parse_info() && !parse_info()->shared_info().is_null()) {
130 return parse_info()->shared_info()->DebugName()->ToCString();
131 }
132 Vector<const char> name_vec = debug_name_;
133 if (name_vec.is_empty()) name_vec = ArrayVector("unknown");
134 std::unique_ptr<char[]> name(new char[name_vec.length() + 1]);
135 memcpy(name.get(), name_vec.start(), name_vec.length());
136 name[name_vec.length()] = '\0';
137 return name;
138 }
139
140 StackFrame::Type CompilationInfo::GetOutputStackFrameType() const {
141 switch (output_code_kind()) {
142 case Code::STUB:
143 case Code::BYTECODE_HANDLER:
144 case Code::HANDLER:
145 case Code::BUILTIN:
146 #define CASE_KIND(kind) case Code::kind:
147 IC_KIND_LIST(CASE_KIND)
148 #undef CASE_KIND
149 return StackFrame::STUB;
150 case Code::WASM_FUNCTION:
151 return StackFrame::WASM;
152 case Code::JS_TO_WASM_FUNCTION:
153 return StackFrame::JS_TO_WASM;
154 case Code::WASM_TO_JS_FUNCTION:
155 return StackFrame::WASM_TO_JS;
156 default:
157 UNIMPLEMENTED();
158 return StackFrame::NONE;
159 }
160 }
161
162 int CompilationInfo::GetDeclareGlobalsFlags() const {
163 DCHECK(DeclareGlobalsLanguageMode::is_valid(parse_info()->language_mode()));
164 return DeclareGlobalsEvalFlag::encode(parse_info()->is_eval()) |
165 DeclareGlobalsNativeFlag::encode(parse_info()->is_native()) |
166 DeclareGlobalsLanguageMode::encode(parse_info()->language_mode());
167 }
168
169 SourcePositionTableBuilder::RecordingMode
170 CompilationInfo::SourcePositionRecordingMode() const {
171 return parse_info() && parse_info()->is_native()
172 ? SourcePositionTableBuilder::OMIT_SOURCE_POSITIONS
173 : SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
174 }
175
176 bool CompilationInfo::ExpectsJSReceiverAsReceiver() {
177 return is_sloppy(parse_info()->language_mode()) && !parse_info()->is_native();
178 }
179
180 bool CompilationInfo::has_native_context() const {
181 return !closure().is_null() && (closure()->native_context() != nullptr);
182 }
183
184 Context* CompilationInfo::native_context() const {
185 return has_native_context() ? closure()->native_context() : nullptr;
186 }
187
188 bool CompilationInfo::has_global_object() const { return has_native_context(); }
189
190 JSGlobalObject* CompilationInfo::global_object() const {
191 return has_global_object() ? native_context()->global_object() : nullptr;
192 }
193
194 void CompilationInfo::SetOptimizing() {
195 DCHECK(has_shared_info());
196 SetMode(OPTIMIZE);
197 optimization_id_ = isolate()->NextOptimizationId();
198 code_flags_ = Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION);
199 }
200
201 void CompilationInfo::AddInlinedFunction(
202 Handle<SharedFunctionInfo> inlined_function) {
203 inlined_functions_.push_back(InlinedFunctionHolder(
204 inlined_function, handle(inlined_function->code())));
205 }
206
207 Code::Kind CompilationInfo::output_code_kind() const {
208 return Code::ExtractKindFromFlags(code_flags_);
209 }
210
211 } // namespace internal
212 } // namespace v8
OLDNEW
« no previous file with comments | « src/compilation-info.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698