OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 263 |
264 void AstLabeler::VisitThisFunction(ThisFunction* expr) { | 264 void AstLabeler::VisitThisFunction(ThisFunction* expr) { |
265 UNREACHABLE(); | 265 UNREACHABLE(); |
266 } | 266 } |
267 | 267 |
268 | 268 |
269 void AstLabeler::VisitDeclaration(Declaration* decl) { | 269 void AstLabeler::VisitDeclaration(Declaration* decl) { |
270 UNREACHABLE(); | 270 UNREACHABLE(); |
271 } | 271 } |
272 | 272 |
| 273 |
| 274 ZoneList<Expression*>* VarUseMap::Lookup(Variable* var) { |
| 275 HashMap::Entry* entry = HashMap::Lookup(var, var->name()->Hash(), true); |
| 276 if (entry->value == NULL) { |
| 277 entry->value = new ZoneList<Expression*>(1); |
| 278 } |
| 279 return reinterpret_cast<ZoneList<Expression*>*>(entry->value); |
| 280 } |
| 281 |
| 282 |
| 283 void LivenessAnalyzer::Analyze(FunctionLiteral* fun) { |
| 284 // Process the function body. |
| 285 VisitStatements(fun->body()); |
| 286 |
| 287 // All variables are implicitly defined at the function start. |
| 288 // Record a definition of all variables live at function entry. |
| 289 for (HashMap::Entry* p = live_vars_.Start(); |
| 290 p != NULL; |
| 291 p = live_vars_.Next(p)) { |
| 292 Variable* var = reinterpret_cast<Variable*>(p->key); |
| 293 RecordDef(var, fun); |
| 294 } |
| 295 } |
| 296 |
| 297 |
| 298 void LivenessAnalyzer::VisitStatements(ZoneList<Statement*>* stmts) { |
| 299 // Visit statements right-to-left. |
| 300 for (int i = stmts->length() - 1; i >= 0; i--) { |
| 301 Visit(stmts->at(i)); |
| 302 } |
| 303 } |
| 304 |
| 305 |
| 306 void LivenessAnalyzer::RecordUse(Variable* var, Expression* expr) { |
| 307 ASSERT(var->is_global() || var->is_this()); |
| 308 ZoneList<Expression*>* uses = live_vars_.Lookup(var); |
| 309 uses->Add(expr); |
| 310 } |
| 311 |
| 312 |
| 313 void LivenessAnalyzer::RecordDef(Variable* var, Expression* expr) { |
| 314 ASSERT(var->is_global() || var->is_this()); |
| 315 |
| 316 // We do not support other expressions that can define variables. |
| 317 ASSERT(expr->AsFunctionLiteral() != NULL); |
| 318 |
| 319 // Add the variable to the list of defined variables. |
| 320 if (expr->defined_vars() == NULL) { |
| 321 expr->set_defined_vars(new ZoneList<DefinitionInfo*>(1)); |
| 322 } |
| 323 DefinitionInfo* def = new DefinitionInfo(); |
| 324 expr->AsFunctionLiteral()->defined_vars()->Add(def); |
| 325 |
| 326 // Compute the last use of the definition. The variable uses are |
| 327 // inserted in reversed evaluation order. The first element |
| 328 // in the list of live uses is the last use. |
| 329 ZoneList<Expression*>* uses = live_vars_.Lookup(var); |
| 330 while (uses->length() > 0) { |
| 331 Expression* use_site = uses->RemoveLast(); |
| 332 use_site->set_var_def(def); |
| 333 if (uses->length() == 0) { |
| 334 def->set_last_use(use_site); |
| 335 } |
| 336 } |
| 337 } |
| 338 |
| 339 |
| 340 // Visitor functions for live variable analysis. |
| 341 void LivenessAnalyzer::VisitDeclaration(Declaration* decl) { |
| 342 UNREACHABLE(); |
| 343 } |
| 344 |
| 345 |
| 346 void LivenessAnalyzer::VisitBlock(Block* stmt) { |
| 347 VisitStatements(stmt->statements()); |
| 348 } |
| 349 |
| 350 |
| 351 void LivenessAnalyzer::VisitExpressionStatement( |
| 352 ExpressionStatement* stmt) { |
| 353 Visit(stmt->expression()); |
| 354 } |
| 355 |
| 356 |
| 357 void LivenessAnalyzer::VisitEmptyStatement(EmptyStatement* stmt) { |
| 358 // Do nothing. |
| 359 } |
| 360 |
| 361 |
| 362 void LivenessAnalyzer::VisitIfStatement(IfStatement* stmt) { |
| 363 UNREACHABLE(); |
| 364 } |
| 365 |
| 366 |
| 367 void LivenessAnalyzer::VisitContinueStatement(ContinueStatement* stmt) { |
| 368 UNREACHABLE(); |
| 369 } |
| 370 |
| 371 |
| 372 void LivenessAnalyzer::VisitBreakStatement(BreakStatement* stmt) { |
| 373 UNREACHABLE(); |
| 374 } |
| 375 |
| 376 |
| 377 void LivenessAnalyzer::VisitReturnStatement(ReturnStatement* stmt) { |
| 378 UNREACHABLE(); |
| 379 } |
| 380 |
| 381 |
| 382 void LivenessAnalyzer::VisitWithEnterStatement( |
| 383 WithEnterStatement* stmt) { |
| 384 UNREACHABLE(); |
| 385 } |
| 386 |
| 387 |
| 388 void LivenessAnalyzer::VisitWithExitStatement(WithExitStatement* stmt) { |
| 389 UNREACHABLE(); |
| 390 } |
| 391 |
| 392 |
| 393 void LivenessAnalyzer::VisitSwitchStatement(SwitchStatement* stmt) { |
| 394 UNREACHABLE(); |
| 395 } |
| 396 |
| 397 |
| 398 void LivenessAnalyzer::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 399 UNREACHABLE(); |
| 400 } |
| 401 |
| 402 |
| 403 void LivenessAnalyzer::VisitWhileStatement(WhileStatement* stmt) { |
| 404 UNREACHABLE(); |
| 405 } |
| 406 |
| 407 |
| 408 void LivenessAnalyzer::VisitForStatement(ForStatement* stmt) { |
| 409 UNREACHABLE(); |
| 410 } |
| 411 |
| 412 |
| 413 void LivenessAnalyzer::VisitForInStatement(ForInStatement* stmt) { |
| 414 UNREACHABLE(); |
| 415 } |
| 416 |
| 417 |
| 418 void LivenessAnalyzer::VisitTryCatchStatement(TryCatchStatement* stmt) { |
| 419 UNREACHABLE(); |
| 420 } |
| 421 |
| 422 |
| 423 void LivenessAnalyzer::VisitTryFinallyStatement( |
| 424 TryFinallyStatement* stmt) { |
| 425 UNREACHABLE(); |
| 426 } |
| 427 |
| 428 |
| 429 void LivenessAnalyzer::VisitDebuggerStatement( |
| 430 DebuggerStatement* stmt) { |
| 431 UNREACHABLE(); |
| 432 } |
| 433 |
| 434 |
| 435 void LivenessAnalyzer::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 436 UNREACHABLE(); |
| 437 } |
| 438 |
| 439 |
| 440 void LivenessAnalyzer::VisitFunctionBoilerplateLiteral( |
| 441 FunctionBoilerplateLiteral* expr) { |
| 442 UNREACHABLE(); |
| 443 } |
| 444 |
| 445 |
| 446 void LivenessAnalyzer::VisitConditional(Conditional* expr) { |
| 447 UNREACHABLE(); |
| 448 } |
| 449 |
| 450 |
| 451 void LivenessAnalyzer::VisitSlot(Slot* expr) { |
| 452 UNREACHABLE(); |
| 453 } |
| 454 |
| 455 |
| 456 void LivenessAnalyzer::VisitVariableProxy(VariableProxy* expr) { |
| 457 Variable* var = expr->var(); |
| 458 ASSERT(var->is_global()); |
| 459 ASSERT(!var->is_this()); |
| 460 RecordUse(var, expr); |
| 461 } |
| 462 |
| 463 |
| 464 void LivenessAnalyzer::VisitLiteral(Literal* expr) { |
| 465 UNREACHABLE(); |
| 466 } |
| 467 |
| 468 |
| 469 void LivenessAnalyzer::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 470 UNREACHABLE(); |
| 471 } |
| 472 |
| 473 |
| 474 void LivenessAnalyzer::VisitObjectLiteral(ObjectLiteral* expr) { |
| 475 UNREACHABLE(); |
| 476 } |
| 477 |
| 478 |
| 479 void LivenessAnalyzer::VisitArrayLiteral(ArrayLiteral* expr) { |
| 480 UNREACHABLE(); |
| 481 } |
| 482 |
| 483 |
| 484 void LivenessAnalyzer::VisitCatchExtensionObject( |
| 485 CatchExtensionObject* expr) { |
| 486 UNREACHABLE(); |
| 487 } |
| 488 |
| 489 |
| 490 void LivenessAnalyzer::VisitAssignment(Assignment* expr) { |
| 491 Property* prop = expr->target()->AsProperty(); |
| 492 ASSERT(prop != NULL); |
| 493 ASSERT(prop->key()->IsPropertyName()); |
| 494 VariableProxy* proxy = prop->obj()->AsVariableProxy(); |
| 495 ASSERT(proxy != NULL && proxy->var()->is_this()); |
| 496 |
| 497 // Record use of this at the assignment node. Assignments to |
| 498 // this-properties are treated like unary operations. |
| 499 RecordUse(proxy->var(), expr); |
| 500 |
| 501 // Visit right-hand side. |
| 502 Visit(expr->value()); |
| 503 } |
| 504 |
| 505 |
| 506 void LivenessAnalyzer::VisitThrow(Throw* expr) { |
| 507 UNREACHABLE(); |
| 508 } |
| 509 |
| 510 |
| 511 void LivenessAnalyzer::VisitProperty(Property* expr) { |
| 512 ASSERT(expr->key()->IsPropertyName()); |
| 513 VariableProxy* proxy = expr->obj()->AsVariableProxy(); |
| 514 ASSERT(proxy != NULL && proxy->var()->is_this()); |
| 515 RecordUse(proxy->var(), expr); |
| 516 } |
| 517 |
| 518 |
| 519 void LivenessAnalyzer::VisitCall(Call* expr) { |
| 520 UNREACHABLE(); |
| 521 } |
| 522 |
| 523 |
| 524 void LivenessAnalyzer::VisitCallNew(CallNew* expr) { |
| 525 UNREACHABLE(); |
| 526 } |
| 527 |
| 528 |
| 529 void LivenessAnalyzer::VisitCallRuntime(CallRuntime* expr) { |
| 530 UNREACHABLE(); |
| 531 } |
| 532 |
| 533 |
| 534 void LivenessAnalyzer::VisitUnaryOperation(UnaryOperation* expr) { |
| 535 UNREACHABLE(); |
| 536 } |
| 537 |
| 538 |
| 539 void LivenessAnalyzer::VisitCountOperation(CountOperation* expr) { |
| 540 UNREACHABLE(); |
| 541 } |
| 542 |
| 543 |
| 544 void LivenessAnalyzer::VisitBinaryOperation(BinaryOperation* expr) { |
| 545 // Visit child nodes in reverse evaluation order. |
| 546 Visit(expr->right()); |
| 547 Visit(expr->left()); |
| 548 } |
| 549 |
| 550 |
| 551 void LivenessAnalyzer::VisitCompareOperation(CompareOperation* expr) { |
| 552 UNREACHABLE(); |
| 553 } |
| 554 |
| 555 |
| 556 void LivenessAnalyzer::VisitThisFunction(ThisFunction* expr) { |
| 557 UNREACHABLE(); |
| 558 } |
| 559 |
| 560 |
273 } } // namespace v8::internal | 561 } } // namespace v8::internal |
OLD | NEW |