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/base/compiler-specific.h" 9 #include "src/compiler/graph-reducer.h" 10 #include "src/compiler/machine-operator.h" 11 #include "src/globals.h" 12 13 namespace v8 { 14 namespace internal { 15 namespace compiler { 16 17 // Forward declarations. 18 class CommonOperatorBuilder; 19 class MachineGraph; 20 21 // Performs constant folding and strength reduction on nodes that have 22 // machine operators. 23 class V8_EXPORT_PRIVATE MachineOperatorReducer final NON_EXPORTED_BASE(Reducer)24 : public NON_EXPORTED_BASE(Reducer) { 25 public: 26 explicit MachineOperatorReducer(MachineGraph* mcgraph, 27 bool allow_signalling_nan = true); 28 ~MachineOperatorReducer(); 29 30 const char* reducer_name() const override { return "MachineOperatorReducer"; } 31 32 Reduction Reduce(Node* node) override; 33 34 private: 35 Node* Float32Constant(volatile float value); 36 Node* Float64Constant(volatile double value); 37 Node* Int32Constant(int32_t value); 38 Node* Int64Constant(int64_t value); 39 Node* Uint32Constant(uint32_t value) { 40 return Int32Constant(bit_cast<int32_t>(value)); 41 } 42 Node* Uint64Constant(uint64_t value) { 43 return Int64Constant(bit_cast<int64_t>(value)); 44 } 45 Node* Float64Mul(Node* lhs, Node* rhs); 46 Node* Float64PowHalf(Node* value); 47 Node* Word32And(Node* lhs, Node* rhs); 48 Node* Word32And(Node* lhs, uint32_t rhs) { 49 return Word32And(lhs, Uint32Constant(rhs)); 50 } 51 Node* Word32Sar(Node* lhs, uint32_t rhs); 52 Node* Word32Shr(Node* lhs, uint32_t rhs); 53 Node* Word32Equal(Node* lhs, Node* rhs); 54 Node* Int32Add(Node* lhs, Node* rhs); 55 Node* Int32Sub(Node* lhs, Node* rhs); 56 Node* Int32Mul(Node* lhs, Node* rhs); 57 Node* Int32Div(Node* dividend, int32_t divisor); 58 Node* Uint32Div(Node* dividend, uint32_t divisor); 59 60 Reduction ReplaceBool(bool value) { return ReplaceInt32(value ? 1 : 0); } 61 Reduction ReplaceFloat32(volatile float value) { 62 return Replace(Float32Constant(value)); 63 } 64 Reduction ReplaceFloat64(volatile double value) { 65 return Replace(Float64Constant(value)); 66 } 67 Reduction ReplaceInt32(int32_t value) { 68 return Replace(Int32Constant(value)); 69 } 70 Reduction ReplaceUint32(uint32_t value) { 71 return Replace(Uint32Constant(value)); 72 } 73 Reduction ReplaceInt64(int64_t value) { 74 return Replace(Int64Constant(value)); 75 } 76 77 Reduction ReduceInt32Add(Node* node); 78 Reduction ReduceInt64Add(Node* node); 79 Reduction ReduceInt32Sub(Node* node); 80 Reduction ReduceInt64Sub(Node* node); 81 Reduction ReduceInt32Div(Node* node); 82 Reduction ReduceUint32Div(Node* node); 83 Reduction ReduceInt32Mod(Node* node); 84 Reduction ReduceUint32Mod(Node* node); 85 Reduction ReduceStore(Node* node); 86 Reduction ReduceProjection(size_t index, Node* node); 87 Reduction ReduceWord32Shifts(Node* node); 88 Reduction ReduceWord32Shl(Node* node); 89 Reduction ReduceWord64Shl(Node* node); 90 Reduction ReduceWord32Shr(Node* node); 91 Reduction ReduceWord64Shr(Node* node); 92 Reduction ReduceWord32Sar(Node* node); 93 Reduction ReduceWord64Sar(Node* node); 94 Reduction ReduceWord32And(Node* node); 95 Reduction TryMatchWord32Ror(Node* node); 96 Reduction ReduceWord32Or(Node* node); 97 Reduction ReduceWord32Xor(Node* node); 98 Reduction ReduceFloat64InsertLowWord32(Node* node); 99 Reduction ReduceFloat64InsertHighWord32(Node* node); 100 Reduction ReduceFloat64Compare(Node* node); 101 Reduction ReduceFloat64RoundDown(Node* node); 102 103 Graph* graph() const; 104 MachineGraph* mcgraph() const { return mcgraph_; } 105 CommonOperatorBuilder* common() const; 106 MachineOperatorBuilder* machine() const; 107 108 MachineGraph* mcgraph_; 109 bool allow_signalling_nan_; 110 }; 111 112 } // namespace compiler 113 } // namespace internal 114 } // namespace v8 115 116 #endif // V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_ 117