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

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

Issue 196353012: VM: Fix infinite recursion in optimization of of string interpolation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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 | no next file » | 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/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/bit_vector.h" 8 #include "vm/bit_vector.h"
9 #include "vm/cpu.h" 9 #include "vm/cpu.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after
3036 // Replace StringInterpolateInstr with a constant string if all inputs are 3036 // Replace StringInterpolateInstr with a constant string if all inputs are
3037 // constant of [string, number, boolean, null]. 3037 // constant of [string, number, boolean, null].
3038 // Leave the CreateArrayInstr and StoreIndexedInstr in the stream in case 3038 // Leave the CreateArrayInstr and StoreIndexedInstr in the stream in case
3039 // deoptimization occurs. 3039 // deoptimization occurs.
3040 Definition* StringInterpolateInstr::Canonicalize(FlowGraph* flow_graph) { 3040 Definition* StringInterpolateInstr::Canonicalize(FlowGraph* flow_graph) {
3041 // The following graph structure is generated by the graph builder: 3041 // The following graph structure is generated by the graph builder:
3042 // v2 <- CreateArray(v0) 3042 // v2 <- CreateArray(v0)
3043 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value. 3043 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value.
3044 // .. 3044 // ..
3045 // v8 <- StringInterpolate(v2) 3045 // v8 <- StringInterpolate(v2)
3046
3047 // Don't compile-time fold when optimizing the interpolation function itself.
3048 if (flow_graph->parsed_function().function().raw() == CallFunction().raw()) {
3049 return this;
3050 }
3051
3046 CreateArrayInstr* create_array = value()->definition()->AsCreateArray(); 3052 CreateArrayInstr* create_array = value()->definition()->AsCreateArray();
3047 ASSERT(create_array != NULL); 3053 ASSERT(create_array != NULL);
3048 // Check if the string interpolation has only constant inputs. 3054 // Check if the string interpolation has only constant inputs.
3049 Value* num_elements = create_array->num_elements(); 3055 Value* num_elements = create_array->num_elements();
3050 if (!num_elements->BindsToConstant() || 3056 if (!num_elements->BindsToConstant() ||
3051 !num_elements->BoundConstant().IsSmi()) { 3057 !num_elements->BoundConstant().IsSmi()) {
3052 return this; 3058 return this;
3053 } 3059 }
3054 intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value(); 3060 intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value();
3055 GrowableArray<ConstantInstr*> constants(length); 3061 GrowableArray<ConstantInstr*> constants(length);
(...skipping 24 matching lines...) Expand all
3080 // Interpolate string at compile time. 3086 // Interpolate string at compile time.
3081 const Array& array_argument = 3087 const Array& array_argument =
3082 Array::Handle(Array::New(length)); 3088 Array::Handle(Array::New(length));
3083 for (intptr_t i = 0; i < constants.length(); i++) { 3089 for (intptr_t i = 0; i < constants.length(); i++) {
3084 array_argument.SetAt(i, constants[i]->value()); 3090 array_argument.SetAt(i, constants[i]->value());
3085 } 3091 }
3086 // Build argument array to pass to the interpolation function. 3092 // Build argument array to pass to the interpolation function.
3087 const Array& interpolate_arg = Array::Handle(Array::New(1)); 3093 const Array& interpolate_arg = Array::Handle(Array::New(1));
3088 interpolate_arg.SetAt(0, array_argument); 3094 interpolate_arg.SetAt(0, array_argument);
3089 // Call interpolation function. 3095 // Call interpolation function.
3090 String& concatenated = String::ZoneHandle(); 3096 const Object& result = Object::Handle(
3091 concatenated ^= 3097 DartEntry::InvokeFunction(CallFunction(), interpolate_arg));
3092 DartEntry::InvokeFunction(CallFunction(), interpolate_arg); 3098 if (result.IsUnhandledException()) {
3093 if (concatenated.IsUnhandledException()) {
3094 return this; 3099 return this;
3095 } 3100 }
3096 concatenated = Symbols::New(concatenated); 3101 ASSERT(result.IsString());
3102 const String& concatenated =
3103 String::ZoneHandle(Symbols::New(String::Cast(result)));
3097 return flow_graph->GetConstant(concatenated); 3104 return flow_graph->GetConstant(concatenated);
3098 } 3105 }
3099 3106
3100 3107
3101 InvokeMathCFunctionInstr::InvokeMathCFunctionInstr( 3108 InvokeMathCFunctionInstr::InvokeMathCFunctionInstr(
3102 ZoneGrowableArray<Value*>* inputs, 3109 ZoneGrowableArray<Value*>* inputs,
3103 intptr_t original_deopt_id, 3110 intptr_t original_deopt_id,
3104 MethodRecognizer::Kind recognized_kind) 3111 MethodRecognizer::Kind recognized_kind)
3105 : inputs_(inputs), 3112 : inputs_(inputs),
3106 recognized_kind_(recognized_kind) { 3113 recognized_kind_(recognized_kind) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 case Token::kTRUNCDIV: return 0; 3242 case Token::kTRUNCDIV: return 0;
3236 case Token::kMOD: return 1; 3243 case Token::kMOD: return 1;
3237 default: UNIMPLEMENTED(); return -1; 3244 default: UNIMPLEMENTED(); return -1;
3238 } 3245 }
3239 } 3246 }
3240 3247
3241 3248
3242 #undef __ 3249 #undef __
3243 3250
3244 } // namespace dart 3251 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698