Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1319)

Side by Side Diff: runtime/vm/flow_graph_builder.cc

Issue 9456009: Fix a pair of bugs in the translation of 'if' nodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 #include "vm/os.h" 9 #include "vm/os.h"
10 #include "vm/parser.h" 10 #include "vm/parser.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // and a pair of effect graph fragments with zero or one available exits. 46 // and a pair of effect graph fragments with zero or one available exits.
47 // We want to append the branch and (if necessary) a join node to this 47 // We want to append the branch and (if necessary) a join node to this
48 // graph fragment. 48 // graph fragment.
49 ASSERT(is_open()); 49 ASSERT(is_open());
50 50
51 // 1. Connect the test to this graph. 51 // 1. Connect the test to this graph.
52 Append(test_fragment); 52 Append(test_fragment);
53 53
54 // 2. Connect the true and false bodies to the test if they are reachable, 54 // 2. Connect the true and false bodies to the test if they are reachable,
55 // and if so record their exits (if any). 55 // and if so record their exits (if any).
56 Instruction* true_exit = NULL;
57 Instruction* false_exit = NULL;
56 if (test_fragment.can_be_true()) { 58 if (test_fragment.can_be_true()) {
57 Instruction* true_exit = NULL;
58 Instruction* false_exit = NULL;
59 TargetEntryInstr* true_entry = new TargetEntryInstr(); 59 TargetEntryInstr* true_entry = new TargetEntryInstr();
60 *test_fragment.true_successor_address() = true_entry; 60 *test_fragment.true_successor_address() = true_entry;
61 true_entry->SetSuccessor(true_fragment.entry()); 61 true_entry->SetSuccessor(true_fragment.entry());
62 true_exit = true_fragment.is_empty() ? true_entry : true_fragment.exit(); 62 true_exit = true_fragment.is_empty() ? true_entry : true_fragment.exit();
63 63
64 TargetEntryInstr* false_entry = new TargetEntryInstr(); 64 TargetEntryInstr* false_entry = new TargetEntryInstr();
65 *test_fragment.false_successor_address() = false_entry; 65 *test_fragment.false_successor_address() = false_entry;
66 false_entry->SetSuccessor(false_fragment.entry()); 66 false_entry->SetSuccessor(false_fragment.entry());
67 false_exit = 67 false_exit =
68 false_fragment.is_empty() ? false_entry : false_fragment.exit(); 68 false_fragment.is_empty() ? false_entry : false_fragment.exit();
srdjan 2012/02/23 16:27:22 When can false_exit and true_exit be NULL, i.e., w
69 }
69 70
71 // 3. Add a join or select one (or neither) of the arms as exit.
72 if (true_exit == NULL) {
73 exit_ = false_exit; // May be NULL.
74 } else if (false_exit == NULL) {
75 exit_ = true_exit;
76 } else {
70 exit_ = new JoinEntryInstr(); 77 exit_ = new JoinEntryInstr();
71 true_exit->SetSuccessor(exit_); 78 true_exit->SetSuccessor(exit_);
72 false_exit->SetSuccessor(exit_); 79 false_exit->SetSuccessor(exit_);
73 } 80 }
74 } 81 }
75 82
76 83
77 void EffectGraphVisitor::TieLoop(const TestGraphVisitor& test_fragment, 84 void EffectGraphVisitor::TieLoop(const TestGraphVisitor& test_fragment,
78 const EffectGraphVisitor& body_fragment) { 85 const EffectGraphVisitor& body_fragment) {
79 // We have: a test graph fragment with zero, one, or two available exits; 86 // We have: a test graph fragment with zero, one, or two available exits;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 Bailout("TestGraphVisitor::VisitConditionalExprNode"); 405 Bailout("TestGraphVisitor::VisitConditionalExprNode");
399 } 406 }
400 407
401 408
402 // <Statement> ::= If { condition: <Expression> 409 // <Statement> ::= If { condition: <Expression>
403 // true_branch: <Sequence> 410 // true_branch: <Sequence>
404 // false_branch: <Sequence> } 411 // false_branch: <Sequence> }
405 void EffectGraphVisitor::VisitIfNode(IfNode* node) { 412 void EffectGraphVisitor::VisitIfNode(IfNode* node) {
406 TestGraphVisitor for_test(owner(), temp_index()); 413 TestGraphVisitor for_test(owner(), temp_index());
407 node->condition()->Visit(&for_test); 414 node->condition()->Visit(&for_test);
408 Append(for_test);
409 415
410 EffectGraphVisitor for_true(owner(), temp_index()); 416 EffectGraphVisitor for_true(owner(), temp_index());
411 EffectGraphVisitor for_false(owner(), temp_index()); 417 EffectGraphVisitor for_false(owner(), temp_index());
412 418
413 if (for_test.can_be_true()) { 419 if (for_test.can_be_true()) {
414 node->true_branch()->Visit(&for_true); 420 node->true_branch()->Visit(&for_true);
415 // The for_false graph fragment will be empty (default graph fragment) 421 // The for_false graph fragment will be empty (default graph fragment)
416 // if we do not call Visit. 422 // if we do not call Visit.
417 if (node->false_branch() != NULL) node->false_branch()->Visit(&for_false); 423 if (node->false_branch() != NULL) node->false_branch()->Visit(&for_false);
418 } 424 }
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 // Number the blocks in reverse postorder starting with 0. 904 // Number the blocks in reverse postorder starting with 0.
899 intptr_t last_index = postorder_block_entries_.length() - 1; 905 intptr_t last_index = postorder_block_entries_.length() - 1;
900 for (intptr_t i = last_index; i >= 0; --i) { 906 for (intptr_t i = last_index; i >= 0; --i) {
901 postorder_block_entries_[i]->SetBlockNumber(last_index - i); 907 postorder_block_entries_[i]->SetBlockNumber(last_index - i);
902 } 908 }
903 } 909 }
904 PrintGraph(); 910 PrintGraph();
905 } 911 }
906 912
907 } // namespace dart 913 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698