| 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/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 static void ResetUseListsInInstruction(Instruction* instr) { | 100 static void ResetUseListsInInstruction(Instruction* instr) { |
| 101 Definition* defn = instr->AsDefinition(); | 101 Definition* defn = instr->AsDefinition(); |
| 102 if (defn != NULL) { | 102 if (defn != NULL) { |
| 103 defn->set_input_use_list(NULL); | 103 defn->set_input_use_list(NULL); |
| 104 defn->set_env_use_list(NULL); | 104 defn->set_env_use_list(NULL); |
| 105 } | 105 } |
| 106 for (intptr_t i = 0; i < instr->InputCount(); ++i) { | 106 for (intptr_t i = 0; i < instr->InputCount(); ++i) { |
| 107 Value* use = instr->InputAt(i); | 107 Value* use = instr->InputAt(i); |
| 108 use->set_instruction(NULL); | 108 use->set_instruction(NULL); |
| 109 use->set_use_index(-1); | 109 use->set_use_index(-1); |
| 110 use->set_previous_use(NULL); |
| 110 use->set_next_use(NULL); | 111 use->set_next_use(NULL); |
| 111 } | 112 } |
| 112 if (instr->env() != NULL) { | 113 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { |
| 113 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { | 114 Value* use = it.CurrentValue(); |
| 114 Value* use = it.CurrentValue(); | 115 use->set_instruction(NULL); |
| 115 use->set_instruction(NULL); | 116 use->set_use_index(-1); |
| 116 use->set_use_index(-1); | 117 use->set_previous_use(NULL); |
| 117 use->set_next_use(NULL); | 118 use->set_next_use(NULL); |
| 118 } | |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 | 122 |
| 123 bool FlowGraph::ResetUseLists() { | 123 bool FlowGraph::ResetUseLists() { |
| 124 // Reset initial definitions. | 124 // Reset initial definitions. |
| 125 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { | 125 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { |
| 126 ResetUseListsInInstruction((*graph_entry_->initial_definitions())[i]); | 126 ResetUseListsInInstruction((*graph_entry_->initial_definitions())[i]); |
| 127 } | 127 } |
| 128 | 128 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 157 intptr_t use_index = 0; | 157 intptr_t use_index = 0; |
| 158 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { | 158 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { |
| 159 Value* use = it.CurrentValue(); | 159 Value* use = it.CurrentValue(); |
| 160 ASSERT(use->use_index() == use_index++); | 160 ASSERT(use->use_index() == use_index++); |
| 161 ASSERT(!FLAG_verify_compiler || | 161 ASSERT(!FLAG_verify_compiler || |
| 162 (1 == MembershipCount(use, use->definition()->env_use_list()))); | 162 (1 == MembershipCount(use, use->definition()->env_use_list()))); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 Definition* defn = instr->AsDefinition(); | 165 Definition* defn = instr->AsDefinition(); |
| 166 if (defn != NULL) { | 166 if (defn != NULL) { |
| 167 for (Value* use = defn->input_use_list(); | 167 Value* prev = NULL; |
| 168 use != NULL; | 168 Value* curr = defn->input_use_list(); |
| 169 use = use->next_use()) { | 169 while (curr != NULL) { |
| 170 ASSERT(defn == use->definition()); | 170 ASSERT(prev == curr->previous_use()); |
| 171 ASSERT(use == use->instruction()->InputAt(use->use_index())); | 171 ASSERT(defn == curr->definition()); |
| 172 ASSERT(curr == curr->instruction()->InputAt(curr->use_index())); |
| 173 prev = curr; |
| 174 curr = curr->next_use(); |
| 172 } | 175 } |
| 173 for (Value* use = defn->env_use_list(); | 176 |
| 174 use != NULL; | 177 prev = NULL; |
| 175 use = use->next_use()) { | 178 curr = defn->env_use_list(); |
| 176 ASSERT(defn == use->definition()); | 179 while (curr != NULL) { |
| 177 ASSERT(use == | 180 ASSERT(prev == curr->previous_use()); |
| 178 use->instruction()->env()->ValueAtUseIndex(use->use_index())); | 181 ASSERT(defn == curr->definition()); |
| 182 ASSERT(curr == |
| 183 curr->instruction()->env()->ValueAtUseIndex(curr->use_index())); |
| 184 prev = curr; |
| 185 curr = curr->next_use(); |
| 179 } | 186 } |
| 180 } | 187 } |
| 181 } | 188 } |
| 182 | 189 |
| 183 | 190 |
| 184 bool FlowGraph::ValidateUseLists() { | 191 bool FlowGraph::ValidateUseLists() { |
| 185 // Validate initial definitions. | 192 // Validate initial definitions. |
| 186 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { | 193 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { |
| 187 ValidateUseListsInInstruction((*graph_entry_->initial_definitions())[i]); | 194 ValidateUseListsInInstruction((*graph_entry_->initial_definitions())[i]); |
| 188 } | 195 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 213 defn->set_env_use_list(NULL); | 220 defn->set_env_use_list(NULL); |
| 214 } | 221 } |
| 215 | 222 |
| 216 | 223 |
| 217 static void RecordInputUses(Instruction* instr) { | 224 static void RecordInputUses(Instruction* instr) { |
| 218 ASSERT(instr != NULL); | 225 ASSERT(instr != NULL); |
| 219 for (intptr_t i = 0; i < instr->InputCount(); ++i) { | 226 for (intptr_t i = 0; i < instr->InputCount(); ++i) { |
| 220 Value* use = instr->InputAt(i); | 227 Value* use = instr->InputAt(i); |
| 221 ASSERT(use->instruction() == NULL); | 228 ASSERT(use->instruction() == NULL); |
| 222 ASSERT(use->use_index() == -1); | 229 ASSERT(use->use_index() == -1); |
| 230 ASSERT(use->previous_use() == NULL); |
| 223 ASSERT(use->next_use() == NULL); | 231 ASSERT(use->next_use() == NULL); |
| 224 DEBUG_ASSERT(!FLAG_verify_compiler || | 232 DEBUG_ASSERT(!FLAG_verify_compiler || |
| 225 (0 == MembershipCount(use, use->definition()->input_use_list()))); | 233 (0 == MembershipCount(use, use->definition()->input_use_list()))); |
| 226 use->set_instruction(instr); | 234 use->set_instruction(instr); |
| 227 use->set_use_index(i); | 235 use->set_use_index(i); |
| 228 use->AddToInputUseList(); | 236 use->AddToInputUseList(); |
| 229 } | 237 } |
| 230 } | 238 } |
| 231 | 239 |
| 232 | 240 |
| 233 static void RecordEnvUses(Instruction* instr) { | 241 static void RecordEnvUses(Instruction* instr) { |
| 234 ASSERT(instr != NULL); | 242 ASSERT(instr != NULL); |
| 235 if (instr->env() == NULL) return; | 243 if (instr->env() == NULL) return; |
| 236 intptr_t use_index = 0; | 244 intptr_t use_index = 0; |
| 237 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { | 245 for (Environment::DeepIterator it(instr->env()); !it.Done(); it.Advance()) { |
| 238 Value* use = it.CurrentValue(); | 246 Value* use = it.CurrentValue(); |
| 239 ASSERT(use->instruction() == NULL); | 247 ASSERT(use->instruction() == NULL); |
| 240 ASSERT(use->use_index() == -1); | 248 ASSERT(use->use_index() == -1); |
| 249 ASSERT(use->previous_use() == NULL); |
| 241 ASSERT(use->next_use() == NULL); | 250 ASSERT(use->next_use() == NULL); |
| 242 DEBUG_ASSERT(!FLAG_verify_compiler || | 251 DEBUG_ASSERT(!FLAG_verify_compiler || |
| 243 (0 == MembershipCount(use, use->definition()->env_use_list()))); | 252 (0 == MembershipCount(use, use->definition()->env_use_list()))); |
| 244 use->set_instruction(instr); | 253 use->set_instruction(instr); |
| 245 use->set_use_index(use_index++); | 254 use->set_use_index(use_index++); |
| 246 use->AddToEnvUseList(); | 255 use->AddToEnvUseList(); |
| 247 } | 256 } |
| 248 } | 257 } |
| 249 | 258 |
| 250 | 259 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 275 block->last_instruction()->SuccessorAt(0)->AsJoinEntry(); | 284 block->last_instruction()->SuccessorAt(0)->AsJoinEntry(); |
| 276 intptr_t pred_index = join->IndexOfPredecessor(block); | 285 intptr_t pred_index = join->IndexOfPredecessor(block); |
| 277 ASSERT(pred_index >= 0); | 286 ASSERT(pred_index >= 0); |
| 278 if (join->phis() != NULL) { | 287 if (join->phis() != NULL) { |
| 279 for (intptr_t i = 0; i < join->phis()->length(); ++i) { | 288 for (intptr_t i = 0; i < join->phis()->length(); ++i) { |
| 280 PhiInstr* phi = (*join->phis())[i]; | 289 PhiInstr* phi = (*join->phis())[i]; |
| 281 if (phi == NULL) continue; | 290 if (phi == NULL) continue; |
| 282 Value* use = phi->InputAt(pred_index); | 291 Value* use = phi->InputAt(pred_index); |
| 283 ASSERT(use->instruction() == NULL); | 292 ASSERT(use->instruction() == NULL); |
| 284 ASSERT(use->use_index() == -1); | 293 ASSERT(use->use_index() == -1); |
| 294 ASSERT(use->previous_use() == NULL); |
| 285 ASSERT(use->next_use() == NULL); | 295 ASSERT(use->next_use() == NULL); |
| 286 DEBUG_ASSERT(!FLAG_verify_compiler || | 296 DEBUG_ASSERT(!FLAG_verify_compiler || |
| 287 (0 == MembershipCount(use, use->definition()->input_use_list()))); | 297 (0 == MembershipCount(use, use->definition()->input_use_list()))); |
| 288 use->set_instruction(phi); | 298 use->set_instruction(phi); |
| 289 use->set_use_index(pred_index); | 299 use->set_use_index(pred_index); |
| 290 use->AddToInputUseList(); | 300 use->AddToInputUseList(); |
| 291 } | 301 } |
| 292 } | 302 } |
| 293 } | 303 } |
| 294 } | 304 } |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 !it.Done(); | 785 !it.Done(); |
| 776 it.Advance()) { | 786 it.Advance()) { |
| 777 ++size; | 787 ++size; |
| 778 } | 788 } |
| 779 } | 789 } |
| 780 return size; | 790 return size; |
| 781 } | 791 } |
| 782 | 792 |
| 783 | 793 |
| 784 } // namespace dart | 794 } // namespace dart |
| OLD | NEW |