| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "test/unittests/compiler/instruction-selector-unittest.h" | 5 #include "test/unittests/compiler/instruction-selector-unittest.h" |
| 6 | 6 |
| 7 #include "src/compiler/graph-inl.h" | 7 #include "src/compiler/graph-inl.h" |
| 8 #include "src/flags.h" | 8 #include "src/flags.h" |
| 9 #include "test/unittests/compiler/compiler-test-utils.h" | 9 #include "test/unittests/compiler/compiler-test-utils.h" |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 // ----------------------------------------------------------------------------- | 161 // ----------------------------------------------------------------------------- |
| 162 // Return. | 162 // Return. |
| 163 | 163 |
| 164 | 164 |
| 165 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { | 165 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { |
| 166 const float kValue = 4.2f; | 166 const float kValue = 4.2f; |
| 167 StreamBuilder m(this, kMachFloat32); | 167 StreamBuilder m(this, kMachFloat32); |
| 168 m.Return(m.Float32Constant(kValue)); | 168 m.Return(m.Float32Constant(kValue)); |
| 169 Stream s = m.Build(kAllInstructions); | 169 Stream s = m.Build(kAllInstructions); |
| 170 ASSERT_EQ(2U, s.size()); | 170 ASSERT_EQ(3U, s.size()); |
| 171 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 171 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
| 172 ASSERT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); | 172 ASSERT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); |
| 173 EXPECT_FLOAT_EQ(kValue, s.ToFloat32(s[0]->OutputAt(0))); | 173 EXPECT_FLOAT_EQ(kValue, s.ToFloat32(s[0]->OutputAt(0))); |
| 174 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 174 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
| 175 EXPECT_EQ(1U, s[1]->InputCount()); | 175 EXPECT_EQ(1U, s[1]->InputCount()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 TARGET_TEST_F(InstructionSelectorTest, ReturnParameter) { | 179 TARGET_TEST_F(InstructionSelectorTest, ReturnParameter) { |
| 180 StreamBuilder m(this, kMachInt32, kMachInt32); | 180 StreamBuilder m(this, kMachInt32, kMachInt32); |
| 181 m.Return(m.Parameter(0)); | 181 m.Return(m.Parameter(0)); |
| 182 Stream s = m.Build(kAllInstructions); | 182 Stream s = m.Build(kAllInstructions); |
| 183 ASSERT_EQ(2U, s.size()); | 183 ASSERT_EQ(3U, s.size()); |
| 184 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 184 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
| 185 ASSERT_EQ(1U, s[0]->OutputCount()); | 185 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 186 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 186 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
| 187 EXPECT_EQ(1U, s[1]->InputCount()); | 187 EXPECT_EQ(1U, s[1]->InputCount()); |
| 188 } | 188 } |
| 189 | 189 |
| 190 | 190 |
| 191 TARGET_TEST_F(InstructionSelectorTest, ReturnZero) { | 191 TARGET_TEST_F(InstructionSelectorTest, ReturnZero) { |
| 192 StreamBuilder m(this, kMachInt32); | 192 StreamBuilder m(this, kMachInt32); |
| 193 m.Return(m.Int32Constant(0)); | 193 m.Return(m.Int32Constant(0)); |
| 194 Stream s = m.Build(kAllInstructions); | 194 Stream s = m.Build(kAllInstructions); |
| 195 ASSERT_EQ(2U, s.size()); | 195 ASSERT_EQ(3U, s.size()); |
| 196 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 196 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
| 197 ASSERT_EQ(1U, s[0]->OutputCount()); | 197 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 198 EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); | 198 EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); |
| 199 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); | 199 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); |
| 200 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 200 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
| 201 EXPECT_EQ(1U, s[1]->InputCount()); | 201 EXPECT_EQ(1U, s[1]->InputCount()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 | 204 |
| 205 // ----------------------------------------------------------------------------- | 205 // ----------------------------------------------------------------------------- |
| 206 // Conversions. | 206 // Conversions. |
| 207 | 207 |
| 208 | 208 |
| 209 TARGET_TEST_F(InstructionSelectorTest, TruncateFloat64ToInt32WithParameter) { | 209 TARGET_TEST_F(InstructionSelectorTest, TruncateFloat64ToInt32WithParameter) { |
| 210 StreamBuilder m(this, kMachInt32, kMachFloat64); | 210 StreamBuilder m(this, kMachInt32, kMachFloat64); |
| 211 m.Return(m.TruncateFloat64ToInt32(m.Parameter(0))); | 211 m.Return(m.TruncateFloat64ToInt32(m.Parameter(0))); |
| 212 Stream s = m.Build(kAllInstructions); | 212 Stream s = m.Build(kAllInstructions); |
| 213 ASSERT_EQ(3U, s.size()); | 213 ASSERT_EQ(4U, s.size()); |
| 214 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 214 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
| 215 EXPECT_EQ(kArchTruncateDoubleToI, s[1]->arch_opcode()); | 215 EXPECT_EQ(kArchTruncateDoubleToI, s[1]->arch_opcode()); |
| 216 EXPECT_EQ(1U, s[1]->InputCount()); | 216 EXPECT_EQ(1U, s[1]->InputCount()); |
| 217 EXPECT_EQ(1U, s[1]->OutputCount()); | 217 EXPECT_EQ(1U, s[1]->OutputCount()); |
| 218 EXPECT_EQ(kArchRet, s[2]->arch_opcode()); | 218 EXPECT_EQ(kArchRet, s[2]->arch_opcode()); |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 // ----------------------------------------------------------------------------- | 222 // ----------------------------------------------------------------------------- |
| 223 // Parameters. | 223 // Parameters. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 244 // ----------------------------------------------------------------------------- | 244 // ----------------------------------------------------------------------------- |
| 245 // Finish. | 245 // Finish. |
| 246 | 246 |
| 247 | 247 |
| 248 TARGET_TEST_F(InstructionSelectorTest, Finish) { | 248 TARGET_TEST_F(InstructionSelectorTest, Finish) { |
| 249 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); | 249 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); |
| 250 Node* param = m.Parameter(0); | 250 Node* param = m.Parameter(0); |
| 251 Node* finish = m.NewNode(m.common()->Finish(1), param, m.graph()->start()); | 251 Node* finish = m.NewNode(m.common()->Finish(1), param, m.graph()->start()); |
| 252 m.Return(finish); | 252 m.Return(finish); |
| 253 Stream s = m.Build(kAllInstructions); | 253 Stream s = m.Build(kAllInstructions); |
| 254 ASSERT_EQ(3U, s.size()); | 254 ASSERT_EQ(4U, s.size()); |
| 255 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 255 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
| 256 ASSERT_EQ(1U, s[0]->OutputCount()); | 256 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 257 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); | 257 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); |
| 258 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output())); | 258 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output())); |
| 259 EXPECT_EQ(kArchNop, s[1]->arch_opcode()); | 259 EXPECT_EQ(kArchNop, s[1]->arch_opcode()); |
| 260 ASSERT_EQ(1U, s[1]->InputCount()); | 260 ASSERT_EQ(1U, s[1]->InputCount()); |
| 261 ASSERT_TRUE(s[1]->InputAt(0)->IsUnallocated()); | 261 ASSERT_TRUE(s[1]->InputAt(0)->IsUnallocated()); |
| 262 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0))); | 262 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0))); |
| 263 ASSERT_EQ(1U, s[1]->OutputCount()); | 263 ASSERT_EQ(1U, s[1]->OutputCount()); |
| 264 ASSERT_TRUE(s[1]->Output()->IsUnallocated()); | 264 ASSERT_TRUE(s[1]->Output()->IsUnallocated()); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12))); | 580 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12))); |
| 581 // Continuation. | 581 // Continuation. |
| 582 | 582 |
| 583 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 583 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
| 584 EXPECT_EQ(index, s.size()); | 584 EXPECT_EQ(index, s.size()); |
| 585 } | 585 } |
| 586 | 586 |
| 587 } // namespace compiler | 587 } // namespace compiler |
| 588 } // namespace internal | 588 } // namespace internal |
| 589 } // namespace v8 | 589 } // namespace v8 |
| OLD | NEW |