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

Side by Side Diff: src/compiler.h

Issue 10701054: Enable stub generation using Hydrogen/Lithium (again) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 18 matching lines...) Expand all
29 #define V8_COMPILER_H_ 29 #define V8_COMPILER_H_
30 30
31 #include "allocation.h" 31 #include "allocation.h"
32 #include "ast.h" 32 #include "ast.h"
33 #include "zone.h" 33 #include "zone.h"
34 34
35 namespace v8 { 35 namespace v8 {
36 namespace internal { 36 namespace internal {
37 37
38 class ScriptDataImpl; 38 class ScriptDataImpl;
39 class HydrogenCodeStub;
39 40
40 // CompilationInfo encapsulates some information known at compile time. It 41 // CompilationInfo encapsulates some information known at compile time. It
41 // is constructed based on the resources available at compile-time. 42 // is constructed based on the resources available at compile-time.
42 class CompilationInfo { 43 class CompilationInfo {
43 public: 44 public:
44 CompilationInfo(Handle<Script> script, Zone* zone); 45 CompilationInfo(Handle<Script> script, Zone* zone);
45 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); 46 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone);
46 CompilationInfo(Handle<JSFunction> closure, Zone* zone); 47 CompilationInfo(Handle<JSFunction> closure, Zone* zone);
48 CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, Zone* zone);
47 49
48 virtual ~CompilationInfo(); 50 virtual ~CompilationInfo();
49 51
50 Isolate* isolate() { 52 Isolate* isolate() {
51 ASSERT(Isolate::Current() == isolate_); 53 ASSERT(Isolate::Current() == isolate_);
52 return isolate_; 54 return isolate_;
53 } 55 }
54 Zone* zone() { 56 Zone* zone() {
55 return zone_; 57 return zone_;
56 } 58 }
57 bool is_lazy() const { return IsLazy::decode(flags_); } 59 bool is_lazy() const { return IsLazy::decode(flags_); }
58 bool is_eval() const { return IsEval::decode(flags_); } 60 bool is_eval() const { return IsEval::decode(flags_); }
59 bool is_global() const { return IsGlobal::decode(flags_); } 61 bool is_global() const { return IsGlobal::decode(flags_); }
60 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } 62 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; }
61 bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; } 63 bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; }
62 LanguageMode language_mode() const { 64 LanguageMode language_mode() const {
63 return LanguageModeField::decode(flags_); 65 return LanguageModeField::decode(flags_);
64 } 66 }
65 bool is_in_loop() const { return IsInLoop::decode(flags_); } 67 bool is_in_loop() const { return IsInLoop::decode(flags_); }
66 FunctionLiteral* function() const { return function_; } 68 FunctionLiteral* function() const { return function_; }
67 Scope* scope() const { return scope_; } 69 Scope* scope() const { return scope_; }
68 Scope* global_scope() const { return global_scope_; } 70 Scope* global_scope() const { return global_scope_; }
69 Handle<Code> code() const { return code_; } 71 Handle<Code> code() const { return code_; }
70 Handle<JSFunction> closure() const { return closure_; } 72 Handle<JSFunction> closure() const { return closure_; }
71 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } 73 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
72 Handle<Script> script() const { return script_; } 74 Handle<Script> script() const { return script_; }
75 HydrogenCodeStub* code_stub() {return code_stub_; }
73 v8::Extension* extension() const { return extension_; } 76 v8::Extension* extension() const { return extension_; }
74 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } 77 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
75 Handle<Context> context() const { return context_; } 78 Handle<Context> context() const { return context_; }
76 BailoutId osr_ast_id() const { return osr_ast_id_; } 79 BailoutId osr_ast_id() const { return osr_ast_id_; }
80 int num_parameters() const;
81 int num_heap_slots() const;
82 Code::Flags flags() const;
77 83
78 void MarkAsEval() { 84 void MarkAsEval() {
79 ASSERT(!is_lazy()); 85 ASSERT(!is_lazy());
80 flags_ |= IsEval::encode(true); 86 flags_ |= IsEval::encode(true);
81 } 87 }
82 void MarkAsGlobal() { 88 void MarkAsGlobal() {
83 ASSERT(!is_lazy()); 89 ASSERT(!is_lazy());
84 flags_ |= IsGlobal::encode(true); 90 flags_ |= IsGlobal::encode(true);
85 } 91 }
86 void SetLanguageMode(LanguageMode language_mode) { 92 void SetLanguageMode(LanguageMode language_mode) {
87 ASSERT(this->language_mode() == CLASSIC_MODE || 93 ASSERT(this->language_mode() == CLASSIC_MODE ||
88 this->language_mode() == language_mode || 94 this->language_mode() == language_mode ||
89 language_mode == EXTENDED_MODE); 95 language_mode == EXTENDED_MODE);
90 flags_ = LanguageModeField::update(flags_, language_mode); 96 flags_ = LanguageModeField::update(flags_, language_mode);
91 } 97 }
92 void MarkAsInLoop() { 98 void MarkAsInLoop() {
93 ASSERT(is_lazy()); 99 ASSERT(is_lazy());
94 flags_ |= IsInLoop::encode(true); 100 flags_ |= IsInLoop::encode(true);
95 } 101 }
96 void MarkAsNative() { 102 void MarkAsNative() {
97 flags_ |= IsNative::encode(true); 103 flags_ |= IsNative::encode(true);
98 } 104 }
105
99 bool is_native() const { 106 bool is_native() const {
100 return IsNative::decode(flags_); 107 return IsNative::decode(flags_);
101 } 108 }
109
110 bool is_calling() const {
111 return is_deferred_calling() || is_non_deferred_calling();
112 }
113
114 void MarkAsDeferredCalling() {
115 flags_ |= IsDeferredCalling::encode(true);
116 }
117
118 bool is_deferred_calling() const {
119 return IsDeferredCalling::decode(flags_);
120 }
121
122 void MarkAsNonDeferredCalling() {
123 flags_ |= IsNonDeferredCalling::encode(true);
124 }
125
126 bool is_non_deferred_calling() const {
127 return IsNonDeferredCalling::decode(flags_);
128 }
129
102 void SetFunction(FunctionLiteral* literal) { 130 void SetFunction(FunctionLiteral* literal) {
103 ASSERT(function_ == NULL); 131 ASSERT(function_ == NULL);
104 function_ = literal; 132 function_ = literal;
105 } 133 }
106 void SetScope(Scope* scope) { 134 void SetScope(Scope* scope) {
107 ASSERT(scope_ == NULL); 135 ASSERT(scope_ == NULL);
108 scope_ = scope; 136 scope_ = scope;
109 } 137 }
110 void SetGlobalScope(Scope* global_scope) { 138 void SetGlobalScope(Scope* global_scope) {
111 ASSERT(global_scope_ == NULL); 139 ASSERT(global_scope_ == NULL);
(...skipping 30 matching lines...) Expand all
142 (closure()->context()->global_object() != NULL); 170 (closure()->context()->global_object() != NULL);
143 } 171 }
144 172
145 GlobalObject* global_object() const { 173 GlobalObject* global_object() const {
146 return has_global_object() ? closure()->context()->global_object() : NULL; 174 return has_global_object() ? closure()->context()->global_object() : NULL;
147 } 175 }
148 176
149 // Accessors for the different compilation modes. 177 // Accessors for the different compilation modes.
150 bool IsOptimizing() const { return mode_ == OPTIMIZE; } 178 bool IsOptimizing() const { return mode_ == OPTIMIZE; }
151 bool IsOptimizable() const { return mode_ == BASE; } 179 bool IsOptimizable() const { return mode_ == BASE; }
180 bool IsStub() const { return mode_ == STUB; }
152 void SetOptimizing(BailoutId osr_ast_id) { 181 void SetOptimizing(BailoutId osr_ast_id) {
153 SetMode(OPTIMIZE); 182 SetMode(OPTIMIZE);
154 osr_ast_id_ = osr_ast_id; 183 osr_ast_id_ = osr_ast_id;
155 } 184 }
156 void DisableOptimization(); 185 void DisableOptimization();
157 186
158 // Deoptimization support. 187 // Deoptimization support.
159 bool HasDeoptimizationSupport() const { 188 bool HasDeoptimizationSupport() const {
160 return SupportsDeoptimization::decode(flags_); 189 return SupportsDeoptimization::decode(flags_);
161 } 190 }
(...skipping 28 matching lines...) Expand all
190 Isolate* isolate_; 219 Isolate* isolate_;
191 220
192 // Compilation mode. 221 // Compilation mode.
193 // BASE is generated by the full codegen, optionally prepared for bailouts. 222 // BASE is generated by the full codegen, optionally prepared for bailouts.
194 // OPTIMIZE is optimized code generated by the Hydrogen-based backend. 223 // OPTIMIZE is optimized code generated by the Hydrogen-based backend.
195 // NONOPT is generated by the full codegen and is not prepared for 224 // NONOPT is generated by the full codegen and is not prepared for
196 // recompilation/bailouts. These functions are never recompiled. 225 // recompilation/bailouts. These functions are never recompiled.
197 enum Mode { 226 enum Mode {
198 BASE, 227 BASE,
199 OPTIMIZE, 228 OPTIMIZE,
200 NONOPT 229 NONOPT,
230 STUB
201 }; 231 };
202 232
203 void Initialize(Mode mode) { 233 void Initialize(Mode mode) {
234 if (mode == STUB) {
235 mode_ = STUB;
236 return;
237 }
204 mode_ = V8::UseCrankshaft() ? mode : NONOPT; 238 mode_ = V8::UseCrankshaft() ? mode : NONOPT;
205 ASSERT(!script_.is_null()); 239 ASSERT(!script_.is_null());
206 if (script_->type()->value() == Script::TYPE_NATIVE) { 240 if (script_->type()->value() == Script::TYPE_NATIVE) {
207 MarkAsNative(); 241 MarkAsNative();
208 } 242 }
209 if (!shared_info_.is_null()) { 243 if (!shared_info_.is_null()) {
210 ASSERT(language_mode() == CLASSIC_MODE); 244 ASSERT(language_mode() == CLASSIC_MODE);
211 SetLanguageMode(shared_info_->language_mode()); 245 SetLanguageMode(shared_info_->language_mode());
212 } 246 }
213 set_bailout_reason("unknown"); 247 set_bailout_reason("unknown");
(...skipping 16 matching lines...) Expand all
230 class IsInLoop: public BitField<bool, 3, 1> {}; 264 class IsInLoop: public BitField<bool, 3, 1> {};
231 // Strict mode - used in eager compilation. 265 // Strict mode - used in eager compilation.
232 class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; 266 class LanguageModeField: public BitField<LanguageMode, 4, 2> {};
233 // Is this a function from our natives. 267 // Is this a function from our natives.
234 class IsNative: public BitField<bool, 6, 1> {}; 268 class IsNative: public BitField<bool, 6, 1> {};
235 // Is this code being compiled with support for deoptimization.. 269 // Is this code being compiled with support for deoptimization..
236 class SupportsDeoptimization: public BitField<bool, 7, 1> {}; 270 class SupportsDeoptimization: public BitField<bool, 7, 1> {};
237 // If compiling for debugging produce just full code matching the 271 // If compiling for debugging produce just full code matching the
238 // initial mode setting. 272 // initial mode setting.
239 class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; 273 class IsCompilingForDebugging: public BitField<bool, 8, 1> {};
274 // If the compiled code contains calls that require building a frame
275 class IsCalling: public BitField<bool, 9, 1> {};
276 // If the compiled code contains calls that require building a frame
277 class IsDeferredCalling: public BitField<bool, 10, 1> {};
278 // If the compiled code contains calls that require building a frame
279 class IsNonDeferredCalling: public BitField<bool, 11, 1> {};
240 280
241 281
242 unsigned flags_; 282 unsigned flags_;
243 283
244 // Fields filled in by the compilation pipeline. 284 // Fields filled in by the compilation pipeline.
245 // AST filled in by the parser. 285 // AST filled in by the parser.
246 FunctionLiteral* function_; 286 FunctionLiteral* function_;
247 // The scope of the function literal as a convenience. Set to indicate 287 // The scope of the function literal as a convenience. Set to indicate
248 // that scopes have been analyzed. 288 // that scopes have been analyzed.
249 Scope* scope_; 289 Scope* scope_;
250 // The global scope provided as a convenience. 290 // The global scope provided as a convenience.
251 Scope* global_scope_; 291 Scope* global_scope_;
292 // For compiled stubs, the stub object
293 HydrogenCodeStub* code_stub_;
252 // The compiled code. 294 // The compiled code.
253 Handle<Code> code_; 295 Handle<Code> code_;
254 296
255 // Possible initial inputs to the compilation process. 297 // Possible initial inputs to the compilation process.
256 Handle<JSFunction> closure_; 298 Handle<JSFunction> closure_;
257 Handle<SharedFunctionInfo> shared_info_; 299 Handle<SharedFunctionInfo> shared_info_;
258 Handle<Script> script_; 300 Handle<Script> script_;
259 301
260 // Fields possibly needed for eager compilation, NULL by default. 302 // Fields possibly needed for eager compilation, NULL by default.
261 v8::Extension* extension_; 303 v8::Extension* extension_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 zone_(script->GetIsolate()), 342 zone_(script->GetIsolate()),
301 zone_scope_(&zone_, DELETE_ON_EXIT) {} 343 zone_scope_(&zone_, DELETE_ON_EXIT) {}
302 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) 344 explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info)
303 : CompilationInfo(shared_info, &zone_), 345 : CompilationInfo(shared_info, &zone_),
304 zone_(shared_info->GetIsolate()), 346 zone_(shared_info->GetIsolate()),
305 zone_scope_(&zone_, DELETE_ON_EXIT) {} 347 zone_scope_(&zone_, DELETE_ON_EXIT) {}
306 explicit CompilationInfoWithZone(Handle<JSFunction> closure) 348 explicit CompilationInfoWithZone(Handle<JSFunction> closure)
307 : CompilationInfo(closure, &zone_), 349 : CompilationInfo(closure, &zone_),
308 zone_(closure->GetIsolate()), 350 zone_(closure->GetIsolate()),
309 zone_scope_(&zone_, DELETE_ON_EXIT) {} 351 zone_scope_(&zone_, DELETE_ON_EXIT) {}
352 explicit CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate)
353 : CompilationInfo(stub, isolate, &zone_),
354 zone_(isolate),
355 zone_scope_(&zone_, DELETE_ON_EXIT) {}
310 356
311 private: 357 private:
312 Zone zone_; 358 Zone zone_;
313 ZoneScope zone_scope_; 359 ZoneScope zone_scope_;
314 }; 360 };
315 361
316 362
317 // A wrapper around a CompilationInfo that detaches the Handles from 363 // A wrapper around a CompilationInfo that detaches the Handles from
318 // the underlying DeferredHandleScope and stores them in info_ on 364 // the underlying DeferredHandleScope and stores them in info_ on
319 // destruction. 365 // destruction.
320 class CompilationHandleScope BASE_EMBEDDED { 366 class CompilationHandleScope BASE_EMBEDDED {
321 public: 367 public:
322 explicit CompilationHandleScope(CompilationInfo* info) 368 explicit CompilationHandleScope(CompilationInfo* info)
323 : deferred_(info->isolate()), info_(info) {} 369 : deferred_(info->isolate()), info_(info) {}
324 ~CompilationHandleScope() { 370 ~CompilationHandleScope() {
325 info_->set_deferred_handles(deferred_.Detach()); 371 info_->set_deferred_handles(deferred_.Detach());
326 } 372 }
327 373
328 private: 374 private:
329 DeferredHandleScope deferred_; 375 DeferredHandleScope deferred_;
330 CompilationInfo* info_; 376 CompilationInfo* info_;
331 }; 377 };
332 378
333 379
334 class HGraph; 380 class HGraph;
335 class HGraphBuilder; 381 class HOptimizedGraphBuilder;
336 class LChunk; 382 class LChunk;
337 383
338 // A helper class that calls the three compilation phases in 384 // A helper class that calls the three compilation phases in
339 // Crankshaft and keeps track of its state. The three phases 385 // Crankshaft and keeps track of its state. The three phases
340 // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either 386 // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either
341 // fail, bail-out to the full code generator or succeed. Apart from 387 // fail, bail-out to the full code generator or succeed. Apart from
342 // their return value, the status of the phase last run can be checked 388 // their return value, the status of the phase last run can be checked
343 // using last_status(). 389 // using last_status().
344 class OptimizingCompiler: public ZoneObject { 390 class OptimizingCompiler: public ZoneObject {
345 public: 391 public:
(...skipping 21 matching lines...) Expand all
367 413
368 MUST_USE_RESULT Status AbortOptimization() { 414 MUST_USE_RESULT Status AbortOptimization() {
369 info_->AbortOptimization(); 415 info_->AbortOptimization();
370 info_->shared_info()->DisableOptimization(info_->bailout_reason()); 416 info_->shared_info()->DisableOptimization(info_->bailout_reason());
371 return SetLastStatus(BAILED_OUT); 417 return SetLastStatus(BAILED_OUT);
372 } 418 }
373 419
374 private: 420 private:
375 CompilationInfo* info_; 421 CompilationInfo* info_;
376 TypeFeedbackOracle* oracle_; 422 TypeFeedbackOracle* oracle_;
377 HGraphBuilder* graph_builder_; 423 HOptimizedGraphBuilder* graph_builder_;
378 HGraph* graph_; 424 HGraph* graph_;
379 LChunk* chunk_; 425 LChunk* chunk_;
380 int64_t time_taken_to_create_graph_; 426 int64_t time_taken_to_create_graph_;
381 int64_t time_taken_to_optimize_; 427 int64_t time_taken_to_optimize_;
382 int64_t time_taken_to_codegen_; 428 int64_t time_taken_to_codegen_;
383 Status last_status_; 429 Status last_status_;
384 430
385 MUST_USE_RESULT Status SetLastStatus(Status status) { 431 MUST_USE_RESULT Status SetLastStatus(Status status) {
386 last_status_ = status; 432 last_status_ = status;
387 return last_status_; 433 return last_status_;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 516
471 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 517 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
472 CompilationInfo* info, 518 CompilationInfo* info,
473 Handle<SharedFunctionInfo> shared); 519 Handle<SharedFunctionInfo> shared);
474 }; 520 };
475 521
476 522
477 } } // namespace v8::internal 523 } } // namespace v8::internal
478 524
479 #endif // V8_COMPILER_H_ 525 #endif // V8_COMPILER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698