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

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

Issue 24837002: Optimize string interpolation by running it at compile time if all inputs are constant. This is don… (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_builder.cc ('k') | 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 6029 matching lines...) Expand 10 before | Expand all | Expand 10 after
6040 } 6040 }
6041 6041
6042 6042
6043 void ConstantPropagator::VisitPolymorphicInstanceCall( 6043 void ConstantPropagator::VisitPolymorphicInstanceCall(
6044 PolymorphicInstanceCallInstr* instr) { 6044 PolymorphicInstanceCallInstr* instr) {
6045 SetValue(instr, non_constant_); 6045 SetValue(instr, non_constant_);
6046 } 6046 }
6047 6047
6048 6048
6049 void ConstantPropagator::VisitStaticCall(StaticCallInstr* instr) { 6049 void ConstantPropagator::VisitStaticCall(StaticCallInstr* instr) {
6050 SetValue(instr, non_constant_); 6050 MethodRecognizer::Kind recognized_kind =
6051 MethodRecognizer::RecognizeKind(instr->function());
6052 if (recognized_kind == MethodRecognizer::kStringBaseInterpolate) {
6053 // static String _interpolate(List values)
6054 //
6055 // Code for calling interpolate is generated by the compiler:
6056 // v2 <- CreateArray(v0)
6057 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value.
6058 // ..
6059 // PushArgument(v2)
6060 // v8 <- StaticCall(_interpolate, v2)
6061 // Detect that all values are constant, interpolate at compile
6062 // time.
6063 ASSERT(instr->ArgumentCount() == 1);
6064 CreateArrayInstr* create_array =
6065 instr->PushArgumentAt(0)->InputAt(0)->definition()->AsCreateArray();
Kevin Millikin (Google) 2013/09/27 10:22:39 PushArgumentAt(0)->InputAt(0)->definition() can be
srdjan 2013/10/01 19:36:49 Done.
6066 ASSERT(create_array != NULL);
6067 const Array& value_arr =
6068 Array::Handle(Array::New(create_array->num_elements()));
Kevin Millikin (Google) 2013/09/27 10:22:39 I don't think we should create this array in the h
srdjan 2013/10/01 19:36:49 Done.
6069 GrowableArray<StoreIndexedInstr*> store_instructions;
6070 // Build the array of literal values to interpolate, abort if a value is
6071 // not literal.
6072 for (Value::Iterator it(create_array->input_use_list());
6073 !it.Done();
6074 it.Advance()) {
6075 Instruction* curr = it.Current()->instruction();
6076 StoreIndexedInstr* store = curr->AsStoreIndexed();
6077 if (store == NULL) {
6078 ASSERT(curr == instr->PushArgumentAt(0));
6079 } else {
6080 store_instructions.Add(store);
6081 ASSERT(store->index()->BindsToConstant() &&
6082 store->index()->IsSmiValue());
6083 if (!store->value()->BindsToConstant()) {
Kevin Millikin (Google) 2013/09/27 10:22:39 We actually want to ask what is the analysis's com
srdjan 2013/10/01 19:36:49 Done.
6084 SetValue(instr, non_constant_);
6085 return;
6086 }
6087 const intptr_t i = Smi::Cast(store->index()->BoundConstant()).Value();
6088 value_arr.SetAt(i, store->value()->BoundConstant());
6089 }
6090 }
6091 // Build argument array to pass to the interpolation function.
6092 const Array& interpolate_arg = Array::Handle(Array::New(1));
6093 interpolate_arg.SetAt(0, value_arr);
6094 // Call interpolation function.
6095 String& concatenated = String::ZoneHandle();
6096 concatenated ^=
6097 DartEntry::InvokeFunction(instr->function(), interpolate_arg);
6098 concatenated ^= concatenated.CheckAndCanonicalize(NULL);
6099 // Remove unnecessary instructions.
6100 instr->PushArgumentAt(0)->RemoveFromGraph();
Kevin Millikin (Google) 2013/09/27 10:22:39 This is not safe. Remember the lattice is unknown
6101 for (intptr_t i = 0; i < store_instructions.length(); i++) {
6102 store_instructions[i]->RemoveFromGraph();
6103 }
6104 create_array->RemoveFromGraph();
6105
6106 SetValue(instr, concatenated);
6107 } else {
6108 SetValue(instr, non_constant_);
6109 }
6051 } 6110 }
6052 6111
6053 6112
6054 void ConstantPropagator::VisitLoadLocal(LoadLocalInstr* instr) { 6113 void ConstantPropagator::VisitLoadLocal(LoadLocalInstr* instr) {
6055 // Instruction is eliminated when translating to SSA. 6114 // Instruction is eliminated when translating to SSA.
6056 UNREACHABLE(); 6115 UNREACHABLE();
6057 } 6116 }
6058 6117
6059 6118
6060 void ConstantPropagator::VisitPushTemp(PushTempInstr* instr) { 6119 void ConstantPropagator::VisitPushTemp(PushTempInstr* instr) {
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
7655 } 7714 }
7656 7715
7657 // Insert materializations at environment uses. 7716 // Insert materializations at environment uses.
7658 for (intptr_t i = 0; i < exits.length(); i++) { 7717 for (intptr_t i = 0; i < exits.length(); i++) {
7659 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); 7718 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields);
7660 } 7719 }
7661 } 7720 }
7662 7721
7663 7722
7664 } // namespace dart 7723 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698