summaryrefslogtreecommitdiff
path: root/deps/v8/test/unittests/compiler/regalloc/live-range-unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/unittests/compiler/regalloc/live-range-unittest.cc')
-rw-r--r--deps/v8/test/unittests/compiler/regalloc/live-range-unittest.cc60
1 files changed, 59 insertions, 1 deletions
diff --git a/deps/v8/test/unittests/compiler/regalloc/live-range-unittest.cc b/deps/v8/test/unittests/compiler/regalloc/live-range-unittest.cc
index fc7b268b44..9ac6ca8810 100644
--- a/deps/v8/test/unittests/compiler/regalloc/live-range-unittest.cc
+++ b/deps/v8/test/unittests/compiler/regalloc/live-range-unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "test/unittests/compiler/live-range-builder.h"
+#include "src/compiler/backend/register-allocator.h"
#include "test/unittests/test-utils.h"
// TODO(mtrofin): would we want to centralize this definition?
@@ -20,6 +20,64 @@ namespace v8 {
namespace internal {
namespace compiler {
+// Utility offering shorthand syntax for building up a range by providing its ID
+// and pairs (start, end) specifying intervals. Circumvents current incomplete
+// support for C++ features such as instantiation lists, on OS X and Android.
+class TestRangeBuilder {
+ public:
+ explicit TestRangeBuilder(Zone* zone)
+ : id_(-1), pairs_(), uses_(), zone_(zone) {}
+
+ TestRangeBuilder& Id(int id) {
+ id_ = id;
+ return *this;
+ }
+ TestRangeBuilder& Add(int start, int end) {
+ pairs_.push_back({start, end});
+ return *this;
+ }
+
+ TestRangeBuilder& AddUse(int pos) {
+ uses_.insert(pos);
+ return *this;
+ }
+
+ TopLevelLiveRange* Build(int start, int end) {
+ return Add(start, end).Build();
+ }
+
+ TopLevelLiveRange* Build() {
+ TopLevelLiveRange* range =
+ new (zone_) TopLevelLiveRange(id_, MachineRepresentation::kTagged);
+ // Traverse the provided interval specifications backwards, because that is
+ // what LiveRange expects.
+ for (int i = static_cast<int>(pairs_.size()) - 1; i >= 0; --i) {
+ Interval pair = pairs_[i];
+ LifetimePosition start = LifetimePosition::FromInt(pair.first);
+ LifetimePosition end = LifetimePosition::FromInt(pair.second);
+ CHECK(start < end);
+ range->AddUseInterval(start, end, zone_);
+ }
+ for (int pos : uses_) {
+ UsePosition* use_position =
+ new (zone_) UsePosition(LifetimePosition::FromInt(pos), nullptr,
+ nullptr, UsePositionHintType::kNone);
+ range->AddUsePosition(use_position);
+ }
+
+ pairs_.clear();
+ return range;
+ }
+
+ private:
+ typedef std::pair<int, int> Interval;
+ typedef std::vector<Interval> IntervalList;
+ int id_;
+ IntervalList pairs_;
+ std::set<int> uses_;
+ Zone* zone_;
+};
+
class LiveRangeUnitTest : public TestWithZone {
public:
// Split helper, to avoid int->LifetimePosition conversion nuisance.