LCOV - code coverage report
Current view: top level - test/unittests/compiler - live-range-builder.h (source / functions) Hit Total Coverage
Test: app.info Lines: 15 15 100.0 %
Date: 2017-10-20 Functions: 2 2 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             : #ifndef V8_LIVE_RANGE_BUILDER_H_
       6             : #define V8_LIVE_RANGE_BUILDER_H_
       7             : 
       8             : #include "src/compiler/register-allocator.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : namespace compiler {
      13             : 
      14             : 
      15             : // Utility offering shorthand syntax for building up a range by providing its ID
      16             : // and pairs (start, end) specifying intervals. Circumvents current incomplete
      17             : // support for C++ features such as instantiation lists, on OS X and Android.
      18         116 : class TestRangeBuilder {
      19             :  public:
      20             :   explicit TestRangeBuilder(Zone* zone)
      21         116 :       : id_(-1), pairs_(), uses_(), zone_(zone) {}
      22             : 
      23             :   TestRangeBuilder& Id(int id) {
      24           1 :     id_ = id;
      25             :     return *this;
      26             :   }
      27             :   TestRangeBuilder& Add(int start, int end) {
      28          90 :     pairs_.push_back({start, end});
      29             :     return *this;
      30             :   }
      31             : 
      32             :   TestRangeBuilder& AddUse(int pos) {
      33             :     uses_.insert(pos);
      34             :     return *this;
      35             :   }
      36             : 
      37             :   TopLevelLiveRange* Build(int start, int end) {
      38          19 :     return Add(start, end).Build();
      39             :   }
      40             : 
      41          58 :   TopLevelLiveRange* Build() {
      42             :     TopLevelLiveRange* range =
      43         116 :         new (zone_) TopLevelLiveRange(id_, MachineRepresentation::kTagged);
      44             :     // Traverse the provided interval specifications backwards, because that is
      45             :     // what LiveRange expects.
      46         296 :     for (int i = static_cast<int>(pairs_.size()) - 1; i >= 0; --i) {
      47         180 :       Interval pair = pairs_[i];
      48             :       LifetimePosition start = LifetimePosition::FromInt(pair.first);
      49             :       LifetimePosition end = LifetimePosition::FromInt(pair.second);
      50          90 :       CHECK(start < end);
      51          90 :       range->AddUseInterval(start, end, zone_);
      52             :     }
      53         140 :     for (int pos : uses_) {
      54             :       UsePosition* use_position =
      55             :           new (zone_) UsePosition(LifetimePosition::FromInt(pos), nullptr,
      56          48 :                                   nullptr, UsePositionHintType::kNone);
      57          24 :       range->AddUsePosition(use_position);
      58             :     }
      59             : 
      60             :     pairs_.clear();
      61          58 :     return range;
      62             :   }
      63             : 
      64             :  private:
      65             :   typedef std::pair<int, int> Interval;
      66             :   typedef std::vector<Interval> IntervalList;
      67             :   int id_;
      68             :   IntervalList pairs_;
      69             :   std::set<int> uses_;
      70             :   Zone* zone_;
      71             : };
      72             : 
      73             : 
      74             : }  // namespace compiler
      75             : }  // namespace internal
      76             : }  // namespace v8
      77             : 
      78             : #endif  // V8_LIVE_RANGE_BUILDER_H_

Generated by: LCOV version 1.10