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.
5 #ifndef V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_
6 #define V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_
8 #include "src/compiler/graph-reducer.h"
9 #include "src/compiler/machine-operator.h"
15 // Forward declarations.
16 class CommonOperatorBuilder;
20 // Performs constant folding and strength reduction on nodes that have
22 class MachineOperatorReducer FINAL : public Reducer {
24 explicit MachineOperatorReducer(JSGraph* jsgraph);
25 ~MachineOperatorReducer();
27 Reduction Reduce(Node* node) OVERRIDE;
30 Node* Float32Constant(volatile float value);
31 Node* Float64Constant(volatile double value);
32 Node* Int32Constant(int32_t value);
33 Node* Int64Constant(int64_t value);
34 Node* Uint32Constant(uint32_t value) {
35 return Int32Constant(bit_cast<uint32_t>(value));
37 Node* Word32And(Node* lhs, Node* rhs);
38 Node* Word32And(Node* lhs, uint32_t rhs) {
39 return Word32And(lhs, Uint32Constant(rhs));
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);
50 Reduction ReplaceBool(bool value) { return ReplaceInt32(value ? 1 : 0); }
51 Reduction ReplaceFloat32(volatile float value) {
52 return Replace(Float32Constant(value));
54 Reduction ReplaceFloat64(volatile double value) {
55 return Replace(Float64Constant(value));
57 Reduction ReplaceInt32(int32_t value) {
58 return Replace(Int32Constant(value));
60 Reduction ReplaceUint32(uint32_t value) {
61 return Replace(Uint32Constant(value));
63 Reduction ReplaceInt64(int64_t value) {
64 return Replace(Int64Constant(value));
67 Reduction ReduceInt32Add(Node* node);
68 Reduction ReduceInt32Sub(Node* node);
69 Reduction ReduceInt32Div(Node* node);
70 Reduction ReduceUint32Div(Node* node);
71 Reduction ReduceInt32Mod(Node* node);
72 Reduction ReduceUint32Mod(Node* node);
73 Reduction ReduceTruncateFloat64ToInt32(Node* node);
74 Reduction ReduceStore(Node* node);
75 Reduction ReduceProjection(size_t index, Node* node);
76 Reduction ReduceWord32Shifts(Node* node);
77 Reduction ReduceWord32Shl(Node* node);
78 Reduction ReduceWord32And(Node* node);
79 Reduction ReduceWord32Or(Node* node);
82 JSGraph* jsgraph() const { return jsgraph_; }
83 CommonOperatorBuilder* common() const;
84 MachineOperatorBuilder* machine() const;
89 } // namespace compiler
90 } // namespace internal
93 #endif // V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_