blob: 593f7f2d22c7a8250f5128a6e230905d459d3d35 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdochc8c1d9e2017-03-08 14:04:23 +00008#include "src/base/compiler-specific.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/compiler/graph-reducer.h"
10#include "src/compiler/machine-operator.h"
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000011#include "src/globals.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012
13namespace v8 {
14namespace internal {
15namespace compiler {
16
17// Forward declarations.
18class CommonOperatorBuilder;
19class JSGraph;
20
21
22// Performs constant folding and strength reduction on nodes that have
23// machine operators.
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000024class V8_EXPORT_PRIVATE MachineOperatorReducer final
25 : public NON_EXPORTED_BASE(Reducer) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026 public:
Ben Murdoch62ed6312017-06-06 11:06:27 +010027 explicit MachineOperatorReducer(JSGraph* jsgraph,
28 bool allow_signalling_nan = true);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029 ~MachineOperatorReducer();
30
Ben Murdoch014dc512016-03-22 12:00:34 +000031 Reduction Reduce(Node* node) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032
33 private:
34 Node* Float32Constant(volatile float value);
35 Node* Float64Constant(volatile double value);
36 Node* Int32Constant(int32_t value);
37 Node* Int64Constant(int64_t value);
Emily Bernier958fae72015-03-24 16:35:39 -040038 Node* Uint32Constant(uint32_t value) {
Ben Murdochf91f0612016-11-29 16:50:11 +000039 return Int32Constant(bit_cast<int32_t>(value));
Emily Bernier958fae72015-03-24 16:35:39 -040040 }
Ben Murdochf91f0612016-11-29 16:50:11 +000041 Node* Uint64Constant(uint64_t value) {
42 return Int64Constant(bit_cast<int64_t>(value));
43 }
44 Node* Float64Mul(Node* lhs, Node* rhs);
45 Node* Float64PowHalf(Node* value);
Emily Bernier958fae72015-03-24 16:35:39 -040046 Node* Word32And(Node* lhs, Node* rhs);
47 Node* Word32And(Node* lhs, uint32_t rhs) {
48 return Word32And(lhs, Uint32Constant(rhs));
49 }
50 Node* Word32Sar(Node* lhs, uint32_t rhs);
51 Node* Word32Shr(Node* lhs, uint32_t rhs);
52 Node* Word32Equal(Node* lhs, Node* rhs);
53 Node* Int32Add(Node* lhs, Node* rhs);
54 Node* Int32Sub(Node* lhs, Node* rhs);
55 Node* Int32Mul(Node* lhs, Node* rhs);
56 Node* Int32Div(Node* dividend, int32_t divisor);
57 Node* Uint32Div(Node* dividend, uint32_t divisor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058
59 Reduction ReplaceBool(bool value) { return ReplaceInt32(value ? 1 : 0); }
60 Reduction ReplaceFloat32(volatile float value) {
61 return Replace(Float32Constant(value));
62 }
63 Reduction ReplaceFloat64(volatile double value) {
64 return Replace(Float64Constant(value));
65 }
66 Reduction ReplaceInt32(int32_t value) {
67 return Replace(Int32Constant(value));
68 }
Emily Bernier958fae72015-03-24 16:35:39 -040069 Reduction ReplaceUint32(uint32_t value) {
70 return Replace(Uint32Constant(value));
71 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072 Reduction ReplaceInt64(int64_t value) {
73 return Replace(Int64Constant(value));
74 }
75
Emily Bernier958fae72015-03-24 16:35:39 -040076 Reduction ReduceInt32Add(Node* node);
Ben Murdochf91f0612016-11-29 16:50:11 +000077 Reduction ReduceInt64Add(Node* node);
Ben Murdoch014dc512016-03-22 12:00:34 +000078 Reduction ReduceInt32Sub(Node* node);
Ben Murdochf91f0612016-11-29 16:50:11 +000079 Reduction ReduceInt64Sub(Node* node);
Emily Bernier958fae72015-03-24 16:35:39 -040080 Reduction ReduceInt32Div(Node* node);
81 Reduction ReduceUint32Div(Node* node);
82 Reduction ReduceInt32Mod(Node* node);
83 Reduction ReduceUint32Mod(Node* node);
Emily Bernier958fae72015-03-24 16:35:39 -040084 Reduction ReduceStore(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000085 Reduction ReduceProjection(size_t index, Node* node);
Emily Bernier958fae72015-03-24 16:35:39 -040086 Reduction ReduceWord32Shifts(Node* node);
87 Reduction ReduceWord32Shl(Node* node);
Ben Murdochf91f0612016-11-29 16:50:11 +000088 Reduction ReduceWord64Shl(Node* node);
Ben Murdoch13e2dad2016-09-16 13:49:30 +010089 Reduction ReduceWord32Shr(Node* node);
Ben Murdochf91f0612016-11-29 16:50:11 +000090 Reduction ReduceWord64Shr(Node* node);
Ben Murdoch014dc512016-03-22 12:00:34 +000091 Reduction ReduceWord32Sar(Node* node);
Ben Murdochf91f0612016-11-29 16:50:11 +000092 Reduction ReduceWord64Sar(Node* node);
Emily Bernier958fae72015-03-24 16:35:39 -040093 Reduction ReduceWord32And(Node* node);
Ben Murdochf3b273f2017-01-17 12:11:28 +000094 Reduction TryMatchWord32Ror(Node* node);
Emily Bernier958fae72015-03-24 16:35:39 -040095 Reduction ReduceWord32Or(Node* node);
Ben Murdochf3b273f2017-01-17 12:11:28 +000096 Reduction ReduceWord32Xor(Node* node);
Ben Murdoch014dc512016-03-22 12:00:34 +000097 Reduction ReduceFloat64InsertLowWord32(Node* node);
98 Reduction ReduceFloat64InsertHighWord32(Node* node);
99 Reduction ReduceFloat64Compare(Node* node);
Ben Murdoch62ed6312017-06-06 11:06:27 +0100100 Reduction ReduceFloat64RoundDown(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101
102 Graph* graph() const;
103 JSGraph* jsgraph() const { return jsgraph_; }
104 CommonOperatorBuilder* common() const;
105 MachineOperatorBuilder* machine() const;
106
107 JSGraph* jsgraph_;
Ben Murdoch62ed6312017-06-06 11:06:27 +0100108 bool allow_signalling_nan_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109};
110
111} // namespace compiler
112} // namespace internal
113} // namespace v8
114
115#endif // V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_