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/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
9 #include "src/compiler/schedule.h" | 9 #include "src/compiler/schedule.h" |
10 #include "src/flags.h" | 10 #include "src/flags.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { | 159 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { |
160 const float kValue = 4.2f; | 160 const float kValue = 4.2f; |
161 StreamBuilder m(this, MachineType::Float32()); | 161 StreamBuilder m(this, MachineType::Float32()); |
162 m.Return(m.Float32Constant(kValue)); | 162 m.Return(m.Float32Constant(kValue)); |
163 Stream s = m.Build(kAllInstructions); | 163 Stream s = m.Build(kAllInstructions); |
164 ASSERT_EQ(3U, s.size()); | 164 ASSERT_EQ(3U, s.size()); |
165 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 165 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
166 ASSERT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); | 166 ASSERT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); |
167 EXPECT_FLOAT_EQ(kValue, s.ToFloat32(s[0]->OutputAt(0))); | 167 EXPECT_FLOAT_EQ(kValue, s.ToFloat32(s[0]->OutputAt(0))); |
168 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 168 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
169 EXPECT_EQ(1U, s[1]->InputCount()); | 169 EXPECT_EQ(2U, s[1]->InputCount()); |
170 } | 170 } |
171 | 171 |
172 | 172 |
173 TARGET_TEST_F(InstructionSelectorTest, ReturnParameter) { | 173 TARGET_TEST_F(InstructionSelectorTest, ReturnParameter) { |
174 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); | 174 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); |
175 m.Return(m.Parameter(0)); | 175 m.Return(m.Parameter(0)); |
176 Stream s = m.Build(kAllInstructions); | 176 Stream s = m.Build(kAllInstructions); |
177 ASSERT_EQ(3U, s.size()); | 177 ASSERT_EQ(3U, s.size()); |
178 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 178 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
179 ASSERT_EQ(1U, s[0]->OutputCount()); | 179 ASSERT_EQ(1U, s[0]->OutputCount()); |
180 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 180 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
181 EXPECT_EQ(1U, s[1]->InputCount()); | 181 EXPECT_EQ(2U, s[1]->InputCount()); |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 TARGET_TEST_F(InstructionSelectorTest, ReturnZero) { | 185 TARGET_TEST_F(InstructionSelectorTest, ReturnZero) { |
186 StreamBuilder m(this, MachineType::Int32()); | 186 StreamBuilder m(this, MachineType::Int32()); |
187 m.Return(m.Int32Constant(0)); | 187 m.Return(m.Int32Constant(0)); |
188 Stream s = m.Build(kAllInstructions); | 188 Stream s = m.Build(kAllInstructions); |
189 ASSERT_EQ(3U, s.size()); | 189 ASSERT_EQ(3U, s.size()); |
190 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 190 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
191 ASSERT_EQ(1U, s[0]->OutputCount()); | 191 ASSERT_EQ(1U, s[0]->OutputCount()); |
192 EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); | 192 EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); |
193 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); | 193 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); |
194 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 194 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
195 EXPECT_EQ(1U, s[1]->InputCount()); | 195 EXPECT_EQ(2U, s[1]->InputCount()); |
196 } | 196 } |
197 | 197 |
198 | 198 |
199 // ----------------------------------------------------------------------------- | 199 // ----------------------------------------------------------------------------- |
200 // Conversions. | 200 // Conversions. |
201 | 201 |
202 TARGET_TEST_F(InstructionSelectorTest, TruncateFloat64ToWord32WithParameter) { | 202 TARGET_TEST_F(InstructionSelectorTest, TruncateFloat64ToWord32WithParameter) { |
203 StreamBuilder m(this, MachineType::Int32(), MachineType::Float64()); | 203 StreamBuilder m(this, MachineType::Int32(), MachineType::Float64()); |
204 m.Return(m.TruncateFloat64ToWord32(m.Parameter(0))); | 204 m.Return(m.TruncateFloat64ToWord32(m.Parameter(0))); |
205 Stream s = m.Build(kAllInstructions); | 205 Stream s = m.Build(kAllInstructions); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 Node* finish = | 244 Node* finish = |
245 m.AddNode(m.common()->FinishRegion(), param, m.graph()->start()); | 245 m.AddNode(m.common()->FinishRegion(), param, m.graph()->start()); |
246 m.Return(finish); | 246 m.Return(finish); |
247 Stream s = m.Build(kAllInstructions); | 247 Stream s = m.Build(kAllInstructions); |
248 ASSERT_EQ(3U, s.size()); | 248 ASSERT_EQ(3U, s.size()); |
249 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 249 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
250 ASSERT_EQ(1U, s[0]->OutputCount()); | 250 ASSERT_EQ(1U, s[0]->OutputCount()); |
251 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); | 251 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); |
252 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 252 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
253 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output())); | 253 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output())); |
254 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0))); | 254 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(1))); |
255 EXPECT_TRUE(s.IsReference(finish)); | 255 EXPECT_TRUE(s.IsReference(finish)); |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 // ----------------------------------------------------------------------------- | 259 // ----------------------------------------------------------------------------- |
260 // Phi. | 260 // Phi. |
261 | 261 |
262 | 262 |
263 typedef InstructionSelectorTestWithParam<MachineType> | 263 typedef InstructionSelectorTestWithParam<MachineType> |
264 InstructionSelectorPhiTest; | 264 InstructionSelectorPhiTest; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(14))); | 616 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(14))); |
617 // Continuation. | 617 // Continuation. |
618 | 618 |
619 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 619 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
620 EXPECT_EQ(index, s.size()); | 620 EXPECT_EQ(index, s.size()); |
621 } | 621 } |
622 | 622 |
623 } // namespace compiler | 623 } // namespace compiler |
624 } // namespace internal | 624 } // namespace internal |
625 } // namespace v8 | 625 } // namespace v8 |
OLD | NEW |