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-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 | 6 |
7 #include "src/compilation-dependencies.h" | 7 #include "src/compilation-dependencies.h" |
8 #include "src/compiler/access-builder.h" | 8 #include "src/compiler/access-builder.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 simplified()->StoreElement( | 307 simplified()->StoreElement( |
308 AccessBuilder::ForFixedArrayElement(receiver_map->elements_kind())), | 308 AccessBuilder::ForFixedArrayElement(receiver_map->elements_kind())), |
309 elements, length, value, effect, control); | 309 elements, length, value, effect, control); |
310 | 310 |
311 ReplaceWithValue(node, value, effect, control); | 311 ReplaceWithValue(node, value, effect, control); |
312 return Replace(value); | 312 return Replace(value); |
313 } | 313 } |
314 return NoChange(); | 314 return NoChange(); |
315 } | 315 } |
316 | 316 |
| 317 namespace { |
| 318 |
| 319 bool HasInstanceTypeWitness(Node* receiver, Node* effect, |
| 320 InstanceType instance_type) { |
| 321 for (Node* dominator = effect;;) { |
| 322 if (dominator->opcode() == IrOpcode::kCheckMaps && |
| 323 dominator->InputAt(0) == receiver) { |
| 324 // Check if all maps have the given {instance_type}. |
| 325 for (int i = 1; i < dominator->op()->ValueInputCount(); ++i) { |
| 326 Node* const map = NodeProperties::GetValueInput(dominator, i); |
| 327 Type* const map_type = NodeProperties::GetType(map); |
| 328 if (!map_type->IsConstant()) return false; |
| 329 Handle<Map> const map_value = |
| 330 Handle<Map>::cast(map_type->AsConstant()->Value()); |
| 331 if (map_value->instance_type() != instance_type) return false; |
| 332 } |
| 333 return true; |
| 334 } |
| 335 switch (dominator->opcode()) { |
| 336 case IrOpcode::kStoreField: { |
| 337 FieldAccess const& access = FieldAccessOf(dominator->op()); |
| 338 if (access.base_is_tagged == kTaggedBase && |
| 339 access.offset == HeapObject::kMapOffset) { |
| 340 return false; |
| 341 } |
| 342 break; |
| 343 } |
| 344 case IrOpcode::kStoreElement: |
| 345 case IrOpcode::kStoreTypedElement: |
| 346 break; |
| 347 default: { |
| 348 DCHECK_EQ(1, dominator->op()->EffectOutputCount()); |
| 349 if (dominator->op()->EffectInputCount() != 1 || |
| 350 !dominator->op()->HasProperty(Operator::kNoWrite)) { |
| 351 // Didn't find any appropriate CheckMaps node. |
| 352 return false; |
| 353 } |
| 354 break; |
| 355 } |
| 356 } |
| 357 dominator = NodeProperties::GetEffectInput(dominator); |
| 358 } |
| 359 } |
| 360 |
| 361 } // namespace |
| 362 |
| 363 // ES6 section 20.3.4.10 Date.prototype.getTime ( ) |
| 364 Reduction JSBuiltinReducer::ReduceDateGetTime(Node* node) { |
| 365 Node* receiver = NodeProperties::GetValueInput(node, 1); |
| 366 Node* effect = NodeProperties::GetEffectInput(node); |
| 367 Node* control = NodeProperties::GetControlInput(node); |
| 368 if (HasInstanceTypeWitness(receiver, effect, JS_DATE_TYPE)) { |
| 369 Node* value = effect = graph()->NewNode( |
| 370 simplified()->LoadField(AccessBuilder::ForJSDateValue()), receiver, |
| 371 effect, control); |
| 372 ReplaceWithValue(node, value, effect, control); |
| 373 return Replace(value); |
| 374 } |
| 375 return NoChange(); |
| 376 } |
| 377 |
317 // ES6 section 20.2.2.1 Math.abs ( x ) | 378 // ES6 section 20.2.2.1 Math.abs ( x ) |
318 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { | 379 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { |
319 JSCallReduction r(node); | 380 JSCallReduction r(node); |
320 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 381 if (r.InputsMatchOne(Type::PlainPrimitive())) { |
321 // Math.abs(a:plain-primitive) -> NumberAbs(ToNumber(a)) | 382 // Math.abs(a:plain-primitive) -> NumberAbs(ToNumber(a)) |
322 Node* input = ToNumber(r.GetJSCallInput(0)); | 383 Node* input = ToNumber(r.GetJSCallInput(0)); |
323 Node* value = graph()->NewNode(simplified()->NumberAbs(), input); | 384 Node* value = graph()->NewNode(simplified()->NumberAbs(), input); |
324 return Replace(value); | 385 return Replace(value); |
325 } | 386 } |
326 return NoChange(); | 387 return NoChange(); |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 | 932 |
872 ReplaceWithValue(node, value, effect, control); | 933 ReplaceWithValue(node, value, effect, control); |
873 return Replace(value); | 934 return Replace(value); |
874 } | 935 } |
875 } | 936 } |
876 } | 937 } |
877 | 938 |
878 return NoChange(); | 939 return NoChange(); |
879 } | 940 } |
880 | 941 |
881 namespace { | |
882 | |
883 bool HasInstanceTypeWitness(Node* receiver, Node* effect, | |
884 InstanceType instance_type) { | |
885 for (Node* dominator = effect;;) { | |
886 if (dominator->opcode() == IrOpcode::kCheckMaps && | |
887 dominator->InputAt(0) == receiver) { | |
888 // Check if all maps have the given {instance_type}. | |
889 for (int i = 1; i < dominator->op()->ValueInputCount(); ++i) { | |
890 Node* const map = NodeProperties::GetValueInput(dominator, i); | |
891 Type* const map_type = NodeProperties::GetType(map); | |
892 if (!map_type->IsConstant()) return false; | |
893 Handle<Map> const map_value = | |
894 Handle<Map>::cast(map_type->AsConstant()->Value()); | |
895 if (map_value->instance_type() != instance_type) return false; | |
896 } | |
897 return true; | |
898 } | |
899 switch (dominator->opcode()) { | |
900 case IrOpcode::kStoreField: { | |
901 FieldAccess const& access = FieldAccessOf(dominator->op()); | |
902 if (access.base_is_tagged == kTaggedBase && | |
903 access.offset == HeapObject::kMapOffset) { | |
904 return false; | |
905 } | |
906 break; | |
907 } | |
908 case IrOpcode::kStoreElement: | |
909 break; | |
910 default: { | |
911 DCHECK_EQ(1, dominator->op()->EffectOutputCount()); | |
912 if (dominator->op()->EffectInputCount() != 1 || | |
913 !dominator->op()->HasProperty(Operator::kNoWrite)) { | |
914 // Didn't find any appropriate CheckMaps node. | |
915 return false; | |
916 } | |
917 break; | |
918 } | |
919 } | |
920 dominator = NodeProperties::GetEffectInput(dominator); | |
921 } | |
922 } | |
923 | |
924 } // namespace | |
925 | |
926 Reduction JSBuiltinReducer::ReduceArrayBufferViewAccessor( | 942 Reduction JSBuiltinReducer::ReduceArrayBufferViewAccessor( |
927 Node* node, InstanceType instance_type, FieldAccess const& access) { | 943 Node* node, InstanceType instance_type, FieldAccess const& access) { |
928 Node* receiver = NodeProperties::GetValueInput(node, 1); | 944 Node* receiver = NodeProperties::GetValueInput(node, 1); |
929 Node* effect = NodeProperties::GetEffectInput(node); | 945 Node* effect = NodeProperties::GetEffectInput(node); |
930 Node* control = NodeProperties::GetControlInput(node); | 946 Node* control = NodeProperties::GetControlInput(node); |
931 if (HasInstanceTypeWitness(receiver, effect, instance_type)) { | 947 if (HasInstanceTypeWitness(receiver, effect, instance_type)) { |
932 // Load the {receiver}s field. | 948 // Load the {receiver}s field. |
933 Node* receiver_value = effect = graph()->NewNode( | 949 Node* receiver_value = effect = graph()->NewNode( |
934 simplified()->LoadField(access), receiver, effect, control); | 950 simplified()->LoadField(access), receiver, effect, control); |
935 | 951 |
(...skipping 20 matching lines...) Expand all Loading... |
956 Reduction reduction = NoChange(); | 972 Reduction reduction = NoChange(); |
957 JSCallReduction r(node); | 973 JSCallReduction r(node); |
958 | 974 |
959 // Dispatch according to the BuiltinFunctionId if present. | 975 // Dispatch according to the BuiltinFunctionId if present. |
960 if (!r.HasBuiltinFunctionId()) return NoChange(); | 976 if (!r.HasBuiltinFunctionId()) return NoChange(); |
961 switch (r.GetBuiltinFunctionId()) { | 977 switch (r.GetBuiltinFunctionId()) { |
962 case kArrayPop: | 978 case kArrayPop: |
963 return ReduceArrayPop(node); | 979 return ReduceArrayPop(node); |
964 case kArrayPush: | 980 case kArrayPush: |
965 return ReduceArrayPush(node); | 981 return ReduceArrayPush(node); |
| 982 case kDateGetTime: |
| 983 return ReduceDateGetTime(node); |
966 case kMathAbs: | 984 case kMathAbs: |
967 reduction = ReduceMathAbs(node); | 985 reduction = ReduceMathAbs(node); |
968 break; | 986 break; |
969 case kMathAcos: | 987 case kMathAcos: |
970 reduction = ReduceMathAcos(node); | 988 reduction = ReduceMathAcos(node); |
971 break; | 989 break; |
972 case kMathAcosh: | 990 case kMathAcosh: |
973 reduction = ReduceMathAcosh(node); | 991 reduction = ReduceMathAcosh(node); |
974 break; | 992 break; |
975 case kMathAsin: | 993 case kMathAsin: |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 } | 1145 } |
1128 | 1146 |
1129 | 1147 |
1130 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 1148 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
1131 return jsgraph()->simplified(); | 1149 return jsgraph()->simplified(); |
1132 } | 1150 } |
1133 | 1151 |
1134 } // namespace compiler | 1152 } // namespace compiler |
1135 } // namespace internal | 1153 } // namespace internal |
1136 } // namespace v8 | 1154 } // namespace v8 |
OLD | NEW |