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

Side by Side Diff: src/rewriter.cc

Issue 660372: Add syntax checker for side-effect-free expressions to AstOptimizer in rewrit... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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
« src/ast.h ('K') | « src/ast.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if (var->type()->IsKnown()) { 237 if (var->type()->IsKnown()) {
238 node->type()->CopyFrom(var->type()); 238 node->type()->CopyFrom(var->type());
239 } else if (node->type()->IsLikelySmi()) { 239 } else if (node->type()->IsLikelySmi()) {
240 var->type()->SetAsLikelySmi(); 240 var->type()->SetAsLikelySmi();
241 } 241 }
242 242
243 if (!var->is_this() && 243 if (!var->is_this() &&
244 !Heap::result_symbol()->Equals(*var->name())) { 244 !Heap::result_symbol()->Equals(*var->name())) {
245 func_name_inferrer_.PushName(var->name()); 245 func_name_inferrer_.PushName(var->name());
246 } 246 }
247
248 if (var->slot() != NULL) {
249 Slot* slot = var->slot();
250 node->set_side_effect_free(
251 (slot->type() == Slot::LOCAL && !slot->is_arguments()) ||
252 slot->type() == Slot::PARAMETER));
253 // stack_height and expression_size remain 0.
254 }
247 } 255 }
248 } 256 }
249 257
250 258
251 void AstOptimizer::VisitLiteral(Literal* node) { 259 void AstOptimizer::VisitLiteral(Literal* node) {
252 Handle<Object> literal = node->handle(); 260 Handle<Object> literal = node->handle();
253 if (literal->IsSmi()) { 261 if (literal->IsSmi()) {
254 node->type()->SetAsLikelySmi(); 262 node->type()->SetAsLikelySmi();
263 node->set_side_effect_free(true);
264 // stack_height and expression_size remain 0.
255 } else if (literal->IsString()) { 265 } else if (literal->IsString()) {
256 Handle<String> lit_str(Handle<String>::cast(literal)); 266 Handle<String> lit_str(Handle<String>::cast(literal));
257 if (!Heap::prototype_symbol()->Equals(*lit_str)) { 267 if (!Heap::prototype_symbol()->Equals(*lit_str)) {
258 func_name_inferrer_.PushName(lit_str); 268 func_name_inferrer_.PushName(lit_str);
259 } 269 }
270 } else if (literal->IsHeapNumber()) {
271 node->set_side_effect_free(true);
272 // stack_height and expression_size remain 0.
260 } 273 }
261 } 274 }
262 275
263 276
264 void AstOptimizer::VisitRegExpLiteral(RegExpLiteral* node) { 277 void AstOptimizer::VisitRegExpLiteral(RegExpLiteral* node) {
265 USE(node); 278 USE(node);
266 } 279 }
267 280
268 281
269 void AstOptimizer::VisitArrayLiteral(ArrayLiteral* node) { 282 void AstOptimizer::VisitArrayLiteral(ArrayLiteral* node) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 node->arguments()->length() >= 2 && 420 node->arguments()->length() >= 2 &&
408 node->arguments()->at(1)->AsFunctionLiteral() != NULL) { 421 node->arguments()->at(1)->AsFunctionLiteral() != NULL) {
409 scoped_fni.Enter(); 422 scoped_fni.Enter();
410 } 423 }
411 OptimizeArguments(node->arguments()); 424 OptimizeArguments(node->arguments());
412 } 425 }
413 426
414 427
415 void AstOptimizer::VisitUnaryOperation(UnaryOperation* node) { 428 void AstOptimizer::VisitUnaryOperation(UnaryOperation* node) {
416 Visit(node->expression()); 429 Visit(node->expression());
430 switch (node->op()) {
431 case Token::ADD:
432 case Token::SUB:
433 node->set_side_effect_free(node->expression()->side_effect_free());
434 node->set_expression_size(node->expression()->expression_size() + 1);
435 node->set_stack_height(node->expression()->stack_height());
436 break;
437 case Token::DELETE:
438 case Token::TYPEOF:
439 case Token::VOID:
440 case Token::BIT_NOT:
441 case Token::NOT:
442 break;
443 default:
444 UNREACHABLE();
445 break;
446 }
417 } 447 }
418 448
419 449
420 void AstOptimizer::VisitCountOperation(CountOperation* node) { 450 void AstOptimizer::VisitCountOperation(CountOperation* node) {
421 // Count operations assume that they work on Smis. 451 // Count operations assume that they work on Smis.
422 node->type()->SetAsLikelySmiIfUnknown(); 452 node->type()->SetAsLikelySmiIfUnknown();
423 node->expression()->type()->SetAsLikelySmiIfUnknown(); 453 node->expression()->type()->SetAsLikelySmiIfUnknown();
424 Visit(node->expression()); 454 Visit(node->expression());
425 } 455 }
426 456
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 if (node->left()->type()->IsUnknown()) { 506 if (node->left()->type()->IsUnknown()) {
477 node->left()->type()->SetAsLikelySmi(); 507 node->left()->type()->SetAsLikelySmi();
478 Visit(node->left()); 508 Visit(node->left());
479 } 509 }
480 if (node->right()->type()->IsUnknown()) { 510 if (node->right()->type()->IsUnknown()) {
481 node->right()->type()->SetAsLikelySmi(); 511 node->right()->type()->SetAsLikelySmi();
482 Visit(node->right()); 512 Visit(node->right());
483 } 513 }
484 } 514 }
485 } 515 }
516 switch (node->op()) {
517 case Token::COMMA:
518 case Token::OR:
519 case Token::AND:
520 case Token::BIT_OR:
521 case Token::BIT_XOR:
522 case Token::BIT_AND:
523 case Token::SHL:
524 case Token::SAR:
525 case Token::SHR:
526 case Token::MOD:
527 break;
528 case Token::ADD:
529 case Token::SUB:
530 case Token::MUL:
531 case Token::DIV:
532 node->set_side_effect_free(node->left()->side_effect_free() &&
533 node->right()->side_effect_free());
534 node->set_expression_size(node->left()->expression_size() +
535 node->right()->expression_size() + 1);
536 node->set_stack_height(Max(node->left()->stack_height(),
537 node->right()->stack_height() + 1));
538 break;
539 default:
540 UNREACHABLE();
541 break;
542 }
486 } 543 }
487 544
488 545
489 void AstOptimizer::VisitCompareOperation(CompareOperation* node) { 546 void AstOptimizer::VisitCompareOperation(CompareOperation* node) {
490 if (node->type()->IsKnown()) { 547 if (node->type()->IsKnown()) {
491 // Propagate useful information down towards the leafs. 548 // Propagate useful information down towards the leafs.
492 node->left()->type()->SetAsLikelySmiIfUnknown(); 549 node->left()->type()->SetAsLikelySmiIfUnknown();
493 node->right()->type()->SetAsLikelySmiIfUnknown(); 550 node->right()->type()->SetAsLikelySmiIfUnknown();
494 } 551 }
495 552
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 optimizer.Optimize(body); 903 optimizer.Optimize(body);
847 if (optimizer.HasStackOverflow()) { 904 if (optimizer.HasStackOverflow()) {
848 return false; 905 return false;
849 } 906 }
850 } 907 }
851 return true; 908 return true;
852 } 909 }
853 910
854 911
855 } } // namespace v8::internal 912 } } // namespace v8::internal
OLDNEW
« src/ast.h ('K') | « src/ast.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698