[turbofan] fix vreg mapping for instruction selector tests
BUG= R=bmeurer@chromium.org Review URL: https://codereview.chromium.org/636543002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24418 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
b6f82c734c
commit
e7a635c853
@ -828,6 +828,8 @@ class InstructionSequence FINAL {
|
||||
BasicBlock* GetBasicBlock(int instruction_index);
|
||||
|
||||
int GetVirtualRegister(const Node* node);
|
||||
// TODO(dcarney): find a way to remove this.
|
||||
const int* GetNodeMapForTesting() const { return node_map_; }
|
||||
|
||||
bool IsReference(int virtual_register) const;
|
||||
bool IsDouble(int virtual_register) const;
|
||||
|
@ -114,7 +114,7 @@ TEST_F(InstructionSelectorTest, BetterLeftOperandTestAddBinop) {
|
||||
EXPECT_EQ(kIA32Add, s[0]->arch_opcode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated());
|
||||
EXPECT_EQ(param2->id(), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0)));
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ TEST_F(InstructionSelectorTest, BetterLeftOperandTestMulBinop) {
|
||||
EXPECT_EQ(kIA32Imul, s[0]->arch_opcode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated());
|
||||
EXPECT_EQ(param2->id(), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0)));
|
||||
}
|
||||
|
||||
|
||||
@ -542,7 +542,7 @@ TEST_P(InstructionSelectorMultTest, Mult32) {
|
||||
EXPECT_EQ(kIA32Imul, s[0]->arch_opcode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
}
|
||||
EXPECT_EQ(param->id(), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->InputAt(0)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "test/unittests/compiler/instruction-selector-unittest.h"
|
||||
|
||||
#include "src/compiler/graph-inl.h"
|
||||
#include "src/flags.h"
|
||||
#include "test/unittests/compiler/compiler-test-utils.h"
|
||||
|
||||
@ -34,6 +35,7 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
|
||||
<< *schedule;
|
||||
}
|
||||
EXPECT_NE(0, graph()->NodeCount());
|
||||
int initial_node_count = graph()->NodeCount();
|
||||
CompilationInfo info(test_->isolate(), test_->zone());
|
||||
Linkage linkage(&info, call_descriptor());
|
||||
InstructionSequence sequence(&linkage, graph(), schedule);
|
||||
@ -46,6 +48,15 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
|
||||
<< sequence;
|
||||
}
|
||||
Stream s;
|
||||
// Map virtual registers.
|
||||
{
|
||||
const int* node_map = sequence.GetNodeMapForTesting();
|
||||
for (int i = 0; i < initial_node_count; ++i) {
|
||||
if (node_map[i] >= 0) {
|
||||
s.virtual_registers_.insert(std::make_pair(i, node_map[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
std::set<int> virtual_registers;
|
||||
for (InstructionSequence::const_iterator i = sequence.begin();
|
||||
i != sequence.end(); ++i) {
|
||||
@ -110,6 +121,13 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
|
||||
}
|
||||
|
||||
|
||||
int InstructionSelectorTest::Stream::ToVreg(const Node* node) const {
|
||||
VirtualRegisters::const_iterator i = virtual_registers_.find(node->id());
|
||||
CHECK(i != virtual_registers_.end());
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Return.
|
||||
|
||||
@ -180,7 +198,7 @@ TARGET_TEST_F(InstructionSelectorTest, DoubleParameter) {
|
||||
Node* param = m.Parameter(0);
|
||||
m.Return(param);
|
||||
Stream s = m.Build(kAllInstructions);
|
||||
EXPECT_TRUE(s.IsDouble(param->id()));
|
||||
EXPECT_TRUE(s.IsDouble(param));
|
||||
}
|
||||
|
||||
|
||||
@ -189,7 +207,7 @@ TARGET_TEST_F(InstructionSelectorTest, ReferenceParameter) {
|
||||
Node* param = m.Parameter(0);
|
||||
m.Return(param);
|
||||
Stream s = m.Build(kAllInstructions);
|
||||
EXPECT_TRUE(s.IsReference(param->id()));
|
||||
EXPECT_TRUE(s.IsReference(param));
|
||||
}
|
||||
|
||||
|
||||
@ -207,16 +225,16 @@ TARGET_TEST_F(InstructionSelectorTest, Finish) {
|
||||
EXPECT_EQ(kArchNop, s[0]->arch_opcode());
|
||||
ASSERT_EQ(1U, s[0]->OutputCount());
|
||||
ASSERT_TRUE(s[0]->Output()->IsUnallocated());
|
||||
EXPECT_EQ(param->id(), s.ToVreg(s[0]->Output()));
|
||||
EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output()));
|
||||
EXPECT_EQ(kArchNop, s[1]->arch_opcode());
|
||||
ASSERT_EQ(1U, s[1]->InputCount());
|
||||
ASSERT_TRUE(s[1]->InputAt(0)->IsUnallocated());
|
||||
EXPECT_EQ(param->id(), s.ToVreg(s[1]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0)));
|
||||
ASSERT_EQ(1U, s[1]->OutputCount());
|
||||
ASSERT_TRUE(s[1]->Output()->IsUnallocated());
|
||||
EXPECT_TRUE(UnallocatedOperand::cast(s[1]->Output())->HasSameAsInputPolicy());
|
||||
EXPECT_EQ(finish->id(), s.ToVreg(s[1]->Output()));
|
||||
EXPECT_TRUE(s.IsReference(finish->id()));
|
||||
EXPECT_EQ(s.ToVreg(finish), s.ToVreg(s[1]->Output()));
|
||||
EXPECT_TRUE(s.IsReference(finish));
|
||||
}
|
||||
|
||||
|
||||
@ -243,8 +261,8 @@ TARGET_TEST_P(InstructionSelectorPhiTest, Doubleness) {
|
||||
Node* phi = m.Phi(type, param0, param1);
|
||||
m.Return(phi);
|
||||
Stream s = m.Build(kAllInstructions);
|
||||
EXPECT_EQ(s.IsDouble(phi->id()), s.IsDouble(param0->id()));
|
||||
EXPECT_EQ(s.IsDouble(phi->id()), s.IsDouble(param1->id()));
|
||||
EXPECT_EQ(s.IsDouble(phi), s.IsDouble(param0));
|
||||
EXPECT_EQ(s.IsDouble(phi), s.IsDouble(param1));
|
||||
}
|
||||
|
||||
|
||||
@ -263,8 +281,8 @@ TARGET_TEST_P(InstructionSelectorPhiTest, Referenceness) {
|
||||
Node* phi = m.Phi(type, param0, param1);
|
||||
m.Return(phi);
|
||||
Stream s = m.Build(kAllInstructions);
|
||||
EXPECT_EQ(s.IsReference(phi->id()), s.IsReference(param0->id()));
|
||||
EXPECT_EQ(s.IsReference(phi->id()), s.IsReference(param1->id()));
|
||||
EXPECT_EQ(s.IsReference(phi), s.IsReference(param0));
|
||||
EXPECT_EQ(s.IsReference(phi), s.IsReference(param1));
|
||||
}
|
||||
|
||||
|
||||
@ -412,9 +430,9 @@ TARGET_TEST_F(InstructionSelectorTest, CallFunctionStubWithDeopt) {
|
||||
EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(5)));
|
||||
|
||||
// Function.
|
||||
EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6)));
|
||||
EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(6)));
|
||||
// Context.
|
||||
EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7)));
|
||||
EXPECT_EQ(s.ToVreg(context), s.ToVreg(call_instr->InputAt(7)));
|
||||
|
||||
EXPECT_EQ(kArchRet, s[index++]->arch_opcode());
|
||||
|
||||
@ -504,9 +522,9 @@ TARGET_TEST_F(InstructionSelectorTest,
|
||||
EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(9)));
|
||||
|
||||
// Function.
|
||||
EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(10)));
|
||||
EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(10)));
|
||||
// Context.
|
||||
EXPECT_EQ(context2->id(), s.ToVreg(call_instr->InputAt(11)));
|
||||
EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(11)));
|
||||
// Continuation.
|
||||
|
||||
EXPECT_EQ(kArchRet, s[index++]->arch_opcode());
|
||||
|
@ -125,22 +125,21 @@ class InstructionSelectorTest : public TestWithContext, public TestWithZone {
|
||||
bool IsDouble(const InstructionOperand* operand) const {
|
||||
return IsDouble(ToVreg(operand));
|
||||
}
|
||||
bool IsDouble(int virtual_register) const {
|
||||
return doubles_.find(virtual_register) != doubles_.end();
|
||||
}
|
||||
|
||||
bool IsDouble(const Node* node) const { return IsDouble(ToVreg(node)); }
|
||||
|
||||
bool IsInteger(const InstructionOperand* operand) const {
|
||||
return IsInteger(ToVreg(operand));
|
||||
}
|
||||
bool IsInteger(int virtual_register) const {
|
||||
return !IsDouble(virtual_register) && !IsReference(virtual_register);
|
||||
}
|
||||
|
||||
bool IsInteger(const Node* node) const { return IsInteger(ToVreg(node)); }
|
||||
|
||||
bool IsReference(const InstructionOperand* operand) const {
|
||||
return IsReference(ToVreg(operand));
|
||||
}
|
||||
bool IsReference(int virtual_register) const {
|
||||
return references_.find(virtual_register) != references_.end();
|
||||
|
||||
bool IsReference(const Node* node) const {
|
||||
return IsReference(ToVreg(node));
|
||||
}
|
||||
|
||||
float ToFloat32(const InstructionOperand* operand) const {
|
||||
@ -161,6 +160,8 @@ class InstructionSelectorTest : public TestWithContext, public TestWithZone {
|
||||
return UnallocatedOperand::cast(operand)->virtual_register();
|
||||
}
|
||||
|
||||
int ToVreg(const Node* node) const;
|
||||
|
||||
FrameStateDescriptor* GetFrameStateDescriptor(int deoptimization_id) {
|
||||
EXPECT_LT(deoptimization_id, GetFrameStateDescriptorCount());
|
||||
return deoptimization_entries_[deoptimization_id];
|
||||
@ -171,6 +172,18 @@ class InstructionSelectorTest : public TestWithContext, public TestWithZone {
|
||||
}
|
||||
|
||||
private:
|
||||
bool IsDouble(int virtual_register) const {
|
||||
return doubles_.find(virtual_register) != doubles_.end();
|
||||
}
|
||||
|
||||
bool IsInteger(int virtual_register) const {
|
||||
return !IsDouble(virtual_register) && !IsReference(virtual_register);
|
||||
}
|
||||
|
||||
bool IsReference(int virtual_register) const {
|
||||
return references_.find(virtual_register) != references_.end();
|
||||
}
|
||||
|
||||
Constant ToConstant(const InstructionOperand* operand) const {
|
||||
ConstantMap::const_iterator i;
|
||||
if (operand->IsConstant()) {
|
||||
@ -188,12 +201,14 @@ class InstructionSelectorTest : public TestWithContext, public TestWithZone {
|
||||
friend class StreamBuilder;
|
||||
|
||||
typedef std::map<int, Constant> ConstantMap;
|
||||
typedef std::map<NodeId, int> VirtualRegisters;
|
||||
|
||||
ConstantMap constants_;
|
||||
ConstantMap immediates_;
|
||||
std::deque<Instruction*> instructions_;
|
||||
std::set<int> doubles_;
|
||||
std::set<int> references_;
|
||||
VirtualRegisters virtual_registers_;
|
||||
std::deque<FrameStateDescriptor*> deoptimization_entries_;
|
||||
};
|
||||
|
||||
|
@ -96,7 +96,7 @@ TEST_F(InstructionSelectorTest, BetterLeftOperandTestAddBinop) {
|
||||
EXPECT_EQ(kX64Add32, s[0]->arch_opcode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated());
|
||||
EXPECT_EQ(param2->id(), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0)));
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ TEST_F(InstructionSelectorTest, BetterLeftOperandTestMulBinop) {
|
||||
EXPECT_EQ(kX64Imul32, s[0]->arch_opcode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated());
|
||||
EXPECT_EQ(param2->id(), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0)));
|
||||
}
|
||||
|
||||
|
||||
@ -415,7 +415,7 @@ TEST_P(InstructionSelectorMultTest, Mult32) {
|
||||
EXPECT_EQ(kX64Imul32, s[0]->arch_opcode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
}
|
||||
EXPECT_EQ(param->id(), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->InputAt(0)));
|
||||
}
|
||||
|
||||
|
||||
@ -431,12 +431,12 @@ TEST_P(InstructionSelectorMultTest, Mult64) {
|
||||
if (m_param.lea_expected) {
|
||||
EXPECT_EQ(kX64Lea, s[0]->arch_opcode());
|
||||
ASSERT_EQ(InputCountForLea(s[0]->addressing_mode()), s[0]->InputCount());
|
||||
EXPECT_EQ(param->id(), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->InputAt(0)));
|
||||
} else {
|
||||
EXPECT_EQ(kX64Imul, s[0]->arch_opcode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
// TODO(dcarney): why is this happening?
|
||||
EXPECT_EQ(param->id(), s.ToVreg(s[0]->InputAt(1)));
|
||||
EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->InputAt(1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user