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

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 Fragment instructions;
4081 bool elide_initialization = false;
4082 instructions += LoadLocal(scopes_->this_variable);
4083 Fragment initializer = TranslateExpression(init);
Vyacheslav Egorov (Google) 2017/03/31 15:00:56 Better init->IsNullLiteral() instead of this.
4084 instructions += initializer;
4085 // Elide initialization if the expression is null.
4086 if (initializer.entry->IsConstant() &&
4087 initializer.entry == initializer.current) {
4088 ConstantInstr* inst = initializer.entry->AsConstant();
4089 if (inst->value().IsNull()) {
4090 elide_initialization = true;
4091 }
4092 }
4093 instructions += StoreInstanceFieldGuarded(field, true);
4094 if (elide_initialization) {
4095 field.RecordStore(Object::null_object());
4096 return Fragment();
4097 } else {
4098 return instructions;
4099 }
4100 }
4101
4102
4076 Fragment FlowGraphBuilder::TranslateInitializers( 4103 Fragment FlowGraphBuilder::TranslateInitializers(
4077 Class* kernel_klass, 4104 Class* kernel_klass,
4078 List<Initializer>* initializers) { 4105 List<Initializer>* initializers) {
4079 Fragment instructions; 4106 Fragment instructions;
4080 4107
4081 // These come from: 4108 // These come from:
4082 // class A { 4109 // class A {
4083 // var x = (expr); 4110 // var x = (expr);
4084 // } 4111 // }
4085 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) { 4112 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) {
4086 Field* kernel_field = kernel_klass->fields()[i]; 4113 Field* kernel_field = kernel_klass->fields()[i];
4087 Expression* init = kernel_field->initializer(); 4114 Expression* init = kernel_field->initializer();
4088 if (!kernel_field->IsStatic() && init != NULL) { 4115 if (!kernel_field->IsStatic() && init != NULL) {
4089 dart::Field& field =
4090 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(kernel_field));
4091
4092 EnterScope(kernel_field); 4116 EnterScope(kernel_field);
4093 instructions += LoadLocal(scopes_->this_variable); 4117 instructions += TranslateFieldInitializer(kernel_field, init);
4094 instructions += TranslateExpression(init);
4095 instructions += StoreInstanceFieldGuarded(field, true);
4096 ExitScope(kernel_field); 4118 ExitScope(kernel_field);
4097 } 4119 }
4098 } 4120 }
4099 4121
4100 // These to come from: 4122 // These to come from:
4101 // class A { 4123 // class A {
4102 // var x; 4124 // var x;
4103 // var y; 4125 // var y;
4104 // A(this.x) : super(expr), y = (expr); 4126 // A(this.x) : super(expr), y = (expr);
4105 // } 4127 // }
4106 for (intptr_t i = 0; i < initializers->length(); i++) { 4128 for (intptr_t i = 0; i < initializers->length(); i++) {
4107 Initializer* initializer = (*initializers)[i]; 4129 Initializer* initializer = (*initializers)[i];
4108 if (initializer->IsFieldInitializer()) { 4130 if (initializer->IsFieldInitializer()) {
4109 FieldInitializer* init = FieldInitializer::Cast(initializer); 4131 FieldInitializer* init = FieldInitializer::Cast(initializer);
4110 dart::Field& field = 4132 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()) { 4133 } else if (initializer->IsSuperInitializer()) {
4117 SuperInitializer* init = SuperInitializer::Cast(initializer); 4134 SuperInitializer* init = SuperInitializer::Cast(initializer);
4118 4135
4119 instructions += LoadLocal(scopes_->this_variable); 4136 instructions += LoadLocal(scopes_->this_variable);
4120 instructions += PushArgument(); 4137 instructions += PushArgument();
4121 4138
4122 ASSERT(init->arguments()->types().length() == 0); 4139 ASSERT(init->arguments()->types().length() == 0);
4123 Array& argument_names = Array::ZoneHandle(Z); 4140 Array& argument_names = Array::ZoneHandle(Z);
4124 instructions += TranslateArguments(init->arguments(), &argument_names); 4141 instructions += TranslateArguments(init->arguments(), &argument_names);
4125 4142
(...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after
6463 thread->clear_sticky_error(); 6480 thread->clear_sticky_error();
6464 return error.raw(); 6481 return error.raw();
6465 } 6482 }
6466 } 6483 }
6467 6484
6468 6485
6469 } // namespace kernel 6486 } // namespace kernel
6470 } // namespace dart 6487 } // namespace dart
6471 6488
6472 #endif // !defined(DART_PRECOMPILED_RUNTIME) 6489 #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