blob: 8200abbf9573553ad74f259f94d89239f7551244 [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
8#include "src/compiler/graph-reducer.h"
9#include "src/compiler/machine-operator.h"
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15// Forward declarations.
16class CommonOperatorBuilder;
17class JSGraph;
18
19
20// Performs constant folding and strength reduction on nodes that have
21// machine operators.
22class MachineOperatorReducer FINAL : public Reducer {
23 public:
24 explicit MachineOperatorReducer(JSGraph* jsgraph);
25 ~MachineOperatorReducer();
26
Emily Bernierd0a1eb72015-03-24 16:35:39 -040027 Reduction Reduce(Node* node) OVERRIDE;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028
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 Bernierd0a1eb72015-03-24 16:35:39 -040034 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 Murdochb8a8cc12014-11-26 15:28:44 +000049
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 Bernierd0a1eb72015-03-24 16:35:39 -040060 Reduction ReplaceUint32(uint32_t value) {
61 return Replace(Uint32Constant(value));
62 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063 Reduction ReplaceInt64(int64_t value) {
64 return Replace(Int64Constant(value));
65 }
66
Emily Bernierd0a1eb72015-03-24 16:35:39 -040067 Reduction ReduceInt32Add(Node* node);
68 Reduction ReduceInt32Div(Node* node);
69 Reduction ReduceUint32Div(Node* node);
70 Reduction ReduceInt32Mod(Node* node);
71 Reduction ReduceUint32Mod(Node* node);
72 Reduction ReduceTruncateFloat64ToInt32(Node* node);
73 Reduction ReduceStore(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074 Reduction ReduceProjection(size_t index, Node* node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040075 Reduction ReduceWord32Shifts(Node* node);
76 Reduction ReduceWord32Shl(Node* node);
77 Reduction ReduceWord32And(Node* node);
78 Reduction ReduceWord32Or(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079
80 Graph* graph() const;
81 JSGraph* jsgraph() const { return jsgraph_; }
82 CommonOperatorBuilder* common() const;
83 MachineOperatorBuilder* machine() const;
84
85 JSGraph* jsgraph_;
86};
87
88} // namespace compiler
89} // namespace internal
90} // namespace v8
91
92#endif // V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_