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

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

Issue 27192005: Add new style of string interpolation optimization: new nodes, working constant folding. (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 | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/flow_graph_type_propagator.cc » ('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 6198 matching lines...) Expand 10 before | Expand all | Expand 10 after
6209 SetValue(instr, non_constant_); 6209 SetValue(instr, non_constant_);
6210 } 6210 }
6211 6211
6212 6212
6213 void ConstantPropagator::VisitStringFromCharCode( 6213 void ConstantPropagator::VisitStringFromCharCode(
6214 StringFromCharCodeInstr* instr) { 6214 StringFromCharCodeInstr* instr) {
6215 SetValue(instr, non_constant_); 6215 SetValue(instr, non_constant_);
6216 } 6216 }
6217 6217
6218 6218
6219 void ConstantPropagator::VisitStringInterpolate(StringInterpolateInstr* instr) {
6220 if (IsNonConstant(instr->constant_value())) {
6221 // Do not bother with costly analysis if we already know that the
6222 // instruction is not a constant.
6223 SetValue(instr, non_constant_);
6224 return;
6225 }
6226 // If all inputs are constant strings, numbers, booleans or null, then
6227 // constant fold.
6228 // TODO(srdjan): Also constant fold an interval of constant arguments.
6229 // v2 <- CreateArray(v0)
6230 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value.
6231 // ..
6232 // v8 <- StringInterpolate(v2)
6233 CreateArrayInstr* create_array =
6234 instr->value()->definition()->AsCreateArray();
6235 ASSERT(create_array != NULL);
6236
6237 // Check if the string interpolation has only constant inputs.
6238 for (Value::Iterator it(create_array->input_use_list());
6239 !it.Done();
6240 it.Advance()) {
6241 Instruction* curr = it.Current()->instruction();
6242 if (curr != instr) {
6243 StoreIndexedInstr* store = curr->AsStoreIndexed();
6244 ASSERT(store != NULL);
6245 const Object& value = store->value()->definition()->constant_value();
6246 if (IsNonConstant(value)) {
6247 SetValue(instr, non_constant_);
6248 return;
6249 } else if (IsUnknown(value)) {
6250 ASSERT(IsUnknown(instr->constant_value()));
6251 return;
6252 }
6253 }
6254 }
6255 // Interpolate string at compile time.
6256 const Array& value_arr =
6257 Array::Handle(Array::New(create_array->num_elements()));
6258 // Build array of literal values to interpolate.
6259 for (Value::Iterator it(create_array->input_use_list());
6260 !it.Done();
6261 it.Advance()) {
6262 Instruction* curr = it.Current()->instruction();
6263 // Skip StringInterpolateInstr.
6264 if (curr != instr) {
6265 StoreIndexedInstr* store = curr->AsStoreIndexed();
6266 ASSERT(store != NULL);
6267 Value* index_value = store->index();
6268 ASSERT(index_value->BindsToConstant() && index_value->IsSmiValue());
6269 const intptr_t ix = Smi::Cast(index_value->BoundConstant()).Value();
6270 ASSERT(IsConstant(store->value()->definition()->constant_value()));
6271 value_arr.SetAt(ix, store->value()->definition()->constant_value());
6272 }
6273 }
6274 // Build argument array to pass to the interpolation function.
6275 const Array& interpolate_arg = Array::Handle(Array::New(1));
6276 interpolate_arg.SetAt(0, value_arr);
6277 // Call interpolation function.
6278 String& concatenated = String::ZoneHandle();
6279 concatenated ^=
6280 DartEntry::InvokeFunction(instr->CallFunction(), interpolate_arg);
6281 if (concatenated.IsUnhandledException()) {
6282 SetValue(instr, non_constant_);
6283 return;
6284 }
6285
6286 concatenated = Symbols::New(concatenated);
6287 SetValue(instr, concatenated);
6288 }
6289
6290
6219 void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) { 6291 void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) {
6220 SetValue(instr, non_constant_); 6292 SetValue(instr, non_constant_);
6221 } 6293 }
6222 6294
6223 6295
6224 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) { 6296 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) {
6225 SetValue(instr, instr->value()->definition()->constant_value()); 6297 SetValue(instr, instr->value()->definition()->constant_value());
6226 } 6298 }
6227 6299
6228 6300
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
6981 !defn->IsStoreStaticField() && 7053 !defn->IsStoreStaticField() &&
6982 !defn->IsStoreVMField()) { 7054 !defn->IsStoreVMField()) {
6983 if (FLAG_trace_constant_propagation) { 7055 if (FLAG_trace_constant_propagation) {
6984 OS::Print("Constant v%" Pd " = %s\n", 7056 OS::Print("Constant v%" Pd " = %s\n",
6985 defn->ssa_temp_index(), 7057 defn->ssa_temp_index(),
6986 defn->constant_value().ToCString()); 7058 defn->constant_value().ToCString());
6987 } 7059 }
6988 ConstantInstr* constant = graph_->GetConstant(defn->constant_value()); 7060 ConstantInstr* constant = graph_->GetConstant(defn->constant_value());
6989 defn->ReplaceUsesWith(constant); 7061 defn->ReplaceUsesWith(constant);
6990 i.RemoveCurrentFromGraph(); 7062 i.RemoveCurrentFromGraph();
7063 if (defn->IsStringInterpolate()) {
7064 CreateArrayInstr* create_array = defn->AsStringInterpolate()->
7065 value()->definition()->AsCreateArray();
7066 for (Value* use = create_array->input_use_list();
7067 use != NULL;
7068 use = create_array->input_use_list()) {
7069 use->instruction()->RemoveFromGraph();
7070 }
7071 create_array->RemoveFromGraph();
7072 }
6991 } 7073 }
6992 } 7074 }
6993 7075
6994 // Replace branches where one target is unreachable with jumps. 7076 // Replace branches where one target is unreachable with jumps.
6995 BranchInstr* branch = block->last_instruction()->AsBranch(); 7077 BranchInstr* branch = block->last_instruction()->AsBranch();
6996 if (branch != NULL) { 7078 if (branch != NULL) {
6997 TargetEntryInstr* if_true = branch->true_successor(); 7079 TargetEntryInstr* if_true = branch->true_successor();
6998 TargetEntryInstr* if_false = branch->false_successor(); 7080 TargetEntryInstr* if_false = branch->false_successor();
6999 JoinEntryInstr* join = NULL; 7081 JoinEntryInstr* join = NULL;
7000 Instruction* next = NULL; 7082 Instruction* next = NULL;
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
7666 } 7748 }
7667 7749
7668 // Insert materializations at environment uses. 7750 // Insert materializations at environment uses.
7669 for (intptr_t i = 0; i < exits.length(); i++) { 7751 for (intptr_t i = 0; i < exits.length(); i++) {
7670 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); 7752 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields);
7671 } 7753 }
7672 } 7754 }
7673 7755
7674 7756
7675 } // namespace dart 7757 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/flow_graph_type_propagator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698