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/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/js-typed-lowering.h" | 7 #include "src/compiler/js-typed-lowering.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/operator-properties.h" | 10 #include "src/compiler/operator-properties.h" |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 Type* const input_type = NodeProperties::GetBounds(input).upper; | 530 Type* const input_type = NodeProperties::GetBounds(input).upper; |
531 if (input_type->Is(Type::Boolean())) { | 531 if (input_type->Is(Type::Boolean())) { |
532 // JSUnaryNot(x:boolean) => BooleanNot(x) | 532 // JSUnaryNot(x:boolean) => BooleanNot(x) |
533 node->set_op(simplified()->BooleanNot()); | 533 node->set_op(simplified()->BooleanNot()); |
534 node->TrimInputCount(1); | 534 node->TrimInputCount(1); |
535 return Changed(node); | 535 return Changed(node); |
536 } else if (input_type->Is(Type::OrderedNumber())) { | 536 } else if (input_type->Is(Type::OrderedNumber())) { |
537 // JSUnaryNot(x:number) => NumberEqual(x,#0) | 537 // JSUnaryNot(x:number) => NumberEqual(x,#0) |
538 node->set_op(simplified()->NumberEqual()); | 538 node->set_op(simplified()->NumberEqual()); |
539 node->ReplaceInput(1, jsgraph()->ZeroConstant()); | 539 node->ReplaceInput(1, jsgraph()->ZeroConstant()); |
540 node->TrimInputCount(2); | 540 DCHECK_EQ(2, node->InputCount()); |
541 return Changed(node); | 541 return Changed(node); |
542 } else if (input_type->Is(Type::String())) { | 542 } else if (input_type->Is(Type::String())) { |
543 // JSUnaryNot(x:string) => NumberEqual(x.length,#0) | 543 // JSUnaryNot(x:string) => NumberEqual(x.length,#0) |
544 FieldAccess const access = AccessBuilder::ForStringLength(graph()->zone()); | 544 FieldAccess const access = AccessBuilder::ForStringLength(graph()->zone()); |
545 // It is safe for the load to be effect-free (i.e. not linked into effect | 545 // It is safe for the load to be effect-free (i.e. not linked into effect |
546 // chain) because we assume String::length to be immutable. | 546 // chain) because we assume String::length to be immutable. |
547 Node* length = graph()->NewNode(simplified()->LoadField(access), input, | 547 Node* length = graph()->NewNode(simplified()->LoadField(access), input, |
548 graph()->start(), graph()->start()); | 548 graph()->start(), graph()->start()); |
549 node->set_op(simplified()->NumberEqual()); | 549 node->set_op(simplified()->NumberEqual()); |
550 node->ReplaceInput(0, length); | 550 node->ReplaceInput(0, length); |
551 node->ReplaceInput(1, jsgraph()->ZeroConstant()); | 551 node->ReplaceInput(1, jsgraph()->ZeroConstant()); |
552 node->TrimInputCount(2); | |
553 NodeProperties::ReplaceWithValue(node, node, length); | 552 NodeProperties::ReplaceWithValue(node, node, length); |
| 553 DCHECK_EQ(2, node->InputCount()); |
554 return Changed(node); | 554 return Changed(node); |
555 } | 555 } |
556 return NoChange(); | 556 return NoChange(); |
557 } | 557 } |
558 | 558 |
559 | 559 |
560 Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) { | 560 Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) { |
561 Node* const input = node->InputAt(0); | 561 Node* const input = node->InputAt(0); |
562 Type* const input_type = NodeProperties::GetBounds(input).upper; | 562 Type* const input_type = NodeProperties::GetBounds(input).upper; |
563 if (input_type->Is(Type::Boolean())) { | 563 if (input_type->Is(Type::Boolean())) { |
564 // JSToBoolean(x:boolean) => x | 564 // JSToBoolean(x:boolean) => x |
565 return Replace(input); | 565 return Replace(input); |
566 } else if (input_type->Is(Type::OrderedNumber())) { | 566 } else if (input_type->Is(Type::OrderedNumber())) { |
567 // JSToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x,#0)) | 567 // JSToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x,#0)) |
568 node->set_op(simplified()->BooleanNot()); | 568 node->set_op(simplified()->BooleanNot()); |
569 node->ReplaceInput(0, graph()->NewNode(simplified()->NumberEqual(), input, | 569 node->ReplaceInput(0, graph()->NewNode(simplified()->NumberEqual(), input, |
570 jsgraph()->ZeroConstant())); | 570 jsgraph()->ZeroConstant())); |
571 node->TrimInputCount(1); | 571 node->TrimInputCount(1); |
572 return Changed(node); | 572 return Changed(node); |
573 } else if (input_type->Is(Type::String())) { | 573 } else if (input_type->Is(Type::String())) { |
574 // JSToBoolean(x:string) => NumberLessThan(#0,x.length) | 574 // JSToBoolean(x:string) => NumberLessThan(#0,x.length) |
575 FieldAccess const access = AccessBuilder::ForStringLength(graph()->zone()); | 575 FieldAccess const access = AccessBuilder::ForStringLength(graph()->zone()); |
576 // It is safe for the load to be effect-free (i.e. not linked into effect | 576 // It is safe for the load to be effect-free (i.e. not linked into effect |
577 // chain) because we assume String::length to be immutable. | 577 // chain) because we assume String::length to be immutable. |
578 Node* length = graph()->NewNode(simplified()->LoadField(access), input, | 578 Node* length = graph()->NewNode(simplified()->LoadField(access), input, |
579 graph()->start(), graph()->start()); | 579 graph()->start(), graph()->start()); |
580 node->set_op(simplified()->NumberLessThan()); | 580 node->set_op(simplified()->NumberLessThan()); |
581 node->ReplaceInput(0, jsgraph()->ZeroConstant()); | 581 node->ReplaceInput(0, jsgraph()->ZeroConstant()); |
582 node->ReplaceInput(1, length); | 582 node->ReplaceInput(1, length); |
583 node->TrimInputCount(2); | 583 DCHECK_EQ(2, node->InputCount()); |
584 return Changed(node); | 584 return Changed(node); |
585 } | 585 } |
586 return NoChange(); | 586 return NoChange(); |
587 } | 587 } |
588 | 588 |
589 | 589 |
590 Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) { | 590 Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) { |
591 if (input->opcode() == IrOpcode::kJSToNumber) { | 591 if (input->opcode() == IrOpcode::kJSToNumber) { |
592 // Recursively try to reduce the input first. | 592 // Recursively try to reduce the input first. |
593 Reduction result = ReduceJSToNumber(input); | 593 Reduction result = ReduceJSToNumber(input); |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 } | 1077 } |
1078 | 1078 |
1079 | 1079 |
1080 MachineOperatorBuilder* JSTypedLowering::machine() const { | 1080 MachineOperatorBuilder* JSTypedLowering::machine() const { |
1081 return jsgraph()->machine(); | 1081 return jsgraph()->machine(); |
1082 } | 1082 } |
1083 | 1083 |
1084 } // namespace compiler | 1084 } // namespace compiler |
1085 } // namespace internal | 1085 } // namespace internal |
1086 } // namespace v8 | 1086 } // namespace v8 |
OLD | NEW |