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/change-lowering.h" | 5 #include "src/compiler/change-lowering.h" |
6 | 6 |
7 #include "src/address-map.h" | 7 #include "src/address-map.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 Reduction ChangeLowering::ChangeTaggedToUI32(Node* value, Node* control, | 277 Reduction ChangeLowering::ChangeTaggedToUI32(Node* value, Node* control, |
278 Signedness signedness) { | 278 Signedness signedness) { |
279 if (NodeProperties::GetType(value)->Is(Type::TaggedSigned())) { | 279 if (NodeProperties::GetType(value)->Is(Type::TaggedSigned())) { |
280 return Replace(ChangeSmiToInt32(value)); | 280 return Replace(ChangeSmiToInt32(value)); |
281 } | 281 } |
282 | 282 |
283 const Operator* op = (signedness == kSigned) | 283 const Operator* op = (signedness == kSigned) |
284 ? machine()->ChangeFloat64ToInt32() | 284 ? machine()->ChangeFloat64ToInt32() |
285 : machine()->ChangeFloat64ToUint32(); | 285 : machine()->ChangeFloat64ToUint32(); |
286 | 286 |
287 if (NodeProperties::GetType(value)->Is(Type::TaggedPointer())) { | 287 if (NodeProperties::GetType(value)->Is(Type::TaggedPointer()) && |
| 288 NodeProperties::GetType(value)->Is(Type::Number())) { |
288 return Replace(graph()->NewNode(op, LoadHeapNumberValue(value, control))); | 289 return Replace(graph()->NewNode(op, LoadHeapNumberValue(value, control))); |
289 } | 290 } |
290 | 291 |
291 Node* check = TestNotSmi(value); | 292 Node* check = TestNotSmi(value); |
292 Node* branch = | 293 Node* branch = |
293 graph()->NewNode(common()->Branch(BranchHint::kFalse), check, control); | 294 graph()->NewNode(common()->Branch(BranchHint::kFalse), check, control); |
294 | 295 |
295 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 296 Node* if_not_smi = graph()->NewNode(common()->IfTrue(), branch); |
296 Node* vtrue = graph()->NewNode(op, LoadHeapNumberValue(value, if_true)); | |
297 | 297 |
298 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 298 Node* vnot_smi; |
299 Node* vfalse = ChangeSmiToInt32(value); | 299 if (NodeProperties::GetType(value)->Maybe(Type::Undefined())) { |
| 300 Node* check_undefined = graph()->NewNode(machine()->WordEqual(), value, |
| 301 jsgraph()->UndefinedConstant()); |
| 302 Node* branch_undefined = graph()->NewNode( |
| 303 common()->Branch(BranchHint::kFalse), check_undefined, if_not_smi); |
300 | 304 |
301 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 305 Node* if_undefined = graph()->NewNode(common()->IfTrue(), branch_undefined); |
| 306 Node* vundefined = jsgraph()->Int32Constant(0); |
| 307 |
| 308 Node* if_not_undefined = |
| 309 graph()->NewNode(common()->IfFalse(), branch_undefined); |
| 310 Node* vheap_number = |
| 311 graph()->NewNode(op, LoadHeapNumberValue(value, if_not_undefined)); |
| 312 |
| 313 if_not_smi = |
| 314 graph()->NewNode(common()->Merge(2), if_undefined, if_not_undefined); |
| 315 vnot_smi = |
| 316 graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), |
| 317 vundefined, vheap_number, if_not_smi); |
| 318 } else { |
| 319 vnot_smi = graph()->NewNode(op, LoadHeapNumberValue(value, if_not_smi)); |
| 320 } |
| 321 |
| 322 Node* if_smi = graph()->NewNode(common()->IfFalse(), branch); |
| 323 Node* vfrom_smi = ChangeSmiToInt32(value); |
| 324 |
| 325 Node* merge = graph()->NewNode(common()->Merge(2), if_not_smi, if_smi); |
302 Node* phi = graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), | 326 Node* phi = graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), |
303 vtrue, vfalse, merge); | 327 vnot_smi, vfrom_smi, merge); |
304 | 328 |
305 return Replace(phi); | 329 return Replace(phi); |
306 } | 330 } |
307 | 331 |
308 | 332 |
309 namespace { | 333 namespace { |
310 | 334 |
311 bool CanCover(Node* value, IrOpcode::Value opcode) { | 335 bool CanCover(Node* value, IrOpcode::Value opcode) { |
312 if (value->opcode() != opcode) return false; | 336 if (value->opcode() != opcode) return false; |
313 bool first = true; | 337 bool first = true; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 406 } |
383 } | 407 } |
384 | 408 |
385 return Replace(phi1); | 409 return Replace(phi1); |
386 } | 410 } |
387 | 411 |
388 Node* check = TestNotSmi(value); | 412 Node* check = TestNotSmi(value); |
389 Node* branch = | 413 Node* branch = |
390 graph()->NewNode(common()->Branch(BranchHint::kFalse), check, control); | 414 graph()->NewNode(common()->Branch(BranchHint::kFalse), check, control); |
391 | 415 |
392 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 416 Node* if_not_smi = graph()->NewNode(common()->IfTrue(), branch); |
393 Node* vtrue = LoadHeapNumberValue(value, if_true); | |
394 | 417 |
395 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 418 Node* vnot_smi; |
396 Node* vfalse = ChangeSmiToFloat64(value); | 419 if (NodeProperties::GetType(value)->Maybe(Type::Undefined())) { |
| 420 Node* check_undefined = graph()->NewNode(machine()->WordEqual(), value, |
| 421 jsgraph()->UndefinedConstant()); |
| 422 Node* branch_undefined = graph()->NewNode( |
| 423 common()->Branch(BranchHint::kFalse), check_undefined, if_not_smi); |
397 | 424 |
398 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 425 Node* if_undefined = graph()->NewNode(common()->IfTrue(), branch_undefined); |
399 Node* phi = graph()->NewNode( | 426 Node* vundefined = |
400 common()->Phi(MachineRepresentation::kFloat64, 2), vtrue, vfalse, merge); | 427 jsgraph()->Float64Constant(std::numeric_limits<double>::quiet_NaN()); |
| 428 |
| 429 Node* if_not_undefined = |
| 430 graph()->NewNode(common()->IfFalse(), branch_undefined); |
| 431 Node* vheap_number = LoadHeapNumberValue(value, if_not_undefined); |
| 432 |
| 433 if_not_smi = |
| 434 graph()->NewNode(common()->Merge(2), if_undefined, if_not_undefined); |
| 435 vnot_smi = |
| 436 graph()->NewNode(common()->Phi(MachineRepresentation::kFloat64, 2), |
| 437 vundefined, vheap_number, if_not_smi); |
| 438 } else { |
| 439 vnot_smi = LoadHeapNumberValue(value, if_not_smi); |
| 440 } |
| 441 |
| 442 Node* if_smi = graph()->NewNode(common()->IfFalse(), branch); |
| 443 Node* vfrom_smi = ChangeSmiToFloat64(value); |
| 444 |
| 445 Node* merge = graph()->NewNode(common()->Merge(2), if_not_smi, if_smi); |
| 446 Node* phi = |
| 447 graph()->NewNode(common()->Phi(MachineRepresentation::kFloat64, 2), |
| 448 vnot_smi, vfrom_smi, merge); |
401 | 449 |
402 return Replace(phi); | 450 return Replace(phi); |
403 } | 451 } |
404 | 452 |
405 | 453 |
406 Reduction ChangeLowering::ChangeUint32ToTagged(Node* value, Node* control) { | 454 Reduction ChangeLowering::ChangeUint32ToTagged(Node* value, Node* control) { |
407 if (NodeProperties::GetType(value)->Is(Type::UnsignedSmall())) { | 455 if (NodeProperties::GetType(value)->Is(Type::UnsignedSmall())) { |
408 return Replace(ChangeUint32ToSmi(value)); | 456 return Replace(ChangeUint32ToSmi(value)); |
409 } | 457 } |
410 | 458 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 } | 770 } |
723 | 771 |
724 | 772 |
725 MachineOperatorBuilder* ChangeLowering::machine() const { | 773 MachineOperatorBuilder* ChangeLowering::machine() const { |
726 return jsgraph()->machine(); | 774 return jsgraph()->machine(); |
727 } | 775 } |
728 | 776 |
729 } // namespace compiler | 777 } // namespace compiler |
730 } // namespace internal | 778 } // namespace internal |
731 } // namespace v8 | 779 } // namespace v8 |
OLD | NEW |