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

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

Issue 9429056: Recognize basic block entries in the flow graph. (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
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/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/os.h" 8 #include "vm/os.h"
9 #include "vm/scopes.h" 9 #include "vm/scopes.h"
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void TempValue::Print() const { 53 void TempValue::Print() const {
54 OS::Print("t%d", index_); 54 OS::Print("t%d", index_);
55 } 55 }
56 56
57 57
58 void ConstantValue::Print() const { 58 void ConstantValue::Print() const {
59 OS::Print("#%s", instance_.ToCString()); 59 OS::Print("#%s", instance_.ToCString());
60 } 60 }
61 61
62 62
63 void Instruction::PrintGotoSuccessor( 63 Instruction* DoInstr::Print() const {
64 Instruction* successor, 64 OS::Print(" ");
65 intptr_t instruction_index, 65 computation_->Print();
66 const GrowableArray<Instruction*>& instruction_list) const { 66 return successor_;
67 if ((instruction_index == 0) || 67 }
68 (instruction_list[instruction_index - 1] != successor)) { 68
69 // Linear search of the instruction list for the successor's index. 69
70 for (intptr_t i = 0; i < instruction_list.length(); ++i) { 70 Instruction* BindInstr::Print() const {
71 if (instruction_list[i] == successor) { 71 OS::Print(" t%d <-", temp_index_);
72 intptr_t instruction_number = instruction_list.length() - i; 72 computation_->Print();
73 OS::Print(" goto %d", instruction_number); 73 return successor_;
74 break; 74 }
75 } 75
76 } 76
77 Instruction* ReturnInstr::Print() const {
78 OS::Print(" return ");
79 value_->Print();
80 return NULL;
81 }
82
83
84 Instruction* BranchInstr::Print() const {
85 OS::Print(" if ");
86 value_->Print();
87 OS::Print(" goto(%d, %d)", true_successor_->GetBlockNumber(),
88 false_successor_->GetBlockNumber());
89 return NULL;
90 }
91
92
93 Instruction* JoinEntryInstr::Print() const {
94 OS::Print("%2d: [join]", block_number_);
95 return successor_;
96 }
97
98
99 Instruction* TargetEntryInstr::Print() const {
100 OS::Print("%2d: [target]", block_number_);
101 return successor_;
102 }
103
104
105 void DoInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
106 flip_mark();
107 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
108 }
109
110
111 void BindInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
112 flip_mark();
113 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
114 }
115
116
117 void ReturnInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
118 flip_mark();
119 }
120
121
122 void BranchInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
123 flip_mark();
124 // Visit the false successor before the true successor so they appear in
125 // true/false order in reverse postorder.
126 if (false_successor_->mark() != mark()) {
127 false_successor_->Postorder(block_entries);
128 }
129 if (true_successor_->mark() != mark()) {
130 true_successor_->Postorder(block_entries);
77 } 131 }
78 } 132 }
79 133
80 134
81 void DoInstr::Print(intptr_t instruction_index, 135 void JoinEntryInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
82 const GrowableArray<Instruction*>& instruction_list) const { 136 flip_mark();
83 computation_->Print(); 137 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
84 PrintGotoSuccessor(successor_, instruction_index, instruction_list); 138 block_entries->Add(this);
85 } 139 }
86 140
87 141
88 void BindInstr::Print( 142 void TargetEntryInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
89 intptr_t instruction_index, 143 flip_mark();
90 const GrowableArray<Instruction*>& instruction_list) const { 144 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
91 OS::Print("t%d <-", temp_index_); 145 block_entries->Add(this);
92 computation_->Print();
93 PrintGotoSuccessor(successor_, instruction_index, instruction_list);
94 } 146 }
95 147
96 148
97 void ReturnInstr::Print(
98 intptr_t instruction_index,
99 const GrowableArray<Instruction*>& instruction_list) const {
100 OS::Print("return ");
101 value_->Print();
102 }
103
104
105 void BranchInstr::Print(
106 intptr_t instruction_index,
107 const GrowableArray<Instruction*>& instruction_list) const {
108 OS::Print("if ");
109 value_->Print();
110 // Linear search for the instruction numbers of the successors.
111 intptr_t true_successor_number = -1;
112 intptr_t false_successor_number = -1;
113 for (intptr_t i = 0; i < instruction_list.length(); ++i) {
114 if (instruction_list[i] == true_successor_) {
115 true_successor_number = instruction_list.length() - i;
116 if (false_successor_number >= 0) break;
117 }
118 if (instruction_list[i] == false_successor_) {
119 false_successor_number = instruction_list.length() - i;
120 if (true_successor_number >= 0) break;
121 }
122 }
123 OS::Print(" goto(%d, %d)", true_successor_number, false_successor_number);
124 }
125
126
127 void JoinEntryInstr::Print(
128 intptr_t instruction_index,
129 const GrowableArray<Instruction*>& instruction_list) const {
130 OS::Print("[join]");
131 PrintGotoSuccessor(successor_, instruction_index, instruction_list);
132 }
133
134
135 void TargetEntryInstr::Print(
136 intptr_t instruction_index,
137 const GrowableArray<Instruction*>& instruction_list) const {
138 OS::Print("[target]");
139 PrintGotoSuccessor(successor_, instruction_index, instruction_list);
140 }
141
142
143 void DoInstr::Postorder(GrowableArray<Instruction*>* visited) {
144 flip_mark();
145 if (successor_->mark() != mark()) successor_->Postorder(visited);
146 visited->Add(this);
147 }
148
149
150 void BindInstr::Postorder(GrowableArray<Instruction*>* visited) {
151 flip_mark();
152 if (successor_->mark() != mark()) successor_->Postorder(visited);
153 visited->Add(this);
154 }
155
156
157 void ReturnInstr::Postorder(GrowableArray<Instruction*>* visited) {
158 flip_mark();
159 visited->Add(this);
160 }
161
162
163 void BranchInstr::Postorder(GrowableArray<Instruction*>* visited) {
164 flip_mark();
165 // Visit the false successor before the true successor so they appear in
166 // true/false order in reverse postorder.
167 if (false_successor_->mark() != mark()) {
168 false_successor_->Postorder(visited);
169 }
170 if (true_successor_->mark() != mark()) {
171 true_successor_->Postorder(visited);
172 }
173 visited->Add(this);
174 }
175
176
177 void JoinEntryInstr::Postorder(GrowableArray<Instruction*>* visited) {
178 flip_mark();
179 if (successor_->mark() != mark()) successor_->Postorder(visited);
180 visited->Add(this);
181 }
182
183
184 void TargetEntryInstr::Postorder(GrowableArray<Instruction*>* visited) {
185 flip_mark();
186 if (successor_->mark() != mark()) successor_->Postorder(visited);
187 visited->Add(this);
188 }
189
190
191 } // namespace dart 149 } // namespace dart
OLDNEW
« runtime/vm/flow_graph_builder.cc ('K') | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698