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 "src/compiler/machine-operator-reducer.h" | 5 #include "src/compiler/machine-operator-reducer.h" |
6 | 6 |
7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/compiler/generic-node-inl.h" | 8 #include "src/compiler/generic-node-inl.h" |
9 #include "src/compiler/graph.h" | 9 #include "src/compiler/graph.h" |
10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
11 #include "src/compiler/node-matchers.h" | 11 #include "src/compiler/node-matchers.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace compiler { | 15 namespace compiler { |
16 | 16 |
17 MachineOperatorReducer::MachineOperatorReducer(JSGraph* jsgraph) | 17 MachineOperatorReducer::MachineOperatorReducer(JSGraph* jsgraph) |
18 : jsgraph_(jsgraph) {} | 18 : jsgraph_(jsgraph) {} |
19 | 19 |
20 | 20 |
21 MachineOperatorReducer::~MachineOperatorReducer() {} | 21 MachineOperatorReducer::~MachineOperatorReducer() {} |
22 | 22 |
23 | 23 |
| 24 Node* MachineOperatorReducer::Float32Constant(volatile float value) { |
| 25 return graph()->NewNode(common()->Float32Constant(value)); |
| 26 } |
| 27 |
| 28 |
24 Node* MachineOperatorReducer::Float64Constant(volatile double value) { | 29 Node* MachineOperatorReducer::Float64Constant(volatile double value) { |
25 return jsgraph()->Float64Constant(value); | 30 return jsgraph()->Float64Constant(value); |
26 } | 31 } |
27 | 32 |
28 | 33 |
29 Node* MachineOperatorReducer::Int32Constant(int32_t value) { | 34 Node* MachineOperatorReducer::Int32Constant(int32_t value) { |
30 return jsgraph()->Int32Constant(value); | 35 return jsgraph()->Int32Constant(value); |
31 } | 36 } |
32 | 37 |
33 | 38 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 return Replace(m.right().node()); | 381 return Replace(m.right().node()); |
377 } | 382 } |
378 if (m.left().IsNaN()) { // NaN % x => NaN | 383 if (m.left().IsNaN()) { // NaN % x => NaN |
379 return Replace(m.left().node()); | 384 return Replace(m.left().node()); |
380 } | 385 } |
381 if (m.IsFoldable()) { // K % K => K | 386 if (m.IsFoldable()) { // K % K => K |
382 return ReplaceFloat64(modulo(m.left().Value(), m.right().Value())); | 387 return ReplaceFloat64(modulo(m.left().Value(), m.right().Value())); |
383 } | 388 } |
384 break; | 389 break; |
385 } | 390 } |
| 391 case IrOpcode::kChangeFloat32ToFloat64: { |
| 392 Float32Matcher m(node->InputAt(0)); |
| 393 if (m.HasValue()) return ReplaceFloat64(m.Value()); |
| 394 break; |
| 395 } |
386 case IrOpcode::kChangeFloat64ToInt32: { | 396 case IrOpcode::kChangeFloat64ToInt32: { |
387 Float64Matcher m(node->InputAt(0)); | 397 Float64Matcher m(node->InputAt(0)); |
388 if (m.HasValue()) return ReplaceInt32(FastD2I(m.Value())); | 398 if (m.HasValue()) return ReplaceInt32(FastD2I(m.Value())); |
389 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); | 399 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); |
390 break; | 400 break; |
391 } | 401 } |
392 case IrOpcode::kChangeFloat64ToUint32: { | 402 case IrOpcode::kChangeFloat64ToUint32: { |
393 Float64Matcher m(node->InputAt(0)); | 403 Float64Matcher m(node->InputAt(0)); |
394 if (m.HasValue()) return ReplaceInt32(FastD2UI(m.Value())); | 404 if (m.HasValue()) return ReplaceInt32(FastD2UI(m.Value())); |
395 if (m.IsChangeUint32ToFloat64()) return Replace(m.node()->InputAt(0)); | 405 if (m.IsChangeUint32ToFloat64()) return Replace(m.node()->InputAt(0)); |
(...skipping 24 matching lines...) Expand all Loading... |
420 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); | 430 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); |
421 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); | 431 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); |
422 break; | 432 break; |
423 } | 433 } |
424 case IrOpcode::kTruncateInt64ToInt32: { | 434 case IrOpcode::kTruncateInt64ToInt32: { |
425 Int64Matcher m(node->InputAt(0)); | 435 Int64Matcher m(node->InputAt(0)); |
426 if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value())); | 436 if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value())); |
427 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0)); | 437 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0)); |
428 break; | 438 break; |
429 } | 439 } |
| 440 case IrOpcode::kTruncateFloat64ToFloat32: { |
| 441 Float64Matcher m(node->InputAt(0)); |
| 442 if (m.HasValue()) return ReplaceFloat32(DoubleToFloat32(m.Value())); |
| 443 if (m.IsChangeFloat32ToFloat64()) return Replace(m.node()->InputAt(0)); |
| 444 break; |
| 445 } |
430 // TODO(turbofan): strength-reduce and fold floating point operations. | 446 // TODO(turbofan): strength-reduce and fold floating point operations. |
431 default: | 447 default: |
432 break; | 448 break; |
433 } | 449 } |
434 return NoChange(); | 450 return NoChange(); |
435 } | 451 } |
436 | 452 |
437 | 453 |
438 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { | 454 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { |
439 switch (node->opcode()) { | 455 switch (node->opcode()) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 496 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
481 return jsgraph()->machine(); | 497 return jsgraph()->machine(); |
482 } | 498 } |
483 | 499 |
484 | 500 |
485 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 501 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
486 | 502 |
487 } // namespace compiler | 503 } // namespace compiler |
488 } // namespace internal | 504 } // namespace internal |
489 } // namespace v8 | 505 } // namespace v8 |
OLD | NEW |