Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
| 9 #include "vm/bit_vector.h" | 9 #include "vm/bit_vector.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 namespace dart { | 32 namespace dart { |
| 33 | 33 |
| 34 DEFINE_FLAG(bool, eliminate_type_checks, true, | 34 DEFINE_FLAG(bool, eliminate_type_checks, true, |
| 35 "Eliminate type checks when allowed by static type analysis."); | 35 "Eliminate type checks when allowed by static type analysis."); |
| 36 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); | 36 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); |
| 37 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables."); | 37 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables."); |
| 38 DEFINE_FLAG(bool, trace_type_check_elimination, false, | 38 DEFINE_FLAG(bool, trace_type_check_elimination, false, |
| 39 "Trace type check elimination at compile time."); | 39 "Trace type check elimination at compile time."); |
| 40 | 40 |
| 41 DECLARE_FLAG(bool, enable_type_checks); | 41 DECLARE_FLAG(bool, enable_type_checks); |
| 42 DECLARE_FLAG(bool, enable_asserts); | |
|
srdjan
2014/12/05 00:49:28
alphabetically.
hausner
2014/12/05 20:36:10
Done.
| |
| 42 DECLARE_FLAG(int, optimization_counter_threshold); | 43 DECLARE_FLAG(int, optimization_counter_threshold); |
| 43 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | 44 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 44 | 45 |
| 45 // Quick access to the locally defined isolate() method. | 46 // Quick access to the locally defined isolate() method. |
| 46 #define I (isolate()) | 47 #define I (isolate()) |
| 47 | 48 |
| 48 // TODO(srdjan): Allow compiler to add constants as they are encountered in | 49 // TODO(srdjan): Allow compiler to add constants as they are encountered in |
| 49 // the compilation. | 50 // the compilation. |
| 50 const double kCommonDoubleConstants[] = | 51 const double kCommonDoubleConstants[] = |
| 51 {-1.0, -0.5, -0.1, 0.0, 0.1, 0.5, 1.0, 2.0, 4.0, 5.0, | 52 {-1.0, -0.5, -0.1, 0.0, 0.1, 0.5, 1.0, 2.0, 4.0, 5.0, |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 877 return CreateSuccessorFor(true_successor_addresses_); | 878 return CreateSuccessorFor(true_successor_addresses_); |
| 878 } | 879 } |
| 879 | 880 |
| 880 | 881 |
| 881 BlockEntryInstr* TestGraphVisitor::CreateFalseSuccessor() const { | 882 BlockEntryInstr* TestGraphVisitor::CreateFalseSuccessor() const { |
| 882 return CreateSuccessorFor(false_successor_addresses_); | 883 return CreateSuccessorFor(false_successor_addresses_); |
| 883 } | 884 } |
| 884 | 885 |
| 885 | 886 |
| 886 void TestGraphVisitor::ReturnValue(Value* value) { | 887 void TestGraphVisitor::ReturnValue(Value* value) { |
| 887 if (FLAG_enable_type_checks) { | 888 if (FLAG_enable_type_checks || FLAG_enable_asserts) { |
| 888 value = Bind(new(I) AssertBooleanInstr(condition_token_pos(), value)); | 889 value = Bind(new(I) AssertBooleanInstr(condition_token_pos(), value)); |
| 889 } | 890 } |
| 890 Value* constant_true = Bind(new(I) ConstantInstr(Bool::True())); | 891 Value* constant_true = Bind(new(I) ConstantInstr(Bool::True())); |
| 891 StrictCompareInstr* comp = | 892 StrictCompareInstr* comp = |
| 892 new(I) StrictCompareInstr(condition_token_pos(), | 893 new(I) StrictCompareInstr(condition_token_pos(), |
| 893 Token::kEQ_STRICT, | 894 Token::kEQ_STRICT, |
| 894 value, | 895 value, |
| 895 constant_true, | 896 constant_true, |
| 896 false); // No number check. | 897 false); // No number check. |
| 897 BranchInstr* branch = new(I) BranchInstr(comp); | 898 BranchInstr* branch = new(I) BranchInstr(comp); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1232 // left: <Expression> | 1233 // left: <Expression> |
| 1233 // right: <Expression> } | 1234 // right: <Expression> } |
| 1234 void EffectGraphVisitor::VisitBinaryOpNode(BinaryOpNode* node) { | 1235 void EffectGraphVisitor::VisitBinaryOpNode(BinaryOpNode* node) { |
| 1235 // Operators "&&" and "||" cannot be overloaded therefore do not call | 1236 // Operators "&&" and "||" cannot be overloaded therefore do not call |
| 1236 // operator. | 1237 // operator. |
| 1237 if ((node->kind() == Token::kAND) || (node->kind() == Token::kOR)) { | 1238 if ((node->kind() == Token::kAND) || (node->kind() == Token::kOR)) { |
| 1238 // See ValueGraphVisitor::VisitBinaryOpNode. | 1239 // See ValueGraphVisitor::VisitBinaryOpNode. |
| 1239 TestGraphVisitor for_left(owner(), node->left()->token_pos()); | 1240 TestGraphVisitor for_left(owner(), node->left()->token_pos()); |
| 1240 node->left()->Visit(&for_left); | 1241 node->left()->Visit(&for_left); |
| 1241 EffectGraphVisitor empty(owner()); | 1242 EffectGraphVisitor empty(owner()); |
| 1242 if (FLAG_enable_type_checks) { | 1243 if (FLAG_enable_type_checks || FLAG_enable_asserts) { |
| 1243 ValueGraphVisitor for_right(owner()); | 1244 ValueGraphVisitor for_right(owner()); |
| 1244 node->right()->Visit(&for_right); | 1245 node->right()->Visit(&for_right); |
| 1245 Value* right_value = for_right.value(); | 1246 Value* right_value = for_right.value(); |
| 1246 for_right.Do(new(I) AssertBooleanInstr(node->right()->token_pos(), | 1247 for_right.Do(new(I) AssertBooleanInstr(node->right()->token_pos(), |
| 1247 right_value)); | 1248 right_value)); |
| 1248 if (node->kind() == Token::kAND) { | 1249 if (node->kind() == Token::kAND) { |
| 1249 Join(for_left, for_right, empty); | 1250 Join(for_left, for_right, empty); |
| 1250 } else { | 1251 } else { |
| 1251 Join(for_left, empty, for_right); | 1252 Join(for_left, empty, for_right); |
| 1252 } | 1253 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1297 // of left is sufficient. | 1298 // of left is sufficient. |
| 1298 // AND: left ? right === true : false; | 1299 // AND: left ? right === true : false; |
| 1299 // OR: left ? true : right === true; | 1300 // OR: left ? true : right === true; |
| 1300 | 1301 |
| 1301 TestGraphVisitor for_test(owner(), node->left()->token_pos()); | 1302 TestGraphVisitor for_test(owner(), node->left()->token_pos()); |
| 1302 node->left()->Visit(&for_test); | 1303 node->left()->Visit(&for_test); |
| 1303 | 1304 |
| 1304 ValueGraphVisitor for_right(owner()); | 1305 ValueGraphVisitor for_right(owner()); |
| 1305 node->right()->Visit(&for_right); | 1306 node->right()->Visit(&for_right); |
| 1306 Value* right_value = for_right.value(); | 1307 Value* right_value = for_right.value(); |
| 1307 if (FLAG_enable_type_checks) { | 1308 if (FLAG_enable_type_checks|| FLAG_enable_asserts) { |
| 1308 right_value = | 1309 right_value = |
| 1309 for_right.Bind(new(I) AssertBooleanInstr(node->right()->token_pos(), | 1310 for_right.Bind(new(I) AssertBooleanInstr(node->right()->token_pos(), |
| 1310 right_value)); | 1311 right_value)); |
| 1311 } | 1312 } |
| 1312 Value* constant_true = for_right.Bind(new(I) ConstantInstr(Bool::True())); | 1313 Value* constant_true = for_right.Bind(new(I) ConstantInstr(Bool::True())); |
| 1313 Value* compare = | 1314 Value* compare = |
| 1314 for_right.Bind(new(I) StrictCompareInstr(node->token_pos(), | 1315 for_right.Bind(new(I) StrictCompareInstr(node->token_pos(), |
| 1315 Token::kEQ_STRICT, | 1316 Token::kEQ_STRICT, |
| 1316 right_value, | 1317 right_value, |
| 1317 constant_true, | 1318 constant_true, |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1756 | 1757 |
| 1757 Definition* result = new(I) InstanceCallInstr( | 1758 Definition* result = new(I) InstanceCallInstr( |
| 1758 node->token_pos(), | 1759 node->token_pos(), |
| 1759 Symbols::EqualOperator(), | 1760 Symbols::EqualOperator(), |
| 1760 Token::kEQ, // Result is negated later for kNE. | 1761 Token::kEQ, // Result is negated later for kNE. |
| 1761 arguments, | 1762 arguments, |
| 1762 Object::null_array(), | 1763 Object::null_array(), |
| 1763 2, | 1764 2, |
| 1764 owner()->ic_data_array()); | 1765 owner()->ic_data_array()); |
| 1765 if (node->kind() == Token::kNE) { | 1766 if (node->kind() == Token::kNE) { |
| 1766 if (FLAG_enable_type_checks) { | 1767 if (FLAG_enable_type_checks || FLAG_enable_asserts) { |
| 1767 Value* value = Bind(result); | 1768 Value* value = Bind(result); |
| 1768 result = new(I) AssertBooleanInstr(node->token_pos(), value); | 1769 result = new(I) AssertBooleanInstr(node->token_pos(), value); |
| 1769 } | 1770 } |
| 1770 Value* value = Bind(result); | 1771 Value* value = Bind(result); |
| 1771 result = new(I) BooleanNegateInstr(value); | 1772 result = new(I) BooleanNegateInstr(value); |
| 1772 } | 1773 } |
| 1773 ReturnDefinition(result); | 1774 ReturnDefinition(result); |
| 1774 return; | 1775 return; |
| 1775 } | 1776 } |
| 1776 | 1777 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1802 } | 1803 } |
| 1803 | 1804 |
| 1804 | 1805 |
| 1805 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) { | 1806 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) { |
| 1806 // "!" cannot be overloaded, therefore do not call operator. | 1807 // "!" cannot be overloaded, therefore do not call operator. |
| 1807 if (node->kind() == Token::kNOT) { | 1808 if (node->kind() == Token::kNOT) { |
| 1808 ValueGraphVisitor for_value(owner()); | 1809 ValueGraphVisitor for_value(owner()); |
| 1809 node->operand()->Visit(&for_value); | 1810 node->operand()->Visit(&for_value); |
| 1810 Append(for_value); | 1811 Append(for_value); |
| 1811 Value* value = for_value.value(); | 1812 Value* value = for_value.value(); |
| 1812 if (FLAG_enable_type_checks) { | 1813 if (FLAG_enable_type_checks || FLAG_enable_asserts) { |
| 1813 value = | 1814 value = |
| 1814 Bind(new(I) AssertBooleanInstr(node->operand()->token_pos(), value)); | 1815 Bind(new(I) AssertBooleanInstr(node->operand()->token_pos(), value)); |
| 1815 } | 1816 } |
| 1816 BooleanNegateInstr* negate = new(I) BooleanNegateInstr(value); | 1817 BooleanNegateInstr* negate = new(I) BooleanNegateInstr(value); |
| 1817 ReturnDefinition(negate); | 1818 ReturnDefinition(negate); |
| 1818 return; | 1819 return; |
| 1819 } | 1820 } |
| 1820 | 1821 |
| 1821 ValueGraphVisitor for_value(owner()); | 1822 ValueGraphVisitor for_value(owner()); |
| 1822 node->operand()->Visit(&for_value); | 1823 node->operand()->Visit(&for_value); |
| (...skipping 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4302 Report::MessageF(Report::kBailout, | 4303 Report::MessageF(Report::kBailout, |
| 4303 Script::Handle(function.script()), | 4304 Script::Handle(function.script()), |
| 4304 function.token_pos(), | 4305 function.token_pos(), |
| 4305 "FlowGraphBuilder Bailout: %s %s", | 4306 "FlowGraphBuilder Bailout: %s %s", |
| 4306 String::Handle(function.name()).ToCString(), | 4307 String::Handle(function.name()).ToCString(), |
| 4307 reason); | 4308 reason); |
| 4308 UNREACHABLE(); | 4309 UNREACHABLE(); |
| 4309 } | 4310 } |
| 4310 | 4311 |
| 4311 } // namespace dart | 4312 } // namespace dart |
| OLD | NEW |