| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_optimizer.h" | 5 #include "vm/flow_graph_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 6295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6306 gen->RemoveAll(aliased_set_->aliased_by_effects()); | 6306 gen->RemoveAll(aliased_set_->aliased_by_effects()); |
| 6307 continue; | 6307 continue; |
| 6308 } | 6308 } |
| 6309 | 6309 |
| 6310 Definition* defn = instr->AsDefinition(); | 6310 Definition* defn = instr->AsDefinition(); |
| 6311 if (defn == NULL) { | 6311 if (defn == NULL) { |
| 6312 continue; | 6312 continue; |
| 6313 } | 6313 } |
| 6314 | 6314 |
| 6315 // For object allocation forward initial values of the fields to | 6315 // For object allocation forward initial values of the fields to |
| 6316 // subsequent loads. For simplicity we ignore escaping objects. | 6316 // subsequent loads. For skip final fields. Final fields are |
| 6317 // | |
| 6318 // The reason to ignore escaping objects is that final fields are | |
| 6319 // initialized in constructor that potentially can be not inlined into | 6317 // initialized in constructor that potentially can be not inlined into |
| 6320 // the function that we are currently optimizing. However at the same | 6318 // the function that we are currently optimizing. However at the same |
| 6321 // time we assume that values of the final fields can be forwarded | 6319 // time we assume that values of the final fields can be forwarded |
| 6322 // across side-effects. If we add 'null' as known values for these | 6320 // across side-effects. If we add 'null' as known values for these |
| 6323 // fields here we will incorrectly propagate this null across | 6321 // fields here we will incorrectly propagate this null across |
| 6324 // constructor invocation. | 6322 // constructor invocation. |
| 6325 // TODO(vegorov): record null-values at least for not final fields of | |
| 6326 // escaping object. | |
| 6327 AllocateObjectInstr* alloc = instr->AsAllocateObject(); | 6323 AllocateObjectInstr* alloc = instr->AsAllocateObject(); |
| 6328 if ((alloc != NULL) && !aliased_set_->CanBeAliased(alloc)) { | 6324 if ((alloc != NULL)) { |
| 6329 for (Value* use = alloc->input_use_list(); | 6325 for (Value* use = alloc->input_use_list(); |
| 6330 use != NULL; | 6326 use != NULL; |
| 6331 use = use->next_use()) { | 6327 use = use->next_use()) { |
| 6332 // Look for all immediate loads from this object. | 6328 // Look for all immediate loads from this object. |
| 6333 if (use->use_index() != 0) { | 6329 if (use->use_index() != 0) { |
| 6334 continue; | 6330 continue; |
| 6335 } | 6331 } |
| 6336 | 6332 |
| 6337 LoadFieldInstr* load = use->instruction()->AsLoadField(); | 6333 LoadFieldInstr* load = use->instruction()->AsLoadField(); |
| 6338 if (load != NULL) { | 6334 if (load != NULL) { |
| 6339 // Found a load. Initialize current value of the field to null for | 6335 // Found a load. Initialize current value of the field to null for |
| 6340 // normal fields, or with type arguments. | 6336 // normal fields, or with type arguments. |
| 6341 gen->Add(load->place_id()); | |
| 6342 if (out_values == NULL) out_values = CreateBlockOutValues(); | |
| 6343 | 6337 |
| 6338 // Forward for all fields for non-escaping objects and only |
| 6339 // non-final fields and type arguments for escaping ones. |
| 6340 if (aliased_set_->CanBeAliased(alloc) && |
| 6341 (load->field() != NULL) && |
| 6342 load->field()->is_final()) { |
| 6343 continue; |
| 6344 } |
| 6345 |
| 6346 Definition* forward_def = graph_->constant_null(); |
| 6344 if (alloc->ArgumentCount() > 0) { | 6347 if (alloc->ArgumentCount() > 0) { |
| 6345 ASSERT(alloc->ArgumentCount() == 1); | 6348 ASSERT(alloc->ArgumentCount() == 1); |
| 6346 intptr_t type_args_offset = | 6349 intptr_t type_args_offset = |
| 6347 alloc->cls().type_arguments_field_offset(); | 6350 alloc->cls().type_arguments_field_offset(); |
| 6348 if (load->offset_in_bytes() == type_args_offset) { | 6351 if (load->offset_in_bytes() == type_args_offset) { |
| 6349 (*out_values)[load->place_id()] = | 6352 forward_def = alloc->PushArgumentAt(0)->value()->definition(); |
| 6350 alloc->PushArgumentAt(0)->value()->definition(); | |
| 6351 continue; | |
| 6352 } | 6353 } |
| 6353 } | 6354 } |
| 6354 (*out_values)[load->place_id()] = graph_->constant_null(); | 6355 gen->Add(load->place_id()); |
| 6356 if (out_values == NULL) out_values = CreateBlockOutValues(); |
| 6357 (*out_values)[load->place_id()] = forward_def; |
| 6355 } | 6358 } |
| 6356 } | 6359 } |
| 6357 continue; | 6360 continue; |
| 6358 } | 6361 } |
| 6359 | 6362 |
| 6360 if (!IsLoadEliminationCandidate(defn)) { | 6363 if (!IsLoadEliminationCandidate(defn)) { |
| 6361 continue; | 6364 continue; |
| 6362 } | 6365 } |
| 6363 | 6366 |
| 6364 const intptr_t place_id = defn->place_id(); | 6367 const intptr_t place_id = defn->place_id(); |
| (...skipping 3559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9924 | 9927 |
| 9925 // Insert materializations at environment uses. | 9928 // Insert materializations at environment uses. |
| 9926 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) { | 9929 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) { |
| 9927 CreateMaterializationAt( | 9930 CreateMaterializationAt( |
| 9928 exits_collector_.exits()[i], alloc, alloc->cls(), *slots); | 9931 exits_collector_.exits()[i], alloc, alloc->cls(), *slots); |
| 9929 } | 9932 } |
| 9930 } | 9933 } |
| 9931 | 9934 |
| 9932 | 9935 |
| 9933 } // namespace dart | 9936 } // namespace dart |
| OLD | NEW |