2014-07-30 13:54:45 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2018-11-12 14:12:52 +00:00
|
|
|
#include "src/compiler/backend/gap-resolver.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
#include "src/base/utils/random-number-generator.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2017-08-02 13:36:27 +00:00
|
|
|
const auto GetRegConfig = RegisterConfiguration::Default;
|
2016-10-03 23:45:51 +00:00
|
|
|
|
2016-10-26 16:04:11 +00:00
|
|
|
// Fragments the given FP operand into an equivalent set of FP operands to
|
|
|
|
// simplify ParallelMove equivalence testing.
|
2016-10-03 23:45:51 +00:00
|
|
|
void GetCanonicalOperands(const InstructionOperand& op,
|
|
|
|
std::vector<InstructionOperand>* fragments) {
|
2022-03-11 02:47:26 +00:00
|
|
|
CHECK_EQ(kFPAliasing, AliasingKind::kCombine);
|
2016-10-03 23:45:51 +00:00
|
|
|
CHECK(op.IsFPLocationOperand());
|
2016-10-26 16:04:11 +00:00
|
|
|
const LocationOperand& loc = LocationOperand::cast(op);
|
|
|
|
MachineRepresentation rep = loc.representation();
|
|
|
|
int base = -1;
|
|
|
|
int aliases = GetRegConfig()->GetAliases(
|
|
|
|
rep, 0, MachineRepresentation::kFloat32, &base);
|
|
|
|
CHECK_LT(0, aliases);
|
|
|
|
CHECK_GE(4, aliases);
|
|
|
|
int index = -1;
|
|
|
|
int step = 1;
|
|
|
|
if (op.IsFPRegister()) {
|
|
|
|
index = loc.register_code() * aliases;
|
|
|
|
} else {
|
|
|
|
index = loc.index();
|
|
|
|
step = -1;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < aliases; i++) {
|
|
|
|
fragments->push_back(AllocatedOperand(loc.location_kind(),
|
|
|
|
MachineRepresentation::kFloat32,
|
|
|
|
index + i * step));
|
|
|
|
}
|
2016-10-03 23:45:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// The state of our move interpreter is the mapping of operands to values. Note
|
|
|
|
// that the actual values don't really matter, all we care about is equality.
|
|
|
|
class InterpreterState {
|
|
|
|
public:
|
2015-04-15 12:36:36 +00:00
|
|
|
void ExecuteInParallel(const ParallelMove* moves) {
|
2014-07-30 13:54:45 +00:00
|
|
|
InterpreterState copy(*this);
|
2015-04-15 12:36:36 +00:00
|
|
|
for (const auto m : *moves) {
|
2016-10-03 23:45:51 +00:00
|
|
|
CHECK(!m->IsRedundant());
|
|
|
|
const InstructionOperand& src = m->source();
|
|
|
|
const InstructionOperand& dst = m->destination();
|
2022-03-11 02:47:26 +00:00
|
|
|
if (kFPAliasing == AliasingKind::kCombine && src.IsFPLocationOperand() &&
|
2016-10-03 23:45:51 +00:00
|
|
|
dst.IsFPLocationOperand()) {
|
2016-10-26 16:04:11 +00:00
|
|
|
// Canonicalize FP location-location moves by fragmenting them into
|
|
|
|
// an equivalent sequence of float32 moves, to simplify state
|
|
|
|
// equivalence testing.
|
2016-10-03 23:45:51 +00:00
|
|
|
std::vector<InstructionOperand> src_fragments;
|
|
|
|
GetCanonicalOperands(src, &src_fragments);
|
|
|
|
CHECK(!src_fragments.empty());
|
|
|
|
std::vector<InstructionOperand> dst_fragments;
|
|
|
|
GetCanonicalOperands(dst, &dst_fragments);
|
|
|
|
CHECK_EQ(src_fragments.size(), dst_fragments.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < src_fragments.size(); ++i) {
|
|
|
|
write(dst_fragments[i], copy.read(src_fragments[i]));
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// All other moves.
|
|
|
|
write(dst, copy.read(src));
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-30 11:27:45 +00:00
|
|
|
void MoveToTempLocation(InstructionOperand& source) {
|
|
|
|
scratch_ = KeyFor(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MoveFromTempLocation(InstructionOperand& dst) {
|
|
|
|
AllocatedOperand src(scratch_.kind, scratch_.rep, scratch_.index);
|
|
|
|
if (kFPAliasing == AliasingKind::kCombine && src.IsFPLocationOperand() &&
|
|
|
|
dst.IsFPLocationOperand()) {
|
|
|
|
// Canonicalize FP location-location moves by fragmenting them into
|
|
|
|
// an equivalent sequence of float32 moves, to simplify state
|
|
|
|
// equivalence testing.
|
|
|
|
std::vector<InstructionOperand> src_fragments;
|
|
|
|
GetCanonicalOperands(src, &src_fragments);
|
|
|
|
CHECK(!src_fragments.empty());
|
|
|
|
std::vector<InstructionOperand> dst_fragments;
|
|
|
|
GetCanonicalOperands(dst, &dst_fragments);
|
|
|
|
CHECK_EQ(src_fragments.size(), dst_fragments.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < src_fragments.size(); ++i) {
|
|
|
|
write(dst_fragments[i], KeyFor(src_fragments[i]));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
write(dst, scratch_);
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
bool operator==(const InterpreterState& other) const {
|
|
|
|
return values_ == other.values_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-10-03 23:45:51 +00:00
|
|
|
// struct for mapping operands to a unique value, that makes it easier to
|
|
|
|
// detect illegal parallel moves, and to evaluate moves for equivalence. This
|
|
|
|
// is a one way transformation. All general register and slot operands are
|
|
|
|
// mapped to the default representation. FP registers and slots are mapped to
|
|
|
|
// float64 except on architectures with non-simple FP register aliasing, where
|
|
|
|
// the actual representation is used.
|
2015-04-09 10:40:41 +00:00
|
|
|
struct Key {
|
|
|
|
bool is_constant;
|
2016-07-20 19:05:48 +00:00
|
|
|
MachineRepresentation rep;
|
[turbofan] Create ExplicitOperands to specify operands without virtual registers
Up until now, if one wanted to specify an explicit stack location or register as an operand for an instruction, it had to also be
explicitly associated with a virtual register as a so-called
FixedRegister or FixedStackSlot.
For the implementation of tail calls, the plan is to use the gap
resolver needs to shuffle stack locations from the caller to the
tail-called callee. In order to do this, it must be possible to
explicitly address operand locations on the stack that are not
associated with virtual registers.
This CL introduces ExplictOperands, which can specify a specific
register or stack location that is not associated with virtual
register. This will allow tail calls to specify the target
locations for the necessary stack moves in the gap for the tail
call without the core register allocation having to know about
the target of the stack moves at all.
In the process this CL:
* creates a new Operand kind, ExplicitOperand, with which
instructions can specify register and stack slots without an
associated virtual register.
* creates a LocationOperand class from which AllocatedOperand and
ExplicitOperand are derived and provides a common interface to
get Register, DoubleRegister and spill slot information.
* removes RegisterOperand, DoubleRegisterOperand,
StackSlotOperand and DoubleStackSlotOperand, they are subsumed
by LocationOperand.
* addresses a cleanup TODO in AllocatedOperand to reduce the
redundancy of AllocatedOperand::Kind by using machine_type() to
determine if an operand corresponds to a general purpose or
double register.
BUG=v8:4076
LOG=n
Review URL: https://codereview.chromium.org/1389373002
Cr-Commit-Position: refs/heads/master@{#31603}
2015-10-27 13:26:35 +00:00
|
|
|
LocationOperand::LocationKind kind;
|
2015-04-09 10:40:41 +00:00
|
|
|
int index;
|
|
|
|
|
|
|
|
bool operator<(const Key& other) const {
|
|
|
|
if (this->is_constant != other.is_constant) {
|
|
|
|
return this->is_constant;
|
|
|
|
}
|
2016-07-20 19:05:48 +00:00
|
|
|
if (this->rep != other.rep) {
|
2016-10-03 23:45:51 +00:00
|
|
|
return this->rep < other.rep;
|
[turbofan] Create ExplicitOperands to specify operands without virtual registers
Up until now, if one wanted to specify an explicit stack location or register as an operand for an instruction, it had to also be
explicitly associated with a virtual register as a so-called
FixedRegister or FixedStackSlot.
For the implementation of tail calls, the plan is to use the gap
resolver needs to shuffle stack locations from the caller to the
tail-called callee. In order to do this, it must be possible to
explicitly address operand locations on the stack that are not
associated with virtual registers.
This CL introduces ExplictOperands, which can specify a specific
register or stack location that is not associated with virtual
register. This will allow tail calls to specify the target
locations for the necessary stack moves in the gap for the tail
call without the core register allocation having to know about
the target of the stack moves at all.
In the process this CL:
* creates a new Operand kind, ExplicitOperand, with which
instructions can specify register and stack slots without an
associated virtual register.
* creates a LocationOperand class from which AllocatedOperand and
ExplicitOperand are derived and provides a common interface to
get Register, DoubleRegister and spill slot information.
* removes RegisterOperand, DoubleRegisterOperand,
StackSlotOperand and DoubleStackSlotOperand, they are subsumed
by LocationOperand.
* addresses a cleanup TODO in AllocatedOperand to reduce the
redundancy of AllocatedOperand::Kind by using machine_type() to
determine if an operand corresponds to a general purpose or
double register.
BUG=v8:4076
LOG=n
Review URL: https://codereview.chromium.org/1389373002
Cr-Commit-Position: refs/heads/master@{#31603}
2015-10-27 13:26:35 +00:00
|
|
|
}
|
2015-04-09 10:40:41 +00:00
|
|
|
if (this->kind != other.kind) {
|
|
|
|
return this->kind < other.kind;
|
|
|
|
}
|
|
|
|
return this->index < other.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const Key& other) const {
|
2016-07-20 19:05:48 +00:00
|
|
|
return this->is_constant == other.is_constant && this->rep == other.rep &&
|
2015-04-09 10:40:41 +00:00
|
|
|
this->kind == other.kind && this->index == other.index;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-03 23:45:51 +00:00
|
|
|
// Internally, the state is a normalized permutation of Value pairs.
|
2019-05-27 11:31:49 +00:00
|
|
|
using Value = Key;
|
|
|
|
using OperandMap = std::map<Key, Value>;
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-04-15 12:36:36 +00:00
|
|
|
Value read(const InstructionOperand& op) const {
|
2014-07-30 13:54:45 +00:00
|
|
|
OperandMap::const_iterator it = values_.find(KeyFor(op));
|
|
|
|
return (it == values_.end()) ? ValueFor(op) : it->second;
|
|
|
|
}
|
|
|
|
|
2016-10-03 23:45:51 +00:00
|
|
|
void write(const InstructionOperand& dst, Value v) {
|
|
|
|
if (v == ValueFor(dst)) {
|
|
|
|
values_.erase(KeyFor(dst));
|
2014-07-30 13:54:45 +00:00
|
|
|
} else {
|
2016-10-03 23:45:51 +00:00
|
|
|
values_[KeyFor(dst)] = v;
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-15 12:36:36 +00:00
|
|
|
static Key KeyFor(const InstructionOperand& op) {
|
|
|
|
bool is_constant = op.IsConstant();
|
2016-07-20 19:05:48 +00:00
|
|
|
MachineRepresentation rep =
|
|
|
|
v8::internal::compiler::InstructionSequence::DefaultRepresentation();
|
[turbofan] Create ExplicitOperands to specify operands without virtual registers
Up until now, if one wanted to specify an explicit stack location or register as an operand for an instruction, it had to also be
explicitly associated with a virtual register as a so-called
FixedRegister or FixedStackSlot.
For the implementation of tail calls, the plan is to use the gap
resolver needs to shuffle stack locations from the caller to the
tail-called callee. In order to do this, it must be possible to
explicitly address operand locations on the stack that are not
associated with virtual registers.
This CL introduces ExplictOperands, which can specify a specific
register or stack location that is not associated with virtual
register. This will allow tail calls to specify the target
locations for the necessary stack moves in the gap for the tail
call without the core register allocation having to know about
the target of the stack moves at all.
In the process this CL:
* creates a new Operand kind, ExplicitOperand, with which
instructions can specify register and stack slots without an
associated virtual register.
* creates a LocationOperand class from which AllocatedOperand and
ExplicitOperand are derived and provides a common interface to
get Register, DoubleRegister and spill slot information.
* removes RegisterOperand, DoubleRegisterOperand,
StackSlotOperand and DoubleStackSlotOperand, they are subsumed
by LocationOperand.
* addresses a cleanup TODO in AllocatedOperand to reduce the
redundancy of AllocatedOperand::Kind by using machine_type() to
determine if an operand corresponds to a general purpose or
double register.
BUG=v8:4076
LOG=n
Review URL: https://codereview.chromium.org/1389373002
Cr-Commit-Position: refs/heads/master@{#31603}
2015-10-27 13:26:35 +00:00
|
|
|
LocationOperand::LocationKind kind;
|
2015-04-09 10:40:41 +00:00
|
|
|
int index;
|
|
|
|
if (!is_constant) {
|
2016-07-20 19:05:48 +00:00
|
|
|
const LocationOperand& loc_op = LocationOperand::cast(op);
|
2016-10-26 16:04:11 +00:00
|
|
|
// Preserve FP representation when FP register aliasing is complex.
|
|
|
|
// Otherwise, canonicalize to kFloat64.
|
2016-10-03 23:45:51 +00:00
|
|
|
if (IsFloatingPoint(loc_op.representation())) {
|
2022-03-11 02:47:26 +00:00
|
|
|
if (kFPAliasing == AliasingKind::kIndependent) {
|
|
|
|
rep = IsSimd128(loc_op.representation())
|
|
|
|
? MachineRepresentation::kSimd128
|
|
|
|
: MachineRepresentation::kFloat64;
|
|
|
|
} else if (kFPAliasing == AliasingKind::kOverlap) {
|
|
|
|
rep = MachineRepresentation::kFloat64;
|
|
|
|
} else {
|
|
|
|
rep = loc_op.representation();
|
|
|
|
}
|
2016-10-03 23:45:51 +00:00
|
|
|
}
|
2016-07-20 19:05:48 +00:00
|
|
|
if (loc_op.IsAnyRegister()) {
|
|
|
|
index = loc_op.register_code();
|
2015-10-02 16:55:12 +00:00
|
|
|
} else {
|
2016-07-20 19:05:48 +00:00
|
|
|
index = loc_op.index();
|
2015-10-02 16:55:12 +00:00
|
|
|
}
|
2016-07-20 19:05:48 +00:00
|
|
|
kind = loc_op.location_kind();
|
2015-04-09 10:40:41 +00:00
|
|
|
} else {
|
2015-04-15 12:36:36 +00:00
|
|
|
index = ConstantOperand::cast(op).virtual_register();
|
[turbofan] Create ExplicitOperands to specify operands without virtual registers
Up until now, if one wanted to specify an explicit stack location or register as an operand for an instruction, it had to also be
explicitly associated with a virtual register as a so-called
FixedRegister or FixedStackSlot.
For the implementation of tail calls, the plan is to use the gap
resolver needs to shuffle stack locations from the caller to the
tail-called callee. In order to do this, it must be possible to
explicitly address operand locations on the stack that are not
associated with virtual registers.
This CL introduces ExplictOperands, which can specify a specific
register or stack location that is not associated with virtual
register. This will allow tail calls to specify the target
locations for the necessary stack moves in the gap for the tail
call without the core register allocation having to know about
the target of the stack moves at all.
In the process this CL:
* creates a new Operand kind, ExplicitOperand, with which
instructions can specify register and stack slots without an
associated virtual register.
* creates a LocationOperand class from which AllocatedOperand and
ExplicitOperand are derived and provides a common interface to
get Register, DoubleRegister and spill slot information.
* removes RegisterOperand, DoubleRegisterOperand,
StackSlotOperand and DoubleStackSlotOperand, they are subsumed
by LocationOperand.
* addresses a cleanup TODO in AllocatedOperand to reduce the
redundancy of AllocatedOperand::Kind by using machine_type() to
determine if an operand corresponds to a general purpose or
double register.
BUG=v8:4076
LOG=n
Review URL: https://codereview.chromium.org/1389373002
Cr-Commit-Position: refs/heads/master@{#31603}
2015-10-27 13:26:35 +00:00
|
|
|
kind = LocationOperand::REGISTER;
|
2015-04-09 10:40:41 +00:00
|
|
|
}
|
2016-07-20 19:05:48 +00:00
|
|
|
Key key = {is_constant, rep, kind, index};
|
2015-04-09 10:40:41 +00:00
|
|
|
return key;
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 12:36:36 +00:00
|
|
|
static Value ValueFor(const InstructionOperand& op) { return KeyFor(op); }
|
2015-04-09 09:15:28 +00:00
|
|
|
|
|
|
|
static InstructionOperand FromKey(Key key) {
|
2015-04-09 10:40:41 +00:00
|
|
|
if (key.is_constant) {
|
|
|
|
return ConstantOperand(key.index);
|
2015-04-09 09:15:28 +00:00
|
|
|
}
|
2016-07-20 19:05:48 +00:00
|
|
|
return AllocatedOperand(key.kind, key.rep, key.index);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
friend std::ostream& operator<<(std::ostream& os,
|
|
|
|
const InterpreterState& is) {
|
2018-11-21 12:44:39 +00:00
|
|
|
const char* space = "";
|
|
|
|
for (auto& value : is.values_) {
|
|
|
|
InstructionOperand source = FromKey(value.second);
|
|
|
|
InstructionOperand destination = FromKey(value.first);
|
|
|
|
os << space << MoveOperands{source, destination};
|
|
|
|
space = " ";
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
OperandMap values_;
|
2022-06-01 16:56:02 +00:00
|
|
|
Key scratch_ = {};
|
2014-07-30 13:54:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// An abstract interpreter for moves, swaps and parallel moves.
|
|
|
|
class MoveInterpreter : public GapResolver::Assembler {
|
|
|
|
public:
|
2015-04-15 12:36:36 +00:00
|
|
|
explicit MoveInterpreter(Zone* zone) : zone_(zone) {}
|
|
|
|
|
2022-05-30 11:27:45 +00:00
|
|
|
void MoveToTempLocation(InstructionOperand* source) final {
|
|
|
|
state_.MoveToTempLocation(*source);
|
|
|
|
}
|
|
|
|
void MoveTempLocationTo(InstructionOperand* dest,
|
|
|
|
MachineRepresentation rep) final {
|
|
|
|
state_.MoveFromTempLocation(*dest);
|
|
|
|
}
|
|
|
|
void SetPendingMove(MoveOperands* move) final {}
|
2015-11-04 13:08:27 +00:00
|
|
|
void AssembleMove(InstructionOperand* source,
|
|
|
|
InstructionOperand* destination) override {
|
2020-07-09 10:43:44 +00:00
|
|
|
ParallelMove* moves = zone_->New<ParallelMove>(zone_);
|
2015-04-15 12:36:36 +00:00
|
|
|
moves->AddMove(*source, *destination);
|
2014-07-30 13:54:45 +00:00
|
|
|
state_.ExecuteInParallel(moves);
|
|
|
|
}
|
2015-11-04 13:08:27 +00:00
|
|
|
void AssembleSwap(InstructionOperand* source,
|
|
|
|
InstructionOperand* destination) override {
|
2020-07-09 10:43:44 +00:00
|
|
|
ParallelMove* moves = zone_->New<ParallelMove>(zone_);
|
2015-04-15 12:36:36 +00:00
|
|
|
moves->AddMove(*source, *destination);
|
|
|
|
moves->AddMove(*destination, *source);
|
2014-07-30 13:54:45 +00:00
|
|
|
state_.ExecuteInParallel(moves);
|
|
|
|
}
|
2015-04-15 12:36:36 +00:00
|
|
|
void AssembleParallelMove(const ParallelMove* moves) {
|
2014-07-30 13:54:45 +00:00
|
|
|
state_.ExecuteInParallel(moves);
|
|
|
|
}
|
|
|
|
|
|
|
|
InterpreterState state() const { return state_; }
|
|
|
|
|
|
|
|
private:
|
2015-04-15 12:36:36 +00:00
|
|
|
Zone* const zone_;
|
2014-07-30 13:54:45 +00:00
|
|
|
InterpreterState state_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParallelMoveCreator : public HandleAndZoneScope {
|
|
|
|
public:
|
|
|
|
ParallelMoveCreator() : rng_(CcTest::random_number_generator()) {}
|
|
|
|
|
2016-10-03 23:45:51 +00:00
|
|
|
// Creates a ParallelMove with 'size' random MoveOperands. Note that illegal
|
|
|
|
// moves will be rejected, so the actual number of MoveOperands may be less.
|
2014-07-30 13:54:45 +00:00
|
|
|
ParallelMove* Create(int size) {
|
2020-07-09 10:43:44 +00:00
|
|
|
ParallelMove* parallel_move = main_zone()->New<ParallelMove>(main_zone());
|
2016-10-03 23:45:51 +00:00
|
|
|
// Valid ParallelMoves can't have interfering destination ops.
|
|
|
|
std::set<InstructionOperand, CompareOperandModuloType> destinations;
|
|
|
|
// Valid ParallelMoves can't have interfering source ops of different reps.
|
|
|
|
std::map<InstructionOperand, MachineRepresentation,
|
|
|
|
CompareOperandModuloType>
|
|
|
|
sources;
|
2014-07-30 13:54:45 +00:00
|
|
|
for (int i = 0; i < size; ++i) {
|
2016-07-20 19:05:48 +00:00
|
|
|
MachineRepresentation rep = RandomRepresentation();
|
2016-06-14 12:26:59 +00:00
|
|
|
MoveOperands mo(CreateRandomOperand(true, rep),
|
|
|
|
CreateRandomOperand(false, rep));
|
2016-10-03 23:45:51 +00:00
|
|
|
if (mo.IsRedundant()) continue;
|
|
|
|
|
|
|
|
const InstructionOperand& dst = mo.destination();
|
|
|
|
bool reject = false;
|
|
|
|
// On architectures where FP register aliasing is non-simple, update the
|
|
|
|
// destinations set with the float equivalents of the operand and check
|
|
|
|
// that all destinations are unique and do not alias each other.
|
2022-03-11 02:47:26 +00:00
|
|
|
if (kFPAliasing == AliasingKind::kCombine &&
|
|
|
|
mo.destination().IsFPLocationOperand()) {
|
2021-09-24 14:43:18 +00:00
|
|
|
std::vector<InstructionOperand> dst_fragments;
|
|
|
|
GetCanonicalOperands(dst, &dst_fragments);
|
|
|
|
CHECK(!dst_fragments.empty());
|
|
|
|
for (size_t j = 0; j < dst_fragments.size(); ++j) {
|
|
|
|
if (destinations.find(dst_fragments[j]) == destinations.end()) {
|
|
|
|
destinations.insert(dst_fragments[j]);
|
2016-10-03 23:45:51 +00:00
|
|
|
} else {
|
|
|
|
reject = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update the sources map, and check that no FP source has multiple
|
|
|
|
// representations.
|
|
|
|
const InstructionOperand& src = mo.source();
|
|
|
|
if (src.IsFPRegister()) {
|
2021-09-24 14:43:18 +00:00
|
|
|
std::vector<InstructionOperand> src_fragments;
|
2016-10-03 23:45:51 +00:00
|
|
|
MachineRepresentation src_rep =
|
|
|
|
LocationOperand::cast(src).representation();
|
2021-09-24 14:43:18 +00:00
|
|
|
GetCanonicalOperands(src, &src_fragments);
|
|
|
|
CHECK(!src_fragments.empty());
|
|
|
|
for (size_t j = 0; j < src_fragments.size(); ++j) {
|
|
|
|
auto find_it = sources.find(src_fragments[j]);
|
2016-10-03 23:45:51 +00:00
|
|
|
if (find_it != sources.end() && find_it->second != src_rep) {
|
|
|
|
reject = true;
|
|
|
|
break;
|
|
|
|
}
|
2021-09-24 14:43:18 +00:00
|
|
|
sources.insert(std::make_pair(src_fragments[j], src_rep));
|
2016-10-03 23:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (destinations.find(dst) == destinations.end()) {
|
|
|
|
destinations.insert(dst);
|
|
|
|
} else {
|
|
|
|
reject = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reject) {
|
2015-04-15 12:36:36 +00:00
|
|
|
parallel_move->AddMove(mo.source(), mo.destination());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return parallel_move;
|
|
|
|
}
|
|
|
|
|
2016-10-03 23:45:51 +00:00
|
|
|
// Creates a ParallelMove from a list of operand pairs. Even operands are
|
|
|
|
// destinations, odd ones are sources.
|
|
|
|
ParallelMove* Create(const std::vector<InstructionOperand>& operand_pairs) {
|
2020-07-09 10:43:44 +00:00
|
|
|
ParallelMove* parallel_move = main_zone()->New<ParallelMove>(main_zone());
|
2016-10-03 23:45:51 +00:00
|
|
|
for (size_t i = 0; i < operand_pairs.size(); i += 2) {
|
|
|
|
const InstructionOperand& dst = operand_pairs[i];
|
|
|
|
const InstructionOperand& src = operand_pairs[i + 1];
|
|
|
|
parallel_move->AddMove(src, dst);
|
|
|
|
}
|
|
|
|
return parallel_move;
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
private:
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineRepresentation RandomRepresentation() {
|
2016-10-03 23:45:51 +00:00
|
|
|
int index = rng_->NextInt(6);
|
2015-04-29 19:36:16 +00:00
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2015-12-10 09:03:30 +00:00
|
|
|
return MachineRepresentation::kWord32;
|
2015-04-29 19:36:16 +00:00
|
|
|
case 1:
|
2015-12-10 09:03:30 +00:00
|
|
|
return MachineRepresentation::kWord64;
|
2015-04-29 19:36:16 +00:00
|
|
|
case 2:
|
2016-07-29 00:47:42 +00:00
|
|
|
return MachineRepresentation::kFloat32;
|
2016-06-14 12:26:59 +00:00
|
|
|
case 3:
|
|
|
|
return MachineRepresentation::kFloat64;
|
|
|
|
case 4:
|
2016-10-03 23:45:51 +00:00
|
|
|
return MachineRepresentation::kSimd128;
|
|
|
|
case 5:
|
2015-12-10 09:03:30 +00:00
|
|
|
return MachineRepresentation::kTagged;
|
2015-04-29 19:36:16 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2018-10-26 07:33:27 +00:00
|
|
|
// min(num_alloctable_general_registers for each arch) == 5 from
|
2017-08-17 12:04:19 +00:00
|
|
|
// assembler-ia32.h
|
2018-10-26 07:33:27 +00:00
|
|
|
const int kMaxIndex = 5;
|
2016-10-03 23:45:51 +00:00
|
|
|
const int kMaxIndices = kMaxIndex + 1;
|
|
|
|
|
|
|
|
// Non-FP slots shouldn't overlap FP slots.
|
|
|
|
// FP slots with different representations shouldn't overlap.
|
|
|
|
int GetValidSlotIndex(MachineRepresentation rep, int index) {
|
|
|
|
DCHECK_GE(kMaxIndex, index);
|
|
|
|
// The first group of slots are for non-FP values.
|
|
|
|
if (!IsFloatingPoint(rep)) return index;
|
|
|
|
// The next group are for float values.
|
|
|
|
int base = kMaxIndices;
|
|
|
|
if (rep == MachineRepresentation::kFloat32) return base + index;
|
|
|
|
// Double values.
|
|
|
|
base += kMaxIndices;
|
|
|
|
if (rep == MachineRepresentation::kFloat64) return base + index * 2;
|
|
|
|
// SIMD values
|
|
|
|
base += kMaxIndices * 2;
|
|
|
|
CHECK_EQ(MachineRepresentation::kSimd128, rep);
|
|
|
|
return base + index * 4;
|
|
|
|
}
|
|
|
|
|
2016-06-14 12:26:59 +00:00
|
|
|
InstructionOperand CreateRandomOperand(bool is_source,
|
|
|
|
MachineRepresentation rep) {
|
2017-08-02 13:36:27 +00:00
|
|
|
auto conf = RegisterConfiguration::Default();
|
2016-10-03 23:45:51 +00:00
|
|
|
auto GetValidRegisterCode = [&conf](MachineRepresentation rep, int index) {
|
2016-06-24 08:23:52 +00:00
|
|
|
switch (rep) {
|
|
|
|
case MachineRepresentation::kFloat32:
|
2016-10-26 16:04:11 +00:00
|
|
|
return conf->RegisterConfiguration::GetAllocatableFloatCode(index);
|
2016-06-24 08:23:52 +00:00
|
|
|
case MachineRepresentation::kFloat64:
|
|
|
|
return conf->RegisterConfiguration::GetAllocatableDoubleCode(index);
|
2016-10-26 16:04:11 +00:00
|
|
|
case MachineRepresentation::kSimd128:
|
|
|
|
return conf->RegisterConfiguration::GetAllocatableSimd128Code(index);
|
2016-06-24 08:23:52 +00:00
|
|
|
default:
|
|
|
|
return conf->RegisterConfiguration::GetAllocatableGeneralCode(index);
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
};
|
2016-10-03 23:45:51 +00:00
|
|
|
int index = rng_->NextInt(kMaxIndex);
|
2015-04-09 09:15:28 +00:00
|
|
|
// destination can't be Constant.
|
2019-09-06 13:04:20 +00:00
|
|
|
switch (rng_->NextInt(is_source ? 3 : 2)) {
|
2014-07-30 13:54:45 +00:00
|
|
|
case 0:
|
2016-10-03 23:45:51 +00:00
|
|
|
return AllocatedOperand(LocationOperand::STACK_SLOT, rep,
|
|
|
|
GetValidSlotIndex(rep, index));
|
2014-07-30 13:54:45 +00:00
|
|
|
case 1:
|
2016-10-03 23:45:51 +00:00
|
|
|
return AllocatedOperand(LocationOperand::REGISTER, rep,
|
|
|
|
GetValidRegisterCode(rep, index));
|
2014-07-30 13:54:45 +00:00
|
|
|
case 2:
|
2015-04-15 12:36:36 +00:00
|
|
|
return ConstantOperand(index);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::base::RandomNumberGenerator* rng_;
|
|
|
|
};
|
|
|
|
|
2016-10-03 23:45:51 +00:00
|
|
|
void RunTest(ParallelMove* pm, Zone* zone) {
|
|
|
|
// Note: The gap resolver modifies the ParallelMove, so interpret first.
|
|
|
|
MoveInterpreter mi1(zone);
|
|
|
|
mi1.AssembleParallelMove(pm);
|
|
|
|
|
|
|
|
MoveInterpreter mi2(zone);
|
|
|
|
GapResolver resolver(&mi2);
|
|
|
|
resolver.Resolve(pm);
|
|
|
|
|
|
|
|
CHECK_EQ(mi1.state(), mi2.state());
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2016-10-26 16:04:11 +00:00
|
|
|
TEST(Aliasing) {
|
|
|
|
// On platforms with simple aliasing, these parallel moves are ill-formed.
|
2022-03-11 02:47:26 +00:00
|
|
|
if (kFPAliasing != AliasingKind::kCombine) return;
|
2016-10-26 16:04:11 +00:00
|
|
|
|
|
|
|
ParallelMoveCreator pmc;
|
|
|
|
Zone* zone = pmc.main_zone();
|
|
|
|
|
|
|
|
auto s0 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat32, 0);
|
|
|
|
auto s1 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat32, 1);
|
|
|
|
auto s2 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat32, 2);
|
|
|
|
auto s3 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat32, 3);
|
|
|
|
auto s4 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat32, 4);
|
|
|
|
|
|
|
|
auto d0 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat64, 0);
|
|
|
|
auto d1 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat64, 1);
|
|
|
|
auto d16 = AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kFloat64, 16);
|
|
|
|
|
|
|
|
// Double slots must be odd to match frame allocation.
|
|
|
|
auto dSlot = AllocatedOperand(LocationOperand::STACK_SLOT,
|
|
|
|
MachineRepresentation::kFloat64, 3);
|
|
|
|
|
|
|
|
// Cycles involving s- and d-registers.
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
s2, s0, // s2 <- s0
|
|
|
|
d0, d1 // d0 <- d1
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
d0, d1, // d0 <- d1
|
|
|
|
s2, s0 // s2 <- s0
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
s2, s1, // s2 <- s1
|
|
|
|
d0, d1 // d0 <- d1
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
d0, d1, // d0 <- d1
|
|
|
|
s2, s1 // s2 <- s1
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
// Two cycles involving a single d-register.
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
d0, d1, // d0 <- d1
|
|
|
|
s2, s1, // s2 <- s1
|
|
|
|
s3, s0 // s3 <- s0
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
// Cycle with a float move that must be deferred until after swaps.
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
d0, d1, // d0 <- d1
|
|
|
|
s2, s0, // s2 <- s0
|
|
|
|
s3, s4 // s3 <- s4 must be deferred
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
// Cycles involving s-registers and a non-aliased d-register.
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
d16, d0, // d16 <- d0
|
|
|
|
s1, s2, // s1 <- s2
|
|
|
|
d1, d16 // d1 <- d16
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
s2, s1, // s1 <- s2
|
|
|
|
d0, d16, // d16 <- d0
|
|
|
|
d16, d1 // d1 <- d16
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
d0, d16, // d0 <- d16
|
|
|
|
d16, d1, // s2 <- s0
|
|
|
|
s3, s0 // d0 <- d1
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
// Cycle involving aliasing registers and a slot.
|
|
|
|
{
|
|
|
|
std::vector<InstructionOperand> moves = {
|
|
|
|
dSlot, d0, // dSlot <- d0
|
|
|
|
d1, dSlot, // d1 <- dSlot
|
|
|
|
s0, s3 // s0 <- s3
|
|
|
|
};
|
|
|
|
RunTest(pmc.Create(moves), zone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
TEST(FuzzResolver) {
|
|
|
|
ParallelMoveCreator pmc;
|
2016-10-03 23:45:51 +00:00
|
|
|
for (int size = 0; size < 80; ++size) {
|
2014-07-30 13:54:45 +00:00
|
|
|
for (int repeat = 0; repeat < 50; ++repeat) {
|
2016-10-03 23:45:51 +00:00
|
|
|
RunTest(pmc.Create(size), pmc.main_zone());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|