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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 } | 519 } |
520 if (r.BothInputsAre(Type::Number())) { | 520 if (r.BothInputsAre(Type::Number())) { |
521 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); | 521 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); |
522 } | 522 } |
523 // TODO(turbofan): js-typed-lowering of StrictEqual(mixed types) | 523 // TODO(turbofan): js-typed-lowering of StrictEqual(mixed types) |
524 return NoChange(); | 524 return NoChange(); |
525 } | 525 } |
526 | 526 |
527 | 527 |
528 Reduction JSTypedLowering::ReduceJSUnaryNot(Node* node) { | 528 Reduction JSTypedLowering::ReduceJSUnaryNot(Node* node) { |
529 Node* input = node->InputAt(0); | 529 Node* const input = node->InputAt(0); |
530 Type* 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,context) => 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,context) => 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 DCHECK_EQ(2, node->InputCount()); | 540 node->TrimInputCount(2); |
541 return Changed(node); | |
542 } else if (input_type->Is(Type::String())) { | |
543 // JSUnaryNot(x:string) => NumberEqual(x.length,#0) | |
Michael Starzinger
2015/03/19 10:10:54
nit: Can we add a one-liner comment that this is s
| |
544 FieldAccess const access = AccessBuilder::ForStringLength(); | |
545 Node* length = graph()->NewNode(simplified()->LoadField(access), input, | |
546 graph()->start(), graph()->start()); | |
547 node->set_op(simplified()->NumberEqual()); | |
548 node->ReplaceInput(0, length); | |
549 node->ReplaceInput(1, jsgraph()->ZeroConstant()); | |
550 node->TrimInputCount(2); | |
551 NodeProperties::ReplaceWithValue(node, node, length); | |
541 return Changed(node); | 552 return Changed(node); |
542 } | 553 } |
543 // JSUnaryNot(x,context) => BooleanNot(AnyToBoolean(x)) | 554 return NoChange(); |
544 node->set_op(simplified()->BooleanNot()); | |
545 node->ReplaceInput(0, graph()->NewNode(simplified()->AnyToBoolean(), input)); | |
546 node->TrimInputCount(1); | |
547 return Changed(node); | |
548 } | 555 } |
549 | 556 |
550 | 557 |
551 Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) { | 558 Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) { |
552 Node* input = node->InputAt(0); | 559 Node* const input = node->InputAt(0); |
553 Type* input_type = NodeProperties::GetBounds(input).upper; | 560 Type* const input_type = NodeProperties::GetBounds(input).upper; |
554 if (input_type->Is(Type::Boolean())) { | 561 if (input_type->Is(Type::Boolean())) { |
555 // JSToBoolean(x:boolean,context) => x | 562 // JSToBoolean(x:boolean) => x |
556 return Replace(input); | 563 return Replace(input); |
564 } else if (input_type->Is(Type::OrderedNumber())) { | |
565 // JSToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x,#0)) | |
566 node->set_op(simplified()->BooleanNot()); | |
567 node->ReplaceInput(0, graph()->NewNode(simplified()->NumberEqual(), input, | |
568 jsgraph()->ZeroConstant())); | |
569 node->TrimInputCount(1); | |
570 return Changed(node); | |
571 } else if (input_type->Is(Type::String())) { | |
572 // JSToBoolean(x:string) => NumberLessThan(#0,x.length) | |
Michael Starzinger
2015/03/19 10:10:54
nit: Likewise about the comment.
| |
573 FieldAccess const access = AccessBuilder::ForStringLength(); | |
574 Node* length = graph()->NewNode(simplified()->LoadField(access), input, | |
575 graph()->start(), graph()->start()); | |
576 node->set_op(simplified()->NumberLessThan()); | |
577 node->ReplaceInput(0, jsgraph()->ZeroConstant()); | |
578 node->ReplaceInput(1, length); | |
579 node->TrimInputCount(2); | |
580 return Changed(node); | |
557 } | 581 } |
558 // JSToBoolean(x,context) => AnyToBoolean(x) | 582 return NoChange(); |
559 node->set_op(simplified()->AnyToBoolean()); | |
560 node->TrimInputCount(1); | |
561 return Changed(node); | |
562 } | 583 } |
563 | 584 |
564 | 585 |
565 Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) { | 586 Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) { |
566 if (input->opcode() == IrOpcode::kJSToNumber) { | 587 if (input->opcode() == IrOpcode::kJSToNumber) { |
567 // Recursively try to reduce the input first. | 588 // Recursively try to reduce the input first. |
568 Reduction result = ReduceJSToNumber(input); | 589 Reduction result = ReduceJSToNumber(input); |
569 if (result.Changed()) return result; | 590 if (result.Changed()) return result; |
570 return Changed(input); // JSToNumber(JSToNumber(x)) => JSToNumber(x) | 591 return Changed(input); // JSToNumber(JSToNumber(x)) => JSToNumber(x) |
571 } | 592 } |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1052 } | 1073 } |
1053 | 1074 |
1054 | 1075 |
1055 MachineOperatorBuilder* JSTypedLowering::machine() const { | 1076 MachineOperatorBuilder* JSTypedLowering::machine() const { |
1056 return jsgraph()->machine(); | 1077 return jsgraph()->machine(); |
1057 } | 1078 } |
1058 | 1079 |
1059 } // namespace compiler | 1080 } // namespace compiler |
1060 } // namespace internal | 1081 } // namespace internal |
1061 } // namespace v8 | 1082 } // namespace v8 |
OLD | NEW |