Reviewers: Benedikt Meurer,

Message:
Committed patchset #2 (id:20001) manually as 24418 (presubmit successful).

Description:
[turbofan] fix vreg mapping for instruction selector tests

BUG=
[email protected]

Committed: https://code.google.com/p/v8/source/detail?r=24418

Please review this at https://codereview.chromium.org/636543002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+65, -30 lines):
  M src/compiler/instruction.h
  M test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc
  M test/unittests/compiler/instruction-selector-unittest.h
  M test/unittests/compiler/instruction-selector-unittest.cc
  M test/unittests/compiler/x64/instruction-selector-x64-unittest.cc


Index: src/compiler/instruction.h
diff --git a/src/compiler/instruction.h b/src/compiler/instruction.h
index 5811d548ff46bfaefe05d67d6c3f83abd1bb87aa..0fe0b0e380b0923ea5053aba12fc8380447af558 100644
--- a/src/compiler/instruction.h
+++ b/src/compiler/instruction.h
@@ -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;
Index: test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc
diff --git a/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc b/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc index 5147728583c2a96f98aedb83e59305e1b10f7de3..e892ad3735957905b893c26e6c0f0dcd3959337d 100644
--- a/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc
+++ b/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc
@@ -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)));
 }


Index: test/unittests/compiler/instruction-selector-unittest.cc
diff --git a/test/unittests/compiler/instruction-selector-unittest.cc b/test/unittests/compiler/instruction-selector-unittest.cc index 6d866c4367efc3d6661ed7b9bf7229a4acdc440e..8b759def7ea9d388e2d3dae02f9ed1445a5bb8a8 100644
--- a/test/unittests/compiler/instruction-selector-unittest.cc
+++ b/test/unittests/compiler/instruction-selector-unittest.cc
@@ -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());
Index: test/unittests/compiler/instruction-selector-unittest.h
diff --git a/test/unittests/compiler/instruction-selector-unittest.h b/test/unittests/compiler/instruction-selector-unittest.h index 4f2cdbc0ffcdab1602311ca2b1ca908c8dec7c3f..d48df12d0794f3f1c241efa3739b0a847a4ac337 100644
--- a/test/unittests/compiler/instruction-selector-unittest.h
+++ b/test/unittests/compiler/instruction-selector-unittest.h
@@ -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_;
   };

Index: test/unittests/compiler/x64/instruction-selector-x64-unittest.cc
diff --git a/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc b/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc index 5488e1cb4a4cedfccbe670cc3a3829ddf882dfb9..d42f68ae5ade989e1fb35cc5bf40167862db90f6 100644
--- a/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc
+++ b/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc
@@ -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)));
   }
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to