LCOV - code coverage report
Current view: top level - src/compiler - live-range-separator.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 69 69 100.0 %
Date: 2017-04-26 Functions: 6 6 100.0 %

          Line data    Source code
       1             : // Copyright 2015 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/compiler/live-range-separator.h"
       6             : #include "src/compiler/register-allocator.h"
       7             : 
       8             : namespace v8 {
       9             : namespace internal {
      10             : namespace compiler {
      11             : 
      12             : 
      13             : #define TRACE(...)                             \
      14             :   do {                                         \
      15             :     if (FLAG_trace_alloc) PrintF(__VA_ARGS__); \
      16             :   } while (false)
      17             : 
      18             : 
      19             : namespace {
      20             : 
      21             : 
      22    30644696 : void CreateSplinter(TopLevelLiveRange *range, RegisterAllocationData *data,
      23             :                     LifetimePosition first_cut, LifetimePosition last_cut) {
      24             :   DCHECK(!range->IsSplinter());
      25             :   // We can ignore ranges that live solely in deferred blocks.
      26             :   // If a range ends right at the end of a deferred block, it is marked by
      27             :   // the range builder as ending at gap start of the next block - since the
      28             :   // end is a position where the variable isn't live. We need to take that
      29             :   // into consideration.
      30             :   LifetimePosition max_allowed_end = last_cut.NextFullStart();
      31             : 
      32    25423733 :   if (first_cut <= range->Start() && max_allowed_end >= range->End()) {
      33    11069758 :     return;
      34             :   }
      35             : 
      36             :   LifetimePosition start = Max(first_cut, range->Start());
      37             :   LifetimePosition end = Min(last_cut, range->End());
      38             : 
      39    11069778 :   if (start < end) {
      40             :     // Ensure the original range has a spill range associated, before it gets
      41             :     // splintered. Splinters will point to it. This way, when attempting to
      42             :     // reuse spill slots of splinters, during allocation, we avoid clobbering
      43             :     // such slots.
      44     9787491 :     if (range->MayRequireSpillRange()) {
      45      866277 :       data->CreateSpillRangeForLiveRange(range);
      46             :     }
      47     9787477 :     if (range->splinter() == nullptr) {
      48     3284200 :       TopLevelLiveRange *splinter =
      49     3284202 :           data->NextLiveRange(range->representation());
      50             :       DCHECK_NULL(data->live_ranges()[splinter->vreg()]);
      51     6568400 :       data->live_ranges()[splinter->vreg()] = splinter;
      52     3284200 :       range->SetSplinter(splinter);
      53             :     }
      54             :     Zone *zone = data->allocation_zone();
      55     9787466 :     TRACE("creating splinter for range %d between %d and %d\n", range->vreg(),
      56             :           start.ToInstructionIndex(), end.ToInstructionIndex());
      57     9787466 :     range->Splinter(start, end, zone);
      58             :   }
      59             : }
      60             : 
      61    10995279 : void SetSlotUse(TopLevelLiveRange *range) {
      62             :   range->set_has_slot_use(false);
      63    16812716 :   for (const UsePosition *pos = range->first_pos();
      64     8406358 :        !range->has_slot_use() && pos != nullptr; pos = pos->next()) {
      65     5817437 :     if (pos->type() == UsePositionType::kRequiresSlot) {
      66             :       range->set_has_slot_use(true);
      67             :     }
      68             :   }
      69     2588921 : }
      70             : 
      71    39886228 : void SplinterLiveRange(TopLevelLiveRange *range, RegisterAllocationData *data) {
      72   103665982 :   const InstructionSequence *code = data->code();
      73    41612802 :   UseInterval *interval = range->first_interval();
      74             : 
      75             :   LifetimePosition first_cut = LifetimePosition::Invalid();
      76    18206012 :   LifetimePosition last_cut = LifetimePosition::Invalid();
      77             : 
      78    59818844 :   while (interval != nullptr) {
      79             :     UseInterval *next_interval = interval->next();
      80             :     const InstructionBlock *first_block =
      81    23406790 :         code->GetInstructionBlock(interval->FirstGapIndex());
      82             :     const InstructionBlock *last_block =
      83    23406795 :         code->GetInstructionBlock(interval->LastGapIndex());
      84             :     int first_block_nr = first_block->rpo_number().ToInt();
      85             :     int last_block_nr = last_block->rpo_number().ToInt();
      86   127072802 :     for (int block_id = first_block_nr; block_id <= last_block_nr; ++block_id) {
      87   136553706 :       const InstructionBlock *current_block =
      88   103665982 :           code->InstructionBlockAt(RpoNumber::FromInt(block_id));
      89   103666012 :       if (current_block->IsDeferred()) {
      90    21817889 :         if (!first_cut.IsValid()) {
      91             :           first_cut = LifetimePosition::GapFromInstructionIndex(
      92             :               current_block->first_instruction_index());
      93             :         }
      94             :         last_cut = LifetimePosition::GapFromInstructionIndex(
      95    21817889 :             current_block->last_instruction_index());
      96             :       } else {
      97    81848123 :         if (first_cut.IsValid()) {
      98    10249819 :           CreateSplinter(range, data, first_cut, last_cut);
      99             :           first_cut = LifetimePosition::Invalid();
     100    10249823 :           last_cut = LifetimePosition::Invalid();
     101             :         }
     102             :       }
     103             :     }
     104             :     interval = next_interval;
     105             :   }
     106             :   // When the range ends in deferred blocks, first_cut will be valid here.
     107             :   // Splinter from there to the last instruction that was in a deferred block.
     108    18206042 :   if (first_cut.IsValid()) {
     109      819998 :     CreateSplinter(range, data, first_cut, last_cut);
     110             :   }
     111             : 
     112             :   // Redo has_slot_use
     113    20385748 :   if (range->has_slot_use() && range->splinter() != nullptr) {
     114     1294468 :     SetSlotUse(range);
     115     1294468 :     SetSlotUse(range->splinter());
     116             :   }
     117    18206068 : }
     118             : 
     119             : }  // namespace
     120             : 
     121             : 
     122    66293427 : void LiveRangeSeparator::Splinter() {
     123      915120 :   size_t virt_reg_count = data()->live_ranges().size();
     124    48087375 :   for (size_t vreg = 0; vreg < virt_reg_count; ++vreg) {
     125   119923543 :     TopLevelLiveRange *range = data()->live_ranges()[vreg];
     126    99385254 :     if (range == nullptr || range->IsEmpty() || range->IsSplinter()) {
     127             :       continue;
     128             :     }
     129             :     int first_instr = range->first_interval()->FirstGapIndex();
     130    22294830 :     if (!data()->code()->GetInstructionBlock(first_instr)->IsDeferred()) {
     131    18206032 :       SplinterLiveRange(range, data());
     132             :     }
     133             :   }
     134      915100 : }
     135             : 
     136             : 
     137     1545660 : void LiveRangeMerger::MarkRangesSpilledInDeferredBlocks() {
     138     1545660 :   const InstructionSequence *code = data()->code();
     139    74581614 :   for (TopLevelLiveRange *top : data()->live_ranges()) {
     140   102669970 :     if (top == nullptr || top->IsEmpty() || top->splinter() == nullptr ||
     141    48750629 :         top->HasSpillOperand() || !top->splinter()->HasSpillRange()) {
     142             :       continue;
     143             :     }
     144             : 
     145     2499492 :     LiveRange *child = top;
     146     2228514 :     for (; child != nullptr; child = child->next()) {
     147     2499722 :       if (child->spilled() ||
     148      901925 :           child->NextSlotPosition(child->Start()) != nullptr) {
     149             :         break;
     150             :       }
     151             :     }
     152     1326819 :     if (child == nullptr) {
     153             :       top->TreatAsSpilledInDeferredBlock(data()->allocation_zone(),
     154      630718 :                                          code->InstructionBlockCount());
     155             :     }
     156             :   }
     157      915104 : }
     158             : 
     159             : 
     160    52287155 : void LiveRangeMerger::Merge() {
     161      915096 :   MarkRangesSpilledInDeferredBlocks();
     162             : 
     163     1830236 :   int live_range_count = static_cast<int>(data()->live_ranges().size());
     164    48087817 :   for (int i = 0; i < live_range_count; ++i) {
     165   170381599 :     TopLevelLiveRange *range = data()->live_ranges()[i];
     166    99386166 :     if (range == nullptr || range->IsEmpty() || !range->IsSplinter()) {
     167             :       continue;
     168             :     }
     169             :     TopLevelLiveRange *splinter_parent = range->splintered_from();
     170             : 
     171             :     int to_remove = range->vreg();
     172     3284242 :     splinter_parent->Merge(range, data()->allocation_zone());
     173     9852690 :     data()->live_ranges()[to_remove] = nullptr;
     174             :   }
     175      915106 : }
     176             : 
     177             : 
     178             : }  // namespace compiler
     179             : }  // namespace internal
     180             : }  // namespace v8

Generated by: LCOV version 1.10