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.h" | 5 #include "vm/flow_graph.h" |
6 | 6 |
7 #include "vm/assert.h" | |
7 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
8 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
9 #include "vm/intermediate_language.h" | 10 #include "vm/intermediate_language.h" |
10 #include "vm/longjump.h" | 11 #include "vm/longjump.h" |
11 #include "vm/growable_array.h" | 12 #include "vm/growable_array.h" |
12 | 13 |
13 namespace dart { | 14 namespace dart { |
14 | 15 |
15 DECLARE_FLAG(bool, trace_optimization); | 16 DECLARE_FLAG(bool, trace_optimization); |
16 | 17 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 return true; // Return true so we can ASSERT the reset code. | 127 return true; // Return true so we can ASSERT the reset code. |
127 } | 128 } |
128 | 129 |
129 | 130 |
130 static void ValidateUseListsInInstruction(Instruction* instr) { | 131 static void ValidateUseListsInInstruction(Instruction* instr) { |
131 ASSERT(instr != NULL); | 132 ASSERT(instr != NULL); |
132 ASSERT(!instr->IsJoinEntry()); | 133 ASSERT(!instr->IsJoinEntry()); |
133 for (intptr_t i = 0; i < instr->InputCount(); ++i) { | 134 for (intptr_t i = 0; i < instr->InputCount(); ++i) { |
134 Value* use = instr->InputAt(i); | 135 Value* use = instr->InputAt(i); |
135 ASSERT(use->use_index() == i); | 136 ASSERT(use->use_index() == i); |
136 ASSERT(1 == MembershipCount(use, use->definition()->input_use_list())); | 137 SLOW_ASSERT(1 == MembershipCount(use, use->definition()->input_use_list())); |
siva
2012/10/01 23:35:40
It sounds like this needs to be
ASSERT(VerifyMembe
| |
137 } | 138 } |
138 if (instr->env() != NULL) { | 139 if (instr->env() != NULL) { |
139 intptr_t use_index = 0; | 140 intptr_t use_index = 0; |
140 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { | 141 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { |
141 Value* use = it.CurrentValue(); | 142 Value* use = it.CurrentValue(); |
142 ASSERT(use->use_index() == use_index++); | 143 ASSERT(use->use_index() == use_index++); |
143 ASSERT(1 == MembershipCount(use, use->definition()->env_use_list())); | 144 SLOW_ASSERT(1 == MembershipCount(use, use->definition()->env_use_list())); |
144 } | 145 } |
145 } | 146 } |
146 Definition* defn = instr->AsDefinition(); | 147 Definition* defn = instr->AsDefinition(); |
147 if (defn != NULL) { | 148 if (defn != NULL) { |
148 for (Value* use = defn->input_use_list(); | 149 for (Value* use = defn->input_use_list(); |
149 use != NULL; | 150 use != NULL; |
150 use = use->next_use()) { | 151 use = use->next_use()) { |
151 ASSERT(defn == use->definition()); | 152 ASSERT(defn == use->definition()); |
152 ASSERT(use == use->instruction()->InputAt(use->use_index())); | 153 ASSERT(use == use->instruction()->InputAt(use->use_index())); |
153 } | 154 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 } | 197 } |
197 | 198 |
198 | 199 |
199 static void RecordInputUses(Instruction* instr) { | 200 static void RecordInputUses(Instruction* instr) { |
200 ASSERT(instr != NULL); | 201 ASSERT(instr != NULL); |
201 for (intptr_t i = 0; i < instr->InputCount(); ++i) { | 202 for (intptr_t i = 0; i < instr->InputCount(); ++i) { |
202 Value* use = instr->InputAt(i); | 203 Value* use = instr->InputAt(i); |
203 ASSERT(use->instruction() == NULL); | 204 ASSERT(use->instruction() == NULL); |
204 ASSERT(use->use_index() == -1); | 205 ASSERT(use->use_index() == -1); |
205 ASSERT(use->next_use() == NULL); | 206 ASSERT(use->next_use() == NULL); |
206 DEBUG_ASSERT(0 == MembershipCount(use, | 207 SLOW_ASSERT(0 == MembershipCount(use, use->definition()->input_use_list())); |
207 use->definition()->input_use_list())); | |
208 use->set_instruction(instr); | 208 use->set_instruction(instr); |
209 use->set_use_index(i); | 209 use->set_use_index(i); |
210 use->AddToInputUseList(); | 210 use->AddToInputUseList(); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 | 214 |
215 static void RecordEnvUses(Instruction* instr) { | 215 static void RecordEnvUses(Instruction* instr) { |
216 ASSERT(instr != NULL); | 216 ASSERT(instr != NULL); |
217 if (instr->env() == NULL) return; | 217 if (instr->env() == NULL) return; |
218 intptr_t use_index = 0; | 218 intptr_t use_index = 0; |
219 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { | 219 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { |
220 Value* use = it.CurrentValue(); | 220 Value* use = it.CurrentValue(); |
221 ASSERT(use->instruction() == NULL); | 221 ASSERT(use->instruction() == NULL); |
222 ASSERT(use->use_index() == -1); | 222 ASSERT(use->use_index() == -1); |
223 ASSERT(use->next_use() == NULL); | 223 ASSERT(use->next_use() == NULL); |
224 DEBUG_ASSERT(0 == MembershipCount(use, use->definition()->env_use_list())); | 224 SLOW_ASSERT(0 == MembershipCount(use, use->definition()->env_use_list())); |
225 use->set_instruction(instr); | 225 use->set_instruction(instr); |
226 use->set_use_index(use_index++); | 226 use->set_use_index(use_index++); |
227 use->AddToEnvUseList(); | 227 use->AddToEnvUseList(); |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 | 231 |
232 static void ComputeUseListsRecursive(BlockEntryInstr* block) { | 232 static void ComputeUseListsRecursive(BlockEntryInstr* block) { |
233 // Clear phi definitions. | 233 // Clear phi definitions. |
234 JoinEntryInstr* join = block->AsJoinEntry(); | 234 JoinEntryInstr* join = block->AsJoinEntry(); |
(...skipping 22 matching lines...) Expand all Loading... | |
257 intptr_t pred_index = join->IndexOfPredecessor(block); | 257 intptr_t pred_index = join->IndexOfPredecessor(block); |
258 ASSERT(pred_index >= 0); | 258 ASSERT(pred_index >= 0); |
259 if (join->phis() != NULL) { | 259 if (join->phis() != NULL) { |
260 for (intptr_t i = 0; i < join->phis()->length(); ++i) { | 260 for (intptr_t i = 0; i < join->phis()->length(); ++i) { |
261 PhiInstr* phi = (*join->phis())[i]; | 261 PhiInstr* phi = (*join->phis())[i]; |
262 if (phi == NULL) continue; | 262 if (phi == NULL) continue; |
263 Value* use = phi->InputAt(pred_index); | 263 Value* use = phi->InputAt(pred_index); |
264 ASSERT(use->instruction() == NULL); | 264 ASSERT(use->instruction() == NULL); |
265 ASSERT(use->use_index() == -1); | 265 ASSERT(use->use_index() == -1); |
266 ASSERT(use->next_use() == NULL); | 266 ASSERT(use->next_use() == NULL); |
267 DEBUG_ASSERT(0 == MembershipCount(use, | 267 SLOW_ASSERT(0 == MembershipCount(use, |
268 use->definition()->input_use_list())); | 268 use->definition()->input_use_list())); |
269 use->set_instruction(phi); | 269 use->set_instruction(phi); |
270 use->set_use_index(pred_index); | 270 use->set_use_index(pred_index); |
271 use->AddToInputUseList(); | 271 use->AddToInputUseList(); |
272 } | 272 } |
273 } | 273 } |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 | 277 |
278 void FlowGraph::ComputeUseLists() { | 278 void FlowGraph::ComputeUseLists() { |
279 DEBUG_ASSERT(ResetUseLists()); | 279 DEBUG_ASSERT(ResetUseLists()); |
280 // Clear initial definitions. | 280 // Clear initial definitions. |
281 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { | 281 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { |
282 ClearUseLists((*graph_entry_->initial_definitions())[i]); | 282 ClearUseLists((*graph_entry_->initial_definitions())[i]); |
283 } | 283 } |
284 ComputeUseListsRecursive(graph_entry_); | 284 ComputeUseListsRecursive(graph_entry_); |
285 DEBUG_ASSERT(ValidateUseLists()); | 285 SLOW_ASSERT(ValidateUseLists()); |
siva
2012/10/01 23:35:40
Ditto comment, this would be
ASSERT(ValidateUseLis
| |
286 } | 286 } |
287 | 287 |
288 | 288 |
289 void FlowGraph::ComputeSSA(intptr_t next_virtual_register_number) { | 289 void FlowGraph::ComputeSSA(intptr_t next_virtual_register_number) { |
290 current_ssa_temp_index_ = next_virtual_register_number; | 290 current_ssa_temp_index_ = next_virtual_register_number; |
291 GrowableArray<BitVector*> dominance_frontier; | 291 GrowableArray<BitVector*> dominance_frontier; |
292 ComputeDominators(&dominance_frontier); | 292 ComputeDominators(&dominance_frontier); |
293 InsertPhis(preorder_, assigned_vars_, dominance_frontier); | 293 InsertPhis(preorder_, assigned_vars_, dominance_frontier); |
294 GrowableArray<PhiInstr*> live_phis; | 294 GrowableArray<PhiInstr*> live_phis; |
295 // Rename uses to reference inserted phis where appropriate. | 295 // Rename uses to reference inserted phis where appropriate. |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 // TODO(zerny): Support multiple exits. | 789 // TODO(zerny): Support multiple exits. |
790 UNREACHABLE(); | 790 UNREACHABLE(); |
791 } | 791 } |
792 | 792 |
793 // TODO(zerny): Adjust pre/post orders. | 793 // TODO(zerny): Adjust pre/post orders. |
794 // TODO(zerny): Update dominator tree. | 794 // TODO(zerny): Update dominator tree. |
795 } | 795 } |
796 | 796 |
797 | 797 |
798 } // namespace dart | 798 } // namespace dart |
OLD | NEW |