| 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/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // by the constant propagation. | 244 // by the constant propagation. |
| 245 TargetEntryInstr* false_block = | 245 TargetEntryInstr* false_block = |
| 246 new TargetEntryInstr(caller_graph_->allocate_block_id(), | 246 new TargetEntryInstr(caller_graph_->allocate_block_id(), |
| 247 call_block->try_index()); | 247 call_block->try_index()); |
| 248 false_block->InheritDeoptTargetAfter(call_); | 248 false_block->InheritDeoptTargetAfter(call_); |
| 249 false_block->LinkTo(call_->next()); | 249 false_block->LinkTo(call_->next()); |
| 250 call_block->ReplaceAsPredecessorWith(false_block); | 250 call_block->ReplaceAsPredecessorWith(false_block); |
| 251 | 251 |
| 252 ConstantInstr* true_const = caller_graph_->GetConstant(Bool::True()); | 252 ConstantInstr* true_const = caller_graph_->GetConstant(Bool::True()); |
| 253 BranchInstr* branch = | 253 BranchInstr* branch = |
| 254 new BranchInstr(new StrictCompareInstr(Token::kEQ_STRICT, | 254 new BranchInstr(new StrictCompareInstr(call_block->start_pos(), |
| 255 Token::kEQ_STRICT, |
| 255 new Value(true_const), | 256 new Value(true_const), |
| 256 new Value(true_const))); | 257 new Value(true_const))); |
| 257 branch->InheritDeoptTarget(call_); | 258 branch->InheritDeoptTarget(call_); |
| 258 *branch->true_successor_address() = callee_entry; | 259 *branch->true_successor_address() = callee_entry; |
| 259 *branch->false_successor_address() = false_block; | 260 *branch->false_successor_address() = false_block; |
| 260 | 261 |
| 261 call_->previous()->AppendInstruction(branch); | 262 call_->previous()->AppendInstruction(branch); |
| 262 call_block->set_last_instruction(branch); | 263 call_block->set_last_instruction(branch); |
| 263 | 264 |
| 264 // Update dominator tree. | 265 // Update dominator tree. |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 return CreateSuccessorFor(false_successor_addresses_); | 645 return CreateSuccessorFor(false_successor_addresses_); |
| 645 } | 646 } |
| 646 | 647 |
| 647 | 648 |
| 648 void TestGraphVisitor::ReturnValue(Value* value) { | 649 void TestGraphVisitor::ReturnValue(Value* value) { |
| 649 if (FLAG_enable_type_checks) { | 650 if (FLAG_enable_type_checks) { |
| 650 value = Bind(new AssertBooleanInstr(condition_token_pos(), value)); | 651 value = Bind(new AssertBooleanInstr(condition_token_pos(), value)); |
| 651 } | 652 } |
| 652 Value* constant_true = Bind(new ConstantInstr(Bool::True())); | 653 Value* constant_true = Bind(new ConstantInstr(Bool::True())); |
| 653 StrictCompareInstr* comp = | 654 StrictCompareInstr* comp = |
| 654 new StrictCompareInstr(Token::kEQ_STRICT, value, constant_true); | 655 new StrictCompareInstr(condition_token_pos(), |
| 656 Token::kEQ_STRICT, |
| 657 value, |
| 658 constant_true); |
| 655 BranchInstr* branch = new BranchInstr(comp); | 659 BranchInstr* branch = new BranchInstr(comp); |
| 656 AddInstruction(branch); | 660 AddInstruction(branch); |
| 657 CloseFragment(); | 661 CloseFragment(); |
| 658 | 662 |
| 659 true_successor_addresses_.Add(branch->true_successor_address()); | 663 true_successor_addresses_.Add(branch->true_successor_address()); |
| 660 false_successor_addresses_.Add(branch->false_successor_address()); | 664 false_successor_addresses_.Add(branch->false_successor_address()); |
| 661 } | 665 } |
| 662 | 666 |
| 663 | 667 |
| 664 void TestGraphVisitor::MergeBranchWithComparison(ComparisonInstr* comp) { | 668 void TestGraphVisitor::MergeBranchWithComparison(ComparisonInstr* comp) { |
| 665 ControlInstruction* branch; | 669 ControlInstruction* branch; |
| 666 if (Token::IsStrictEqualityOperator(comp->kind())) { | 670 if (Token::IsStrictEqualityOperator(comp->kind())) { |
| 667 branch = new BranchInstr(new StrictCompareInstr(comp->kind(), | 671 branch = new BranchInstr(new StrictCompareInstr(comp->token_pos(), |
| 672 comp->kind(), |
| 668 comp->left(), | 673 comp->left(), |
| 669 comp->right())); | 674 comp->right())); |
| 670 } else if (Token::IsEqualityOperator(comp->kind()) && | 675 } else if (Token::IsEqualityOperator(comp->kind()) && |
| 671 (comp->left()->BindsToConstantNull() || | 676 (comp->left()->BindsToConstantNull() || |
| 672 comp->right()->BindsToConstantNull())) { | 677 comp->right()->BindsToConstantNull())) { |
| 673 branch = new BranchInstr(new StrictCompareInstr( | 678 branch = new BranchInstr(new StrictCompareInstr( |
| 679 comp->token_pos(), |
| 674 (comp->kind() == Token::kEQ) ? Token::kEQ_STRICT : Token::kNE_STRICT, | 680 (comp->kind() == Token::kEQ) ? Token::kEQ_STRICT : Token::kNE_STRICT, |
| 675 comp->left(), | 681 comp->left(), |
| 676 comp->right())); | 682 comp->right())); |
| 677 } else { | 683 } else { |
| 678 branch = new BranchInstr(comp, FLAG_enable_type_checks); | 684 branch = new BranchInstr(comp, FLAG_enable_type_checks); |
| 679 } | 685 } |
| 680 AddInstruction(branch); | 686 AddInstruction(branch); |
| 681 CloseFragment(); | 687 CloseFragment(); |
| 682 true_successor_addresses_.Add(branch->true_successor_address()); | 688 true_successor_addresses_.Add(branch->true_successor_address()); |
| 683 false_successor_addresses_.Add(branch->false_successor_address()); | 689 false_successor_addresses_.Add(branch->false_successor_address()); |
| 684 } | 690 } |
| 685 | 691 |
| 686 | 692 |
| 687 void TestGraphVisitor::MergeBranchWithNegate(BooleanNegateInstr* neg) { | 693 void TestGraphVisitor::MergeBranchWithNegate(BooleanNegateInstr* neg) { |
| 688 ASSERT(!FLAG_enable_type_checks); | 694 ASSERT(!FLAG_enable_type_checks); |
| 689 Value* constant_true = Bind(new ConstantInstr(Bool::True())); | 695 Value* constant_true = Bind(new ConstantInstr(Bool::True())); |
| 690 BranchInstr* branch = new BranchInstr( | 696 BranchInstr* branch = new BranchInstr( |
| 691 new StrictCompareInstr(Token::kNE_STRICT, neg->value(), constant_true)); | 697 new StrictCompareInstr(condition_token_pos(), |
| 698 Token::kNE_STRICT, |
| 699 neg->value(), |
| 700 constant_true)); |
| 692 AddInstruction(branch); | 701 AddInstruction(branch); |
| 693 CloseFragment(); | 702 CloseFragment(); |
| 694 true_successor_addresses_.Add(branch->true_successor_address()); | 703 true_successor_addresses_.Add(branch->true_successor_address()); |
| 695 false_successor_addresses_.Add(branch->false_successor_address()); | 704 false_successor_addresses_.Add(branch->false_successor_address()); |
| 696 } | 705 } |
| 697 | 706 |
| 698 | 707 |
| 699 void TestGraphVisitor::ReturnDefinition(Definition* definition) { | 708 void TestGraphVisitor::ReturnDefinition(Definition* definition) { |
| 700 ComparisonInstr* comp = definition->AsComparison(); | 709 ComparisonInstr* comp = definition->AsComparison(); |
| 701 if (comp != NULL) { | 710 if (comp != NULL) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 ValueGraphVisitor for_right(owner(), temp_index()); | 992 ValueGraphVisitor for_right(owner(), temp_index()); |
| 984 node->right()->Visit(&for_right); | 993 node->right()->Visit(&for_right); |
| 985 Value* right_value = for_right.value(); | 994 Value* right_value = for_right.value(); |
| 986 if (FLAG_enable_type_checks) { | 995 if (FLAG_enable_type_checks) { |
| 987 right_value = | 996 right_value = |
| 988 for_right.Bind(new AssertBooleanInstr(node->right()->token_pos(), | 997 for_right.Bind(new AssertBooleanInstr(node->right()->token_pos(), |
| 989 right_value)); | 998 right_value)); |
| 990 } | 999 } |
| 991 Value* constant_true = for_right.Bind(new ConstantInstr(Bool::True())); | 1000 Value* constant_true = for_right.Bind(new ConstantInstr(Bool::True())); |
| 992 Value* compare = | 1001 Value* compare = |
| 993 for_right.Bind(new StrictCompareInstr(Token::kEQ_STRICT, | 1002 for_right.Bind(new StrictCompareInstr(node->token_pos(), |
| 1003 Token::kEQ_STRICT, |
| 994 right_value, | 1004 right_value, |
| 995 constant_true)); | 1005 constant_true)); |
| 996 for_right.Do(BuildStoreExprTemp(compare)); | 1006 for_right.Do(BuildStoreExprTemp(compare)); |
| 997 | 1007 |
| 998 if (node->kind() == Token::kAND) { | 1008 if (node->kind() == Token::kAND) { |
| 999 ValueGraphVisitor for_false(owner(), temp_index()); | 1009 ValueGraphVisitor for_false(owner(), temp_index()); |
| 1000 Value* constant_false = for_false.Bind(new ConstantInstr(Bool::False())); | 1010 Value* constant_false = for_false.Bind(new ConstantInstr(Bool::False())); |
| 1001 for_false.Do(BuildStoreExprTemp(constant_false)); | 1011 for_false.Do(BuildStoreExprTemp(constant_false)); |
| 1002 Join(for_test, for_right, for_false); | 1012 Join(for_test, for_right, for_false); |
| 1003 } else { | 1013 } else { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 return; | 1303 return; |
| 1294 } | 1304 } |
| 1295 if ((node->kind() == Token::kEQ_STRICT) || | 1305 if ((node->kind() == Token::kEQ_STRICT) || |
| 1296 (node->kind() == Token::kNE_STRICT)) { | 1306 (node->kind() == Token::kNE_STRICT)) { |
| 1297 ValueGraphVisitor for_left_value(owner(), temp_index()); | 1307 ValueGraphVisitor for_left_value(owner(), temp_index()); |
| 1298 node->left()->Visit(&for_left_value); | 1308 node->left()->Visit(&for_left_value); |
| 1299 Append(for_left_value); | 1309 Append(for_left_value); |
| 1300 ValueGraphVisitor for_right_value(owner(), temp_index()); | 1310 ValueGraphVisitor for_right_value(owner(), temp_index()); |
| 1301 node->right()->Visit(&for_right_value); | 1311 node->right()->Visit(&for_right_value); |
| 1302 Append(for_right_value); | 1312 Append(for_right_value); |
| 1303 StrictCompareInstr* comp = new StrictCompareInstr( | 1313 StrictCompareInstr* comp = new StrictCompareInstr(node->token_pos(), |
| 1304 node->kind(), for_left_value.value(), for_right_value.value()); | 1314 node->kind(), |
| 1315 for_left_value.value(), |
| 1316 for_right_value.value()); |
| 1305 ReturnDefinition(comp); | 1317 ReturnDefinition(comp); |
| 1306 return; | 1318 return; |
| 1307 } | 1319 } |
| 1308 | 1320 |
| 1309 if ((node->kind() == Token::kEQ) || (node->kind() == Token::kNE)) { | 1321 if ((node->kind() == Token::kEQ) || (node->kind() == Token::kNE)) { |
| 1310 ValueGraphVisitor for_left_value(owner(), temp_index()); | 1322 ValueGraphVisitor for_left_value(owner(), temp_index()); |
| 1311 node->left()->Visit(&for_left_value); | 1323 node->left()->Visit(&for_left_value); |
| 1312 Append(for_left_value); | 1324 Append(for_left_value); |
| 1313 ValueGraphVisitor for_right_value(owner(), temp_index()); | 1325 ValueGraphVisitor for_right_value(owner(), temp_index()); |
| 1314 node->right()->Visit(&for_right_value); | 1326 node->right()->Visit(&for_right_value); |
| (...skipping 2108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3423 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3435 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 3424 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3436 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3425 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3437 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 3426 const Error& error = Error::Handle( | 3438 const Error& error = Error::Handle( |
| 3427 LanguageError::New(String::Handle(String::New(chars)))); | 3439 LanguageError::New(String::Handle(String::New(chars)))); |
| 3428 Isolate::Current()->long_jump_base()->Jump(1, error); | 3440 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3429 } | 3441 } |
| 3430 | 3442 |
| 3431 | 3443 |
| 3432 } // namespace dart | 3444 } // namespace dart |
| OLD | NEW |