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/js-typed-lowering.h" | 5 #include "src/compiler/js-typed-lowering.h" |
6 | 6 |
7 #include "src/ast/modules.h" | 7 #include "src/ast/modules.h" |
8 #include "src/builtins/builtins-utils.h" | 8 #include "src/builtins/builtins-utils.h" |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/compilation-dependencies.h" | 10 #include "src/compilation-dependencies.h" |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 } | 993 } |
994 | 994 |
995 Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) { | 995 Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) { |
996 Node* const input = node->InputAt(0); | 996 Node* const input = node->InputAt(0); |
997 Type* const input_type = NodeProperties::GetType(input); | 997 Type* const input_type = NodeProperties::GetType(input); |
998 if (input_type->Is(Type::Boolean())) { | 998 if (input_type->Is(Type::Boolean())) { |
999 // JSToBoolean(x:boolean) => x | 999 // JSToBoolean(x:boolean) => x |
1000 return Replace(input); | 1000 return Replace(input); |
1001 } else if (input_type->Is(Type::OrderedNumber())) { | 1001 } else if (input_type->Is(Type::OrderedNumber())) { |
1002 // JSToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x,#0)) | 1002 // JSToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x,#0)) |
1003 RelaxEffectsAndControls(node); | |
1004 node->ReplaceInput(0, graph()->NewNode(simplified()->NumberEqual(), input, | 1003 node->ReplaceInput(0, graph()->NewNode(simplified()->NumberEqual(), input, |
1005 jsgraph()->ZeroConstant())); | 1004 jsgraph()->ZeroConstant())); |
1006 node->TrimInputCount(1); | 1005 node->TrimInputCount(1); |
1007 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); | 1006 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
1008 return Changed(node); | 1007 return Changed(node); |
1009 } else if (input_type->Is(Type::Number())) { | 1008 } else if (input_type->Is(Type::Number())) { |
1010 // JSToBoolean(x:number) => NumberToBoolean(x) | 1009 // JSToBoolean(x:number) => NumberToBoolean(x) |
1011 RelaxEffectsAndControls(node); | |
1012 node->TrimInputCount(1); | 1010 node->TrimInputCount(1); |
1013 NodeProperties::ChangeOp(node, simplified()->NumberToBoolean()); | 1011 NodeProperties::ChangeOp(node, simplified()->NumberToBoolean()); |
1014 return Changed(node); | 1012 return Changed(node); |
| 1013 } else if (input_type->Is(Type::DetectableReceiverOrNull())) { |
| 1014 // JSToBoolean(x:detectable receiver \/ null) |
| 1015 // => BooleanNot(ReferenceEqual(x,#null)) |
| 1016 node->ReplaceInput(0, graph()->NewNode(simplified()->ReferenceEqual(), |
| 1017 input, jsgraph()->NullConstant())); |
| 1018 node->TrimInputCount(1); |
| 1019 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
| 1020 return Changed(node); |
| 1021 } else if (input_type->Is(Type::ReceiverOrNullOrUndefined())) { |
| 1022 // JSToBoolean(x:receiver \/ null \/ undefined) |
| 1023 // => BooleanNot(ObjectIsUndetectable(x)) |
| 1024 node->ReplaceInput( |
| 1025 0, graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); |
| 1026 node->TrimInputCount(1); |
| 1027 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
| 1028 return Changed(node); |
1015 } | 1029 } |
1016 return NoChange(); | 1030 return NoChange(); |
1017 } | 1031 } |
1018 | 1032 |
1019 Reduction JSTypedLowering::ReduceJSToInteger(Node* node) { | 1033 Reduction JSTypedLowering::ReduceJSToInteger(Node* node) { |
1020 Node* const input = NodeProperties::GetValueInput(node, 0); | 1034 Node* const input = NodeProperties::GetValueInput(node, 0); |
1021 Type* const input_type = NodeProperties::GetType(input); | 1035 Type* const input_type = NodeProperties::GetType(input); |
1022 if (input_type->Is(type_cache_.kIntegerOrMinusZero)) { | 1036 if (input_type->Is(type_cache_.kIntegerOrMinusZero)) { |
1023 // JSToInteger(x:integer) => x | 1037 // JSToInteger(x:integer) => x |
1024 ReplaceWithValue(node, input); | 1038 ReplaceWithValue(node, input); |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2313 } | 2327 } |
2314 | 2328 |
2315 | 2329 |
2316 CompilationDependencies* JSTypedLowering::dependencies() const { | 2330 CompilationDependencies* JSTypedLowering::dependencies() const { |
2317 return dependencies_; | 2331 return dependencies_; |
2318 } | 2332 } |
2319 | 2333 |
2320 } // namespace compiler | 2334 } // namespace compiler |
2321 } // namespace internal | 2335 } // namespace internal |
2322 } // namespace v8 | 2336 } // namespace v8 |
OLD | NEW |