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

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

Issue 34523007: Move String interpolation constant folding from constant propagator to canonicalizer (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | « no previous file | runtime/vm/intermediate_language.h » ('j') | 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) 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/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 6392 matching lines...) Expand 10 before | Expand all | Expand 10 after
6403 } 6403 }
6404 6404
6405 6405
6406 void ConstantPropagator::VisitStringFromCharCode( 6406 void ConstantPropagator::VisitStringFromCharCode(
6407 StringFromCharCodeInstr* instr) { 6407 StringFromCharCodeInstr* instr) {
6408 SetValue(instr, non_constant_); 6408 SetValue(instr, non_constant_);
6409 } 6409 }
6410 6410
6411 6411
6412 void ConstantPropagator::VisitStringInterpolate(StringInterpolateInstr* instr) { 6412 void ConstantPropagator::VisitStringInterpolate(StringInterpolateInstr* instr) {
6413 // TODO(srdjan): Remove the code below and enable constant folding once
6414 // issue resolved.
6415 SetValue(instr, non_constant_); 6413 SetValue(instr, non_constant_);
6416 return; 6414 return;
6417
6418 if (IsNonConstant(instr->constant_value())) {
6419 // Do not bother with costly analysis if we already know that the
6420 // instruction is not a constant.
6421 SetValue(instr, non_constant_);
6422 return;
6423 }
6424 // If all inputs are constant strings, numbers, booleans or null, then
6425 // constant fold.
6426 // TODO(srdjan): Also constant fold an interval of constant arguments.
6427 // v2 <- CreateArray(v0)
6428 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value.
6429 // ..
6430 // v8 <- StringInterpolate(v2)
6431 CreateArrayInstr* create_array =
6432 instr->value()->definition()->AsCreateArray();
6433 ASSERT(create_array != NULL);
6434
6435 // Check if the string interpolation has only constant inputs.
6436 for (Value::Iterator it(create_array->input_use_list());
6437 !it.Done();
6438 it.Advance()) {
6439 Instruction* curr = it.Current()->instruction();
6440 if (curr != instr) {
6441 StoreIndexedInstr* store = curr->AsStoreIndexed();
6442 ASSERT(store != NULL);
6443 const Object& value = store->value()->definition()->constant_value();
6444 if (IsNonConstant(value)) {
6445 SetValue(instr, non_constant_);
6446 return;
6447 } else if (IsUnknown(value)) {
6448 ASSERT(IsUnknown(instr->constant_value()));
6449 return;
6450 }
6451 }
6452 }
6453 // Interpolate string at compile time.
6454 const Array& value_arr =
6455 Array::Handle(Array::New(create_array->num_elements()));
6456 // Build array of literal values to interpolate.
6457 for (Value::Iterator it(create_array->input_use_list());
6458 !it.Done();
6459 it.Advance()) {
6460 Instruction* curr = it.Current()->instruction();
6461 // Skip StringInterpolateInstr.
6462 if (curr != instr) {
6463 StoreIndexedInstr* store = curr->AsStoreIndexed();
6464 ASSERT(store != NULL);
6465 Value* index_value = store->index();
6466 ASSERT(index_value->BindsToConstant() && index_value->IsSmiValue());
6467 const intptr_t ix = Smi::Cast(index_value->BoundConstant()).Value();
6468 ASSERT(IsConstant(store->value()->definition()->constant_value()));
6469 value_arr.SetAt(ix, store->value()->definition()->constant_value());
6470 }
6471 }
6472 // Build argument array to pass to the interpolation function.
6473 const Array& interpolate_arg = Array::Handle(Array::New(1));
6474 interpolate_arg.SetAt(0, value_arr);
6475 // Call interpolation function.
6476 String& concatenated = String::ZoneHandle();
6477 concatenated ^=
6478 DartEntry::InvokeFunction(instr->CallFunction(), interpolate_arg);
6479 if (concatenated.IsUnhandledException()) {
6480 SetValue(instr, non_constant_);
6481 return;
6482 }
6483
6484 concatenated = Symbols::New(concatenated);
6485 SetValue(instr, concatenated);
6486 } 6415 }
6487 6416
6488 6417
6489 void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) { 6418 void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) {
6490 SetValue(instr, non_constant_); 6419 SetValue(instr, non_constant_);
6491 } 6420 }
6492 6421
6493 6422
6494 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) { 6423 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) {
6495 SetValue(instr, instr->value()->definition()->constant_value()); 6424 SetValue(instr, instr->value()->definition()->constant_value());
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
7251 !defn->IsStoreStaticField() && 7180 !defn->IsStoreStaticField() &&
7252 !defn->IsStoreVMField()) { 7181 !defn->IsStoreVMField()) {
7253 if (FLAG_trace_constant_propagation) { 7182 if (FLAG_trace_constant_propagation) {
7254 OS::Print("Constant v%" Pd " = %s\n", 7183 OS::Print("Constant v%" Pd " = %s\n",
7255 defn->ssa_temp_index(), 7184 defn->ssa_temp_index(),
7256 defn->constant_value().ToCString()); 7185 defn->constant_value().ToCString());
7257 } 7186 }
7258 ConstantInstr* constant = graph_->GetConstant(defn->constant_value()); 7187 ConstantInstr* constant = graph_->GetConstant(defn->constant_value());
7259 defn->ReplaceUsesWith(constant); 7188 defn->ReplaceUsesWith(constant);
7260 i.RemoveCurrentFromGraph(); 7189 i.RemoveCurrentFromGraph();
7261 if (defn->IsStringInterpolate()) {
7262 CreateArrayInstr* create_array = defn->AsStringInterpolate()->
7263 value()->definition()->AsCreateArray();
7264 for (Value* use = create_array->input_use_list();
7265 use != NULL;
7266 use = create_array->input_use_list()) {
7267 use->instruction()->RemoveFromGraph();
7268 }
7269 create_array->RemoveFromGraph();
7270 }
7271 } 7190 }
7272 } 7191 }
7273 7192
7274 // Replace branches where one target is unreachable with jumps. 7193 // Replace branches where one target is unreachable with jumps.
7275 BranchInstr* branch = block->last_instruction()->AsBranch(); 7194 BranchInstr* branch = block->last_instruction()->AsBranch();
7276 if (branch != NULL) { 7195 if (branch != NULL) {
7277 TargetEntryInstr* if_true = branch->true_successor(); 7196 TargetEntryInstr* if_true = branch->true_successor();
7278 TargetEntryInstr* if_false = branch->false_successor(); 7197 TargetEntryInstr* if_false = branch->false_successor();
7279 JoinEntryInstr* join = NULL; 7198 JoinEntryInstr* join = NULL;
7280 Instruction* next = NULL; 7199 Instruction* next = NULL;
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
7946 } 7865 }
7947 7866
7948 // Insert materializations at environment uses. 7867 // Insert materializations at environment uses.
7949 for (intptr_t i = 0; i < exits.length(); i++) { 7868 for (intptr_t i = 0; i < exits.length(); i++) {
7950 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); 7869 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields);
7951 } 7870 }
7952 } 7871 }
7953 7872
7954 7873
7955 } // namespace dart 7874 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698