Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_ |
| 6 | #define V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_ |
| 7 | |
| 8 | #include "src/compiler/graph-reducer.h" |
| 9 | #include "src/compiler/machine-operator.h" |
| 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | namespace compiler { |
| 14 | |
| 15 | // Forward declarations. |
| 16 | class CommonOperatorBuilder; |
| 17 | class JSGraph; |
| 18 | |
| 19 | |
| 20 | // Performs constant folding and strength reduction on nodes that have |
| 21 | // machine operators. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | class MachineOperatorReducer final : public Reducer { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 23 | public: |
| 24 | explicit MachineOperatorReducer(JSGraph* jsgraph); |
| 25 | ~MachineOperatorReducer(); |
| 26 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 27 | Reduction Reduce(Node* node) override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | |
| 29 | private: |
| 30 | Node* Float32Constant(volatile float value); |
| 31 | Node* Float64Constant(volatile double value); |
| 32 | Node* Int32Constant(int32_t value); |
| 33 | Node* Int64Constant(int64_t value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 34 | Node* Uint32Constant(uint32_t value) { |
| 35 | return Int32Constant(bit_cast<uint32_t>(value)); |
| 36 | } |
| 37 | Node* Word32And(Node* lhs, Node* rhs); |
| 38 | Node* Word32And(Node* lhs, uint32_t rhs) { |
| 39 | return Word32And(lhs, Uint32Constant(rhs)); |
| 40 | } |
| 41 | Node* Word32Sar(Node* lhs, uint32_t rhs); |
| 42 | Node* Word32Shr(Node* lhs, uint32_t rhs); |
| 43 | Node* Word32Equal(Node* lhs, Node* rhs); |
| 44 | Node* Int32Add(Node* lhs, Node* rhs); |
| 45 | Node* Int32Sub(Node* lhs, Node* rhs); |
| 46 | Node* Int32Mul(Node* lhs, Node* rhs); |
| 47 | Node* Int32Div(Node* dividend, int32_t divisor); |
| 48 | Node* Uint32Div(Node* dividend, uint32_t divisor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 49 | |
| 50 | Reduction ReplaceBool(bool value) { return ReplaceInt32(value ? 1 : 0); } |
| 51 | Reduction ReplaceFloat32(volatile float value) { |
| 52 | return Replace(Float32Constant(value)); |
| 53 | } |
| 54 | Reduction ReplaceFloat64(volatile double value) { |
| 55 | return Replace(Float64Constant(value)); |
| 56 | } |
| 57 | Reduction ReplaceInt32(int32_t value) { |
| 58 | return Replace(Int32Constant(value)); |
| 59 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 60 | Reduction ReplaceUint32(uint32_t value) { |
| 61 | return Replace(Uint32Constant(value)); |
| 62 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | Reduction ReplaceInt64(int64_t value) { |
| 64 | return Replace(Int64Constant(value)); |
| 65 | } |
| 66 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 67 | Reduction ReduceInt32Add(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 68 | Reduction ReduceInt32Sub(Node* node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 69 | Reduction ReduceInt32Div(Node* node); |
| 70 | Reduction ReduceUint32Div(Node* node); |
| 71 | Reduction ReduceInt32Mod(Node* node); |
| 72 | Reduction ReduceUint32Mod(Node* node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 73 | Reduction ReduceStore(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 74 | Reduction ReduceProjection(size_t index, Node* node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 75 | Reduction ReduceWord32Shifts(Node* node); |
| 76 | Reduction ReduceWord32Shl(Node* node); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 77 | Reduction ReduceWord32Shr(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 78 | Reduction ReduceWord32Sar(Node* node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 79 | Reduction ReduceWord32And(Node* node); |
| 80 | Reduction ReduceWord32Or(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | Reduction ReduceFloat64InsertLowWord32(Node* node); |
| 82 | Reduction ReduceFloat64InsertHighWord32(Node* node); |
| 83 | Reduction ReduceFloat64Compare(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 84 | |
| 85 | Graph* graph() const; |
| 86 | JSGraph* jsgraph() const { return jsgraph_; } |
| 87 | CommonOperatorBuilder* common() const; |
| 88 | MachineOperatorBuilder* machine() const; |
| 89 | |
| 90 | JSGraph* jsgraph_; |
| 91 | }; |
| 92 | |
| 93 | } // namespace compiler |
| 94 | } // namespace internal |
| 95 | } // namespace v8 |
| 96 | |
| 97 | #endif // V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_ |