OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/typed-optimization.h" | 5 #include "src/compiler/typed-optimization.h" |
6 | 6 |
7 #include "src/compilation-dependencies.h" | 7 #include "src/compilation-dependencies.h" |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/simplified-operator.h" | 10 #include "src/compiler/simplified-operator.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 switch (node->opcode()) { | 76 switch (node->opcode()) { |
77 case IrOpcode::kCheckHeapObject: | 77 case IrOpcode::kCheckHeapObject: |
78 return ReduceCheckHeapObject(node); | 78 return ReduceCheckHeapObject(node); |
79 case IrOpcode::kCheckMaps: | 79 case IrOpcode::kCheckMaps: |
80 return ReduceCheckMaps(node); | 80 return ReduceCheckMaps(node); |
81 case IrOpcode::kCheckString: | 81 case IrOpcode::kCheckString: |
82 return ReduceCheckString(node); | 82 return ReduceCheckString(node); |
83 case IrOpcode::kLoadField: | 83 case IrOpcode::kLoadField: |
84 return ReduceLoadField(node); | 84 return ReduceLoadField(node); |
85 case IrOpcode::kNumberCeil: | 85 case IrOpcode::kNumberCeil: |
86 case IrOpcode::kNumberFloor: | |
87 case IrOpcode::kNumberRound: | 86 case IrOpcode::kNumberRound: |
88 case IrOpcode::kNumberTrunc: | 87 case IrOpcode::kNumberTrunc: |
89 return ReduceNumberRoundop(node); | 88 return ReduceNumberRoundop(node); |
| 89 case IrOpcode::kNumberFloor: |
| 90 return ReduceNumberFloor(node); |
90 case IrOpcode::kNumberToUint8Clamped: | 91 case IrOpcode::kNumberToUint8Clamped: |
91 return ReduceNumberToUint8Clamped(node); | 92 return ReduceNumberToUint8Clamped(node); |
92 case IrOpcode::kPhi: | 93 case IrOpcode::kPhi: |
93 return ReducePhi(node); | 94 return ReducePhi(node); |
94 case IrOpcode::kSelect: | 95 case IrOpcode::kSelect: |
95 return ReduceSelect(node); | 96 return ReduceSelect(node); |
96 default: | 97 default: |
97 break; | 98 break; |
98 } | 99 } |
99 return NoChange(); | 100 return NoChange(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 179 } |
179 } | 180 } |
180 Node* const value = jsgraph()->HeapConstant(object_map); | 181 Node* const value = jsgraph()->HeapConstant(object_map); |
181 ReplaceWithValue(node, value); | 182 ReplaceWithValue(node, value); |
182 return Replace(value); | 183 return Replace(value); |
183 } | 184 } |
184 } | 185 } |
185 return NoChange(); | 186 return NoChange(); |
186 } | 187 } |
187 | 188 |
| 189 Reduction TypedOptimization::ReduceNumberFloor(Node* node) { |
| 190 Node* const input = NodeProperties::GetValueInput(node, 0); |
| 191 Type* const input_type = NodeProperties::GetType(input); |
| 192 if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) { |
| 193 return Replace(input); |
| 194 } |
| 195 if (input_type->Is(Type::PlainNumber()) && |
| 196 input->opcode() == IrOpcode::kNumberDivide) { |
| 197 Node* const lhs = NodeProperties::GetValueInput(input, 0); |
| 198 Type* const lhs_type = NodeProperties::GetType(lhs); |
| 199 Node* const rhs = NodeProperties::GetValueInput(input, 1); |
| 200 Type* const rhs_type = NodeProperties::GetType(rhs); |
| 201 if (lhs_type->Is(Type::Unsigned32()) && rhs_type->Is(Type::Unsigned32())) { |
| 202 // We can replace |
| 203 // |
| 204 // NumberFloor(NumberDivide(lhs: unsigned32, |
| 205 // rhs: unsigned32)): plain-number |
| 206 // |
| 207 // with |
| 208 // |
| 209 // NumberToUint32(NumberDivide(lhs, rhs)) |
| 210 // |
| 211 // and just smash the type of the {lhs} on the {node}, |
| 212 // as the truncated result must be in the same range as |
| 213 // {lhs} since {rhs} cannot be less than 1 (due to the |
| 214 // plain-number type constraint on the {node}). |
| 215 NodeProperties::ChangeOp(node, simplified()->NumberToUint32()); |
| 216 NodeProperties::SetType(node, lhs_type); |
| 217 return Changed(node); |
| 218 } |
| 219 } |
| 220 return NoChange(); |
| 221 } |
| 222 |
188 Reduction TypedOptimization::ReduceNumberRoundop(Node* node) { | 223 Reduction TypedOptimization::ReduceNumberRoundop(Node* node) { |
189 Node* const input = NodeProperties::GetValueInput(node, 0); | 224 Node* const input = NodeProperties::GetValueInput(node, 0); |
190 Type* const input_type = NodeProperties::GetType(input); | 225 Type* const input_type = NodeProperties::GetType(input); |
191 if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) { | 226 if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) { |
192 return Replace(input); | 227 return Replace(input); |
193 } | 228 } |
194 return NoChange(); | 229 return NoChange(); |
195 } | 230 } |
196 | 231 |
197 Reduction TypedOptimization::ReduceNumberToUint8Clamped(Node* node) { | 232 Reduction TypedOptimization::ReduceNumberToUint8Clamped(Node* node) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 302 |
268 Isolate* TypedOptimization::isolate() const { return jsgraph()->isolate(); } | 303 Isolate* TypedOptimization::isolate() const { return jsgraph()->isolate(); } |
269 | 304 |
270 SimplifiedOperatorBuilder* TypedOptimization::simplified() const { | 305 SimplifiedOperatorBuilder* TypedOptimization::simplified() const { |
271 return jsgraph()->simplified(); | 306 return jsgraph()->simplified(); |
272 } | 307 } |
273 | 308 |
274 } // namespace compiler | 309 } // namespace compiler |
275 } // namespace internal | 310 } // namespace internal |
276 } // namespace v8 | 311 } // namespace v8 |
OLD | NEW |