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::BooleanOrNullOrUndefined(), | |
533 Type::Union(Type::Symbol(), | |
534 Type::Union(Type::Receiver(), | |
535 Type::Union(Type::Hole(), | |
536 Type::HeapConstant( | |
537 factory()->empty_string(), | |
538 graph()->zone()), | |
539 graph()->zone()), | |
540 graph()->zone()), | |
541 graph()->zone()), | |
542 graph()->zone())), | |
Yang
2017/02/09 06:41:41
can we have a helper function that returns this mo
Benedikt Meurer
2017/02/09 06:58:24
Done.
| |
531 type_cache_(TypeCache::Get()) { | 543 type_cache_(TypeCache::Get()) { |
532 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { | 544 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { |
533 double min = kMinInt / (1 << k); | 545 double min = kMinInt / (1 << k); |
534 double max = kMaxInt / (1 << k); | 546 double max = kMaxInt / (1 << k); |
535 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); | 547 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); |
536 } | 548 } |
537 } | 549 } |
538 | 550 |
539 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { | 551 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { |
540 JSBinopReduction r(this, node); | 552 JSBinopReduction r(this, node); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 return Replace(replacement); | 1015 return Replace(replacement); |
1004 } | 1016 } |
1005 } | 1017 } |
1006 | 1018 |
1007 Reduction const reduction = ReduceJSEqualTypeOf(node, invert); | 1019 Reduction const reduction = ReduceJSEqualTypeOf(node, invert); |
1008 if (reduction.Changed()) return reduction; | 1020 if (reduction.Changed()) return reduction; |
1009 | 1021 |
1010 if (r.BothInputsAre(Type::Unique())) { | 1022 if (r.BothInputsAre(Type::Unique())) { |
1011 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); | 1023 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); |
1012 } | 1024 } |
1013 if (r.OneInputIs(Type::NonStringUniqueOrHole())) { | 1025 if (r.OneInputIs(pointer_comparable_type_)) { |
1014 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); | 1026 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); |
1015 } | 1027 } |
1016 if (r.IsInternalizedStringCompareOperation()) { | 1028 if (r.IsInternalizedStringCompareOperation()) { |
1017 r.CheckInputsToInternalizedString(); | 1029 r.CheckInputsToInternalizedString(); |
1018 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); | 1030 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); |
1019 } | 1031 } |
1020 if (r.BothInputsAre(Type::String())) { | 1032 if (r.BothInputsAre(Type::String())) { |
1021 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); | 1033 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); |
1022 } | 1034 } |
1023 | 1035 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); | 1079 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
1068 return Changed(node); | 1080 return Changed(node); |
1069 } else if (input_type->Is(Type::ReceiverOrNullOrUndefined())) { | 1081 } else if (input_type->Is(Type::ReceiverOrNullOrUndefined())) { |
1070 // JSToBoolean(x:receiver \/ null \/ undefined) | 1082 // JSToBoolean(x:receiver \/ null \/ undefined) |
1071 // => BooleanNot(ObjectIsUndetectable(x)) | 1083 // => BooleanNot(ObjectIsUndetectable(x)) |
1072 node->ReplaceInput( | 1084 node->ReplaceInput( |
1073 0, graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); | 1085 0, graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); |
1074 node->TrimInputCount(1); | 1086 node->TrimInputCount(1); |
1075 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); | 1087 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); |
1076 return Changed(node); | 1088 return Changed(node); |
1089 } else if (input_type->Is(Type::String())) { | |
1090 // JSToBoolean(x:string) => BooleanNot(ReferenceEqual(x,"")) | |
1091 node->ReplaceInput(0, | |
1092 graph()->NewNode(simplified()->ReferenceEqual(), input, | |
1093 jsgraph()->EmptyStringConstant())); | |
1094 node->TrimInputCount(1); | |
1095 NodeProperties::ChangeOp(node, simplified()->BooleanNot()); | |
1096 return Changed(node); | |
1077 } | 1097 } |
1078 return NoChange(); | 1098 return NoChange(); |
1079 } | 1099 } |
1080 | 1100 |
1081 Reduction JSTypedLowering::ReduceJSToInteger(Node* node) { | 1101 Reduction JSTypedLowering::ReduceJSToInteger(Node* node) { |
1082 Node* const input = NodeProperties::GetValueInput(node, 0); | 1102 Node* const input = NodeProperties::GetValueInput(node, 0); |
1083 Type* const input_type = NodeProperties::GetType(input); | 1103 Type* const input_type = NodeProperties::GetType(input); |
1084 if (input_type->Is(type_cache_.kIntegerOrMinusZero)) { | 1104 if (input_type->Is(type_cache_.kIntegerOrMinusZero)) { |
1085 // JSToInteger(x:integer) => x | 1105 // JSToInteger(x:integer) => x |
1086 ReplaceWithValue(node, input); | 1106 ReplaceWithValue(node, input); |
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2461 } | 2481 } |
2462 | 2482 |
2463 | 2483 |
2464 CompilationDependencies* JSTypedLowering::dependencies() const { | 2484 CompilationDependencies* JSTypedLowering::dependencies() const { |
2465 return dependencies_; | 2485 return dependencies_; |
2466 } | 2486 } |
2467 | 2487 |
2468 } // namespace compiler | 2488 } // namespace compiler |
2469 } // namespace internal | 2489 } // namespace internal |
2470 } // namespace v8 | 2490 } // namespace v8 |
OLD | NEW |