OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/simplified-operator-reducer.h" | 5 #include "src/compiler/simplified-operator-reducer.h" |
6 | 6 |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/machine-operator.h" | 8 #include "src/compiler/machine-operator.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/operator-properties.h" | 10 #include "src/compiler/operator-properties.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 if (m.IsChangeBitToTagged()) return Decision::kFalse; | 27 if (m.IsChangeBitToTagged()) return Decision::kFalse; |
28 if (m.IsChangeInt31ToTaggedSigned()) return Decision::kTrue; | 28 if (m.IsChangeInt31ToTaggedSigned()) return Decision::kTrue; |
29 if (m.IsHeapConstant()) return Decision::kFalse; | 29 if (m.IsHeapConstant()) return Decision::kFalse; |
30 return Decision::kUnknown; | 30 return Decision::kUnknown; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 SimplifiedOperatorReducer::SimplifiedOperatorReducer(Editor* editor, | 35 SimplifiedOperatorReducer::SimplifiedOperatorReducer(Editor* editor, |
36 JSGraph* jsgraph) | 36 JSGraph* jsgraph) |
37 : AdvancedReducer(editor), | 37 : AdvancedReducer(editor), jsgraph_(jsgraph) {} |
38 jsgraph_(jsgraph), | |
39 type_cache_(TypeCache::Get()) {} | |
40 | 38 |
41 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} | 39 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} |
42 | 40 |
43 | 41 |
44 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { | 42 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { |
45 switch (node->opcode()) { | 43 switch (node->opcode()) { |
46 case IrOpcode::kBooleanNot: { | 44 case IrOpcode::kBooleanNot: { |
47 HeapObjectMatcher m(node->InputAt(0)); | 45 HeapObjectMatcher m(node->InputAt(0)); |
48 if (m.HasValue()) { | 46 if (m.HasValue()) { |
49 return Replace(jsgraph()->BooleanConstant(!m.Value()->BooleanValue())); | 47 return Replace(jsgraph()->BooleanConstant(!m.Value()->BooleanValue())); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 case Decision::kUnknown: | 153 case Decision::kUnknown: |
156 break; | 154 break; |
157 } | 155 } |
158 break; | 156 break; |
159 } | 157 } |
160 case IrOpcode::kNumberAbs: { | 158 case IrOpcode::kNumberAbs: { |
161 NumberMatcher m(node->InputAt(0)); | 159 NumberMatcher m(node->InputAt(0)); |
162 if (m.HasValue()) return ReplaceNumber(std::fabs(m.Value())); | 160 if (m.HasValue()) return ReplaceNumber(std::fabs(m.Value())); |
163 break; | 161 break; |
164 } | 162 } |
165 case IrOpcode::kNumberCeil: | 163 case IrOpcode::kReferenceEqual: { |
166 case IrOpcode::kNumberFloor: | 164 HeapObjectBinopMatcher m(node); |
167 case IrOpcode::kNumberRound: | 165 if (m.left().node() == m.right().node()) return ReplaceBoolean(true); |
168 case IrOpcode::kNumberTrunc: { | |
169 Node* const input = NodeProperties::GetValueInput(node, 0); | |
170 Type* const input_type = NodeProperties::GetType(input); | |
171 if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) { | |
172 return Replace(input); | |
173 } | |
174 break; | 166 break; |
175 } | 167 } |
176 case IrOpcode::kReferenceEqual: | |
177 return ReduceReferenceEqual(node); | |
178 default: | 168 default: |
179 break; | 169 break; |
180 } | 170 } |
181 return NoChange(); | 171 return NoChange(); |
182 } | 172 } |
183 | 173 |
184 Reduction SimplifiedOperatorReducer::ReduceReferenceEqual(Node* node) { | |
185 DCHECK_EQ(IrOpcode::kReferenceEqual, node->opcode()); | |
186 Node* const left = NodeProperties::GetValueInput(node, 0); | |
187 Node* const right = NodeProperties::GetValueInput(node, 1); | |
188 HeapObjectMatcher match_left(left); | |
189 HeapObjectMatcher match_right(right); | |
190 if (match_left.HasValue() && match_right.HasValue()) { | |
191 if (match_left.Value().is_identical_to(match_right.Value())) { | |
192 return Replace(jsgraph()->TrueConstant()); | |
193 } else { | |
194 return Replace(jsgraph()->FalseConstant()); | |
195 } | |
196 } | |
197 return NoChange(); | |
198 } | |
199 | |
200 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, | 174 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, |
201 Node* a) { | 175 Node* a) { |
202 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op)); | 176 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op)); |
203 DCHECK_LE(1, node->InputCount()); | 177 DCHECK_LE(1, node->InputCount()); |
204 node->ReplaceInput(0, a); | 178 node->ReplaceInput(0, a); |
205 NodeProperties::ChangeOp(node, op); | 179 NodeProperties::ChangeOp(node, op); |
206 return Changed(node); | 180 return Changed(node); |
207 } | 181 } |
208 | 182 |
209 Reduction SimplifiedOperatorReducer::ReplaceBoolean(bool value) { | 183 Reduction SimplifiedOperatorReducer::ReplaceBoolean(bool value) { |
(...skipping 23 matching lines...) Expand all Loading... |
233 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } | 207 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } |
234 | 208 |
235 | 209 |
236 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { | 210 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { |
237 return jsgraph()->machine(); | 211 return jsgraph()->machine(); |
238 } | 212 } |
239 | 213 |
240 } // namespace compiler | 214 } // namespace compiler |
241 } // namespace internal | 215 } // namespace internal |
242 } // namespace v8 | 216 } // namespace v8 |
OLD | NEW |