| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/compiler/ast-loop-assignment-analyzer.h" | 9 #include "src/compiler/ast-loop-assignment-analyzer.h" |
| 10 #include "src/compiler/control-builders.h" | 10 #include "src/compiler/control-builders.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 // Control scope implementation for a TryCatchStatement. | 359 // Control scope implementation for a TryCatchStatement. |
| 360 class AstGraphBuilder::ControlScopeForCatch : public ControlScope { | 360 class AstGraphBuilder::ControlScopeForCatch : public ControlScope { |
| 361 public: | 361 public: |
| 362 ControlScopeForCatch(AstGraphBuilder* owner, TryCatchStatement* stmt, | 362 ControlScopeForCatch(AstGraphBuilder* owner, TryCatchStatement* stmt, |
| 363 TryCatchBuilder* control) | 363 TryCatchBuilder* control) |
| 364 : ControlScope(owner), | 364 : ControlScope(owner), |
| 365 control_(control), | 365 control_(control), |
| 366 outer_prediction_(owner->try_catch_prediction_) { | 366 outer_prediction_(owner->try_catch_prediction_) { |
| 367 builder()->try_nesting_level_++; // Increment nesting. | 367 builder()->try_nesting_level_++; // Increment nesting. |
| 368 builder()->try_catch_prediction_ = stmt->catch_predicted(); | 368 builder()->try_catch_prediction_ = stmt->catch_prediction(); |
| 369 } | 369 } |
| 370 ~ControlScopeForCatch() { | 370 ~ControlScopeForCatch() { |
| 371 builder()->try_nesting_level_--; // Decrement nesting. | 371 builder()->try_nesting_level_--; // Decrement nesting. |
| 372 builder()->try_catch_prediction_ = outer_prediction_; | 372 builder()->try_catch_prediction_ = outer_prediction_; |
| 373 } | 373 } |
| 374 | 374 |
| 375 protected: | 375 protected: |
| 376 bool Execute(Command cmd, Statement* target, Node** value) override { | 376 bool Execute(Command cmd, Statement* target, Node** value) override { |
| 377 switch (cmd) { | 377 switch (cmd) { |
| 378 case CMD_THROW: | 378 case CMD_THROW: |
| 379 control_->Throw(*value); | 379 control_->Throw(*value); |
| 380 return true; | 380 return true; |
| 381 case CMD_BREAK: | 381 case CMD_BREAK: |
| 382 case CMD_CONTINUE: | 382 case CMD_CONTINUE: |
| 383 case CMD_RETURN: | 383 case CMD_RETURN: |
| 384 break; | 384 break; |
| 385 } | 385 } |
| 386 return false; | 386 return false; |
| 387 } | 387 } |
| 388 | 388 |
| 389 private: | 389 private: |
| 390 TryCatchBuilder* control_; | 390 TryCatchBuilder* control_; |
| 391 bool outer_prediction_; | 391 HandlerTable::CatchPrediction outer_prediction_; |
| 392 }; | 392 }; |
| 393 | 393 |
| 394 | 394 |
| 395 // Control scope implementation for a TryFinallyStatement. | 395 // Control scope implementation for a TryFinallyStatement. |
| 396 class AstGraphBuilder::ControlScopeForFinally : public ControlScope { | 396 class AstGraphBuilder::ControlScopeForFinally : public ControlScope { |
| 397 public: | 397 public: |
| 398 ControlScopeForFinally(AstGraphBuilder* owner, TryFinallyStatement* stmt, | 398 ControlScopeForFinally(AstGraphBuilder* owner, TryFinallyStatement* stmt, |
| 399 DeferredCommands* commands, TryFinallyBuilder* control) | 399 DeferredCommands* commands, TryFinallyBuilder* control) |
| 400 : ControlScope(owner), | 400 : ControlScope(owner), |
| 401 commands_(commands), | 401 commands_(commands), |
| 402 control_(control), | 402 control_(control), |
| 403 outer_prediction_(owner->try_catch_prediction_) { | 403 outer_prediction_(owner->try_catch_prediction_) { |
| 404 builder()->try_nesting_level_++; // Increment nesting. | 404 builder()->try_nesting_level_++; // Increment nesting. |
| 405 builder()->try_catch_prediction_ = stmt->catch_predicted(); | 405 builder()->try_catch_prediction_ = stmt->catch_prediction(); |
| 406 } | 406 } |
| 407 ~ControlScopeForFinally() { | 407 ~ControlScopeForFinally() { |
| 408 builder()->try_nesting_level_--; // Decrement nesting. | 408 builder()->try_nesting_level_--; // Decrement nesting. |
| 409 builder()->try_catch_prediction_ = outer_prediction_; | 409 builder()->try_catch_prediction_ = outer_prediction_; |
| 410 } | 410 } |
| 411 | 411 |
| 412 protected: | 412 protected: |
| 413 bool Execute(Command cmd, Statement* target, Node** value) override { | 413 bool Execute(Command cmd, Statement* target, Node** value) override { |
| 414 Node* token = commands_->RecordCommand(cmd, target, *value); | 414 Node* token = commands_->RecordCommand(cmd, target, *value); |
| 415 control_->LeaveTry(token, *value); | 415 control_->LeaveTry(token, *value); |
| 416 return true; | 416 return true; |
| 417 } | 417 } |
| 418 | 418 |
| 419 private: | 419 private: |
| 420 DeferredCommands* commands_; | 420 DeferredCommands* commands_; |
| 421 TryFinallyBuilder* control_; | 421 TryFinallyBuilder* control_; |
| 422 bool outer_prediction_; | 422 HandlerTable::CatchPrediction outer_prediction_; |
| 423 }; | 423 }; |
| 424 | 424 |
| 425 | 425 |
| 426 // Helper for generating before and after frame states. | 426 // Helper for generating before and after frame states. |
| 427 class AstGraphBuilder::FrameStateBeforeAndAfter { | 427 class AstGraphBuilder::FrameStateBeforeAndAfter { |
| 428 public: | 428 public: |
| 429 FrameStateBeforeAndAfter(AstGraphBuilder* builder, BailoutId id_before) | 429 FrameStateBeforeAndAfter(AstGraphBuilder* builder, BailoutId id_before) |
| 430 : builder_(builder), frame_state_before_(nullptr) { | 430 : builder_(builder), frame_state_before_(nullptr) { |
| 431 frame_state_before_ = id_before == BailoutId::None() | 431 frame_state_before_ = id_before == BailoutId::None() |
| 432 ? builder_->GetEmptyFrameState() | 432 ? builder_->GetEmptyFrameState() |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 : isolate_(info->isolate()), | 482 : isolate_(info->isolate()), |
| 483 local_zone_(local_zone), | 483 local_zone_(local_zone), |
| 484 info_(info), | 484 info_(info), |
| 485 jsgraph_(jsgraph), | 485 jsgraph_(jsgraph), |
| 486 environment_(nullptr), | 486 environment_(nullptr), |
| 487 ast_context_(nullptr), | 487 ast_context_(nullptr), |
| 488 globals_(0, local_zone), | 488 globals_(0, local_zone), |
| 489 execution_control_(nullptr), | 489 execution_control_(nullptr), |
| 490 execution_context_(nullptr), | 490 execution_context_(nullptr), |
| 491 try_nesting_level_(0), | 491 try_nesting_level_(0), |
| 492 try_catch_prediction_(false), | 492 try_catch_prediction_(HandlerTable::UNCAUGHT), |
| 493 input_buffer_size_(0), | 493 input_buffer_size_(0), |
| 494 input_buffer_(nullptr), | 494 input_buffer_(nullptr), |
| 495 exit_controls_(local_zone), | 495 exit_controls_(local_zone), |
| 496 loop_assignment_analysis_(loop), | 496 loop_assignment_analysis_(loop), |
| 497 type_hint_analysis_(type_hint_analysis), | 497 type_hint_analysis_(type_hint_analysis), |
| 498 state_values_cache_(jsgraph), | 498 state_values_cache_(jsgraph), |
| 499 liveness_analyzer_(static_cast<size_t>(info->scope()->num_stack_slots()), | 499 liveness_analyzer_(static_cast<size_t>(info->scope()->num_stack_slots()), |
| 500 local_zone), | 500 local_zone), |
| 501 frame_state_function_info_(common()->CreateFrameStateFunctionInfo( | 501 frame_state_function_info_(common()->CreateFrameStateFunctionInfo( |
| 502 FrameStateType::kJavaScriptFunction, info->num_parameters() + 1, | 502 FrameStateType::kJavaScriptFunction, info->num_parameters() + 1, |
| (...skipping 3668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4171 if (NodeProperties::IsControl(result)) { | 4171 if (NodeProperties::IsControl(result)) { |
| 4172 environment_->UpdateControlDependency(result); | 4172 environment_->UpdateControlDependency(result); |
| 4173 } | 4173 } |
| 4174 // Update the current effect dependency for effect-producing nodes. | 4174 // Update the current effect dependency for effect-producing nodes. |
| 4175 if (result->op()->EffectOutputCount() > 0) { | 4175 if (result->op()->EffectOutputCount() > 0) { |
| 4176 environment_->UpdateEffectDependency(result); | 4176 environment_->UpdateEffectDependency(result); |
| 4177 } | 4177 } |
| 4178 // Add implicit exception continuation for throwing nodes. | 4178 // Add implicit exception continuation for throwing nodes. |
| 4179 if (!result->op()->HasProperty(Operator::kNoThrow) && inside_try_scope) { | 4179 if (!result->op()->HasProperty(Operator::kNoThrow) && inside_try_scope) { |
| 4180 // Conservative prediction whether caught locally. | 4180 // Conservative prediction whether caught locally. |
| 4181 IfExceptionHint hint = try_catch_prediction_ | 4181 IfExceptionHint hint = |
| 4182 ? IfExceptionHint::kLocallyCaught | 4182 ExceptionHintFromCatchPrediction(try_catch_prediction_); |
| 4183 : IfExceptionHint::kLocallyUncaught; | |
| 4184 // Copy the environment for the success continuation. | 4183 // Copy the environment for the success continuation. |
| 4185 Environment* success_env = environment()->CopyForConditional(); | 4184 Environment* success_env = environment()->CopyForConditional(); |
| 4186 const Operator* op = common()->IfException(hint); | 4185 const Operator* op = common()->IfException(hint); |
| 4187 Node* effect = environment()->GetEffectDependency(); | 4186 Node* effect = environment()->GetEffectDependency(); |
| 4188 Node* on_exception = graph()->NewNode(op, effect, result); | 4187 Node* on_exception = graph()->NewNode(op, effect, result); |
| 4189 environment_->UpdateControlDependency(on_exception); | 4188 environment_->UpdateControlDependency(on_exception); |
| 4190 environment_->UpdateEffectDependency(on_exception); | 4189 environment_->UpdateEffectDependency(on_exception); |
| 4191 execution_control()->ThrowValue(on_exception); | 4190 execution_control()->ThrowValue(on_exception); |
| 4192 set_environment(success_env); | 4191 set_environment(success_env); |
| 4193 } | 4192 } |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4411 // Phi does not exist yet, introduce one. | 4410 // Phi does not exist yet, introduce one. |
| 4412 value = NewPhi(inputs, value, control); | 4411 value = NewPhi(inputs, value, control); |
| 4413 value->ReplaceInput(inputs - 1, other); | 4412 value->ReplaceInput(inputs - 1, other); |
| 4414 } | 4413 } |
| 4415 return value; | 4414 return value; |
| 4416 } | 4415 } |
| 4417 | 4416 |
| 4418 } // namespace compiler | 4417 } // namespace compiler |
| 4419 } // namespace internal | 4418 } // namespace internal |
| 4420 } // namespace v8 | 4419 } // namespace v8 |
| OLD | NEW |