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/common-node-cache.h" | 8 #include "src/compiler/common-node-cache.h" |
9 #include "src/compiler/generic-node-inl.h" | 9 #include "src/compiler/generic-node-inl.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 | 23 |
24 MachineOperatorReducer::MachineOperatorReducer(Graph* graph, | 24 MachineOperatorReducer::MachineOperatorReducer(Graph* graph, |
25 CommonNodeCache* cache) | 25 CommonNodeCache* cache) |
26 : graph_(graph), | 26 : graph_(graph), |
27 cache_(cache), | 27 cache_(cache), |
28 common_(graph->zone()), | 28 common_(graph->zone()), |
29 machine_(graph->zone()) {} | 29 machine_(graph->zone()) {} |
30 | 30 |
31 | 31 |
| 32 Node* MachineOperatorReducer::Float64Constant(volatile double value) { |
| 33 Node** loc = cache_->FindFloat64Constant(value); |
| 34 if (*loc == NULL) { |
| 35 *loc = graph_->NewNode(common_.Float64Constant(value)); |
| 36 } |
| 37 return *loc; |
| 38 } |
| 39 |
| 40 |
32 Node* MachineOperatorReducer::Int32Constant(int32_t value) { | 41 Node* MachineOperatorReducer::Int32Constant(int32_t value) { |
33 Node** loc = cache_->FindInt32Constant(value); | 42 Node** loc = cache_->FindInt32Constant(value); |
34 if (*loc == NULL) { | 43 if (*loc == NULL) { |
35 *loc = graph_->NewNode(common_.Int32Constant(value)); | 44 *loc = graph_->NewNode(common_.Int32Constant(value)); |
36 } | 45 } |
37 return *loc; | 46 return *loc; |
38 } | 47 } |
39 | 48 |
40 | 49 |
41 Node* MachineOperatorReducer::Float64Constant(volatile double value) { | 50 Node* MachineOperatorReducer::Int64Constant(int64_t value) { |
42 Node** loc = cache_->FindFloat64Constant(value); | 51 return graph_->NewNode(common_.Int64Constant(value)); |
43 if (*loc == NULL) { | |
44 *loc = graph_->NewNode(common_.Float64Constant(value)); | |
45 } | |
46 return *loc; | |
47 } | 52 } |
48 | 53 |
49 | 54 |
50 // Perform constant folding and strength reduction on machine operators. | 55 // Perform constant folding and strength reduction on machine operators. |
51 Reduction MachineOperatorReducer::Reduce(Node* node) { | 56 Reduction MachineOperatorReducer::Reduce(Node* node) { |
52 switch (node->opcode()) { | 57 switch (node->opcode()) { |
53 case IrOpcode::kWord32And: { | 58 case IrOpcode::kWord32And: { |
54 Int32BinopMatcher m(node); | 59 Int32BinopMatcher m(node); |
55 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0 | 60 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0 |
56 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x | 61 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return Replace(m.right().node()); | 390 return Replace(m.right().node()); |
386 } | 391 } |
387 if (m.left().IsNaN()) { // NaN % x => NaN | 392 if (m.left().IsNaN()) { // NaN % x => NaN |
388 return Replace(m.left().node()); | 393 return Replace(m.left().node()); |
389 } | 394 } |
390 if (m.IsFoldable()) { // K % K => K | 395 if (m.IsFoldable()) { // K % K => K |
391 return ReplaceFloat64(modulo(m.left().Value(), m.right().Value())); | 396 return ReplaceFloat64(modulo(m.left().Value(), m.right().Value())); |
392 } | 397 } |
393 break; | 398 break; |
394 } | 399 } |
| 400 case IrOpcode::kChangeFloat64ToInt32: { |
| 401 Float64Matcher m(node->InputAt(0)); |
| 402 if (m.HasValue()) return ReplaceInt32(FastD2I(m.Value())); |
| 403 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); |
| 404 break; |
| 405 } |
| 406 case IrOpcode::kChangeFloat64ToUint32: { |
| 407 Float64Matcher m(node->InputAt(0)); |
| 408 if (m.HasValue()) return ReplaceInt32(FastD2UI(m.Value())); |
| 409 if (m.IsChangeUint32ToFloat64()) return Replace(m.node()->InputAt(0)); |
| 410 break; |
| 411 } |
| 412 case IrOpcode::kChangeInt32ToFloat64: { |
| 413 Int32Matcher m(node->InputAt(0)); |
| 414 if (m.HasValue()) return ReplaceFloat64(FastI2D(m.Value())); |
| 415 break; |
| 416 } |
| 417 case IrOpcode::kChangeInt32ToInt64: { |
| 418 Int32Matcher m(node->InputAt(0)); |
| 419 if (m.HasValue()) return ReplaceInt64(m.Value()); |
| 420 break; |
| 421 } |
| 422 case IrOpcode::kChangeUint32ToFloat64: { |
| 423 Uint32Matcher m(node->InputAt(0)); |
| 424 if (m.HasValue()) return ReplaceFloat64(FastUI2D(m.Value())); |
| 425 break; |
| 426 } |
| 427 case IrOpcode::kChangeUint32ToUint64: { |
| 428 Uint32Matcher m(node->InputAt(0)); |
| 429 if (m.HasValue()) return ReplaceInt64(static_cast<uint64_t>(m.Value())); |
| 430 break; |
| 431 } |
| 432 case IrOpcode::kTruncateFloat64ToInt32: { |
| 433 Float64Matcher m(node->InputAt(0)); |
| 434 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); |
| 435 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); |
| 436 break; |
| 437 } |
| 438 case IrOpcode::kTruncateInt64ToInt32: { |
| 439 Int64Matcher m(node->InputAt(0)); |
| 440 if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value())); |
| 441 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0)); |
| 442 break; |
| 443 } |
395 // TODO(turbofan): strength-reduce and fold floating point operations. | 444 // TODO(turbofan): strength-reduce and fold floating point operations. |
396 default: | 445 default: |
397 break; | 446 break; |
398 } | 447 } |
399 return NoChange(); | 448 return NoChange(); |
400 } | 449 } |
401 } | 450 } |
402 } | 451 } |
403 } // namespace v8::internal::compiler | 452 } // namespace v8::internal::compiler |
OLD | NEW |