OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "src/compiler/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
6 #include "src/compiler/diamond.h" | |
6 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/js-intrinsic-lowering.h" | 8 #include "src/compiler/js-intrinsic-lowering.h" |
8 #include "src/compiler/js-operator.h" | 9 #include "src/compiler/js-operator.h" |
9 #include "test/unittests/compiler/graph-unittest.h" | 10 #include "test/unittests/compiler/graph-unittest.h" |
10 #include "test/unittests/compiler/node-test-utils.h" | 11 #include "test/unittests/compiler/node-test-utils.h" |
11 #include "testing/gmock-support.h" | 12 #include "testing/gmock-support.h" |
12 | 13 |
14 | |
13 using testing::_; | 15 using testing::_; |
14 using testing::AllOf; | 16 using testing::AllOf; |
15 using testing::BitEq; | 17 using testing::BitEq; |
16 using testing::Capture; | 18 using testing::Capture; |
17 using testing::CaptureEq; | 19 using testing::CaptureEq; |
18 | 20 |
19 | 21 |
20 namespace v8 { | 22 namespace v8 { |
21 namespace internal { | 23 namespace internal { |
22 namespace compiler { | 24 namespace compiler { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 Reduction const r = Reduce(graph()->NewNode( | 238 Reduction const r = Reduce(graph()->NewNode( |
237 javascript()->CallRuntime(Runtime::kInlineJSValueGetValue, 1), input, | 239 javascript()->CallRuntime(Runtime::kInlineJSValueGetValue, 1), input, |
238 context, effect, control)); | 240 context, effect, control)); |
239 ASSERT_TRUE(r.Changed()); | 241 ASSERT_TRUE(r.Changed()); |
240 EXPECT_THAT(r.replacement(), | 242 EXPECT_THAT(r.replacement(), |
241 IsLoadField(AccessBuilder::ForValue(), input, effect, control)); | 243 IsLoadField(AccessBuilder::ForValue(), input, effect, control)); |
242 } | 244 } |
243 | 245 |
244 | 246 |
245 // ----------------------------------------------------------------------------- | 247 // ----------------------------------------------------------------------------- |
248 // %_Likely | |
249 | |
250 TEST_F(JSIntrinsicLoweringTest, Likely) { | |
251 Node* const input = Parameter(0); | |
252 Node* const context = Parameter(1); | |
253 Node* const effect = graph()->start(); | |
254 Node* const control = graph()->start(); | |
255 Node* const likely = | |
256 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineLikely, 1), | |
257 input, context, effect, control); | |
258 Node* const to_boolean = | |
259 graph()->NewNode(javascript()->ToBoolean(), likely, context); | |
260 Diamond d(graph(), common(), to_boolean); | |
261 graph()->SetEnd(graph()->NewNode(common()->End(), d.merge)); | |
262 | |
263 ASSERT_TRUE(BranchHint::kNone == BranchHintOf(d.branch->op())); | |
Michael Starzinger
2015/03/31 12:49:03
nit: ASSERT_EQ
Sven Panne
2015/03/31 13:01:34
Done.
| |
264 Reduction const r = Reduce(likely); | |
265 ASSERT_TRUE(r.Changed()); | |
266 ASSERT_TRUE(input->op()->Equals(r.replacement()->op())); | |
Michael Starzinger
2015/03/31 12:49:03
nit: EXPECT_THAT(r.replacement(), input)
Sven Panne
2015/03/31 13:01:34
Done.
| |
267 ASSERT_TRUE(BranchHint::kTrue == BranchHintOf(d.branch->op())); | |
Michael Starzinger
2015/03/31 12:49:03
nit: EXPECT_EQ
Sven Panne
2015/03/31 13:01:35
Done.
| |
268 } | |
269 | |
270 | |
271 // ----------------------------------------------------------------------------- | |
246 // %_MathFloor | 272 // %_MathFloor |
247 | 273 |
248 | 274 |
249 TEST_F(JSIntrinsicLoweringTest, InlineMathFloor) { | 275 TEST_F(JSIntrinsicLoweringTest, InlineMathFloor) { |
250 Node* const input = Parameter(0); | 276 Node* const input = Parameter(0); |
251 Node* const context = Parameter(1); | 277 Node* const context = Parameter(1); |
252 Node* const effect = graph()->start(); | 278 Node* const effect = graph()->start(); |
253 Node* const control = graph()->start(); | 279 Node* const control = graph()->start(); |
254 Reduction const r = Reduce( | 280 Reduction const r = Reduce( |
255 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineMathFloor, 1), | 281 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineMathFloor, 1), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 Node* const control = graph()->start(); | 332 Node* const control = graph()->start(); |
307 Reduction const r = Reduce( | 333 Reduction const r = Reduce( |
308 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineMathClz32, 1), | 334 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineMathClz32, 1), |
309 input, context, effect, control)); | 335 input, context, effect, control)); |
310 ASSERT_TRUE(r.Changed()); | 336 ASSERT_TRUE(r.Changed()); |
311 EXPECT_THAT(r.replacement(), IsWord32Clz(input)); | 337 EXPECT_THAT(r.replacement(), IsWord32Clz(input)); |
312 } | 338 } |
313 | 339 |
314 | 340 |
315 // ----------------------------------------------------------------------------- | 341 // ----------------------------------------------------------------------------- |
342 // %_Unlikely | |
343 | |
344 TEST_F(JSIntrinsicLoweringTest, Unlikely) { | |
345 Node* const input = Parameter(0); | |
346 Node* const context = Parameter(1); | |
347 Node* const effect = graph()->start(); | |
348 Node* const control = graph()->start(); | |
349 Node* const unlikely = | |
350 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineUnlikely, 1), | |
351 input, context, effect, control); | |
352 Node* const to_boolean = | |
353 graph()->NewNode(javascript()->ToBoolean(), unlikely, context); | |
354 Diamond d(graph(), common(), to_boolean); | |
355 graph()->SetEnd(graph()->NewNode(common()->End(), d.merge)); | |
356 | |
357 ASSERT_TRUE(BranchHint::kNone == BranchHintOf(d.branch->op())); | |
Michael Starzinger
2015/03/31 12:49:03
nit: Same as the three comments above.
| |
358 Reduction const r = Reduce(unlikely); | |
359 ASSERT_TRUE(r.Changed()); | |
360 ASSERT_TRUE(input->op()->Equals(r.replacement()->op())); | |
361 ASSERT_TRUE(BranchHint::kFalse == BranchHintOf(d.branch->op())); | |
362 } | |
363 | |
364 | |
365 // ----------------------------------------------------------------------------- | |
316 // %_ValueOf | 366 // %_ValueOf |
317 | 367 |
318 | 368 |
319 TEST_F(JSIntrinsicLoweringTest, InlineValueOf) { | 369 TEST_F(JSIntrinsicLoweringTest, InlineValueOf) { |
320 Node* const input = Parameter(0); | 370 Node* const input = Parameter(0); |
321 Node* const context = Parameter(1); | 371 Node* const context = Parameter(1); |
322 Node* const effect = graph()->start(); | 372 Node* const effect = graph()->start(); |
323 Node* const control = graph()->start(); | 373 Node* const control = graph()->start(); |
324 Reduction const r = Reduce( | 374 Reduction const r = Reduce( |
325 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineValueOf, 1), | 375 graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineValueOf, 1), |
(...skipping 24 matching lines...) Expand all Loading... | |
350 CaptureEq(&if_false0)))))), | 400 CaptureEq(&if_false0)))))), |
351 IsMerge( | 401 IsMerge( |
352 IsIfTrue(AllOf(CaptureEq(&branch0), | 402 IsIfTrue(AllOf(CaptureEq(&branch0), |
353 IsBranch(IsObjectIsSmi(input), control))), | 403 IsBranch(IsObjectIsSmi(input), control))), |
354 AllOf(CaptureEq(&if_false0), IsIfFalse(CaptureEq(&branch0)))))); | 404 AllOf(CaptureEq(&if_false0), IsIfFalse(CaptureEq(&branch0)))))); |
355 } | 405 } |
356 | 406 |
357 } // namespace compiler | 407 } // namespace compiler |
358 } // namespace internal | 408 } // namespace internal |
359 } // namespace v8 | 409 } // namespace v8 |
OLD | NEW |