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

Side by Side Diff: src/hydrogen-gvn.cc

Issue 17657004: Refactor Hydrogen GVN into an HPhase and use the phase zone. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Correct CL Created 7 years, 5 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/hydrogen-gvn.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 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 for (int i = 0; i < kNumberOfTrackedSideEffects; i++) { 354 for (int i = 0; i < kNumberOfTrackedSideEffects; i++) {
355 GVNFlag changes_flag = HValue::ChangesFlagFromInt(i); 355 GVNFlag changes_flag = HValue::ChangesFlagFromInt(i);
356 if (flags.Contains(changes_flag)) { 356 if (flags.Contains(changes_flag)) {
357 if (data_[i] == NULL) count_++; 357 if (data_[i] == NULL) count_++;
358 data_[i] = instr; 358 data_[i] = instr;
359 } 359 }
360 } 360 }
361 } 361 }
362 362
363 363
364 HGlobalValueNumberer::HGlobalValueNumberer(HGraph* graph, CompilationInfo* info) 364 HGlobalValueNumberingPhase::HGlobalValueNumberingPhase(HGraph* graph)
365 : graph_(graph), 365 : HPhase("H_Global value numbering", graph),
366 info_(info),
367 removed_side_effects_(false), 366 removed_side_effects_(false),
368 zone_(graph->isolate()),
369 block_side_effects_(graph->blocks()->length(), zone()), 367 block_side_effects_(graph->blocks()->length(), zone()),
370 loop_side_effects_(graph->blocks()->length(), zone()), 368 loop_side_effects_(graph->blocks()->length(), zone()),
371 visited_on_paths_(zone(), graph->blocks()->length()) { 369 visited_on_paths_(zone(), graph->blocks()->length()) {
372 ASSERT(!AllowHandleAllocation::IsAllowed()); 370 ASSERT(!AllowHandleAllocation::IsAllowed());
373 block_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), 371 block_side_effects_.AddBlock(GVNFlagSet(), graph->blocks()->length(),
374 zone()); 372 zone());
375 loop_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), 373 loop_side_effects_.AddBlock(GVNFlagSet(), graph->blocks()->length(),
376 zone()); 374 zone());
377 } 375 }
378 376
379 bool HGlobalValueNumberer::Analyze() { 377 void HGlobalValueNumberingPhase::Analyze() {
380 removed_side_effects_ = false; 378 removed_side_effects_ = false;
381 ComputeBlockSideEffects(); 379 ComputeBlockSideEffects();
382 if (FLAG_loop_invariant_code_motion) { 380 if (FLAG_loop_invariant_code_motion) {
383 LoopInvariantCodeMotion(); 381 LoopInvariantCodeMotion();
384 } 382 }
385 AnalyzeGraph(); 383 AnalyzeGraph();
386 return removed_side_effects_;
387 } 384 }
388 385
389 386
390 void HGlobalValueNumberer::ComputeBlockSideEffects() { 387 void HGlobalValueNumberingPhase::ComputeBlockSideEffects() {
391 // The Analyze phase of GVN can be called multiple times. Clear loop side 388 // The Analyze phase of GVN can be called multiple times. Clear loop side
392 // effects before computing them to erase the contents from previous Analyze 389 // effects before computing them to erase the contents from previous Analyze
393 // passes. 390 // passes.
394 for (int i = 0; i < loop_side_effects_.length(); ++i) { 391 for (int i = 0; i < loop_side_effects_.length(); ++i) {
395 loop_side_effects_[i].RemoveAll(); 392 loop_side_effects_[i].RemoveAll();
396 } 393 }
397 for (int i = graph_->blocks()->length() - 1; i >= 0; --i) { 394 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) {
398 // Compute side effects for the block. 395 // Compute side effects for the block.
399 HBasicBlock* block = graph_->blocks()->at(i); 396 HBasicBlock* block = graph()->blocks()->at(i);
400 HInstruction* instr = block->first(); 397 HInstruction* instr = block->first();
401 int id = block->block_id(); 398 int id = block->block_id();
402 GVNFlagSet side_effects; 399 GVNFlagSet side_effects;
403 while (instr != NULL) { 400 while (instr != NULL) {
404 side_effects.Add(instr->ChangesFlags()); 401 side_effects.Add(instr->ChangesFlags());
405 if (instr->IsSoftDeoptimize()) { 402 if (instr->IsSoftDeoptimize()) {
406 block_side_effects_[id].RemoveAll(); 403 block_side_effects_[id].RemoveAll();
407 side_effects.RemoveAll(); 404 side_effects.RemoveAll();
408 break; 405 break;
409 } 406 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 OS::SNPrintF(buffer, "0x%08X", flags.ToIntegral()); 503 OS::SNPrintF(buffer, "0x%08X", flags.ToIntegral());
507 #endif 504 #endif
508 size_t string_len = strlen(underlying_buffer) + 1; 505 size_t string_len = strlen(underlying_buffer) + 1;
509 ASSERT(string_len <= sizeof(underlying_buffer)); 506 ASSERT(string_len <= sizeof(underlying_buffer));
510 char* result = new char[strlen(underlying_buffer) + 1]; 507 char* result = new char[strlen(underlying_buffer) + 1];
511 OS::MemCopy(result, underlying_buffer, string_len); 508 OS::MemCopy(result, underlying_buffer, string_len);
512 return SmartArrayPointer<char>(result); 509 return SmartArrayPointer<char>(result);
513 } 510 }
514 511
515 512
516 void HGlobalValueNumberer::LoopInvariantCodeMotion() { 513 void HGlobalValueNumberingPhase::LoopInvariantCodeMotion() {
517 TRACE_GVN_1("Using optimistic loop invariant code motion: %s\n", 514 TRACE_GVN_1("Using optimistic loop invariant code motion: %s\n",
518 graph_->use_optimistic_licm() ? "yes" : "no"); 515 graph()->use_optimistic_licm() ? "yes" : "no");
519 for (int i = graph_->blocks()->length() - 1; i >= 0; --i) { 516 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) {
520 HBasicBlock* block = graph_->blocks()->at(i); 517 HBasicBlock* block = graph()->blocks()->at(i);
521 if (block->IsLoopHeader()) { 518 if (block->IsLoopHeader()) {
522 GVNFlagSet side_effects = loop_side_effects_[block->block_id()]; 519 GVNFlagSet side_effects = loop_side_effects_[block->block_id()];
523 TRACE_GVN_2("Try loop invariant motion for block B%d %s\n", 520 TRACE_GVN_2("Try loop invariant motion for block B%d %s\n",
524 block->block_id(), 521 block->block_id(),
525 *GetGVNFlagsString(side_effects)); 522 *GetGVNFlagsString(side_effects));
526 523
527 GVNFlagSet accumulated_first_time_depends; 524 GVNFlagSet accumulated_first_time_depends;
528 GVNFlagSet accumulated_first_time_changes; 525 GVNFlagSet accumulated_first_time_changes;
529 HBasicBlock* last = block->loop_information()->GetLastBackEdge(); 526 HBasicBlock* last = block->loop_information()->GetLastBackEdge();
530 for (int j = block->block_id(); j <= last->block_id(); ++j) { 527 for (int j = block->block_id(); j <= last->block_id(); ++j) {
531 ProcessLoopBlock(graph_->blocks()->at(j), block, side_effects, 528 ProcessLoopBlock(graph()->blocks()->at(j), block, side_effects,
532 &accumulated_first_time_depends, 529 &accumulated_first_time_depends,
533 &accumulated_first_time_changes); 530 &accumulated_first_time_changes);
534 } 531 }
535 } 532 }
536 } 533 }
537 } 534 }
538 535
539 536
540 void HGlobalValueNumberer::ProcessLoopBlock( 537 void HGlobalValueNumberingPhase::ProcessLoopBlock(
541 HBasicBlock* block, 538 HBasicBlock* block,
542 HBasicBlock* loop_header, 539 HBasicBlock* loop_header,
543 GVNFlagSet loop_kills, 540 GVNFlagSet loop_kills,
544 GVNFlagSet* first_time_depends, 541 GVNFlagSet* first_time_depends,
545 GVNFlagSet* first_time_changes) { 542 GVNFlagSet* first_time_changes) {
546 HBasicBlock* pre_header = loop_header->predecessors()->at(0); 543 HBasicBlock* pre_header = loop_header->predecessors()->at(0);
547 GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills); 544 GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills);
548 TRACE_GVN_2("Loop invariant motion for B%d %s\n", 545 TRACE_GVN_2("Loop invariant motion for B%d %s\n",
549 block->block_id(), 546 block->block_id(),
550 *GetGVNFlagsString(depends_flags)); 547 *GetGVNFlagsString(depends_flags));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (!(previous_changes == *first_time_changes)) { 592 if (!(previous_changes == *first_time_changes)) {
596 TRACE_GVN_1("Updated first-time accumulated %s\n", 593 TRACE_GVN_1("Updated first-time accumulated %s\n",
597 *GetGVNFlagsString(*first_time_changes)); 594 *GetGVNFlagsString(*first_time_changes));
598 } 595 }
599 } 596 }
600 instr = next; 597 instr = next;
601 } 598 }
602 } 599 }
603 600
604 601
605 bool HGlobalValueNumberer::AllowCodeMotion() { 602 bool HGlobalValueNumberingPhase::AllowCodeMotion() {
606 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; 603 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count;
607 } 604 }
608 605
609 606
610 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, 607 bool HGlobalValueNumberingPhase::ShouldMove(HInstruction* instr,
611 HBasicBlock* loop_header) { 608 HBasicBlock* loop_header) {
612 // If we've disabled code motion or we're in a block that unconditionally 609 // If we've disabled code motion or we're in a block that unconditionally
613 // deoptimizes, don't move any instructions. 610 // deoptimizes, don't move any instructions.
614 return AllowCodeMotion() && !instr->block()->IsDeoptimizing(); 611 return AllowCodeMotion() && !instr->block()->IsDeoptimizing();
615 } 612 }
616 613
617 614
618 GVNFlagSet HGlobalValueNumberer::CollectSideEffectsOnPathsToDominatedBlock( 615 GVNFlagSet
616 HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock(
619 HBasicBlock* dominator, HBasicBlock* dominated) { 617 HBasicBlock* dominator, HBasicBlock* dominated) {
620 GVNFlagSet side_effects; 618 GVNFlagSet side_effects;
621 for (int i = 0; i < dominated->predecessors()->length(); ++i) { 619 for (int i = 0; i < dominated->predecessors()->length(); ++i) {
622 HBasicBlock* block = dominated->predecessors()->at(i); 620 HBasicBlock* block = dominated->predecessors()->at(i);
623 if (dominator->block_id() < block->block_id() && 621 if (dominator->block_id() < block->block_id() &&
624 block->block_id() < dominated->block_id() && 622 block->block_id() < dominated->block_id() &&
625 visited_on_paths_.Add(block->block_id())) { 623 visited_on_paths_.Add(block->block_id())) {
626 side_effects.Add(block_side_effects_[block->block_id()]); 624 side_effects.Add(block_side_effects_[block->block_id()]);
627 if (block->IsLoopHeader()) { 625 if (block->IsLoopHeader()) {
628 side_effects.Add(loop_side_effects_[block->block_id()]); 626 side_effects.Add(loop_side_effects_[block->block_id()]);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 HValueMap* map_; 746 HValueMap* map_;
749 HSideEffectMap dominators_; 747 HSideEffectMap dominators_;
750 int dominated_index_; 748 int dominated_index_;
751 int length_; 749 int length_;
752 }; 750 };
753 751
754 // This is a recursive traversal of the dominator tree but it has been turned 752 // This is a recursive traversal of the dominator tree but it has been turned
755 // into a loop to avoid stack overflows. 753 // into a loop to avoid stack overflows.
756 // The logical "stack frames" of the recursion are kept in a list of 754 // The logical "stack frames" of the recursion are kept in a list of
757 // GvnBasicBlockState instances. 755 // GvnBasicBlockState instances.
758 void HGlobalValueNumberer::AnalyzeGraph() { 756 void HGlobalValueNumberingPhase::AnalyzeGraph() {
759 HBasicBlock* entry_block = graph_->entry_block(); 757 HBasicBlock* entry_block = graph()->entry_block();
760 HValueMap* entry_map = new(zone()) HValueMap(zone()); 758 HValueMap* entry_map = new(zone()) HValueMap(zone());
761 GvnBasicBlockState* current = 759 GvnBasicBlockState* current =
762 GvnBasicBlockState::CreateEntry(zone(), entry_block, entry_map); 760 GvnBasicBlockState::CreateEntry(zone(), entry_block, entry_map);
763 761
764 while (current != NULL) { 762 while (current != NULL) {
765 HBasicBlock* block = current->block(); 763 HBasicBlock* block = current->block();
766 HValueMap* map = current->map(); 764 HValueMap* map = current->map();
767 HSideEffectMap* dominators = current->dominators(); 765 HSideEffectMap* dominators = current->dominators();
768 766
769 TRACE_GVN_2("Analyzing block B%d%s\n", 767 TRACE_GVN_2("Analyzing block B%d%s\n",
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 dominated); 846 dominated);
849 successor_map->Kill(side_effects_on_all_paths); 847 successor_map->Kill(side_effects_on_all_paths);
850 successor_dominators->Kill(side_effects_on_all_paths); 848 successor_dominators->Kill(side_effects_on_all_paths);
851 } 849 }
852 } 850 }
853 current = next; 851 current = next;
854 } 852 }
855 } 853 }
856 854
857 } } // namespace v8::internal 855 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-gvn.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698