Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 ~CompilationHandleScope() { | 305 ~CompilationHandleScope() { |
| 306 info_->set_deferred_handles(deferred_.Detach()); | 306 info_->set_deferred_handles(deferred_.Detach()); |
| 307 } | 307 } |
| 308 | 308 |
| 309 private: | 309 private: |
| 310 DeferredHandleScope deferred_; | 310 DeferredHandleScope deferred_; |
| 311 CompilationInfo* info_; | 311 CompilationInfo* info_; |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 | 314 |
| 315 class HGraph; | |
| 316 class HGraphBuilder; | |
| 317 class LChunk; | |
| 318 | |
| 319 // A helper class that calls the three compilation phases in | |
| 320 // Crankshaft and keeps track of its state. The three phases | |
| 321 // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either | |
| 322 // fail, bail-out to the full code generator or succeed. Apart from | |
| 323 // their return value, the status of the phase last run can be checked | |
| 324 // using last_status(). | |
| 325 class OptimizingCompiler: public ZoneObject { | |
| 326 public: | |
| 327 explicit OptimizingCompiler(CompilationInfo* info) | |
| 328 : info_(info), | |
| 329 oracle_(NULL), | |
| 330 graph_builder_(NULL), | |
| 331 graph_(NULL), | |
| 332 chunk_(NULL), | |
| 333 time_taken_to_create_graph_(0), | |
| 334 time_taken_to_optimize_(0), | |
| 335 time_taken_to_codegen_(0), | |
| 336 is_inline_bailout_(false), | |
| 337 last_status_(FAILED) { } | |
| 338 | |
| 339 enum Status { | |
| 340 FAILED, BAILED_OUT, SUCCEEDED | |
| 341 }; | |
| 342 | |
| 343 Status CreateGraph(); | |
|
danno
2012/07/16 15:05:02
MUST_USE_RESULT for this and the next two?
sanjoy
2012/07/17 08:09:39
Done.
| |
| 344 Status OptimizeGraph(); | |
| 345 Status GenerateAndInstallCode(); | |
| 346 | |
| 347 Status last_status() const { return last_status_; } | |
| 348 CompilationInfo* info() const { return info_; } | |
| 349 | |
| 350 private: | |
| 351 CompilationInfo* info_; | |
| 352 TypeFeedbackOracle* oracle_; | |
| 353 HGraphBuilder* graph_builder_; | |
| 354 HGraph* graph_; | |
| 355 LChunk* chunk_; | |
| 356 int64_t time_taken_to_create_graph_; | |
| 357 int64_t time_taken_to_optimize_; | |
| 358 int64_t time_taken_to_codegen_; | |
| 359 bool is_inline_bailout_; | |
| 360 Status last_status_; | |
| 361 | |
| 362 MUST_USE_RESULT Status SetLastStatus(Status status) { | |
| 363 last_status_ = status; | |
| 364 return last_status_; | |
| 365 } | |
| 366 void RecordOptimizationStats(); | |
| 367 MUST_USE_RESULT Status AbortOptimization() { | |
| 368 info_->AbortOptimization(); | |
| 369 if (!is_inline_bailout_) { | |
| 370 // Mark the shared code as unoptimizable unless it was an inlined | |
| 371 // function that bailed out. | |
| 372 info_->shared_info()->DisableOptimization(); | |
| 373 } | |
| 374 return SetLastStatus(BAILED_OUT); | |
| 375 } | |
| 376 | |
| 377 struct Timer { | |
| 378 Timer(OptimizingCompiler* compiler, int64_t* location) | |
| 379 : compiler_(compiler), | |
| 380 start_(OS::Ticks()), | |
| 381 location_(location) { } | |
| 382 | |
| 383 ~Timer() { | |
| 384 *location_ += (OS::Ticks() - start_); | |
| 385 } | |
| 386 | |
| 387 OptimizingCompiler* compiler_; | |
| 388 int64_t start_; | |
| 389 int64_t* location_; | |
| 390 }; | |
| 391 }; | |
| 392 | |
| 393 | |
| 315 // The V8 compiler | 394 // The V8 compiler |
| 316 // | 395 // |
| 317 // General strategy: Source code is translated into an anonymous function w/o | 396 // General strategy: Source code is translated into an anonymous function w/o |
| 318 // parameters which then can be executed. If the source code contains other | 397 // parameters which then can be executed. If the source code contains other |
| 319 // functions, they will be compiled and allocated as part of the compilation | 398 // functions, they will be compiled and allocated as part of the compilation |
| 320 // of the source code. | 399 // of the source code. |
| 321 | 400 |
| 322 // Please note this interface returns shared function infos. This means you | 401 // Please note this interface returns shared function infos. This means you |
| 323 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a | 402 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a |
| 324 // real function with a context. | 403 // real function with a context. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 | 455 |
| 377 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 456 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 378 CompilationInfo* info, | 457 CompilationInfo* info, |
| 379 Handle<SharedFunctionInfo> shared); | 458 Handle<SharedFunctionInfo> shared); |
| 380 }; | 459 }; |
| 381 | 460 |
| 382 | 461 |
| 383 } } // namespace v8::internal | 462 } } // namespace v8::internal |
| 384 | 463 |
| 385 #endif // V8_COMPILER_H_ | 464 #endif // V8_COMPILER_H_ |
| OLD | NEW |