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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // - immediately put in type bounds for all new nodes | 521 // - immediately put in type bounds for all new nodes |
522 // - relax effects from generic but not-side-effecting operations | 522 // - relax effects from generic but not-side-effecting operations |
523 | 523 |
524 JSTypedLowering::JSTypedLowering(Editor* editor, | 524 JSTypedLowering::JSTypedLowering(Editor* editor, |
525 CompilationDependencies* dependencies, | 525 CompilationDependencies* dependencies, |
526 Flags flags, JSGraph* jsgraph, Zone* zone) | 526 Flags flags, JSGraph* jsgraph, Zone* zone) |
527 : AdvancedReducer(editor), | 527 : AdvancedReducer(editor), |
528 dependencies_(dependencies), | 528 dependencies_(dependencies), |
529 flags_(flags), | 529 flags_(flags), |
530 jsgraph_(jsgraph), | 530 jsgraph_(jsgraph), |
| 531 pointer_comparable_type_(Type::Union( |
| 532 Type::Oddball(), |
| 533 Type::Union( |
| 534 Type::SymbolOrReceiver(), |
| 535 Type::HeapConstant(factory()->empty_string(), graph()->zone()), |
| 536 graph()->zone()), |
| 537 graph()->zone())), |
531 type_cache_(TypeCache::Get()) { | 538 type_cache_(TypeCache::Get()) { |
532 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { | 539 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { |
533 double min = kMinInt / (1 << k); | 540 double min = kMinInt / (1 << k); |
534 double max = kMaxInt / (1 << k); | 541 double max = kMaxInt / (1 << k); |
535 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); | 542 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); |
536 } | 543 } |
537 } | 544 } |
538 | 545 |
539 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { | 546 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { |
540 JSBinopReduction r(this, node); | 547 JSBinopReduction r(this, node); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 return Replace(replacement); | 1010 return Replace(replacement); |
1004 } | 1011 } |
1005 } | 1012 } |
1006 | 1013 |
1007 Reduction const reduction = ReduceJSEqualTypeOf(node, invert); | 1014 Reduction const reduction = ReduceJSEqualTypeOf(node, invert); |
1008 if (reduction.Changed()) return reduction; | 1015 if (reduction.Changed()) return reduction; |
1009 | 1016 |
1010 if (r.BothInputsAre(Type::Unique())) { | 1017 if (r.BothInputsAre(Type::Unique())) { |
1011 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); | 1018 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); |
1012 } | 1019 } |
1013 if (r.OneInputIs(Type::NonStringUniqueOrHole())) { | 1020 if (r.OneInputIs(pointer_comparable_type_)) { |
1014 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); | 1021 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); |
1015 } | 1022 } |
1016 if (r.IsInternalizedStringCompareOperation()) { | 1023 if (r.IsInternalizedStringCompareOperation()) { |
1017 r.CheckInputsToInternalizedString(); | 1024 r.CheckInputsToInternalizedString(); |
1018 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); | 1025 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); |
1019 } | 1026 } |
1020 if (r.BothInputsAre(Type::String())) { | 1027 if (r.BothInputsAre(Type::String())) { |
1021 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); | 1028 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); |
1022 } | 1029 } |
1023 | 1030 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); | 1074 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
1068 return Changed(node); | 1075 return Changed(node); |
1069 } else if (input_type->Is(Type::ReceiverOrNullOrUndefined())) { | 1076 } else if (input_type->Is(Type::ReceiverOrNullOrUndefined())) { |
1070 // JSToBoolean(x:receiver \/ null \/ undefined) | 1077 // JSToBoolean(x:receiver \/ null \/ undefined) |
1071 // => BooleanNot(ObjectIsUndetectable(x)) | 1078 // => BooleanNot(ObjectIsUndetectable(x)) |
1072 node->ReplaceInput( | 1079 node->ReplaceInput( |
1073 0, graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); | 1080 0, graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); |
1074 node->TrimInputCount(1); | 1081 node->TrimInputCount(1); |
1075 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); | 1082 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
1076 return Changed(node); | 1083 return Changed(node); |
| 1084 } else if (input_type->Is(Type::String())) { |
| 1085 // JSToBoolean(x:string) => BooleanNot(ReferenceEqual(x,"")) |
| 1086 node->ReplaceInput(0, |
| 1087 graph()->NewNode(simplified()->ReferenceEqual(), input, |
| 1088 jsgraph()->EmptyStringConstant())); |
| 1089 node->TrimInputCount(1); |
| 1090 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
| 1091 return Changed(node); |
1077 } | 1092 } |
1078 return NoChange(); | 1093 return NoChange(); |
1079 } | 1094 } |
1080 | 1095 |
1081 Reduction JSTypedLowering::ReduceJSToInteger(Node* node) { | 1096 Reduction JSTypedLowering::ReduceJSToInteger(Node* node) { |
1082 Node* const input = NodeProperties::GetValueInput(node, 0); | 1097 Node* const input = NodeProperties::GetValueInput(node, 0); |
1083 Type* const input_type = NodeProperties::GetType(input); | 1098 Type* const input_type = NodeProperties::GetType(input); |
1084 if (input_type->Is(type_cache_.kIntegerOrMinusZero)) { | 1099 if (input_type->Is(type_cache_.kIntegerOrMinusZero)) { |
1085 // JSToInteger(x:integer) => x | 1100 // JSToInteger(x:integer) => x |
1086 ReplaceWithValue(node, input); | 1101 ReplaceWithValue(node, input); |
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2461 } | 2476 } |
2462 | 2477 |
2463 | 2478 |
2464 CompilationDependencies* JSTypedLowering::dependencies() const { | 2479 CompilationDependencies* JSTypedLowering::dependencies() const { |
2465 return dependencies_; | 2480 return dependencies_; |
2466 } | 2481 } |
2467 | 2482 |
2468 } // namespace compiler | 2483 } // namespace compiler |
2469 } // namespace internal | 2484 } // namespace internal |
2470 } // namespace v8 | 2485 } // namespace v8 |
OLD | NEW |