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

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

Issue 2891053003: Add support for converted closures with explicit contexts to VM (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/kernel_binary_flowgraph.h" 5 #include "vm/kernel_binary_flowgraph.h"
6 6
7 #include "vm/longjump.h" 7 #include "vm/longjump.h"
8 #include "vm/object_store.h" 8 #include "vm/object_store.h"
9 9
10 #if !defined(DART_PRECOMPILED_RUNTIME) 10 #if !defined(DART_PRECOMPILED_RUNTIME)
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 case kPositiveIntLiteral: 1220 case kPositiveIntLiteral:
1221 return BuildIntLiteral(false, position); 1221 return BuildIntLiteral(false, position);
1222 case kDoubleLiteral: 1222 case kDoubleLiteral:
1223 return BuildDoubleLiteral(position); 1223 return BuildDoubleLiteral(position);
1224 case kTrueLiteral: 1224 case kTrueLiteral:
1225 return BuildBoolLiteral(true, position); 1225 return BuildBoolLiteral(true, position);
1226 case kFalseLiteral: 1226 case kFalseLiteral:
1227 return BuildBoolLiteral(false, position); 1227 return BuildBoolLiteral(false, position);
1228 case kNullLiteral: 1228 case kNullLiteral:
1229 return BuildNullLiteral(position); 1229 return BuildNullLiteral(position);
1230 case kVectorCreation:
1231 return BuildVectorCreation(position);
1232 case kVectorGet:
1233 return BuildVectorGet(position);
1234 case kVectorSet:
1235 return BuildVectorSet(position);
1236 case kVectorCopy:
1237 return BuildVectorCopy(position);
1238 case kClosureCreation:
1239 return BuildClosureCreation(position);
1230 default: 1240 default:
1231 UNREACHABLE(); 1241 UNREACHABLE();
1232 } 1242 }
1233 1243
1234 return Fragment(); 1244 return Fragment();
1235 } 1245 }
1236 1246
1237 Fragment StreamingFlowGraphBuilder::BuildStatement() { 1247 Fragment StreamingFlowGraphBuilder::BuildStatement() {
1238 Tag tag = ReadTag(); // read tag. 1248 Tag tag = ReadTag(); // read tag.
1239 switch (tag) { 1249 switch (tag) {
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 1935
1926 GrowableArray<YieldContinuation>& 1936 GrowableArray<YieldContinuation>&
1927 StreamingFlowGraphBuilder::yield_continuations() { 1937 StreamingFlowGraphBuilder::yield_continuations() {
1928 return flow_graph_builder_->yield_continuations_; 1938 return flow_graph_builder_->yield_continuations_;
1929 } 1939 }
1930 1940
1931 Value* StreamingFlowGraphBuilder::stack() { 1941 Value* StreamingFlowGraphBuilder::stack() {
1932 return flow_graph_builder_->stack_; 1942 return flow_graph_builder_->stack_;
1933 } 1943 }
1934 1944
1945 void StreamingFlowGraphBuilder::Push(Definition* definition) {
1946 flow_graph_builder_->Push(definition);
1947 }
1948
1935 Value* StreamingFlowGraphBuilder::Pop() { 1949 Value* StreamingFlowGraphBuilder::Pop() {
1936 return flow_graph_builder_->Pop(); 1950 return flow_graph_builder_->Pop();
1937 } 1951 }
1938 1952
1939 Tag StreamingFlowGraphBuilder::PeekArgumentsFirstPositionalTag() { 1953 Tag StreamingFlowGraphBuilder::PeekArgumentsFirstPositionalTag() {
1940 // read parts of arguments, then go back to before doing so. 1954 // read parts of arguments, then go back to before doing so.
1941 intptr_t offset = ReaderOffset(); 1955 intptr_t offset = ReaderOffset();
1942 ReadUInt(); // read number of arguments. 1956 ReadUInt(); // read number of arguments.
1943 1957
1944 // List of types. 1958 // List of types.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 Fragment StreamingFlowGraphBuilder::StrictCompare(Token::Kind kind, 2119 Fragment StreamingFlowGraphBuilder::StrictCompare(Token::Kind kind,
2106 bool number_check) { 2120 bool number_check) {
2107 return flow_graph_builder_->StrictCompare(kind, number_check); 2121 return flow_graph_builder_->StrictCompare(kind, number_check);
2108 } 2122 }
2109 2123
2110 Fragment StreamingFlowGraphBuilder::AllocateObject(const dart::Class& klass, 2124 Fragment StreamingFlowGraphBuilder::AllocateObject(const dart::Class& klass,
2111 intptr_t argument_count) { 2125 intptr_t argument_count) {
2112 return flow_graph_builder_->AllocateObject(klass, argument_count); 2126 return flow_graph_builder_->AllocateObject(klass, argument_count);
2113 } 2127 }
2114 2128
2129 Fragment StreamingFlowGraphBuilder::AllocateObject(
2130 const dart::Class& klass,
2131 const Function& closure_function) {
2132 return flow_graph_builder_->AllocateObject(klass, closure_function);
2133 }
2134
2135 Fragment StreamingFlowGraphBuilder::AllocateContext(int size) {
2136 return flow_graph_builder_->AllocateContext(size);
2137 }
2138
2139 Fragment StreamingFlowGraphBuilder::LoadField(intptr_t offset) {
2140 return flow_graph_builder_->LoadField(offset);
2141 }
2142
2115 Fragment StreamingFlowGraphBuilder::InstanceCall(TokenPosition position, 2143 Fragment StreamingFlowGraphBuilder::InstanceCall(TokenPosition position,
2116 const dart::String& name, 2144 const dart::String& name,
2117 Token::Kind kind, 2145 Token::Kind kind,
2118 intptr_t argument_count, 2146 intptr_t argument_count,
2119 const Array& argument_names, 2147 const Array& argument_names,
2120 intptr_t num_args_checked) { 2148 intptr_t num_args_checked) {
2121 return flow_graph_builder_->InstanceCall(position, name, kind, argument_count, 2149 return flow_graph_builder_->InstanceCall(position, name, kind, argument_count,
2122 argument_names, num_args_checked); 2150 argument_names, num_args_checked);
2123 } 2151 }
2124 2152
2125 Fragment StreamingFlowGraphBuilder::StoreLocal(TokenPosition position, 2153 Fragment StreamingFlowGraphBuilder::StoreLocal(TokenPosition position,
2126 LocalVariable* variable) { 2154 LocalVariable* variable) {
2127 return flow_graph_builder_->StoreLocal(position, variable); 2155 return flow_graph_builder_->StoreLocal(position, variable);
2128 } 2156 }
2129 2157
2130 Fragment StreamingFlowGraphBuilder::StoreStaticField(TokenPosition position, 2158 Fragment StreamingFlowGraphBuilder::StoreStaticField(TokenPosition position,
2131 const dart::Field& field) { 2159 const dart::Field& field) {
2132 return flow_graph_builder_->StoreStaticField(position, field); 2160 return flow_graph_builder_->StoreStaticField(position, field);
2133 } 2161 }
2134 2162
2163 Fragment StreamingFlowGraphBuilder::StoreInstanceField(TokenPosition position,
2164 intptr_t offset) {
2165 return flow_graph_builder_->StoreInstanceField(position, offset);
2166 }
2167
2135 Fragment StreamingFlowGraphBuilder::StringInterpolate(TokenPosition position) { 2168 Fragment StreamingFlowGraphBuilder::StringInterpolate(TokenPosition position) {
2136 return flow_graph_builder_->StringInterpolate(position); 2169 return flow_graph_builder_->StringInterpolate(position);
2137 } 2170 }
2138 2171
2139 Fragment StreamingFlowGraphBuilder::StringInterpolateSingle( 2172 Fragment StreamingFlowGraphBuilder::StringInterpolateSingle(
2140 TokenPosition position) { 2173 TokenPosition position) {
2141 return flow_graph_builder_->StringInterpolateSingle(position); 2174 return flow_graph_builder_->StringInterpolateSingle(position);
2142 } 2175 }
2143 2176
2144 Fragment StreamingFlowGraphBuilder::ThrowTypeError() { 2177 Fragment StreamingFlowGraphBuilder::ThrowTypeError() {
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 3071
3039 // Let condition be always true. 3072 // Let condition be always true.
3040 instructions += Constant(Bool::True()); 3073 instructions += Constant(Bool::True());
3041 } else { 3074 } else {
3042 instructions += PushArgument(); 3075 instructions += PushArgument();
3043 3076
3044 // See if simple instanceOf is applicable. 3077 // See if simple instanceOf is applicable.
3045 if (dart::FlowGraphBuilder::SimpleInstanceOfType(type)) { 3078 if (dart::FlowGraphBuilder::SimpleInstanceOfType(type)) {
3046 instructions += Constant(type); 3079 instructions += Constant(type);
3047 instructions += PushArgument(); // Type. 3080 instructions += PushArgument(); // Type.
3048 instructions += InstanceCall(position, dart::Library::PrivateCoreLibName( 3081 instructions += InstanceCall(
3049 Symbols::_simpleInstanceOf()), 3082 position,
3050 Token::kIS, 2, 2); // 2 checked arguments. 3083 dart::Library::PrivateCoreLibName(Symbols::_simpleInstanceOf()),
3084 Token::kIS, 2, 2); // 2 checked arguments.
3051 return instructions; 3085 return instructions;
3052 } 3086 }
3053 3087
3054 if (!type.IsInstantiated(kCurrentClass)) { 3088 if (!type.IsInstantiated(kCurrentClass)) {
3055 instructions += LoadInstantiatorTypeArguments(); 3089 instructions += LoadInstantiatorTypeArguments();
3056 } else { 3090 } else {
3057 instructions += NullConstant(); 3091 instructions += NullConstant();
3058 } 3092 }
3059 instructions += PushArgument(); // Instantiator type arguments. 3093 instructions += PushArgument(); // Instantiator type arguments.
3060 3094
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
3365 3399
3366 return Constant(Bool::Get(value)); 3400 return Constant(Bool::Get(value));
3367 } 3401 }
3368 3402
3369 Fragment StreamingFlowGraphBuilder::BuildNullLiteral(TokenPosition* position) { 3403 Fragment StreamingFlowGraphBuilder::BuildNullLiteral(TokenPosition* position) {
3370 if (position != NULL) *position = TokenPosition::kNoSource; 3404 if (position != NULL) *position = TokenPosition::kNoSource;
3371 3405
3372 return Constant(Instance::ZoneHandle(Z, Instance::null())); 3406 return Constant(Instance::ZoneHandle(Z, Instance::null()));
3373 } 3407 }
3374 3408
3409 Fragment StreamingFlowGraphBuilder::BuildVectorCreation(
3410 TokenPosition* position) {
3411 if (position != NULL) *position = TokenPosition::kNoSource;
3412
3413 intptr_t size = ReadUInt(); // read size.
3414 return AllocateContext(size);
3415 }
3416
3417 Fragment StreamingFlowGraphBuilder::BuildVectorGet(TokenPosition* position) {
3418 if (position != NULL) *position = TokenPosition::kNoSource;
3419
3420 Fragment instructions = BuildExpression(); // read expression.
3421 intptr_t index = ReadUInt(); // read index.
3422 instructions += LoadField(Context::variable_offset(index));
3423 return instructions;
3424 }
3425
3426 Fragment StreamingFlowGraphBuilder::BuildVectorSet(TokenPosition* position) {
3427 if (position != NULL) *position = TokenPosition::kNoSource;
3428
3429 Fragment instructions = BuildExpression(); // read vector expression.
3430 intptr_t index = ReadUInt(); // read index.
3431 instructions += BuildExpressionStatement(); // read value expression.
jensj 2017/05/18 11:19:05 Shouldn't this just be BuildExpression();?
Dmitry Stefantsov 2017/05/18 12:18:53 Yes, of course. Thanks! Fixed.
3432
3433 // The assigned value is the result of the expression.
3434 LocalVariable* result = MakeTemporary();
3435
3436 Value* value = Pop();
3437 StoreInstanceFieldInstr* store = new (Z)
3438 StoreInstanceFieldInstr(Context::variable_offset(index), Pop(), value,
3439 kNoStoreBarrier, TokenPosition::kNoSource);
3440 instructions <<= store;
3441
3442 // Load the result that is stored in the temporary variable.
3443 instructions += LoadLocal(result);
3444
3445 return instructions;
3446 }
3447
3448 Fragment StreamingFlowGraphBuilder::BuildVectorCopy(TokenPosition* position) {
3449 if (position != NULL) *position = TokenPosition::kNoSource;
3450
3451 Fragment instructions = BuildExpression(); // read vector expression.
3452 CloneContextInstr* clone_instruction =
3453 new (Z) CloneContextInstr(TokenPosition::kNoSource, Pop());
3454 instructions <<= clone_instruction;
3455 Push(clone_instruction);
3456
3457 return instructions;
3458 }
3459
3460 Fragment StreamingFlowGraphBuilder::BuildClosureCreation(
3461 TokenPosition* position) {
3462 if (position != NULL) *position = TokenPosition::kNoSource;
3463
3464 NameIndex function_reference =
3465 ReadCanonicalNameReference(); // read function reference.
3466 Function& function = Function::ZoneHandle(
3467 Z, H.LookupStaticMethodByKernelProcedure(function_reference));
3468 function = function.ConvertedClosureFunction();
3469 ASSERT(!function.IsNull());
3470
3471 const dart::Class& closure_class =
3472 dart::Class::ZoneHandle(Z, I->object_store()->closure_class());
3473 Fragment instructions = AllocateObject(closure_class, function);
3474 LocalVariable* closure = MakeTemporary();
3475
3476 instructions += BuildExpression(); // read vector expression.
jensj 2017/05/18 11:19:06 from the kernel_binary.cc file I would guess the c
Dmitry Stefantsov 2017/05/18 12:18:52 Yep. Thanks!
3477 LocalVariable* context = MakeTemporary();
3478
3479 instructions += LoadLocal(closure);
3480 instructions += Constant(function);
3481 instructions +=
3482 StoreInstanceField(TokenPosition::kNoSource, Closure::function_offset());
3483
3484 instructions += LoadLocal(closure);
3485 instructions += LoadLocal(context);
3486 instructions +=
3487 StoreInstanceField(TokenPosition::kNoSource, Closure::context_offset());
3488
3489 instructions += Drop();
3490
3491 return instructions;
jensj 2017/05/18 11:19:06 Isn't there a SkipDartType or something missing?
Dmitry Stefantsov 2017/05/18 12:18:52 Yes. I should have put an invocation of SkipDartTy
3492 }
3493
3375 Fragment StreamingFlowGraphBuilder::BuildInvalidStatement() { 3494 Fragment StreamingFlowGraphBuilder::BuildInvalidStatement() {
3376 H.ReportError("Invalid statements not implemented yet!"); 3495 H.ReportError("Invalid statements not implemented yet!");
3377 return Fragment(); 3496 return Fragment();
3378 } 3497 }
3379 3498
3380 Fragment StreamingFlowGraphBuilder::BuildExpressionStatement() { 3499 Fragment StreamingFlowGraphBuilder::BuildExpressionStatement() {
3381 Fragment instructions = BuildExpression(); // read expression. 3500 Fragment instructions = BuildExpression(); // read expression.
3382 instructions += Drop(); 3501 instructions += Drop();
3383 return instructions; 3502 return instructions;
3384 } 3503 }
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
4311 } 4430 }
4312 instructions += StoreLocal(position, variable); 4431 instructions += StoreLocal(position, variable);
4313 instructions += Drop(); 4432 instructions += Drop();
4314 return instructions; 4433 return instructions;
4315 } 4434 }
4316 4435
4317 } // namespace kernel 4436 } // namespace kernel
4318 } // namespace dart 4437 } // namespace dart
4319 4438
4320 #endif // !defined(DART_PRECOMPILED_RUNTIME) 4439 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698