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

Side by Side Diff: src/rewriter.cc

Issue 668256: Add AST analysis that flags expressions that will have ToInt32 applied to the... (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
« no previous file with comments | « src/flag-definitions.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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 247
248 if (var->slot() != NULL) { 248 if (FLAG_safe_int32_compiler) {
249 Slot* slot = var->slot(); 249 Slot* slot = var->slot();
250 node->set_side_effect_free( 250 if (slot != NULL) {
251 (slot->type() == Slot::LOCAL && !slot->is_arguments()) || 251 node->set_side_effect_free(
252 slot->type() == Slot::PARAMETER); 252 (slot->type() == Slot::LOCAL && !slot->is_arguments()) ||
253 // stack_height and expression_size remain 0. 253 slot->type() == Slot::PARAMETER);
254 }
254 } 255 }
255 } 256 }
256 } 257 }
257 258
258 259
259 void AstOptimizer::VisitLiteral(Literal* node) { 260 void AstOptimizer::VisitLiteral(Literal* node) {
260 Handle<Object> literal = node->handle(); 261 Handle<Object> literal = node->handle();
261 if (literal->IsSmi()) { 262 if (literal->IsSmi()) {
262 node->type()->SetAsLikelySmi(); 263 node->type()->SetAsLikelySmi();
263 node->set_side_effect_free(true); 264 node->set_side_effect_free(true);
264 // stack_height and expression_size remain 0.
265 } else if (literal->IsString()) { 265 } else if (literal->IsString()) {
266 Handle<String> lit_str(Handle<String>::cast(literal)); 266 Handle<String> lit_str(Handle<String>::cast(literal));
267 if (!Heap::prototype_symbol()->Equals(*lit_str)) { 267 if (!Heap::prototype_symbol()->Equals(*lit_str)) {
268 func_name_inferrer_.PushName(lit_str); 268 func_name_inferrer_.PushName(lit_str);
269 } 269 }
270 } else if (literal->IsHeapNumber()) { 270 } else if (literal->IsHeapNumber()) {
271 node->set_side_effect_free(true); 271 node->set_side_effect_free(true);
272 // stack_height and expression_size remain 0.
273 } 272 }
274 } 273 }
275 274
276 275
277 void AstOptimizer::VisitRegExpLiteral(RegExpLiteral* node) { 276 void AstOptimizer::VisitRegExpLiteral(RegExpLiteral* node) {
278 USE(node); 277 USE(node);
279 } 278 }
280 279
281 280
282 void AstOptimizer::VisitArrayLiteral(ArrayLiteral* node) { 281 void AstOptimizer::VisitArrayLiteral(ArrayLiteral* node) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 node->arguments()->length() >= 2 && 419 node->arguments()->length() >= 2 &&
421 node->arguments()->at(1)->AsFunctionLiteral() != NULL) { 420 node->arguments()->at(1)->AsFunctionLiteral() != NULL) {
422 scoped_fni.Enter(); 421 scoped_fni.Enter();
423 } 422 }
424 OptimizeArguments(node->arguments()); 423 OptimizeArguments(node->arguments());
425 } 424 }
426 425
427 426
428 void AstOptimizer::VisitUnaryOperation(UnaryOperation* node) { 427 void AstOptimizer::VisitUnaryOperation(UnaryOperation* node) {
429 Visit(node->expression()); 428 Visit(node->expression());
430 switch (node->op()) { 429 if (FLAG_safe_int32_compiler) {
431 case Token::ADD: 430 switch (node->op()) {
432 case Token::SUB: 431 case Token::BIT_NOT:
433 node->set_side_effect_free(node->expression()->side_effect_free()); 432 node->expression()->set_to_int32(true);
434 node->set_expression_size(node->expression()->expression_size() + 1); 433 // Fall through.
435 node->set_stack_height(node->expression()->stack_height()); 434 case Token::ADD:
436 break; 435 case Token::SUB:
437 case Token::DELETE: 436 case Token::NOT:
438 case Token::TYPEOF: 437 node->set_side_effect_free(node->expression()->side_effect_free());
439 case Token::VOID: 438 break;
440 case Token::BIT_NOT: 439 case Token::DELETE:
441 case Token::NOT: 440 case Token::TYPEOF:
442 break; 441 case Token::VOID:
443 default: 442 break;
444 UNREACHABLE(); 443 default:
445 break; 444 UNREACHABLE();
445 break;
446 }
447 } else if (node->op() == Token::BIT_NOT) {
448 node->expression()->set_to_int32(true);
446 } 449 }
447 } 450 }
448 451
449 452
450 void AstOptimizer::VisitCountOperation(CountOperation* node) { 453 void AstOptimizer::VisitCountOperation(CountOperation* node) {
451 // Count operations assume that they work on Smis. 454 // Count operations assume that they work on Smis.
452 node->type()->SetAsLikelySmiIfUnknown(); 455 node->type()->SetAsLikelySmiIfUnknown();
453 node->expression()->type()->SetAsLikelySmiIfUnknown(); 456 node->expression()->type()->SetAsLikelySmiIfUnknown();
454 Visit(node->expression()); 457 Visit(node->expression());
455 } 458 }
456 459
457 460
458 void AstOptimizer::VisitBinaryOperation(BinaryOperation* node) { 461 void AstOptimizer::VisitBinaryOperation(BinaryOperation* node) {
459 // Depending on the operation we can propagate this node's type down the 462 // Depending on the operation we can propagate this node's type down the
460 // AST nodes. 463 // AST nodes.
461 switch (node->op()) { 464 switch (node->op()) {
462 case Token::COMMA: 465 case Token::COMMA:
463 case Token::OR: 466 case Token::OR:
464 case Token::AND: 467 case Token::AND:
465 break; 468 break;
466 case Token::BIT_OR: 469 case Token::BIT_OR:
467 case Token::BIT_XOR: 470 case Token::BIT_XOR:
468 case Token::BIT_AND: 471 case Token::BIT_AND:
469 case Token::SHL: 472 case Token::SHL:
470 case Token::SAR: 473 case Token::SAR:
471 case Token::SHR: 474 case Token::SHR:
472 node->type()->SetAsLikelySmiIfUnknown(); 475 node->type()->SetAsLikelySmiIfUnknown();
473 node->left()->type()->SetAsLikelySmiIfUnknown(); 476 node->left()->type()->SetAsLikelySmiIfUnknown();
474 node->right()->type()->SetAsLikelySmiIfUnknown(); 477 node->right()->type()->SetAsLikelySmiIfUnknown();
478 node->left()->set_to_int32(true);
479 node->right()->set_to_int32(true);
475 break; 480 break;
476 case Token::ADD: 481 case Token::ADD:
477 case Token::SUB: 482 case Token::SUB:
478 case Token::MUL: 483 case Token::MUL:
479 case Token::DIV: 484 case Token::DIV:
480 case Token::MOD: 485 case Token::MOD:
481 if (node->type()->IsLikelySmi()) { 486 if (node->type()->IsLikelySmi()) {
482 node->left()->type()->SetAsLikelySmiIfUnknown(); 487 node->left()->type()->SetAsLikelySmiIfUnknown();
483 node->right()->type()->SetAsLikelySmiIfUnknown(); 488 node->right()->type()->SetAsLikelySmiIfUnknown();
484 } 489 }
(...skipping 21 matching lines...) Expand all
506 if (node->left()->type()->IsUnknown()) { 511 if (node->left()->type()->IsUnknown()) {
507 node->left()->type()->SetAsLikelySmi(); 512 node->left()->type()->SetAsLikelySmi();
508 Visit(node->left()); 513 Visit(node->left());
509 } 514 }
510 if (node->right()->type()->IsUnknown()) { 515 if (node->right()->type()->IsUnknown()) {
511 node->right()->type()->SetAsLikelySmi(); 516 node->right()->type()->SetAsLikelySmi();
512 Visit(node->right()); 517 Visit(node->right());
513 } 518 }
514 } 519 }
515 } 520 }
516 switch (node->op()) { 521
517 case Token::COMMA: 522 if (FLAG_safe_int32_compiler) {
518 case Token::OR: 523 switch (node->op()) {
519 case Token::AND: 524 case Token::COMMA:
520 case Token::BIT_OR: 525 case Token::OR:
521 case Token::BIT_XOR: 526 case Token::AND:
522 case Token::BIT_AND: 527 break;
523 case Token::SHL: 528 case Token::BIT_OR:
524 case Token::SAR: 529 case Token::BIT_XOR:
525 case Token::SHR: 530 case Token::BIT_AND:
526 case Token::MOD: 531 case Token::SHL:
527 break; 532 case Token::SAR:
528 case Token::ADD: 533 case Token::SHR:
529 case Token::SUB: 534 case Token::ADD:
530 case Token::MUL: 535 case Token::SUB:
531 case Token::DIV: 536 case Token::MUL:
532 node->set_side_effect_free(node->left()->side_effect_free() && 537 case Token::DIV:
533 node->right()->side_effect_free()); 538 case Token::MOD:
534 node->set_expression_size(node->left()->expression_size() + 539 node->set_side_effect_free(node->left()->side_effect_free() &&
535 node->right()->expression_size() + 1); 540 node->right()->side_effect_free());
536 node->set_stack_height(Max(node->left()->stack_height(), 541 break;
537 node->right()->stack_height() + 1)); 542 default:
538 break; 543 UNREACHABLE();
539 default: 544 break;
540 UNREACHABLE(); 545 }
541 break;
542 } 546 }
543 } 547 }
544 548
545 549
546 void AstOptimizer::VisitCompareOperation(CompareOperation* node) { 550 void AstOptimizer::VisitCompareOperation(CompareOperation* node) {
547 if (node->type()->IsKnown()) { 551 if (node->type()->IsKnown()) {
548 // Propagate useful information down towards the leafs. 552 // Propagate useful information down towards the leafs.
549 node->left()->type()->SetAsLikelySmiIfUnknown(); 553 node->left()->type()->SetAsLikelySmiIfUnknown();
550 node->right()->type()->SetAsLikelySmiIfUnknown(); 554 node->right()->type()->SetAsLikelySmiIfUnknown();
551 } 555 }
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 optimizer.Optimize(body); 907 optimizer.Optimize(body);
904 if (optimizer.HasStackOverflow()) { 908 if (optimizer.HasStackOverflow()) {
905 return false; 909 return false;
906 } 910 }
907 } 911 }
908 return true; 912 return true;
909 } 913 }
910 914
911 915
912 } } // namespace v8::internal 916 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698