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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 // ----------------------------------------------------------------------------- | 143 // ----------------------------------------------------------------------------- |
144 // Return. | 144 // Return. |
145 | 145 |
146 | 146 |
147 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { | 147 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { |
148 const float kValue = 4.2f; | 148 const float kValue = 4.2f; |
149 StreamBuilder m(this, kMachFloat32); | 149 StreamBuilder m(this, kMachFloat32); |
150 m.Return(m.Float32Constant(kValue)); | 150 m.Return(m.Float32Constant(kValue)); |
151 Stream s = m.Build(kAllInstructions); | 151 Stream s = m.Build(kAllInstructions); |
152 ASSERT_EQ(2U, s.size()); | 152 ASSERT_EQ(3U, s.size()); |
153 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 153 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
154 ASSERT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); | 154 ASSERT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); |
155 EXPECT_FLOAT_EQ(kValue, s.ToFloat32(s[0]->OutputAt(0))); | 155 EXPECT_FLOAT_EQ(kValue, s.ToFloat32(s[0]->OutputAt(0))); |
156 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 156 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
157 EXPECT_EQ(1U, s[1]->InputCount()); | 157 EXPECT_EQ(1U, s[1]->InputCount()); |
158 } | 158 } |
159 | 159 |
160 | 160 |
161 TARGET_TEST_F(InstructionSelectorTest, ReturnParameter) { | 161 TARGET_TEST_F(InstructionSelectorTest, ReturnParameter) { |
162 StreamBuilder m(this, kMachInt32, kMachInt32); | 162 StreamBuilder m(this, kMachInt32, kMachInt32); |
163 m.Return(m.Parameter(0)); | 163 m.Return(m.Parameter(0)); |
164 Stream s = m.Build(kAllInstructions); | 164 Stream s = m.Build(kAllInstructions); |
165 ASSERT_EQ(2U, s.size()); | 165 ASSERT_EQ(3U, s.size()); |
166 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 166 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
167 ASSERT_EQ(1U, s[0]->OutputCount()); | 167 ASSERT_EQ(1U, s[0]->OutputCount()); |
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(1U, s[1]->InputCount()); |
170 } | 170 } |
171 | 171 |
172 | 172 |
173 TARGET_TEST_F(InstructionSelectorTest, ReturnZero) { | 173 TARGET_TEST_F(InstructionSelectorTest, ReturnZero) { |
174 StreamBuilder m(this, kMachInt32); | 174 StreamBuilder m(this, kMachInt32); |
175 m.Return(m.Int32Constant(0)); | 175 m.Return(m.Int32Constant(0)); |
176 Stream s = m.Build(kAllInstructions); | 176 Stream s = m.Build(kAllInstructions); |
177 ASSERT_EQ(2U, 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(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); | 180 EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); |
181 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); | 181 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); |
182 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | 182 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
183 EXPECT_EQ(1U, s[1]->InputCount()); | 183 EXPECT_EQ(1U, s[1]->InputCount()); |
184 } | 184 } |
185 | 185 |
186 | 186 |
187 // ----------------------------------------------------------------------------- | 187 // ----------------------------------------------------------------------------- |
188 // Conversions. | 188 // Conversions. |
189 | 189 |
190 | 190 |
191 TARGET_TEST_F(InstructionSelectorTest, TruncateFloat64ToInt32WithParameter) { | 191 TARGET_TEST_F(InstructionSelectorTest, TruncateFloat64ToInt32WithParameter) { |
192 StreamBuilder m(this, kMachInt32, kMachFloat64); | 192 StreamBuilder m(this, kMachInt32, kMachFloat64); |
193 m.Return(m.TruncateFloat64ToInt32(m.Parameter(0))); | 193 m.Return(m.TruncateFloat64ToInt32(m.Parameter(0))); |
194 Stream s = m.Build(kAllInstructions); | 194 Stream s = m.Build(kAllInstructions); |
195 ASSERT_EQ(3U, s.size()); | 195 ASSERT_EQ(4U, s.size()); |
196 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 196 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
197 EXPECT_EQ(kArchTruncateDoubleToI, s[1]->arch_opcode()); | 197 EXPECT_EQ(kArchTruncateDoubleToI, s[1]->arch_opcode()); |
198 EXPECT_EQ(1U, s[1]->InputCount()); | 198 EXPECT_EQ(1U, s[1]->InputCount()); |
199 EXPECT_EQ(1U, s[1]->OutputCount()); | 199 EXPECT_EQ(1U, s[1]->OutputCount()); |
200 EXPECT_EQ(kArchRet, s[2]->arch_opcode()); | 200 EXPECT_EQ(kArchRet, s[2]->arch_opcode()); |
201 } | 201 } |
202 | 202 |
203 | 203 |
204 // ----------------------------------------------------------------------------- | 204 // ----------------------------------------------------------------------------- |
205 // Parameters. | 205 // Parameters. |
(...skipping 20 matching lines...) Expand all Loading... |
226 // ----------------------------------------------------------------------------- | 226 // ----------------------------------------------------------------------------- |
227 // Finish. | 227 // Finish. |
228 | 228 |
229 | 229 |
230 TARGET_TEST_F(InstructionSelectorTest, Finish) { | 230 TARGET_TEST_F(InstructionSelectorTest, Finish) { |
231 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); | 231 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); |
232 Node* param = m.Parameter(0); | 232 Node* param = m.Parameter(0); |
233 Node* finish = m.NewNode(m.common()->Finish(1), param, m.graph()->start()); | 233 Node* finish = m.NewNode(m.common()->Finish(1), param, m.graph()->start()); |
234 m.Return(finish); | 234 m.Return(finish); |
235 Stream s = m.Build(kAllInstructions); | 235 Stream s = m.Build(kAllInstructions); |
236 ASSERT_EQ(3U, s.size()); | 236 ASSERT_EQ(4U, s.size()); |
237 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 237 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
238 ASSERT_EQ(1U, s[0]->OutputCount()); | 238 ASSERT_EQ(1U, s[0]->OutputCount()); |
239 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); | 239 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); |
240 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output())); | 240 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output())); |
241 EXPECT_EQ(kArchNop, s[1]->arch_opcode()); | 241 EXPECT_EQ(kArchNop, s[1]->arch_opcode()); |
242 ASSERT_EQ(1U, s[1]->InputCount()); | 242 ASSERT_EQ(1U, s[1]->InputCount()); |
243 ASSERT_TRUE(s[1]->InputAt(0)->IsUnallocated()); | 243 ASSERT_TRUE(s[1]->InputAt(0)->IsUnallocated()); |
244 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0))); | 244 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0))); |
245 ASSERT_EQ(1U, s[1]->OutputCount()); | 245 ASSERT_EQ(1U, s[1]->OutputCount()); |
246 ASSERT_TRUE(s[1]->Output()->IsUnallocated()); | 246 ASSERT_TRUE(s[1]->Output()->IsUnallocated()); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12))); | 562 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12))); |
563 // Continuation. | 563 // Continuation. |
564 | 564 |
565 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 565 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
566 EXPECT_EQ(index, s.size()); | 566 EXPECT_EQ(index, s.size()); |
567 } | 567 } |
568 | 568 |
569 } // namespace compiler | 569 } // namespace compiler |
570 } // namespace internal | 570 } // namespace internal |
571 } // namespace v8 | 571 } // namespace v8 |
OLD | NEW |