| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 Zone* zone_; | 446 Zone* zone_; |
| 447 ZoneList<HFieldApproximation*> fields_; | 447 ZoneList<HFieldApproximation*> fields_; |
| 448 HAliasAnalyzer* aliasing_; | 448 HAliasAnalyzer* aliasing_; |
| 449 }; | 449 }; |
| 450 | 450 |
| 451 | 451 |
| 452 // Support for HFlowEngine: collect store effects within loops. | 452 // Support for HFlowEngine: collect store effects within loops. |
| 453 class HLoadEliminationEffects : public ZoneObject { | 453 class HLoadEliminationEffects : public ZoneObject { |
| 454 public: | 454 public: |
| 455 explicit HLoadEliminationEffects(Zone* zone) | 455 explicit HLoadEliminationEffects(Zone* zone) |
| 456 : zone_(zone), | 456 : zone_(zone), stores_(5, zone) { } |
| 457 maps_stored_(false), | |
| 458 fields_stored_(false), | |
| 459 elements_stored_(false), | |
| 460 stores_(5, zone) { } | |
| 461 | 457 |
| 462 inline bool Disabled() { | 458 inline bool Disabled() { |
| 463 return false; // Effects are _not_ disabled. | 459 return false; // Effects are _not_ disabled. |
| 464 } | 460 } |
| 465 | 461 |
| 466 // Process a possibly side-effecting instruction. | 462 // Process a possibly side-effecting instruction. |
| 467 void Process(HInstruction* instr, Zone* zone) { | 463 void Process(HInstruction* instr, Zone* zone) { |
| 468 switch (instr->opcode()) { | 464 if (instr->IsStoreNamedField()) { |
| 469 case HValue::kStoreNamedField: { | 465 stores_.Add(HStoreNamedField::cast(instr), zone_); |
| 470 stores_.Add(HStoreNamedField::cast(instr), zone_); | 466 } else { |
| 471 break; | 467 flags_.Add(instr->ChangesFlags()); |
| 472 } | |
| 473 case HValue::kOsrEntry: { | |
| 474 // Kill everything. Loads must not be hoisted past the OSR entry. | |
| 475 maps_stored_ = true; | |
| 476 fields_stored_ = true; | |
| 477 elements_stored_ = true; | |
| 478 } | |
| 479 default: { | |
| 480 fields_stored_ |= instr->CheckChangesFlag(kInobjectFields); | |
| 481 maps_stored_ |= instr->CheckChangesFlag(kMaps); | |
| 482 maps_stored_ |= instr->CheckChangesFlag(kElementsKind); | |
| 483 elements_stored_ |= instr->CheckChangesFlag(kElementsKind); | |
| 484 elements_stored_ |= instr->CheckChangesFlag(kElementsPointer); | |
| 485 } | |
| 486 } | 468 } |
| 487 } | 469 } |
| 488 | 470 |
| 489 // Apply these effects to the given load elimination table. | 471 // Apply these effects to the given load elimination table. |
| 490 void Apply(HLoadEliminationTable* table) { | 472 void Apply(HLoadEliminationTable* table) { |
| 491 if (fields_stored_) { | 473 // Loads must not be hoisted past the OSR entry, therefore we kill |
| 474 // everything if we see an OSR entry. |
| 475 if (flags_.Contains(kInobjectFields) || flags_.Contains(kOsrEntries)) { |
| 492 table->Kill(); | 476 table->Kill(); |
| 493 return; | 477 return; |
| 494 } | 478 } |
| 495 if (maps_stored_) { | 479 if (flags_.Contains(kElementsKind) || flags_.Contains(kMaps)) { |
| 496 table->KillOffset(JSObject::kMapOffset); | 480 table->KillOffset(JSObject::kMapOffset); |
| 497 } | 481 } |
| 498 if (elements_stored_) { | 482 if (flags_.Contains(kElementsKind) || flags_.Contains(kElementsPointer)) { |
| 499 table->KillOffset(JSObject::kElementsOffset); | 483 table->KillOffset(JSObject::kElementsOffset); |
| 500 } | 484 } |
| 501 | 485 |
| 502 // Kill non-agreeing fields for each store contained in these effects. | 486 // Kill non-agreeing fields for each store contained in these effects. |
| 503 for (int i = 0; i < stores_.length(); i++) { | 487 for (int i = 0; i < stores_.length(); i++) { |
| 504 table->KillStore(stores_[i]); | 488 table->KillStore(stores_[i]); |
| 505 } | 489 } |
| 506 } | 490 } |
| 507 | 491 |
| 508 // Union these effects with the other effects. | 492 // Union these effects with the other effects. |
| 509 void Union(HLoadEliminationEffects* that, Zone* zone) { | 493 void Union(HLoadEliminationEffects* that, Zone* zone) { |
| 510 maps_stored_ |= that->maps_stored_; | 494 flags_.Add(that->flags_); |
| 511 fields_stored_ |= that->fields_stored_; | |
| 512 elements_stored_ |= that->elements_stored_; | |
| 513 for (int i = 0; i < that->stores_.length(); i++) { | 495 for (int i = 0; i < that->stores_.length(); i++) { |
| 514 stores_.Add(that->stores_[i], zone); | 496 stores_.Add(that->stores_[i], zone); |
| 515 } | 497 } |
| 516 } | 498 } |
| 517 | 499 |
| 518 private: | 500 private: |
| 519 Zone* zone_; | 501 Zone* zone_; |
| 520 bool maps_stored_ : 1; | 502 GVNFlagSet flags_; |
| 521 bool fields_stored_ : 1; | |
| 522 bool elements_stored_ : 1; | |
| 523 ZoneList<HStoreNamedField*> stores_; | 503 ZoneList<HStoreNamedField*> stores_; |
| 524 }; | 504 }; |
| 525 | 505 |
| 526 | 506 |
| 527 // The main routine of the analysis phase. Use the HFlowEngine for either a | 507 // The main routine of the analysis phase. Use the HFlowEngine for either a |
| 528 // local or a global analysis. | 508 // local or a global analysis. |
| 529 void HLoadEliminationPhase::Run() { | 509 void HLoadEliminationPhase::Run() { |
| 530 HFlowEngine<HLoadEliminationTable, HLoadEliminationEffects> | 510 HFlowEngine<HLoadEliminationTable, HLoadEliminationEffects> |
| 531 engine(graph(), zone()); | 511 engine(graph(), zone()); |
| 532 HAliasAnalyzer aliasing; | 512 HAliasAnalyzer aliasing; |
| 533 HLoadEliminationTable* table = | 513 HLoadEliminationTable* table = |
| 534 new(zone()) HLoadEliminationTable(zone(), &aliasing); | 514 new(zone()) HLoadEliminationTable(zone(), &aliasing); |
| 535 | 515 |
| 536 if (GLOBAL) { | 516 if (GLOBAL) { |
| 537 // Perform a global analysis. | 517 // Perform a global analysis. |
| 538 engine.AnalyzeDominatedBlocks(graph()->blocks()->at(0), table); | 518 engine.AnalyzeDominatedBlocks(graph()->blocks()->at(0), table); |
| 539 } else { | 519 } else { |
| 540 // Perform only local analysis. | 520 // Perform only local analysis. |
| 541 for (int i = 0; i < graph()->blocks()->length(); i++) { | 521 for (int i = 0; i < graph()->blocks()->length(); i++) { |
| 542 table->Kill(); | 522 table->Kill(); |
| 543 engine.AnalyzeOneBlock(graph()->blocks()->at(i), table); | 523 engine.AnalyzeOneBlock(graph()->blocks()->at(i), table); |
| 544 } | 524 } |
| 545 } | 525 } |
| 546 } | 526 } |
| 547 | 527 |
| 548 } } // namespace v8::internal | 528 } } // namespace v8::internal |
| OLD | NEW |