2015-08-31 09:57:33 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_LIVE_RANGE_BUILDER_H_
|
|
|
|
#define V8_LIVE_RANGE_BUILDER_H_
|
|
|
|
|
|
|
|
#include "src/compiler/register-allocator.h"
|
|
|
|
|
|
|
|
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:
|
2015-08-31 13:26:57 +00:00
|
|
|
explicit TestRangeBuilder(Zone* zone)
|
|
|
|
: id_(-1), pairs_(), uses_(), zone_(zone) {}
|
2015-08-31 09:57:33 +00:00
|
|
|
|
|
|
|
TestRangeBuilder& Id(int id) {
|
|
|
|
id_ = id;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
TestRangeBuilder& Add(int start, int end) {
|
|
|
|
pairs_.push_back({start, end});
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-08-31 13:26:57 +00:00
|
|
|
TestRangeBuilder& AddUse(int pos) {
|
|
|
|
uses_.insert(pos);
|
|
|
|
return *this;
|
|
|
|
}
|
2015-08-31 09:57:33 +00:00
|
|
|
|
2015-08-31 13:26:57 +00:00
|
|
|
TopLevelLiveRange* Build(int start, int end) {
|
|
|
|
return Add(start, end).Build();
|
|
|
|
}
|
|
|
|
|
|
|
|
TopLevelLiveRange* Build() {
|
2015-08-31 09:57:33 +00:00
|
|
|
TopLevelLiveRange* range =
|
2015-12-10 09:03:30 +00:00
|
|
|
new (zone_) TopLevelLiveRange(id_, MachineRepresentation::kTagged);
|
2015-08-31 09:57:33 +00:00
|
|
|
// 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_);
|
|
|
|
}
|
2015-08-31 13:26:57 +00:00
|
|
|
for (int pos : uses_) {
|
|
|
|
UsePosition* use_position =
|
|
|
|
new (zone_) UsePosition(LifetimePosition::FromInt(pos), nullptr,
|
|
|
|
nullptr, UsePositionHintType::kNone);
|
|
|
|
range->AddUsePosition(use_position);
|
|
|
|
}
|
2015-08-31 09:57:33 +00:00
|
|
|
|
|
|
|
pairs_.clear();
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::pair<int, int> Interval;
|
|
|
|
typedef std::vector<Interval> IntervalList;
|
|
|
|
int id_;
|
|
|
|
IntervalList pairs_;
|
2015-08-31 13:26:57 +00:00
|
|
|
std::set<int> uses_;
|
2015-08-31 09:57:33 +00:00
|
|
|
Zone* zone_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_LIVE_RANGE_BUILDER_H_
|