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 // 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 #ifndef V8_FULL_CODEGEN_FULL_CODEGEN_H_ | 5 #ifndef V8_FULL_CODEGEN_FULL_CODEGEN_H_ |
| 6 #define V8_FULL_CODEGEN_FULL_CODEGEN_H_ | 6 #define V8_FULL_CODEGEN_FULL_CODEGEN_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/assert-scope.h" | 9 #include "src/assert-scope.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| 11 #include "src/ast/scopes.h" | 11 #include "src/ast/scopes.h" |
| 12 #include "src/bit-vector.h" | 12 #include "src/bit-vector.h" |
| 13 #include "src/code-factory.h" | 13 #include "src/code-factory.h" |
| 14 #include "src/code-stubs.h" | 14 #include "src/code-stubs.h" |
| 15 #include "src/codegen.h" | 15 #include "src/codegen.h" |
| 16 #include "src/compiler.h" | 16 #include "src/compiler.h" |
| 17 #include "src/deoptimizer.h" | |
| 17 #include "src/globals.h" | 18 #include "src/globals.h" |
| 18 #include "src/objects.h" | 19 #include "src/objects.h" |
| 19 | 20 |
| 20 namespace v8 { | 21 namespace v8 { |
| 21 namespace internal { | 22 namespace internal { |
| 22 | 23 |
| 23 // Forward declarations. | 24 // Forward declarations. |
| 24 class JumpPatchSite; | 25 class JumpPatchSite; |
| 25 | 26 |
| 26 // ----------------------------------------------------------------------------- | 27 // ----------------------------------------------------------------------------- |
| 27 // Full code generator. | 28 // Full code generator. |
| 28 | 29 |
| 29 class FullCodeGenerator: public AstVisitor { | 30 class FullCodeGenerator: public AstVisitor { |
| 30 public: | 31 public: |
| 31 enum State { | |
|
Michael Starzinger
2016/05/17 14:41:53
If we were to add "using Deoptimizer::BailoutState
rmcilroy
2016/05/17 15:20:05
As discussed offline - needed to use typedef and k
| |
| 32 NO_REGISTERS, | |
| 33 TOS_REG | |
| 34 }; | |
| 35 | |
| 36 FullCodeGenerator(MacroAssembler* masm, CompilationInfo* info) | 32 FullCodeGenerator(MacroAssembler* masm, CompilationInfo* info) |
| 37 : masm_(masm), | 33 : masm_(masm), |
| 38 info_(info), | 34 info_(info), |
| 39 isolate_(info->isolate()), | 35 isolate_(info->isolate()), |
| 40 zone_(info->zone()), | 36 zone_(info->zone()), |
| 41 scope_(info->scope()), | 37 scope_(info->scope()), |
| 42 nesting_stack_(NULL), | 38 nesting_stack_(NULL), |
| 43 loop_depth_(0), | 39 loop_depth_(0), |
| 44 try_catch_depth_(0), | 40 try_catch_depth_(0), |
| 45 operand_stack_depth_(0), | 41 operand_stack_depth_(0), |
| 46 globals_(NULL), | 42 globals_(NULL), |
| 47 context_(NULL), | 43 context_(NULL), |
| 48 bailout_entries_(info->HasDeoptimizationSupport() | 44 bailout_entries_(info->HasDeoptimizationSupport() |
| 49 ? info->literal()->ast_node_count() | 45 ? info->literal()->ast_node_count() |
| 50 : 0, | 46 : 0, |
| 51 info->zone()), | 47 info->zone()), |
| 52 back_edges_(2, info->zone()), | 48 back_edges_(2, info->zone()), |
| 53 handler_table_(info->zone()), | 49 handler_table_(info->zone()), |
| 54 ic_total_count_(0) { | 50 ic_total_count_(0) { |
| 55 DCHECK(!info->IsStub()); | 51 DCHECK(!info->IsStub()); |
| 56 Initialize(); | 52 Initialize(); |
| 57 } | 53 } |
| 58 | 54 |
| 59 void Initialize(); | 55 void Initialize(); |
| 60 | 56 |
| 61 static bool MakeCode(CompilationInfo* info); | 57 static bool MakeCode(CompilationInfo* info); |
| 62 | 58 |
| 63 // Encode state and pc-offset as a BitField<type, start, size>. | 59 // Encode bailout state and pc-offset as a BitField<type, start, size>. |
| 64 // Only use 30 bits because we encode the result as a smi. | 60 // Only use 30 bits because we encode the result as a smi. |
| 65 class StateField : public BitField<State, 0, 1> { }; | 61 class BailoutStateField : public BitField<Deoptimizer::BailoutState, 0, 1> {}; |
| 66 class PcField : public BitField<unsigned, 1, 30-1> { }; | 62 class PcField : public BitField<unsigned, 1, 30 - 1> {}; |
| 67 | |
| 68 static const char* State2String(State state) { | |
| 69 switch (state) { | |
| 70 case NO_REGISTERS: return "NO_REGISTERS"; | |
| 71 case TOS_REG: return "TOS_REG"; | |
| 72 } | |
| 73 UNREACHABLE(); | |
| 74 return NULL; | |
| 75 } | |
| 76 | 63 |
| 77 static const int kMaxBackEdgeWeight = 127; | 64 static const int kMaxBackEdgeWeight = 127; |
| 78 | 65 |
| 79 // Platform-specific code size multiplier. | 66 // Platform-specific code size multiplier. |
| 80 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87 | 67 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87 |
| 81 static const int kCodeSizeMultiplier = 105; | 68 static const int kCodeSizeMultiplier = 105; |
| 82 #elif V8_TARGET_ARCH_X64 | 69 #elif V8_TARGET_ARCH_X64 |
| 83 static const int kCodeSizeMultiplier = 165; | 70 static const int kCodeSizeMultiplier = 165; |
| 84 #elif V8_TARGET_ARCH_ARM | 71 #elif V8_TARGET_ARCH_ARM |
| 85 static const int kCodeSizeMultiplier = 149; | 72 static const int kCodeSizeMultiplier = 149; |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 // An operand used to read/write a known (PARAMETER, LOCAL, or CONTEXT) | 346 // An operand used to read/write a known (PARAMETER, LOCAL, or CONTEXT) |
| 360 // variable. May emit code to traverse the context chain, loading the | 347 // variable. May emit code to traverse the context chain, loading the |
| 361 // found context into the scratch register. Writing to this operand will | 348 // found context into the scratch register. Writing to this operand will |
| 362 // need the write barrier if location is CONTEXT. | 349 // need the write barrier if location is CONTEXT. |
| 363 MemOperand VarOperand(Variable* var, Register scratch); | 350 MemOperand VarOperand(Variable* var, Register scratch); |
| 364 | 351 |
| 365 void VisitForEffect(Expression* expr) { | 352 void VisitForEffect(Expression* expr) { |
| 366 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); | 353 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); |
| 367 EffectContext context(this); | 354 EffectContext context(this); |
| 368 Visit(expr); | 355 Visit(expr); |
| 369 PrepareForBailout(expr, NO_REGISTERS); | 356 PrepareForBailout(expr, Deoptimizer::BailoutState::NO_REGISTERS); |
| 370 } | 357 } |
| 371 | 358 |
| 372 void VisitForAccumulatorValue(Expression* expr) { | 359 void VisitForAccumulatorValue(Expression* expr) { |
| 373 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); | 360 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); |
| 374 AccumulatorValueContext context(this); | 361 AccumulatorValueContext context(this); |
| 375 Visit(expr); | 362 Visit(expr); |
| 376 PrepareForBailout(expr, TOS_REG); | 363 PrepareForBailout(expr, Deoptimizer::BailoutState::TOS_REGISTER); |
| 377 } | 364 } |
| 378 | 365 |
| 379 void VisitForStackValue(Expression* expr) { | 366 void VisitForStackValue(Expression* expr) { |
| 380 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); | 367 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); |
| 381 StackValueContext context(this); | 368 StackValueContext context(this); |
| 382 Visit(expr); | 369 Visit(expr); |
| 383 PrepareForBailout(expr, NO_REGISTERS); | 370 PrepareForBailout(expr, Deoptimizer::BailoutState::NO_REGISTERS); |
| 384 } | 371 } |
| 385 | 372 |
| 386 void VisitForControl(Expression* expr, | 373 void VisitForControl(Expression* expr, |
| 387 Label* if_true, | 374 Label* if_true, |
| 388 Label* if_false, | 375 Label* if_false, |
| 389 Label* fall_through) { | 376 Label* fall_through) { |
| 390 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); | 377 if (FLAG_verify_operand_stack_depth) EmitOperandStackDepthCheck(); |
| 391 TestContext context(this, expr, if_true, if_false, fall_through); | 378 TestContext context(this, expr, if_true, if_false, fall_through); |
| 392 Visit(expr); | 379 Visit(expr); |
| 393 // For test contexts, we prepare for bailout before branching, not at | 380 // For test contexts, we prepare for bailout before branching, not at |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 void EmitLiteralCompareTypeof(Expression* expr, | 432 void EmitLiteralCompareTypeof(Expression* expr, |
| 446 Expression* sub_expr, | 433 Expression* sub_expr, |
| 447 Handle<String> check); | 434 Handle<String> check); |
| 448 | 435 |
| 449 // Platform-specific code for equality comparison with a nil-like value. | 436 // Platform-specific code for equality comparison with a nil-like value. |
| 450 void EmitLiteralCompareNil(CompareOperation* expr, | 437 void EmitLiteralCompareNil(CompareOperation* expr, |
| 451 Expression* sub_expr, | 438 Expression* sub_expr, |
| 452 NilValue nil); | 439 NilValue nil); |
| 453 | 440 |
| 454 // Bailout support. | 441 // Bailout support. |
| 455 void PrepareForBailout(Expression* node, State state); | 442 void PrepareForBailout(Expression* node, Deoptimizer::BailoutState state); |
| 456 void PrepareForBailoutForId(BailoutId id, State state); | 443 void PrepareForBailoutForId(BailoutId id, Deoptimizer::BailoutState state); |
| 457 | 444 |
| 458 // Returns a smi for the index into the FixedArray that backs the feedback | 445 // Returns a smi for the index into the FixedArray that backs the feedback |
| 459 // vector | 446 // vector |
| 460 Smi* SmiFromSlot(FeedbackVectorSlot slot) const { | 447 Smi* SmiFromSlot(FeedbackVectorSlot slot) const { |
| 461 return Smi::FromInt(TypeFeedbackVector::GetIndexFromSpec( | 448 return Smi::FromInt(TypeFeedbackVector::GetIndexFromSpec( |
| 462 literal()->feedback_vector_spec(), slot)); | 449 literal()->feedback_vector_spec(), slot)); |
| 463 } | 450 } |
| 464 | 451 |
| 465 // Record a call's return site offset, used to rebuild the frame if the | 452 // Record a call's return site offset, used to rebuild the frame if the |
| 466 // called function was inlined at the site. | 453 // called function was inlined at the site. |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1070 Address start_; | 1057 Address start_; |
| 1071 Address instruction_start_; | 1058 Address instruction_start_; |
| 1072 uint32_t length_; | 1059 uint32_t length_; |
| 1073 }; | 1060 }; |
| 1074 | 1061 |
| 1075 | 1062 |
| 1076 } // namespace internal | 1063 } // namespace internal |
| 1077 } // namespace v8 | 1064 } // namespace v8 |
| 1078 | 1065 |
| 1079 #endif // V8_FULL_CODEGEN_FULL_CODEGEN_H_ | 1066 #endif // V8_FULL_CODEGEN_FULL_CODEGEN_H_ |
| OLD | NEW |