| 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/simplified-lowering.h" | 5 #include "src/compiler/simplified-lowering.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "src/address-map.h" | 9 #include "src/address-map.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 case kExternalFloat32Array: | 81 case kExternalFloat32Array: |
| 82 return MachineRepresentation::kFloat32; | 82 return MachineRepresentation::kFloat32; |
| 83 case kExternalFloat64Array: | 83 case kExternalFloat64Array: |
| 84 return MachineRepresentation::kFloat64; | 84 return MachineRepresentation::kFloat64; |
| 85 } | 85 } |
| 86 UNREACHABLE(); | 86 UNREACHABLE(); |
| 87 return MachineRepresentation::kNone; | 87 return MachineRepresentation::kNone; |
| 88 } | 88 } |
| 89 | 89 |
| 90 UseInfo CheckedUseInfoAsWord32FromHint( | 90 UseInfo CheckedUseInfoAsWord32FromHint( |
| 91 NumberOperationHint hint, CheckForMinusZeroMode minus_zero_mode = | 91 NumberOperationHint hint, |
| 92 CheckForMinusZeroMode::kCheckForMinusZero) { | 92 IdentifyZeros identify_zeros = kDistinguishZeros) { |
| 93 switch (hint) { | 93 switch (hint) { |
| 94 case NumberOperationHint::kSignedSmall: | 94 case NumberOperationHint::kSignedSmall: |
| 95 return UseInfo::CheckedSignedSmallAsWord32(minus_zero_mode); | 95 return UseInfo::CheckedSignedSmallAsWord32(identify_zeros); |
| 96 case NumberOperationHint::kSigned32: | 96 case NumberOperationHint::kSigned32: |
| 97 return UseInfo::CheckedSigned32AsWord32(minus_zero_mode); | 97 return UseInfo::CheckedSigned32AsWord32(identify_zeros); |
| 98 case NumberOperationHint::kNumber: | 98 case NumberOperationHint::kNumber: |
| 99 return UseInfo::CheckedNumberAsWord32(); | 99 return UseInfo::CheckedNumberAsWord32(); |
| 100 case NumberOperationHint::kNumberOrOddball: | 100 case NumberOperationHint::kNumberOrOddball: |
| 101 return UseInfo::CheckedNumberOrOddballAsWord32(); | 101 return UseInfo::CheckedNumberOrOddballAsWord32(); |
| 102 } | 102 } |
| 103 UNREACHABLE(); | 103 UNREACHABLE(); |
| 104 return UseInfo::None(); | 104 return UseInfo::None(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 UseInfo CheckedUseInfoAsFloat64FromHint(NumberOperationHint hint) { | 107 UseInfo CheckedUseInfoAsFloat64FromHint(NumberOperationHint hint) { |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 CommonOperatorBuilder* common() const { return jsgraph_->common(); } | 1160 CommonOperatorBuilder* common() const { return jsgraph_->common(); } |
| 1161 SimplifiedOperatorBuilder* simplified() const { | 1161 SimplifiedOperatorBuilder* simplified() const { |
| 1162 return jsgraph_->simplified(); | 1162 return jsgraph_->simplified(); |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 void LowerToCheckedInt32Mul(Node* node, Truncation truncation, | 1165 void LowerToCheckedInt32Mul(Node* node, Truncation truncation, |
| 1166 Type* input0_type, Type* input1_type) { | 1166 Type* input0_type, Type* input1_type) { |
| 1167 // If one of the inputs is positive and/or truncation is being applied, | 1167 // If one of the inputs is positive and/or truncation is being applied, |
| 1168 // there is no need to return -0. | 1168 // there is no need to return -0. |
| 1169 CheckForMinusZeroMode mz_mode = | 1169 CheckForMinusZeroMode mz_mode = |
| 1170 truncation.IsUsedAsWord32() || | 1170 truncation.IdentifiesZeroAndMinusZero() || |
| 1171 (input0_type->Is(Type::OrderedNumber()) && | 1171 (input0_type->Is(Type::OrderedNumber()) && |
| 1172 input0_type->Min() > 0) || | 1172 input0_type->Min() > 0) || |
| 1173 (input1_type->Is(Type::OrderedNumber()) && | 1173 (input1_type->Is(Type::OrderedNumber()) && |
| 1174 input1_type->Min() > 0) | 1174 input1_type->Min() > 0) |
| 1175 ? CheckForMinusZeroMode::kDontCheckForMinusZero | 1175 ? CheckForMinusZeroMode::kDontCheckForMinusZero |
| 1176 : CheckForMinusZeroMode::kCheckForMinusZero; | 1176 : CheckForMinusZeroMode::kCheckForMinusZero; |
| 1177 | 1177 |
| 1178 NodeProperties::ChangeOp(node, simplified()->CheckedInt32Mul(mz_mode)); | 1178 NodeProperties::ChangeOp(node, simplified()->CheckedInt32Mul(mz_mode)); |
| 1179 } | 1179 } |
| 1180 | 1180 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 // Handle the case when no int32 checks on inputs are necessary (but | 1219 // Handle the case when no int32 checks on inputs are necessary (but |
| 1220 // an overflow check is needed on the output). | 1220 // an overflow check is needed on the output). |
| 1221 // TODO(jarin) We should not look at the upper bound because the typer | 1221 // TODO(jarin) We should not look at the upper bound because the typer |
| 1222 // could have already baked in some feedback into the upper bound. | 1222 // could have already baked in some feedback into the upper bound. |
| 1223 if (BothInputsAre(node, Type::Signed32()) || | 1223 if (BothInputsAre(node, Type::Signed32()) || |
| 1224 (BothInputsAre(node, Type::Signed32OrMinusZero()) && | 1224 (BothInputsAre(node, Type::Signed32OrMinusZero()) && |
| 1225 GetUpperBound(node)->Is(type_cache_.kSafeInteger))) { | 1225 GetUpperBound(node)->Is(type_cache_.kSafeInteger))) { |
| 1226 VisitBinop(node, UseInfo::TruncatingWord32(), | 1226 VisitBinop(node, UseInfo::TruncatingWord32(), |
| 1227 MachineRepresentation::kWord32, Type::Signed32()); | 1227 MachineRepresentation::kWord32, Type::Signed32()); |
| 1228 } else { | 1228 } else { |
| 1229 UseInfo left_use = CheckedUseInfoAsWord32FromHint(hint); | 1229 // If the output's truncation is identify-zeros, we can pass it |
| 1230 // along. Moreover, if the operation is addition and we know the |
| 1231 // right-hand side is not minus zero, we do not have to distinguish |
| 1232 // between 0 and -0. |
| 1233 IdentifyZeros left_identify_zeros = truncation.identify_zeros(); |
| 1234 if (node->opcode() == IrOpcode::kSpeculativeNumberAdd && |
| 1235 !right_feedback_type->Maybe(Type::MinusZero())) { |
| 1236 left_identify_zeros = kIdentifyZeros; |
| 1237 } |
| 1238 UseInfo left_use = |
| 1239 CheckedUseInfoAsWord32FromHint(hint, left_identify_zeros); |
| 1230 // For CheckedInt32Add and CheckedInt32Sub, we don't need to do | 1240 // For CheckedInt32Add and CheckedInt32Sub, we don't need to do |
| 1231 // a minus zero check for the right hand side, since we already | 1241 // a minus zero check for the right hand side, since we already |
| 1232 // know that the left hand side is a proper Signed32 value, | 1242 // know that the left hand side is a proper Signed32 value, |
| 1233 // potentially guarded by a check. | 1243 // potentially guarded by a check. |
| 1234 UseInfo right_use = CheckedUseInfoAsWord32FromHint( | 1244 UseInfo right_use = |
| 1235 hint, CheckForMinusZeroMode::kDontCheckForMinusZero); | 1245 CheckedUseInfoAsWord32FromHint(hint, kIdentifyZeros); |
| 1236 VisitBinop(node, left_use, right_use, MachineRepresentation::kWord32, | 1246 VisitBinop(node, left_use, right_use, MachineRepresentation::kWord32, |
| 1237 Type::Signed32()); | 1247 Type::Signed32()); |
| 1238 } | 1248 } |
| 1239 if (lower()) { | 1249 if (lower()) { |
| 1240 if (CanOverflowSigned32(node->op(), left_feedback_type, | 1250 if (CanOverflowSigned32(node->op(), left_feedback_type, |
| 1241 right_feedback_type, graph_zone())) { | 1251 right_feedback_type, graph_zone())) { |
| 1242 ChangeToInt32OverflowOp(node); | 1252 ChangeToInt32OverflowOp(node); |
| 1243 } else { | 1253 } else { |
| 1244 ChangeToPureOp(node, Int32Op(node)); | 1254 ChangeToPureOp(node, Int32Op(node)); |
| 1245 } | 1255 } |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2273 Type* length_type = TypeOf(node->InputAt(1)); | 2283 Type* length_type = TypeOf(node->InputAt(1)); |
| 2274 if (index_type->Is(Type::Unsigned32())) { | 2284 if (index_type->Is(Type::Unsigned32())) { |
| 2275 VisitBinop(node, UseInfo::TruncatingWord32(), | 2285 VisitBinop(node, UseInfo::TruncatingWord32(), |
| 2276 MachineRepresentation::kWord32); | 2286 MachineRepresentation::kWord32); |
| 2277 if (lower() && index_type->Max() < length_type->Min()) { | 2287 if (lower() && index_type->Max() < length_type->Min()) { |
| 2278 // The bounds check is redundant if we already know that | 2288 // The bounds check is redundant if we already know that |
| 2279 // the index is within the bounds of [0.0, length[. | 2289 // the index is within the bounds of [0.0, length[. |
| 2280 DeferReplacement(node, node->InputAt(0)); | 2290 DeferReplacement(node, node->InputAt(0)); |
| 2281 } | 2291 } |
| 2282 } else { | 2292 } else { |
| 2283 VisitBinop(node, UseInfo::CheckedSigned32AsWord32(), | 2293 VisitBinop(node, UseInfo::CheckedSigned32AsWord32(kIdentifyZeros), |
| 2284 UseInfo::TruncatingWord32(), | 2294 UseInfo::TruncatingWord32(), |
| 2285 MachineRepresentation::kWord32); | 2295 MachineRepresentation::kWord32); |
| 2286 } | 2296 } |
| 2287 return; | 2297 return; |
| 2288 } | 2298 } |
| 2289 case IrOpcode::kCheckHeapObject: { | 2299 case IrOpcode::kCheckHeapObject: { |
| 2290 if (InputCannotBe(node, Type::SignedSmall())) { | 2300 if (InputCannotBe(node, Type::SignedSmall())) { |
| 2291 VisitUnop(node, UseInfo::AnyTagged(), | 2301 VisitUnop(node, UseInfo::AnyTagged(), |
| 2292 MachineRepresentation::kTaggedPointer); | 2302 MachineRepresentation::kTaggedPointer); |
| 2293 } else { | 2303 } else { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2339 MachineRepresentation::kTaggedPointer); | 2349 MachineRepresentation::kTaggedPointer); |
| 2340 if (lower()) DeferReplacement(node, node->InputAt(0)); | 2350 if (lower()) DeferReplacement(node, node->InputAt(0)); |
| 2341 } else { | 2351 } else { |
| 2342 VisitUnop(node, UseInfo::CheckedHeapObjectAsTaggedPointer(), | 2352 VisitUnop(node, UseInfo::CheckedHeapObjectAsTaggedPointer(), |
| 2343 MachineRepresentation::kTaggedPointer); | 2353 MachineRepresentation::kTaggedPointer); |
| 2344 } | 2354 } |
| 2345 return; | 2355 return; |
| 2346 } | 2356 } |
| 2347 case IrOpcode::kCheckSmi: { | 2357 case IrOpcode::kCheckSmi: { |
| 2348 if (SmiValuesAre32Bits() && truncation.IsUsedAsWord32()) { | 2358 if (SmiValuesAre32Bits() && truncation.IsUsedAsWord32()) { |
| 2349 VisitUnop(node, UseInfo::CheckedSignedSmallAsWord32(), | 2359 VisitUnop(node, |
| 2360 UseInfo::CheckedSignedSmallAsWord32(kDistinguishZeros), |
| 2350 MachineRepresentation::kWord32); | 2361 MachineRepresentation::kWord32); |
| 2351 } else { | 2362 } else { |
| 2352 VisitUnop(node, UseInfo::CheckedSignedSmallAsTaggedSigned(), | 2363 VisitUnop(node, UseInfo::CheckedSignedSmallAsTaggedSigned(), |
| 2353 MachineRepresentation::kTaggedSigned); | 2364 MachineRepresentation::kTaggedSigned); |
| 2354 } | 2365 } |
| 2355 if (lower()) DeferReplacement(node, node->InputAt(0)); | 2366 if (lower()) DeferReplacement(node, node->InputAt(0)); |
| 2356 return; | 2367 return; |
| 2357 } | 2368 } |
| 2358 case IrOpcode::kCheckString: { | 2369 case IrOpcode::kCheckString: { |
| 2359 if (InputIs(node, Type::String())) { | 2370 if (InputIs(node, Type::String())) { |
| (...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3570 isolate(), graph()->zone(), callable.descriptor(), 0, flags, | 3581 isolate(), graph()->zone(), callable.descriptor(), 0, flags, |
| 3571 Operator::kNoProperties); | 3582 Operator::kNoProperties); |
| 3572 to_number_operator_.set(common()->Call(desc)); | 3583 to_number_operator_.set(common()->Call(desc)); |
| 3573 } | 3584 } |
| 3574 return to_number_operator_.get(); | 3585 return to_number_operator_.get(); |
| 3575 } | 3586 } |
| 3576 | 3587 |
| 3577 } // namespace compiler | 3588 } // namespace compiler |
| 3578 } // namespace internal | 3589 } // namespace internal |
| 3579 } // namespace v8 | 3590 } // namespace v8 |
| OLD | NEW |