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

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

Issue 9634009: Implement increment of locals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | « runtime/vm/flow_graph_builder.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "vm/ast_printer.h" 7 #include "vm/ast_printer.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/intermediate_language.h" 9 #include "vm/intermediate_language.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 ? Token::Str(Token::kNEGATE) 332 ? Token::Str(Token::kNEGATE)
333 : node->Name())); 333 : node->Name()));
334 InstanceCallComp* call = 334 InstanceCallComp* call =
335 new InstanceCallComp(node->id(), node->token_index(), name, 335 new InstanceCallComp(node->id(), node->token_index(), name,
336 arguments, Array::ZoneHandle(), 1); 336 arguments, Array::ZoneHandle(), 1);
337 ReturnComputation(call); 337 ReturnComputation(call);
338 } 338 }
339 339
340 340
341 void EffectGraphVisitor::VisitIncrOpLocalNode(IncrOpLocalNode* node) { 341 void EffectGraphVisitor::VisitIncrOpLocalNode(IncrOpLocalNode* node) {
342 Bailout("EffectGraphVisitor::VisitIncrOpLocalNode"); 342 ASSERT((node->kind() == Token::kINCR) || (node->kind() == Token::kDECR));
343 // In an effect context, treat postincrement as if it were preincrement
344 // because its value is not needed.
345
346 // 1. Load the value.
347 LoadLocalComp* load = new LoadLocalComp(node->local());
348 AddInstruction(new BindInstr(temp_index(), load));
349 // 2. Increment.
350 BuildIncrOpIncrement(node->kind(), node->id(), node->token_index(),
351 temp_index() + 1);
352 // 3. Perform the store, resulting in the new value.
353 StoreLocalComp* store =
354 new StoreLocalComp(node->local(), new TempVal(temp_index()));
355 ReturnComputation(store);
343 } 356 }
344 357
345 358
359 void ValueGraphVisitor::VisitIncrOpLocalNode(IncrOpLocalNode* node) {
360 ASSERT((node->kind() == Token::kINCR) || (node->kind() == Token::kDECR));
361 if (node->prefix()) {
362 // Base class handles preincrement.
363 EffectGraphVisitor::VisitIncrOpLocalNode(node);
364 return;
365 }
366 // For postincrement, duplicate the original value to use one copy as the
367 // result.
368 //
369 // 1. Load the value.
370 LoadLocalComp* load = new LoadLocalComp(node->local());
371 AddInstruction(new BindInstr(temp_index(), load));
372 // 2. Duplicate it to increment.
373 AddInstruction(new PickTempInstr(temp_index() + 1, temp_index()));
374 // 3. Increment.
375 BuildIncrOpIncrement(node->kind(), node->id(), node->token_index(),
376 temp_index() + 2);
377 // 4. Perform the store and return the original value.
378 StoreLocalComp* store =
379 new StoreLocalComp(node->local(), new TempVal(temp_index() + 1));
380 AddInstruction(new DoInstr(store));
381 ReturnValue(new TempVal(AllocateTempIndex()));
382 }
383
384
346 int EffectGraphVisitor::BuildIncrOpFieldLoad(IncrOpInstanceFieldNode* node, 385 int EffectGraphVisitor::BuildIncrOpFieldLoad(IncrOpInstanceFieldNode* node,
347 int start_index) { 386 int start_index) {
348 // Evaluate the receiver and duplicate it (it has two uses). 387 // Evaluate the receiver and duplicate it (it has two uses).
349 // t_n <- ... receiver ... 388 // t_n <- ... receiver ...
350 // t_n+1 <- Pick(t_n) 389 // t_n+1 <- Pick(t_n)
351 ArgumentGraphVisitor for_receiver(owner(), start_index); 390 ArgumentGraphVisitor for_receiver(owner(), start_index);
352 node->receiver()->Visit(&for_receiver); 391 node->receiver()->Visit(&for_receiver);
353 Append(for_receiver); 392 Append(for_receiver);
354 const int next_index = for_receiver.temp_index(); 393 const int next_index = for_receiver.temp_index();
355 ASSERT(next_index == start_index + 1); 394 ASSERT(next_index == start_index + 1);
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 } 1156 }
1118 1157
1119 1158
1120 void FlowGraphPrinter::VisitDo(DoInstr* instr) { 1159 void FlowGraphPrinter::VisitDo(DoInstr* instr) {
1121 OS::Print(" "); 1160 OS::Print(" ");
1122 instr->computation()->Accept(this); 1161 instr->computation()->Accept(this);
1123 } 1162 }
1124 1163
1125 1164
1126 void FlowGraphPrinter::VisitBind(BindInstr* instr) { 1165 void FlowGraphPrinter::VisitBind(BindInstr* instr) {
1127 OS::Print(" t%d <-", instr->temp_index()); 1166 OS::Print(" t%d <- ", instr->temp_index());
1128 instr->computation()->Accept(this); 1167 instr->computation()->Accept(this);
1129 } 1168 }
1130 1169
1131 1170
1132 void FlowGraphPrinter::VisitReturn(ReturnInstr* instr) { 1171 void FlowGraphPrinter::VisitReturn(ReturnInstr* instr) {
1133 OS::Print(" return "); 1172 OS::Print(" return ");
1134 instr->value()->Accept(this); 1173 instr->value()->Accept(this);
1135 } 1174 }
1136 1175
1137 1176
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 char* chars = reinterpret_cast<char*>( 1215 char* chars = reinterpret_cast<char*>(
1177 Isolate::Current()->current_zone()->Allocate(len)); 1216 Isolate::Current()->current_zone()->Allocate(len));
1178 OS::SNPrint(chars, len, kFormat, function_name, reason); 1217 OS::SNPrint(chars, len, kFormat, function_name, reason);
1179 const Error& error = Error::Handle( 1218 const Error& error = Error::Handle(
1180 LanguageError::New(String::Handle(String::New(chars)))); 1219 LanguageError::New(String::Handle(String::New(chars))));
1181 Isolate::Current()->long_jump_base()->Jump(1, error); 1220 Isolate::Current()->long_jump_base()->Jump(1, error);
1182 } 1221 }
1183 1222
1184 1223
1185 } // namespace dart 1224 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698