2014-11-27 09:19:31 +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.
|
|
|
|
|
|
|
|
#ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_
|
|
|
|
#define V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_
|
|
|
|
|
2016-07-25 11:12:42 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-11-27 09:19:31 +00:00
|
|
|
#include "src/compiler/instruction.h"
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2015-01-23 16:29:50 +00:00
|
|
|
class InstructionSequenceTest : public TestWithIsolateAndZone {
|
2014-11-27 09:19:31 +00:00
|
|
|
public:
|
2015-10-02 16:55:12 +00:00
|
|
|
static const int kDefaultNRegs = 8;
|
2014-11-27 09:19:31 +00:00
|
|
|
static const int kNoValue = kMinInt;
|
2016-10-10 11:06:42 +00:00
|
|
|
static const MachineRepresentation kNoRep = MachineRepresentation::kNone;
|
2016-10-26 16:04:11 +00:00
|
|
|
static const MachineRepresentation kFloat32 = MachineRepresentation::kFloat32;
|
2016-10-10 11:06:42 +00:00
|
|
|
static const MachineRepresentation kFloat64 = MachineRepresentation::kFloat64;
|
2016-10-26 16:04:11 +00:00
|
|
|
static const MachineRepresentation kSimd128 = MachineRepresentation::kSimd128;
|
2014-11-27 09:19:31 +00:00
|
|
|
|
2015-02-25 16:37:49 +00:00
|
|
|
typedef RpoNumber Rpo;
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
struct VReg {
|
|
|
|
VReg() : value_(kNoValue) {}
|
|
|
|
VReg(PhiInstruction* phi) : value_(phi->virtual_register()) {} // NOLINT
|
2016-10-10 11:06:42 +00:00
|
|
|
explicit VReg(int value, MachineRepresentation rep = kNoRep)
|
|
|
|
: value_(value), rep_(rep) {}
|
2014-11-27 09:19:31 +00:00
|
|
|
int value_;
|
2016-10-10 11:06:42 +00:00
|
|
|
MachineRepresentation rep_ = kNoRep;
|
2014-11-27 09:19:31 +00:00
|
|
|
};
|
|
|
|
|
2015-02-24 11:09:03 +00:00
|
|
|
typedef std::pair<VReg, VReg> VRegPair;
|
|
|
|
|
2014-11-27 09:19:31 +00:00
|
|
|
enum TestOperandType {
|
|
|
|
kInvalid,
|
|
|
|
kSameAsFirst,
|
|
|
|
kRegister,
|
|
|
|
kFixedRegister,
|
|
|
|
kSlot,
|
|
|
|
kFixedSlot,
|
[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
|
|
|
kExplicit,
|
2014-11-27 09:19:31 +00:00
|
|
|
kImmediate,
|
|
|
|
kNone,
|
2014-12-12 11:15:13 +00:00
|
|
|
kConstant,
|
|
|
|
kUnique,
|
|
|
|
kUniqueRegister
|
2014-11-27 09:19:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TestOperand {
|
2016-10-10 11:06:42 +00:00
|
|
|
TestOperand() : type_(kInvalid), vreg_(), value_(kNoValue), rep_(kNoRep) {}
|
|
|
|
explicit TestOperand(TestOperandType type)
|
|
|
|
: type_(type), vreg_(), value_(kNoValue), rep_(kNoRep) {}
|
|
|
|
// For tests that do register allocation.
|
2014-11-27 09:19:31 +00:00
|
|
|
TestOperand(TestOperandType type, VReg vreg, int value = kNoValue)
|
2016-10-10 11:06:42 +00:00
|
|
|
: type_(type), vreg_(vreg), value_(value), rep_(vreg.rep_) {}
|
|
|
|
// For immediates, constants, and tests that don't do register allocation.
|
|
|
|
TestOperand(TestOperandType type, int value,
|
|
|
|
MachineRepresentation rep = kNoRep)
|
|
|
|
: type_(type), vreg_(), value_(value), rep_(rep) {}
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
TestOperandType type_;
|
|
|
|
VReg vreg_;
|
|
|
|
int value_;
|
2016-10-10 11:06:42 +00:00
|
|
|
MachineRepresentation rep_;
|
2014-11-27 09:19:31 +00:00
|
|
|
};
|
|
|
|
|
2016-10-10 11:06:42 +00:00
|
|
|
static TestOperand Same() { return TestOperand(kSameAsFirst); }
|
2014-11-27 09:19:31 +00:00
|
|
|
|
[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
|
|
|
static TestOperand ExplicitReg(int index) {
|
|
|
|
TestOperandType type = kExplicit;
|
2016-10-10 11:06:42 +00:00
|
|
|
return TestOperand(type, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static TestOperand ExplicitFPReg(int index,
|
|
|
|
MachineRepresentation rep = kFloat64) {
|
|
|
|
TestOperandType type = kExplicit;
|
|
|
|
return TestOperand(type, index, 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
|
|
|
}
|
|
|
|
|
2014-11-27 09:19:31 +00:00
|
|
|
static TestOperand Reg(VReg vreg, int index = kNoValue) {
|
2016-10-10 11:06:42 +00:00
|
|
|
TestOperandType type = (index == kNoValue) ? kRegister : kFixedRegister;
|
2014-11-27 09:19:31 +00:00
|
|
|
return TestOperand(type, vreg, index);
|
|
|
|
}
|
|
|
|
|
2016-10-10 11:06:42 +00:00
|
|
|
static TestOperand Reg(int index = kNoValue,
|
|
|
|
MachineRepresentation rep = kNoRep) {
|
|
|
|
return Reg(VReg(kNoValue, rep), index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static TestOperand FPReg(int index = kNoValue,
|
|
|
|
MachineRepresentation rep = kFloat64) {
|
|
|
|
return Reg(index, rep);
|
|
|
|
}
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
static TestOperand Slot(VReg vreg, int index = kNoValue) {
|
2016-10-10 11:06:42 +00:00
|
|
|
TestOperandType type = (index == kNoValue) ? kSlot : kFixedSlot;
|
2014-11-27 09:19:31 +00:00
|
|
|
return TestOperand(type, vreg, index);
|
|
|
|
}
|
|
|
|
|
2016-10-10 11:06:42 +00:00
|
|
|
static TestOperand Slot(int index = kNoValue,
|
|
|
|
MachineRepresentation rep = kNoRep) {
|
|
|
|
return Slot(VReg(kNoValue, rep), index);
|
|
|
|
}
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
static TestOperand Const(int index) {
|
|
|
|
CHECK_NE(kNoValue, index);
|
2016-10-10 11:06:42 +00:00
|
|
|
return TestOperand(kConstant, index);
|
2014-11-27 09:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static TestOperand Use(VReg vreg) { return TestOperand(kNone, vreg); }
|
|
|
|
|
|
|
|
static TestOperand Use() { return Use(VReg()); }
|
|
|
|
|
2014-12-12 11:15:13 +00:00
|
|
|
static TestOperand Unique(VReg vreg) { return TestOperand(kUnique, vreg); }
|
|
|
|
|
|
|
|
static TestOperand UniqueReg(VReg vreg) {
|
|
|
|
return TestOperand(kUniqueRegister, vreg);
|
|
|
|
}
|
|
|
|
|
2014-11-27 09:19:31 +00:00
|
|
|
enum BlockCompletionType { kBlockEnd, kFallThrough, kBranch, kJump };
|
|
|
|
|
|
|
|
struct BlockCompletion {
|
|
|
|
BlockCompletionType type_;
|
|
|
|
TestOperand op_;
|
|
|
|
int offset_0_;
|
|
|
|
int offset_1_;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BlockCompletion FallThrough() {
|
|
|
|
BlockCompletion completion = {kFallThrough, TestOperand(), 1, kNoValue};
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BlockCompletion Jump(int offset) {
|
|
|
|
BlockCompletion completion = {kJump, TestOperand(), offset, kNoValue};
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BlockCompletion Branch(TestOperand op, int left_offset,
|
|
|
|
int right_offset) {
|
|
|
|
BlockCompletion completion = {kBranch, op, left_offset, right_offset};
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BlockCompletion Last() {
|
|
|
|
BlockCompletion completion = {kBlockEnd, TestOperand(), kNoValue, kNoValue};
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
|
|
|
InstructionSequenceTest();
|
|
|
|
|
|
|
|
void SetNumRegs(int num_general_registers, int num_double_registers);
|
2016-10-10 11:06:42 +00:00
|
|
|
int GetNumRegs(MachineRepresentation rep);
|
|
|
|
int GetAllocatableCode(int index, MachineRepresentation rep = kNoRep);
|
2016-11-09 13:47:29 +00:00
|
|
|
const RegisterConfiguration* config();
|
2014-11-27 09:19:31 +00:00
|
|
|
InstructionSequence* sequence();
|
|
|
|
|
|
|
|
void StartLoop(int loop_blocks);
|
|
|
|
void EndLoop();
|
2015-08-06 16:21:23 +00:00
|
|
|
void StartBlock(bool deferred = false);
|
2015-02-24 11:09:03 +00:00
|
|
|
Instruction* EndBlock(BlockCompletion completion = FallThrough());
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
TestOperand Imm(int32_t imm = 0);
|
|
|
|
VReg Define(TestOperand output_op);
|
|
|
|
VReg Parameter(TestOperand output_op = Reg()) { return Define(output_op); }
|
2016-10-10 11:06:42 +00:00
|
|
|
VReg FPParameter(MachineRepresentation rep = kFloat64) {
|
|
|
|
return Parameter(FPReg(kNoValue, rep));
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineRepresentation GetCanonicalRep(TestOperand op) {
|
|
|
|
return IsFloatingPoint(op.rep_) ? op.rep_
|
|
|
|
: sequence()->DefaultRepresentation();
|
|
|
|
}
|
2014-11-27 09:19:31 +00:00
|
|
|
|
2015-02-24 11:09:03 +00:00
|
|
|
Instruction* Return(TestOperand input_op_0);
|
|
|
|
Instruction* Return(VReg vreg) { return Return(Reg(vreg, 0)); }
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
PhiInstruction* Phi(VReg incoming_vreg_0 = VReg(),
|
|
|
|
VReg incoming_vreg_1 = VReg(),
|
|
|
|
VReg incoming_vreg_2 = VReg(),
|
|
|
|
VReg incoming_vreg_3 = VReg());
|
2015-02-09 13:02:41 +00:00
|
|
|
PhiInstruction* Phi(VReg incoming_vreg_0, size_t input_count);
|
|
|
|
void SetInput(PhiInstruction* phi, size_t input, VReg vreg);
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
VReg DefineConstant(int32_t imm = 0);
|
2015-02-24 11:09:03 +00:00
|
|
|
Instruction* EmitNop();
|
|
|
|
Instruction* EmitI(size_t input_size, TestOperand* inputs);
|
|
|
|
Instruction* EmitI(TestOperand input_op_0 = TestOperand(),
|
|
|
|
TestOperand input_op_1 = TestOperand(),
|
|
|
|
TestOperand input_op_2 = TestOperand(),
|
|
|
|
TestOperand input_op_3 = TestOperand());
|
2014-12-12 11:15:13 +00:00
|
|
|
VReg EmitOI(TestOperand output_op, size_t input_size, TestOperand* inputs);
|
|
|
|
VReg EmitOI(TestOperand output_op, TestOperand input_op_0 = TestOperand(),
|
|
|
|
TestOperand input_op_1 = TestOperand(),
|
|
|
|
TestOperand input_op_2 = TestOperand(),
|
|
|
|
TestOperand input_op_3 = TestOperand());
|
2015-02-24 11:09:03 +00:00
|
|
|
VRegPair EmitOOI(TestOperand output_op_0, TestOperand output_op_1,
|
|
|
|
size_t input_size, TestOperand* inputs);
|
|
|
|
VRegPair EmitOOI(TestOperand output_op_0, TestOperand output_op_1,
|
|
|
|
TestOperand input_op_0 = TestOperand(),
|
|
|
|
TestOperand input_op_1 = TestOperand(),
|
|
|
|
TestOperand input_op_2 = TestOperand(),
|
|
|
|
TestOperand input_op_3 = TestOperand());
|
2014-11-27 09:19:31 +00:00
|
|
|
VReg EmitCall(TestOperand output_op, size_t input_size, TestOperand* inputs);
|
|
|
|
VReg EmitCall(TestOperand output_op, TestOperand input_op_0 = TestOperand(),
|
|
|
|
TestOperand input_op_1 = TestOperand(),
|
|
|
|
TestOperand input_op_2 = TestOperand(),
|
|
|
|
TestOperand input_op_3 = TestOperand());
|
|
|
|
|
|
|
|
InstructionBlock* current_block() const { return current_block_; }
|
|
|
|
|
|
|
|
// Called after all instructions have been inserted.
|
|
|
|
void WireBlocks();
|
|
|
|
|
|
|
|
private:
|
2016-10-10 11:06:42 +00:00
|
|
|
virtual bool DoesRegisterAllocation() const { return true; }
|
|
|
|
|
|
|
|
VReg NewReg(TestOperand op = TestOperand()) {
|
|
|
|
int vreg = sequence()->NextVirtualRegister();
|
|
|
|
if (IsFloatingPoint(op.rep_))
|
|
|
|
sequence()->MarkAsRepresentation(op.rep_, vreg);
|
|
|
|
return VReg(vreg, op.rep_);
|
|
|
|
}
|
2014-11-27 09:19:31 +00:00
|
|
|
|
2016-10-10 11:06:42 +00:00
|
|
|
static TestOperand Invalid() { return TestOperand(kInvalid); }
|
2014-11-27 09:19:31 +00:00
|
|
|
|
2015-02-24 11:09:03 +00:00
|
|
|
Instruction* EmitBranch(TestOperand input_op);
|
|
|
|
Instruction* EmitFallThrough();
|
|
|
|
Instruction* EmitJump();
|
2014-11-27 09:19:31 +00:00
|
|
|
Instruction* NewInstruction(InstructionCode code, size_t outputs_size,
|
2015-02-04 12:38:47 +00:00
|
|
|
InstructionOperand* outputs,
|
2014-11-27 09:19:31 +00:00
|
|
|
size_t inputs_size = 0,
|
2015-02-04 12:38:47 +00:00
|
|
|
InstructionOperand* inputs = nullptr,
|
2014-11-27 09:19:31 +00:00
|
|
|
size_t temps_size = 0,
|
2015-02-04 12:38:47 +00:00
|
|
|
InstructionOperand* temps = nullptr);
|
|
|
|
InstructionOperand Unallocated(TestOperand op,
|
|
|
|
UnallocatedOperand::ExtendedPolicy policy);
|
|
|
|
InstructionOperand Unallocated(TestOperand op,
|
|
|
|
UnallocatedOperand::ExtendedPolicy policy,
|
|
|
|
UnallocatedOperand::Lifetime lifetime);
|
|
|
|
InstructionOperand Unallocated(TestOperand op,
|
|
|
|
UnallocatedOperand::ExtendedPolicy policy,
|
|
|
|
int index);
|
|
|
|
InstructionOperand Unallocated(TestOperand op,
|
|
|
|
UnallocatedOperand::BasicPolicy policy,
|
|
|
|
int index);
|
|
|
|
InstructionOperand* ConvertInputs(size_t input_size, TestOperand* inputs);
|
|
|
|
InstructionOperand ConvertInputOp(TestOperand op);
|
|
|
|
InstructionOperand ConvertOutputOp(VReg vreg, TestOperand op);
|
2015-08-06 16:21:23 +00:00
|
|
|
InstructionBlock* NewBlock(bool deferred = false);
|
2014-11-27 09:19:31 +00:00
|
|
|
void WireBlock(size_t block_offset, int jump_offset);
|
|
|
|
|
2015-02-24 11:09:03 +00:00
|
|
|
Instruction* Emit(InstructionCode code, size_t outputs_size = 0,
|
|
|
|
InstructionOperand* outputs = nullptr,
|
|
|
|
size_t inputs_size = 0,
|
|
|
|
InstructionOperand* inputs = nullptr, size_t temps_size = 0,
|
|
|
|
InstructionOperand* temps = nullptr, bool is_call = false);
|
2014-11-27 09:19:31 +00:00
|
|
|
|
2015-02-24 11:09:03 +00:00
|
|
|
Instruction* AddInstruction(Instruction* instruction);
|
2014-11-27 09:19:31 +00:00
|
|
|
|
|
|
|
struct LoopData {
|
|
|
|
Rpo loop_header_;
|
|
|
|
int expected_blocks_;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<LoopData> LoopBlocks;
|
|
|
|
typedef std::map<int, const Instruction*> Instructions;
|
|
|
|
typedef std::vector<BlockCompletion> Completions;
|
|
|
|
|
2016-07-25 11:12:42 +00:00
|
|
|
std::unique_ptr<RegisterConfiguration> config_;
|
2014-11-27 09:19:31 +00:00
|
|
|
InstructionSequence* sequence_;
|
|
|
|
int num_general_registers_;
|
|
|
|
int num_double_registers_;
|
|
|
|
|
|
|
|
// Block building state.
|
|
|
|
InstructionBlocks instruction_blocks_;
|
|
|
|
Instructions instructions_;
|
|
|
|
Completions completions_;
|
|
|
|
LoopBlocks loop_blocks_;
|
|
|
|
InstructionBlock* current_block_;
|
|
|
|
bool block_returns_;
|
2016-07-25 11:12:42 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(InstructionSequenceTest);
|
2014-11-27 09:19:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_
|