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/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
6 #include "src/compiler/graph-inl.h" | 6 #include "src/compiler/graph-inl.h" |
7 #include "src/compiler/js-builtin-reducer.h" | 7 #include "src/compiler/js-builtin-reducer.h" |
8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
9 #include "src/compiler/node-aux-data-inl.h" | 9 #include "src/compiler/node-aux-data-inl.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 // JSToBoolean(x:undetectable) => #false | 539 // JSToBoolean(x:undetectable) => #false |
540 return ReplaceWith(jsgraph()->FalseConstant()); | 540 return ReplaceWith(jsgraph()->FalseConstant()); |
541 } | 541 } |
542 if (input_type->Is(Type::OrderedNumber())) { | 542 if (input_type->Is(Type::OrderedNumber())) { |
543 // JSToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x, #0)) | 543 // JSToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x, #0)) |
544 Node* cmp = graph()->NewNode(simplified()->NumberEqual(), input, | 544 Node* cmp = graph()->NewNode(simplified()->NumberEqual(), input, |
545 jsgraph()->ZeroConstant()); | 545 jsgraph()->ZeroConstant()); |
546 Node* inv = graph()->NewNode(simplified()->BooleanNot(), cmp); | 546 Node* inv = graph()->NewNode(simplified()->BooleanNot(), cmp); |
547 return ReplaceWith(inv); | 547 return ReplaceWith(inv); |
548 } | 548 } |
549 // TODO(turbofan): js-typed-lowering of ToBoolean(string) | 549 if (input_type->Is(Type::String())) { |
| 550 // JSToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0)) |
| 551 FieldAccess access = AccessBuilder::ForStringLength(); |
| 552 Node* length = graph()->NewNode(simplified()->LoadField(access), input, |
| 553 graph()->start(), graph()->start()); |
| 554 Node* cmp = graph()->NewNode(simplified()->NumberEqual(), length, |
| 555 jsgraph()->ZeroConstant()); |
| 556 Node* inv = graph()->NewNode(simplified()->BooleanNot(), cmp); |
| 557 return ReplaceWith(inv); |
| 558 } |
| 559 if (input->opcode() == IrOpcode::kPhi && input_type->Is(Type::Primitive())) { |
| 560 // JSToBoolean(phi(x1,...,xn):primitive) |
| 561 // => phi(JSToBoolean(x1),...,JSToBoolean(xn)) |
| 562 int input_count = input->InputCount() - 1; |
| 563 Node** inputs = zone()->NewArray<Node*>(input_count + 1); |
| 564 for (int i = 0; i < input_count; ++i) { |
| 565 Node* value = input->InputAt(i); |
| 566 // Recursively try to reduce the value first. |
| 567 Reduction result = ReduceJSToBooleanInput(value); |
| 568 if (result.Changed()) { |
| 569 inputs[i] = result.replacement(); |
| 570 } else { |
| 571 inputs[i] = graph()->NewNode(javascript()->ToBoolean(), value, |
| 572 jsgraph()->ZeroConstant(), |
| 573 graph()->start(), graph()->start()); |
| 574 } |
| 575 } |
| 576 inputs[input_count] = input->InputAt(input_count); |
| 577 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, input_count), |
| 578 input_count + 1, inputs); |
| 579 return ReplaceWith(phi); |
| 580 } |
550 return NoChange(); | 581 return NoChange(); |
551 } | 582 } |
552 | 583 |
553 | 584 |
554 Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) { | 585 Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) { |
555 Node* key = NodeProperties::GetValueInput(node, 1); | 586 Node* key = NodeProperties::GetValueInput(node, 1); |
556 Node* base = NodeProperties::GetValueInput(node, 0); | 587 Node* base = NodeProperties::GetValueInput(node, 0); |
557 Type* key_type = NodeProperties::GetBounds(key).upper; | 588 Type* key_type = NodeProperties::GetBounds(key).upper; |
558 Type* base_type = NodeProperties::GetBounds(base).upper; | 589 Type* base_type = NodeProperties::GetBounds(base).upper; |
559 // TODO(mstarzinger): This lowering is not correct if: | 590 // TODO(mstarzinger): This lowering is not correct if: |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 return JSBuiltinReducer(jsgraph()).Reduce(node); | 749 return JSBuiltinReducer(jsgraph()).Reduce(node); |
719 default: | 750 default: |
720 break; | 751 break; |
721 } | 752 } |
722 return NoChange(); | 753 return NoChange(); |
723 } | 754 } |
724 | 755 |
725 } // namespace compiler | 756 } // namespace compiler |
726 } // namespace internal | 757 } // namespace internal |
727 } // namespace v8 | 758 } // namespace v8 |
OLD | NEW |