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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (input_type->Is(Type::String())) { | 549 if (input_type->Is(Type::String())) { |
550 // JSToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0)) | 550 // JSToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0)) |
551 FieldAccess access = AccessBuilder::ForStringLength(); | 551 FieldAccess access = AccessBuilder::ForStringLength(); |
552 Node* length = graph()->NewNode(simplified()->LoadField(access), input, | 552 Node* length = graph()->NewNode(simplified()->LoadField(access), input, |
553 graph()->start(), graph()->start()); | 553 graph()->start(), graph()->start()); |
554 Node* cmp = graph()->NewNode(simplified()->NumberEqual(), length, | 554 Node* cmp = graph()->NewNode(simplified()->NumberEqual(), length, |
555 jsgraph()->ZeroConstant()); | 555 jsgraph()->ZeroConstant()); |
556 Node* inv = graph()->NewNode(simplified()->BooleanNot(), cmp); | 556 Node* inv = graph()->NewNode(simplified()->BooleanNot(), cmp); |
557 return ReplaceWith(inv); | 557 return ReplaceWith(inv); |
558 } | 558 } |
559 if (input->opcode() == IrOpcode::kPhi && input_type->Is(Type::Primitive())) { | 559 // TODO(turbofan): We need some kinda of PrimitiveToBoolean simplified |
560 // JSToBoolean(phi(x1,...,xn):primitive) | 560 // operator, then we can do the pushing in the SimplifiedOperatorReducer |
| 561 // and do not need to protect against stack overflow (because of backedges |
| 562 // in phis) below. |
| 563 if (input->opcode() == IrOpcode::kPhi && |
| 564 input_type->Is( |
| 565 Type::Union(Type::Boolean(), Type::OrderedNumber(), zone()))) { |
| 566 // JSToBoolean(phi(x1,...,xn):ordered-number|boolean) |
561 // => phi(JSToBoolean(x1),...,JSToBoolean(xn)) | 567 // => phi(JSToBoolean(x1),...,JSToBoolean(xn)) |
562 int input_count = input->InputCount() - 1; | 568 int input_count = input->InputCount() - 1; |
563 Node** inputs = zone()->NewArray<Node*>(input_count + 1); | 569 Node** inputs = zone()->NewArray<Node*>(input_count + 1); |
564 for (int i = 0; i < input_count; ++i) { | 570 for (int i = 0; i < input_count; ++i) { |
565 Node* value = input->InputAt(i); | 571 Node* value = input->InputAt(i); |
| 572 Type* value_type = NodeProperties::GetBounds(value).upper; |
566 // Recursively try to reduce the value first. | 573 // Recursively try to reduce the value first. |
567 Reduction result = ReduceJSToBooleanInput(value); | 574 Reduction result = (value_type->Is(Type::Boolean()) || |
| 575 value_type->Is(Type::OrderedNumber())) |
| 576 ? ReduceJSToBooleanInput(value) |
| 577 : NoChange(); |
568 if (result.Changed()) { | 578 if (result.Changed()) { |
569 inputs[i] = result.replacement(); | 579 inputs[i] = result.replacement(); |
570 } else { | 580 } else { |
571 inputs[i] = graph()->NewNode(javascript()->ToBoolean(), value, | 581 inputs[i] = graph()->NewNode(javascript()->ToBoolean(), value, |
572 jsgraph()->ZeroConstant(), | 582 jsgraph()->ZeroConstant(), |
573 graph()->start(), graph()->start()); | 583 graph()->start(), graph()->start()); |
574 } | 584 } |
575 } | 585 } |
576 inputs[input_count] = input->InputAt(input_count); | 586 inputs[input_count] = input->InputAt(input_count); |
577 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, input_count), | 587 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, input_count), |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 return JSBuiltinReducer(jsgraph()).Reduce(node); | 755 return JSBuiltinReducer(jsgraph()).Reduce(node); |
746 default: | 756 default: |
747 break; | 757 break; |
748 } | 758 } |
749 return NoChange(); | 759 return NoChange(); |
750 } | 760 } |
751 | 761 |
752 } // namespace compiler | 762 } // namespace compiler |
753 } // namespace internal | 763 } // namespace internal |
754 } // namespace v8 | 764 } // namespace v8 |
OLD | NEW |