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

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

Issue 2790603002: VM [KERNEL] Elide null-initialization of the fields (Closed)
Patch Set: VM [KERNEL] Elide null-initialization of the fields Created 3 years, 8 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
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | 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) 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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "vm/kernel_to_il.h" 9 #include "vm/kernel_to_il.h"
10 10
(...skipping 4055 matching lines...) Expand 10 before | Expand all | Expand 10 after
4066 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry(intptr_t try_index) { 4066 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry(intptr_t try_index) {
4067 return new (Z) JoinEntryInstr(AllocateBlockId(), try_index); 4067 return new (Z) JoinEntryInstr(AllocateBlockId(), try_index);
4068 } 4068 }
4069 4069
4070 4070
4071 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry() { 4071 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry() {
4072 return new (Z) JoinEntryInstr(AllocateBlockId(), CurrentTryIndex()); 4072 return new (Z) JoinEntryInstr(AllocateBlockId(), CurrentTryIndex());
4073 } 4073 }
4074 4074
4075 4075
4076 Fragment FlowGraphBuilder::TranslateFieldInitializer(Field* kernel_field,
4077 Expression* init) {
4078 dart::Field& field =
4079 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(kernel_field));
4080 if (init->IsNullLiteral()) {
4081 field.RecordStore(Object::null_object());
4082 return Fragment();
4083 }
4084 Fragment instructions;
4085 instructions += LoadLocal(scopes_->this_variable);
4086 instructions += TranslateExpression(init);
4087 instructions += StoreInstanceFieldGuarded(field, true);
4088 return instructions;
4089 }
4090
4091
4076 Fragment FlowGraphBuilder::TranslateInitializers( 4092 Fragment FlowGraphBuilder::TranslateInitializers(
4077 Class* kernel_klass, 4093 Class* kernel_klass,
4078 List<Initializer>* initializers) { 4094 List<Initializer>* initializers) {
4079 Fragment instructions; 4095 Fragment instructions;
4080 4096
4081 // These come from: 4097 // These come from:
4082 // class A { 4098 // class A {
4083 // var x = (expr); 4099 // var x = (expr);
4084 // } 4100 // }
4085 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) { 4101 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) {
4086 Field* kernel_field = kernel_klass->fields()[i]; 4102 Field* kernel_field = kernel_klass->fields()[i];
4087 Expression* init = kernel_field->initializer(); 4103 Expression* init = kernel_field->initializer();
4088 if (!kernel_field->IsStatic() && init != NULL) { 4104 if (!kernel_field->IsStatic() && init != NULL) {
4089 dart::Field& field =
4090 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(kernel_field));
4091
4092 EnterScope(kernel_field); 4105 EnterScope(kernel_field);
4093 instructions += LoadLocal(scopes_->this_variable); 4106 instructions += TranslateFieldInitializer(kernel_field, init);
4094 instructions += TranslateExpression(init);
4095 instructions += StoreInstanceFieldGuarded(field, true);
4096 ExitScope(kernel_field); 4107 ExitScope(kernel_field);
4097 } 4108 }
4098 } 4109 }
4099 4110
4100 // These to come from: 4111 // These to come from:
4101 // class A { 4112 // class A {
4102 // var x; 4113 // var x;
4103 // var y; 4114 // var y;
4104 // A(this.x) : super(expr), y = (expr); 4115 // A(this.x) : super(expr), y = (expr);
4105 // } 4116 // }
4106 for (intptr_t i = 0; i < initializers->length(); i++) { 4117 for (intptr_t i = 0; i < initializers->length(); i++) {
4107 Initializer* initializer = (*initializers)[i]; 4118 Initializer* initializer = (*initializers)[i];
4108 if (initializer->IsFieldInitializer()) { 4119 if (initializer->IsFieldInitializer()) {
4109 FieldInitializer* init = FieldInitializer::Cast(initializer); 4120 FieldInitializer* init = FieldInitializer::Cast(initializer);
4110 dart::Field& field = 4121 instructions += TranslateFieldInitializer(init->field(), init->value());
4111 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(init->field()));
4112
4113 instructions += LoadLocal(scopes_->this_variable);
4114 instructions += TranslateExpression(init->value());
4115 instructions += StoreInstanceFieldGuarded(field, true);
4116 } else if (initializer->IsSuperInitializer()) { 4122 } else if (initializer->IsSuperInitializer()) {
4117 SuperInitializer* init = SuperInitializer::Cast(initializer); 4123 SuperInitializer* init = SuperInitializer::Cast(initializer);
4118 4124
4119 instructions += LoadLocal(scopes_->this_variable); 4125 instructions += LoadLocal(scopes_->this_variable);
4120 instructions += PushArgument(); 4126 instructions += PushArgument();
4121 4127
4122 ASSERT(init->arguments()->types().length() == 0); 4128 ASSERT(init->arguments()->types().length() == 0);
4123 Array& argument_names = Array::ZoneHandle(Z); 4129 Array& argument_names = Array::ZoneHandle(Z);
4124 instructions += TranslateArguments(init->arguments(), &argument_names); 4130 instructions += TranslateArguments(init->arguments(), &argument_names);
4125 4131
(...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after
6463 thread->clear_sticky_error(); 6469 thread->clear_sticky_error();
6464 return error.raw(); 6470 return error.raw();
6465 } 6471 }
6466 } 6472 }
6467 6473
6468 6474
6469 } // namespace kernel 6475 } // namespace kernel
6470 } // namespace dart 6476 } // namespace dart
6471 6477
6472 #endif // !defined(DART_PRECOMPILED_RUNTIME) 6478 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698