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

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

Issue 9732022: Do not use recursion for depth-first traversal of straight line code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | « runtime/vm/intermediate_language.h ('k') | 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/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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // 3. The last entry in the preorder array is the spanning-tree parent. 112 // 3. The last entry in the preorder array is the spanning-tree parent.
113 parent->Add(preorder->Last()); 113 parent->Add(preorder->Last());
114 114
115 // 4. Assign preorder number and add the block entry to the list. 115 // 4. Assign preorder number and add the block entry to the list.
116 set_preorder_number(preorder->length()); 116 set_preorder_number(preorder->length());
117 preorder->Add(this); 117 preorder->Add(this);
118 // The preorder and parent arrays are both indexed by preorder block 118 // The preorder and parent arrays are both indexed by preorder block
119 // number, so they should stay in lockstep. 119 // number, so they should stay in lockstep.
120 ASSERT(preorder->length() == parent->length()); 120 ASSERT(preorder->length() == parent->length());
121 121
122 // 5. Recursively visit the successor. 122 // 5. Iterate straight-line successors until a branch instruction or
123 // another basic block entry instruction, and visit that instruction.
123 ASSERT(successor_ != NULL); 124 ASSERT(successor_ != NULL);
124 successor_->DiscoverBlocks(this, preorder, postorder, parent); 125 Instruction* next = successor_;
126 while ((next != NULL) && !next->IsBlockEntry() && !next->IsBranch()) {
127 set_last_instruction(next);
128 next = next->StraightLineSuccessor();
129 }
130 if (next != NULL) {
131 next->DiscoverBlocks(this, preorder, postorder, parent);
132 }
125 133
126 // 6. Assign postorder number and add the block entry to the list. 134 // 6. Assign postorder number and add the block entry to the list.
127 set_postorder_number(postorder->length()); 135 set_postorder_number(postorder->length());
128 postorder->Add(this); 136 postorder->Add(this);
129 } 137 }
130 138
131 139
132 void TargetEntryInstr::DiscoverBlocks( 140 void TargetEntryInstr::DiscoverBlocks(
133 BlockEntryInstr* current_block, 141 BlockEntryInstr* current_block,
134 GrowableArray<BlockEntryInstr*>* preorder, 142 GrowableArray<BlockEntryInstr*>* preorder,
(...skipping 10 matching lines...) Expand all
145 // The global graph entry has a NULL parent. 153 // The global graph entry has a NULL parent.
146 parent->Add(preorder->is_empty() ? NULL : preorder->Last()); 154 parent->Add(preorder->is_empty() ? NULL : preorder->Last());
147 155
148 // 4. Assign preorder number and add the block entry to the list. 156 // 4. Assign preorder number and add the block entry to the list.
149 set_preorder_number(preorder->length()); 157 set_preorder_number(preorder->length());
150 preorder->Add(this); 158 preorder->Add(this);
151 // The preorder and parent arrays are indexed by preorder block number, so 159 // The preorder and parent arrays are indexed by preorder block number, so
152 // they should stay in lockstep. 160 // they should stay in lockstep.
153 ASSERT(preorder->length() == parent->length()); 161 ASSERT(preorder->length() == parent->length());
154 162
155 // 5. Recursively visit the successor. 163 // 5. Iterate straight-line successors until a branch instruction or
164 // another basic block entry instruction, and visit that instruction.
156 ASSERT(successor_ != NULL); 165 ASSERT(successor_ != NULL);
157 successor_->DiscoverBlocks(this, preorder, postorder, parent); 166 Instruction* next = successor_;
167 while ((next != NULL) &&
168 !next->IsBlockEntry() &&
169 !next->IsBranch()) {
170 set_last_instruction(next);
171 next = next->StraightLineSuccessor();
172 }
173 if (next != NULL) {
174 next->DiscoverBlocks(this, preorder, postorder, parent);
175 }
158 176
159 // 6. Assign postorder number and add the block entry to the list. 177 // 6. Assign postorder number and add the block entry to the list.
160 set_postorder_number(postorder->length()); 178 set_postorder_number(postorder->length());
161 postorder->Add(this); 179 postorder->Add(this);
162 } 180 }
163 181
164 182
165 void PickTempInstr::DiscoverBlocks(
166 BlockEntryInstr* current_block,
167 GrowableArray<BlockEntryInstr*>* preorder,
168 GrowableArray<BlockEntryInstr*>* postorder,
169 GrowableArray<BlockEntryInstr*>* parent) {
170 current_block->set_last_instruction(this);
171 ASSERT(successor_ != NULL);
172 successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
173 }
174
175
176 void TuckTempInstr::DiscoverBlocks(
177 BlockEntryInstr* current_block,
178 GrowableArray<BlockEntryInstr*>* preorder,
179 GrowableArray<BlockEntryInstr*>* postorder,
180 GrowableArray<BlockEntryInstr*>* parent) {
181 current_block->set_last_instruction(this);
182 ASSERT(successor_ != NULL);
183 successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
184 }
185
186
187 void DoInstr::DiscoverBlocks(
188 BlockEntryInstr* current_block,
189 GrowableArray<BlockEntryInstr*>* preorder,
190 GrowableArray<BlockEntryInstr*>* postorder,
191 GrowableArray<BlockEntryInstr*>* parent) {
192 current_block->set_last_instruction(this);
193 ASSERT(successor_ != NULL);
194 successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
195 }
196
197
198 void BindInstr::DiscoverBlocks(
199 BlockEntryInstr* current_block,
200 GrowableArray<BlockEntryInstr*>* preorder,
201 GrowableArray<BlockEntryInstr*>* postorder,
202 GrowableArray<BlockEntryInstr*>* parent) {
203 current_block->set_last_instruction(this);
204 ASSERT(successor_ != NULL);
205 successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
206 }
207
208
209 void ReturnInstr::DiscoverBlocks(
210 BlockEntryInstr* current_block,
211 GrowableArray<BlockEntryInstr*>* preorder,
212 GrowableArray<BlockEntryInstr*>* postorder,
213 GrowableArray<BlockEntryInstr*>* parent) {
214 current_block->set_last_instruction(this);
215 }
216
217
218 void ThrowInstr::DiscoverBlocks(
219 BlockEntryInstr* current_block,
220 GrowableArray<BlockEntryInstr*>* preorder,
221 GrowableArray<BlockEntryInstr*>* postorder,
222 GrowableArray<BlockEntryInstr*>* parent) {
223 current_block->set_last_instruction(this);
224 }
225
226
227 void ReThrowInstr::DiscoverBlocks(
228 BlockEntryInstr* current_block,
229 GrowableArray<BlockEntryInstr*>* preorder,
230 GrowableArray<BlockEntryInstr*>* postorder,
231 GrowableArray<BlockEntryInstr*>* parent) {
232 current_block->set_last_instruction(this);
233 }
234
235
236 void BranchInstr::DiscoverBlocks( 183 void BranchInstr::DiscoverBlocks(
237 BlockEntryInstr* current_block, 184 BlockEntryInstr* current_block,
238 GrowableArray<BlockEntryInstr*>* preorder, 185 GrowableArray<BlockEntryInstr*>* preorder,
239 GrowableArray<BlockEntryInstr*>* postorder, 186 GrowableArray<BlockEntryInstr*>* postorder,
240 GrowableArray<BlockEntryInstr*>* parent) { 187 GrowableArray<BlockEntryInstr*>* parent) {
241 current_block->set_last_instruction(this); 188 current_block->set_last_instruction(this);
242 // Visit the false successor before the true successor so they appear in 189 // Visit the false successor before the true successor so they appear in
243 // true/false order in reverse postorder used as the block ordering in the 190 // true/false order in reverse postorder used as the block ordering in the
244 // nonoptimizing compiler. 191 // nonoptimizing compiler.
245 ASSERT(true_successor_ != NULL); 192 ASSERT(true_successor_ != NULL);
246 ASSERT(false_successor_ != NULL); 193 ASSERT(false_successor_ != NULL);
247 false_successor_->DiscoverBlocks(current_block, preorder, postorder, parent); 194 false_successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
248 true_successor_->DiscoverBlocks(current_block, preorder, postorder, parent); 195 true_successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
249 } 196 }
250 197
251 198
252 } // namespace dart 199 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698