| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #ifndef V8_HYDROGEN_H_ | 28 #ifndef V8_HYDROGEN_H_ |
| 29 #define V8_HYDROGEN_H_ | 29 #define V8_HYDROGEN_H_ |
| 30 | 30 |
| 31 #include "v8.h" | 31 #include "v8.h" |
| 32 | 32 |
| 33 #include "allocation.h" | 33 #include "allocation.h" |
| 34 #include "ast.h" | 34 #include "ast.h" |
| 35 #include "compiler.h" | 35 #include "compiler.h" |
| 36 #include "hydrogen-instructions.h" | 36 #include "hydrogen-instructions.h" |
| 37 #include "type-info.h" | |
| 38 #include "zone.h" | 37 #include "zone.h" |
| 39 #include "scopes.h" | 38 #include "scopes.h" |
| 40 | 39 |
| 41 namespace v8 { | 40 namespace v8 { |
| 42 namespace internal { | 41 namespace internal { |
| 43 | 42 |
| 44 // Forward declarations. | 43 // Forward declarations. |
| 45 class BitVector; | 44 class BitVector; |
| 46 class FunctionState; | 45 class FunctionState; |
| 47 class HEnvironment; | 46 class HEnvironment; |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 790 |
| 792 private: | 791 private: |
| 793 ArgumentsAllowedFlag flag_; | 792 ArgumentsAllowedFlag flag_; |
| 794 }; | 793 }; |
| 795 | 794 |
| 796 | 795 |
| 797 class TestContext: public AstContext { | 796 class TestContext: public AstContext { |
| 798 public: | 797 public: |
| 799 TestContext(HOptimizedGraphBuilder* owner, | 798 TestContext(HOptimizedGraphBuilder* owner, |
| 800 Expression* condition, | 799 Expression* condition, |
| 801 TypeFeedbackOracle* oracle, | |
| 802 HBasicBlock* if_true, | 800 HBasicBlock* if_true, |
| 803 HBasicBlock* if_false) | 801 HBasicBlock* if_false) |
| 804 : AstContext(owner, Expression::kTest), | 802 : AstContext(owner, Expression::kTest), |
| 805 condition_(condition), | 803 condition_(condition), |
| 806 oracle_(oracle), | |
| 807 if_true_(if_true), | 804 if_true_(if_true), |
| 808 if_false_(if_false) { | 805 if_false_(if_false) { |
| 809 } | 806 } |
| 810 | 807 |
| 811 virtual void ReturnValue(HValue* value); | 808 virtual void ReturnValue(HValue* value); |
| 812 virtual void ReturnInstruction(HInstruction* instr, BailoutId ast_id); | 809 virtual void ReturnInstruction(HInstruction* instr, BailoutId ast_id); |
| 813 virtual void ReturnControl(HControlInstruction* instr, BailoutId ast_id); | 810 virtual void ReturnControl(HControlInstruction* instr, BailoutId ast_id); |
| 814 virtual void ReturnContinuation(HIfContinuation* continuation, | 811 virtual void ReturnContinuation(HIfContinuation* continuation, |
| 815 BailoutId ast_id); | 812 BailoutId ast_id); |
| 816 | 813 |
| 817 static TestContext* cast(AstContext* context) { | 814 static TestContext* cast(AstContext* context) { |
| 818 ASSERT(context->IsTest()); | 815 ASSERT(context->IsTest()); |
| 819 return reinterpret_cast<TestContext*>(context); | 816 return reinterpret_cast<TestContext*>(context); |
| 820 } | 817 } |
| 821 | 818 |
| 822 Expression* condition() const { return condition_; } | 819 Expression* condition() const { return condition_; } |
| 823 TypeFeedbackOracle* oracle() const { return oracle_; } | |
| 824 HBasicBlock* if_true() const { return if_true_; } | 820 HBasicBlock* if_true() const { return if_true_; } |
| 825 HBasicBlock* if_false() const { return if_false_; } | 821 HBasicBlock* if_false() const { return if_false_; } |
| 826 | 822 |
| 827 private: | 823 private: |
| 828 // Build the shared core part of the translation unpacking a value into | 824 // Build the shared core part of the translation unpacking a value into |
| 829 // control flow. | 825 // control flow. |
| 830 void BuildBranch(HValue* value); | 826 void BuildBranch(HValue* value); |
| 831 | 827 |
| 832 Expression* condition_; | 828 Expression* condition_; |
| 833 TypeFeedbackOracle* oracle_; | |
| 834 HBasicBlock* if_true_; | 829 HBasicBlock* if_true_; |
| 835 HBasicBlock* if_false_; | 830 HBasicBlock* if_false_; |
| 836 }; | 831 }; |
| 837 | 832 |
| 838 | 833 |
| 839 class FunctionState { | 834 class FunctionState { |
| 840 public: | 835 public: |
| 841 FunctionState(HOptimizedGraphBuilder* owner, | 836 FunctionState(HOptimizedGraphBuilder* owner, |
| 842 CompilationInfo* info, | 837 CompilationInfo* info, |
| 843 TypeFeedbackOracle* oracle, | |
| 844 InliningKind inlining_kind); | 838 InliningKind inlining_kind); |
| 845 ~FunctionState(); | 839 ~FunctionState(); |
| 846 | 840 |
| 847 CompilationInfo* compilation_info() { return compilation_info_; } | 841 CompilationInfo* compilation_info() { return compilation_info_; } |
| 848 TypeFeedbackOracle* oracle() { return oracle_; } | |
| 849 AstContext* call_context() { return call_context_; } | 842 AstContext* call_context() { return call_context_; } |
| 850 InliningKind inlining_kind() const { return inlining_kind_; } | 843 InliningKind inlining_kind() const { return inlining_kind_; } |
| 851 HBasicBlock* function_return() { return function_return_; } | 844 HBasicBlock* function_return() { return function_return_; } |
| 852 TestContext* test_context() { return test_context_; } | 845 TestContext* test_context() { return test_context_; } |
| 853 void ClearInlinedTestContext() { | 846 void ClearInlinedTestContext() { |
| 854 delete test_context_; | 847 delete test_context_; |
| 855 test_context_ = NULL; | 848 test_context_ = NULL; |
| 856 } | 849 } |
| 857 | 850 |
| 858 FunctionState* outer() { return outer_; } | 851 FunctionState* outer() { return outer_; } |
| 859 | 852 |
| 860 HEnterInlined* entry() { return entry_; } | 853 HEnterInlined* entry() { return entry_; } |
| 861 void set_entry(HEnterInlined* entry) { entry_ = entry; } | 854 void set_entry(HEnterInlined* entry) { entry_ = entry; } |
| 862 | 855 |
| 863 HArgumentsElements* arguments_elements() { return arguments_elements_; } | 856 HArgumentsElements* arguments_elements() { return arguments_elements_; } |
| 864 void set_arguments_elements(HArgumentsElements* arguments_elements) { | 857 void set_arguments_elements(HArgumentsElements* arguments_elements) { |
| 865 arguments_elements_ = arguments_elements; | 858 arguments_elements_ = arguments_elements; |
| 866 } | 859 } |
| 867 | 860 |
| 868 bool arguments_pushed() { return arguments_elements() != NULL; } | 861 bool arguments_pushed() { return arguments_elements() != NULL; } |
| 869 | 862 |
| 870 private: | 863 private: |
| 871 HOptimizedGraphBuilder* owner_; | 864 HOptimizedGraphBuilder* owner_; |
| 872 | 865 |
| 873 CompilationInfo* compilation_info_; | 866 CompilationInfo* compilation_info_; |
| 874 TypeFeedbackOracle* oracle_; | |
| 875 | 867 |
| 876 // During function inlining, expression context of the call being | 868 // During function inlining, expression context of the call being |
| 877 // inlined. NULL when not inlining. | 869 // inlined. NULL when not inlining. |
| 878 AstContext* call_context_; | 870 AstContext* call_context_; |
| 879 | 871 |
| 880 // The kind of call which is currently being inlined. | 872 // The kind of call which is currently being inlined. |
| 881 InliningKind inlining_kind_; | 873 InliningKind inlining_kind_; |
| 882 | 874 |
| 883 // When inlining in an effect or value context, this is the return block. | 875 // When inlining in an effect or value context, this is the return block. |
| 884 // It is NULL otherwise. When inlining in a test context, there are a | 876 // It is NULL otherwise. When inlining in a test context, there are a |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 HGraphBuilder(); | 1335 HGraphBuilder(); |
| 1344 CompilationInfo* info_; | 1336 CompilationInfo* info_; |
| 1345 HGraph* graph_; | 1337 HGraph* graph_; |
| 1346 HBasicBlock* current_block_; | 1338 HBasicBlock* current_block_; |
| 1347 int no_side_effects_scope_count_; | 1339 int no_side_effects_scope_count_; |
| 1348 }; | 1340 }; |
| 1349 | 1341 |
| 1350 | 1342 |
| 1351 class HOptimizedGraphBuilder: public HGraphBuilder, public AstVisitor { | 1343 class HOptimizedGraphBuilder: public HGraphBuilder, public AstVisitor { |
| 1352 public: | 1344 public: |
| 1353 enum BreakType { BREAK, CONTINUE }; | |
| 1354 enum SwitchType { UNKNOWN_SWITCH, SMI_SWITCH, STRING_SWITCH }; | |
| 1355 | |
| 1356 // A class encapsulating (lazily-allocated) break and continue blocks for | 1345 // A class encapsulating (lazily-allocated) break and continue blocks for |
| 1357 // a breakable statement. Separated from BreakAndContinueScope so that it | 1346 // a breakable statement. Separated from BreakAndContinueScope so that it |
| 1358 // can have a separate lifetime. | 1347 // can have a separate lifetime. |
| 1359 class BreakAndContinueInfo BASE_EMBEDDED { | 1348 class BreakAndContinueInfo BASE_EMBEDDED { |
| 1360 public: | 1349 public: |
| 1361 explicit BreakAndContinueInfo(BreakableStatement* target, | 1350 explicit BreakAndContinueInfo(BreakableStatement* target, |
| 1362 int drop_extra = 0) | 1351 int drop_extra = 0) |
| 1363 : target_(target), | 1352 : target_(target), |
| 1364 break_block_(NULL), | 1353 break_block_(NULL), |
| 1365 continue_block_(NULL), | 1354 continue_block_(NULL), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1390 owner->set_break_scope(this); | 1379 owner->set_break_scope(this); |
| 1391 } | 1380 } |
| 1392 | 1381 |
| 1393 ~BreakAndContinueScope() { owner_->set_break_scope(next_); } | 1382 ~BreakAndContinueScope() { owner_->set_break_scope(next_); } |
| 1394 | 1383 |
| 1395 BreakAndContinueInfo* info() { return info_; } | 1384 BreakAndContinueInfo* info() { return info_; } |
| 1396 HOptimizedGraphBuilder* owner() { return owner_; } | 1385 HOptimizedGraphBuilder* owner() { return owner_; } |
| 1397 BreakAndContinueScope* next() { return next_; } | 1386 BreakAndContinueScope* next() { return next_; } |
| 1398 | 1387 |
| 1399 // Search the break stack for a break or continue target. | 1388 // Search the break stack for a break or continue target. |
| 1389 enum BreakType { BREAK, CONTINUE }; |
| 1400 HBasicBlock* Get(BreakableStatement* stmt, BreakType type, int* drop_extra); | 1390 HBasicBlock* Get(BreakableStatement* stmt, BreakType type, int* drop_extra); |
| 1401 | 1391 |
| 1402 private: | 1392 private: |
| 1403 BreakAndContinueInfo* info_; | 1393 BreakAndContinueInfo* info_; |
| 1404 HOptimizedGraphBuilder* owner_; | 1394 HOptimizedGraphBuilder* owner_; |
| 1405 BreakAndContinueScope* next_; | 1395 BreakAndContinueScope* next_; |
| 1406 }; | 1396 }; |
| 1407 | 1397 |
| 1408 HOptimizedGraphBuilder(CompilationInfo* info, TypeFeedbackOracle* oracle); | 1398 explicit HOptimizedGraphBuilder(CompilationInfo* info); |
| 1409 | 1399 |
| 1410 virtual bool BuildGraph(); | 1400 virtual bool BuildGraph(); |
| 1411 | 1401 |
| 1412 // Simple accessors. | 1402 // Simple accessors. |
| 1413 BreakAndContinueScope* break_scope() const { return break_scope_; } | 1403 BreakAndContinueScope* break_scope() const { return break_scope_; } |
| 1414 void set_break_scope(BreakAndContinueScope* head) { break_scope_ = head; } | 1404 void set_break_scope(BreakAndContinueScope* head) { break_scope_ = head; } |
| 1415 | 1405 |
| 1416 bool inline_bailout() { return inline_bailout_; } | 1406 bool inline_bailout() { return inline_bailout_; } |
| 1417 | 1407 |
| 1418 void AddSoftDeoptimize(); | 1408 void AddSoftDeoptimize(); |
| 1419 | 1409 |
| 1420 void Bailout(const char* reason); | 1410 void Bailout(const char* reason); |
| 1421 | 1411 |
| 1422 HBasicBlock* CreateJoin(HBasicBlock* first, | 1412 HBasicBlock* CreateJoin(HBasicBlock* first, |
| 1423 HBasicBlock* second, | 1413 HBasicBlock* second, |
| 1424 BailoutId join_id); | 1414 BailoutId join_id); |
| 1425 | 1415 |
| 1426 TypeFeedbackOracle* oracle() const { return function_state()->oracle(); } | |
| 1427 | |
| 1428 FunctionState* function_state() const { return function_state_; } | 1416 FunctionState* function_state() const { return function_state_; } |
| 1429 | 1417 |
| 1430 void VisitDeclarations(ZoneList<Declaration*>* declarations); | 1418 void VisitDeclarations(ZoneList<Declaration*>* declarations); |
| 1431 | 1419 |
| 1432 void* operator new(size_t size, Zone* zone) { | 1420 void* operator new(size_t size, Zone* zone) { |
| 1433 return zone->New(static_cast<int>(size)); | 1421 return zone->New(static_cast<int>(size)); |
| 1434 } | 1422 } |
| 1435 void operator delete(void* pointer, Zone* zone) { } | 1423 void operator delete(void* pointer, Zone* zone) { } |
| 1436 void operator delete(void* pointer) { } | 1424 void operator delete(void* pointer) { } |
| 1437 | 1425 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 EmbeddedVector<char, 64> filename_; | 2013 EmbeddedVector<char, 64> filename_; |
| 2026 HeapStringAllocator string_allocator_; | 2014 HeapStringAllocator string_allocator_; |
| 2027 StringStream trace_; | 2015 StringStream trace_; |
| 2028 int indent_; | 2016 int indent_; |
| 2029 }; | 2017 }; |
| 2030 | 2018 |
| 2031 | 2019 |
| 2032 } } // namespace v8::internal | 2020 } } // namespace v8::internal |
| 2033 | 2021 |
| 2034 #endif // V8_HYDROGEN_H_ | 2022 #endif // V8_HYDROGEN_H_ |
| OLD | NEW |