OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/double.h" | 8 #include "src/double.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/hydrogen-infer-representation.h" | 10 #include "src/hydrogen-infer-representation.h" |
(...skipping 3953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3964 return false; | 3964 return false; |
3965 } | 3965 } |
3966 } | 3966 } |
3967 | 3967 |
3968 | 3968 |
3969 #define H_CONSTANT_INT(val) \ | 3969 #define H_CONSTANT_INT(val) \ |
3970 HConstant::New(isolate, zone, context, static_cast<int32_t>(val)) | 3970 HConstant::New(isolate, zone, context, static_cast<int32_t>(val)) |
3971 #define H_CONSTANT_DOUBLE(val) \ | 3971 #define H_CONSTANT_DOUBLE(val) \ |
3972 HConstant::New(isolate, zone, context, static_cast<double>(val)) | 3972 HConstant::New(isolate, zone, context, static_cast<double>(val)) |
3973 | 3973 |
3974 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \ | 3974 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \ |
3975 HInstruction* HInstr::New(Isolate* isolate, Zone* zone, HValue* context, \ | 3975 HInstruction* HInstr::New(Isolate* isolate, Zone* zone, HValue* context, \ |
3976 HValue* left, HValue* right, \ | 3976 HValue* left, HValue* right, Strength strength) { \ |
3977 LanguageMode language_mode) { \ | 3977 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \ |
3978 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \ | 3978 HConstant* c_left = HConstant::cast(left); \ |
3979 HConstant* c_left = HConstant::cast(left); \ | 3979 HConstant* c_right = HConstant::cast(right); \ |
3980 HConstant* c_right = HConstant::cast(right); \ | 3980 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ |
3981 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ | 3981 double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \ |
3982 double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \ | 3982 if (IsInt32Double(double_res)) { \ |
3983 if (IsInt32Double(double_res)) { \ | 3983 return H_CONSTANT_INT(double_res); \ |
3984 return H_CONSTANT_INT(double_res); \ | 3984 } \ |
3985 } \ | 3985 return H_CONSTANT_DOUBLE(double_res); \ |
3986 return H_CONSTANT_DOUBLE(double_res); \ | 3986 } \ |
3987 } \ | 3987 } \ |
3988 } \ | 3988 return new (zone) HInstr(context, left, right, strength); \ |
3989 return new (zone) HInstr(context, left, right, language_mode); \ | |
3990 } | 3989 } |
3991 | 3990 |
3992 | 3991 |
3993 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +) | 3992 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +) |
3994 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *) | 3993 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *) |
3995 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -) | 3994 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -) |
3996 | 3995 |
3997 #undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR | 3996 #undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR |
3998 | 3997 |
3999 | 3998 |
4000 HInstruction* HStringAdd::New(Isolate* isolate, Zone* zone, HValue* context, | 3999 HInstruction* HStringAdd::New(Isolate* isolate, Zone* zone, HValue* context, |
4001 HValue* left, HValue* right, | 4000 HValue* left, HValue* right, Strength strength, |
4002 LanguageMode language_mode, | |
4003 PretenureFlag pretenure_flag, | 4001 PretenureFlag pretenure_flag, |
4004 StringAddFlags flags, | 4002 StringAddFlags flags, |
4005 Handle<AllocationSite> allocation_site) { | 4003 Handle<AllocationSite> allocation_site) { |
4006 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { | 4004 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
4007 HConstant* c_right = HConstant::cast(right); | 4005 HConstant* c_right = HConstant::cast(right); |
4008 HConstant* c_left = HConstant::cast(left); | 4006 HConstant* c_left = HConstant::cast(left); |
4009 if (c_left->HasStringValue() && c_right->HasStringValue()) { | 4007 if (c_left->HasStringValue() && c_right->HasStringValue()) { |
4010 Handle<String> left_string = c_left->StringValue(); | 4008 Handle<String> left_string = c_left->StringValue(); |
4011 Handle<String> right_string = c_right->StringValue(); | 4009 Handle<String> right_string = c_right->StringValue(); |
4012 // Prevent possible exception by invalid string length. | 4010 // Prevent possible exception by invalid string length. |
4013 if (left_string->length() + right_string->length() < String::kMaxLength) { | 4011 if (left_string->length() + right_string->length() < String::kMaxLength) { |
4014 MaybeHandle<String> concat = isolate->factory()->NewConsString( | 4012 MaybeHandle<String> concat = isolate->factory()->NewConsString( |
4015 c_left->StringValue(), c_right->StringValue()); | 4013 c_left->StringValue(), c_right->StringValue()); |
4016 return HConstant::New(isolate, zone, context, concat.ToHandleChecked()); | 4014 return HConstant::New(isolate, zone, context, concat.ToHandleChecked()); |
4017 } | 4015 } |
4018 } | 4016 } |
4019 } | 4017 } |
4020 return new(zone) HStringAdd( | 4018 return new (zone) HStringAdd(context, left, right, strength, pretenure_flag, |
4021 context, left, right, language_mode, pretenure_flag, flags, | 4019 flags, allocation_site); |
4022 allocation_site); | |
4023 } | 4020 } |
4024 | 4021 |
4025 | 4022 |
4026 std::ostream& HStringAdd::PrintDataTo(std::ostream& os) const { // NOLINT | 4023 std::ostream& HStringAdd::PrintDataTo(std::ostream& os) const { // NOLINT |
4027 if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { | 4024 if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
4028 os << "_CheckBoth"; | 4025 os << "_CheckBoth"; |
4029 } else if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_LEFT) { | 4026 } else if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_LEFT) { |
4030 os << "_CheckLeft"; | 4027 os << "_CheckLeft"; |
4031 } else if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_RIGHT) { | 4028 } else if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_RIGHT) { |
4032 os << "_CheckRight"; | 4029 os << "_CheckRight"; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4210 } | 4207 } |
4211 // All comparisons failed, must be NaN. | 4208 // All comparisons failed, must be NaN. |
4212 return H_CONSTANT_DOUBLE(std::numeric_limits<double>::quiet_NaN()); | 4209 return H_CONSTANT_DOUBLE(std::numeric_limits<double>::quiet_NaN()); |
4213 } | 4210 } |
4214 } | 4211 } |
4215 return new(zone) HMathMinMax(context, left, right, op); | 4212 return new(zone) HMathMinMax(context, left, right, op); |
4216 } | 4213 } |
4217 | 4214 |
4218 | 4215 |
4219 HInstruction* HMod::New(Isolate* isolate, Zone* zone, HValue* context, | 4216 HInstruction* HMod::New(Isolate* isolate, Zone* zone, HValue* context, |
4220 HValue* left, HValue* right, | 4217 HValue* left, HValue* right, Strength strength) { |
4221 LanguageMode language_mode) { | |
4222 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { | 4218 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
4223 HConstant* c_left = HConstant::cast(left); | 4219 HConstant* c_left = HConstant::cast(left); |
4224 HConstant* c_right = HConstant::cast(right); | 4220 HConstant* c_right = HConstant::cast(right); |
4225 if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) { | 4221 if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) { |
4226 int32_t dividend = c_left->Integer32Value(); | 4222 int32_t dividend = c_left->Integer32Value(); |
4227 int32_t divisor = c_right->Integer32Value(); | 4223 int32_t divisor = c_right->Integer32Value(); |
4228 if (dividend == kMinInt && divisor == -1) { | 4224 if (dividend == kMinInt && divisor == -1) { |
4229 return H_CONSTANT_DOUBLE(-0.0); | 4225 return H_CONSTANT_DOUBLE(-0.0); |
4230 } | 4226 } |
4231 if (divisor != 0) { | 4227 if (divisor != 0) { |
4232 int32_t res = dividend % divisor; | 4228 int32_t res = dividend % divisor; |
4233 if ((res == 0) && (dividend < 0)) { | 4229 if ((res == 0) && (dividend < 0)) { |
4234 return H_CONSTANT_DOUBLE(-0.0); | 4230 return H_CONSTANT_DOUBLE(-0.0); |
4235 } | 4231 } |
4236 return H_CONSTANT_INT(res); | 4232 return H_CONSTANT_INT(res); |
4237 } | 4233 } |
4238 } | 4234 } |
4239 } | 4235 } |
4240 return new(zone) HMod(context, left, right, language_mode); | 4236 return new (zone) HMod(context, left, right, strength); |
4241 } | 4237 } |
4242 | 4238 |
4243 | 4239 |
4244 HInstruction* HDiv::New(Isolate* isolate, Zone* zone, HValue* context, | 4240 HInstruction* HDiv::New(Isolate* isolate, Zone* zone, HValue* context, |
4245 HValue* left, HValue* right, | 4241 HValue* left, HValue* right, Strength strength) { |
4246 LanguageMode language_mode) { | |
4247 // If left and right are constant values, try to return a constant value. | 4242 // If left and right are constant values, try to return a constant value. |
4248 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { | 4243 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
4249 HConstant* c_left = HConstant::cast(left); | 4244 HConstant* c_left = HConstant::cast(left); |
4250 HConstant* c_right = HConstant::cast(right); | 4245 HConstant* c_right = HConstant::cast(right); |
4251 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { | 4246 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
4252 if (c_right->DoubleValue() != 0) { | 4247 if (c_right->DoubleValue() != 0) { |
4253 double double_res = c_left->DoubleValue() / c_right->DoubleValue(); | 4248 double double_res = c_left->DoubleValue() / c_right->DoubleValue(); |
4254 if (IsInt32Double(double_res)) { | 4249 if (IsInt32Double(double_res)) { |
4255 return H_CONSTANT_INT(double_res); | 4250 return H_CONSTANT_INT(double_res); |
4256 } | 4251 } |
4257 return H_CONSTANT_DOUBLE(double_res); | 4252 return H_CONSTANT_DOUBLE(double_res); |
4258 } else { | 4253 } else { |
4259 int sign = Double(c_left->DoubleValue()).Sign() * | 4254 int sign = Double(c_left->DoubleValue()).Sign() * |
4260 Double(c_right->DoubleValue()).Sign(); // Right could be -0. | 4255 Double(c_right->DoubleValue()).Sign(); // Right could be -0. |
4261 return H_CONSTANT_DOUBLE(sign * V8_INFINITY); | 4256 return H_CONSTANT_DOUBLE(sign * V8_INFINITY); |
4262 } | 4257 } |
4263 } | 4258 } |
4264 } | 4259 } |
4265 return new(zone) HDiv(context, left, right, language_mode); | 4260 return new (zone) HDiv(context, left, right, strength); |
4266 } | 4261 } |
4267 | 4262 |
4268 | 4263 |
4269 HInstruction* HBitwise::New(Isolate* isolate, Zone* zone, HValue* context, | 4264 HInstruction* HBitwise::New(Isolate* isolate, Zone* zone, HValue* context, |
4270 Token::Value op, HValue* left, HValue* right, | 4265 Token::Value op, HValue* left, HValue* right, |
4271 LanguageMode language_mode) { | 4266 Strength strength) { |
4272 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { | 4267 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
4273 HConstant* c_left = HConstant::cast(left); | 4268 HConstant* c_left = HConstant::cast(left); |
4274 HConstant* c_right = HConstant::cast(right); | 4269 HConstant* c_right = HConstant::cast(right); |
4275 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { | 4270 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
4276 int32_t result; | 4271 int32_t result; |
4277 int32_t v_left = c_left->NumberValueAsInteger32(); | 4272 int32_t v_left = c_left->NumberValueAsInteger32(); |
4278 int32_t v_right = c_right->NumberValueAsInteger32(); | 4273 int32_t v_right = c_right->NumberValueAsInteger32(); |
4279 switch (op) { | 4274 switch (op) { |
4280 case Token::BIT_XOR: | 4275 case Token::BIT_XOR: |
4281 result = v_left ^ v_right; | 4276 result = v_left ^ v_right; |
4282 break; | 4277 break; |
4283 case Token::BIT_AND: | 4278 case Token::BIT_AND: |
4284 result = v_left & v_right; | 4279 result = v_left & v_right; |
4285 break; | 4280 break; |
4286 case Token::BIT_OR: | 4281 case Token::BIT_OR: |
4287 result = v_left | v_right; | 4282 result = v_left | v_right; |
4288 break; | 4283 break; |
4289 default: | 4284 default: |
4290 result = 0; // Please the compiler. | 4285 result = 0; // Please the compiler. |
4291 UNREACHABLE(); | 4286 UNREACHABLE(); |
4292 } | 4287 } |
4293 return H_CONSTANT_INT(result); | 4288 return H_CONSTANT_INT(result); |
4294 } | 4289 } |
4295 } | 4290 } |
4296 return new(zone) HBitwise(context, op, left, right, language_mode); | 4291 return new (zone) HBitwise(context, op, left, right, strength); |
4297 } | 4292 } |
4298 | 4293 |
4299 | 4294 |
4300 #define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \ | 4295 #define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \ |
4301 HInstruction* HInstr::New(Isolate* isolate, Zone* zone, HValue* context, \ | 4296 HInstruction* HInstr::New(Isolate* isolate, Zone* zone, HValue* context, \ |
4302 HValue* left, HValue* right, \ | 4297 HValue* left, HValue* right, Strength strength) { \ |
4303 LanguageMode language_mode) { \ | 4298 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \ |
4304 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \ | 4299 HConstant* c_left = HConstant::cast(left); \ |
4305 HConstant* c_left = HConstant::cast(left); \ | 4300 HConstant* c_right = HConstant::cast(right); \ |
4306 HConstant* c_right = HConstant::cast(right); \ | 4301 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ |
4307 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ | 4302 return H_CONSTANT_INT(result); \ |
4308 return H_CONSTANT_INT(result); \ | 4303 } \ |
4309 } \ | 4304 } \ |
4310 } \ | 4305 return new (zone) HInstr(context, left, right, strength); \ |
4311 return new (zone) HInstr(context, left, right, language_mode); \ | |
4312 } | 4306 } |
4313 | 4307 |
4314 | 4308 |
4315 DEFINE_NEW_H_BITWISE_INSTR(HSar, | 4309 DEFINE_NEW_H_BITWISE_INSTR(HSar, |
4316 c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f)) | 4310 c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f)) |
4317 DEFINE_NEW_H_BITWISE_INSTR(HShl, | 4311 DEFINE_NEW_H_BITWISE_INSTR(HShl, |
4318 c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f)) | 4312 c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f)) |
4319 | 4313 |
4320 #undef DEFINE_NEW_H_BITWISE_INSTR | 4314 #undef DEFINE_NEW_H_BITWISE_INSTR |
4321 | 4315 |
4322 | 4316 |
4323 HInstruction* HShr::New(Isolate* isolate, Zone* zone, HValue* context, | 4317 HInstruction* HShr::New(Isolate* isolate, Zone* zone, HValue* context, |
4324 HValue* left, HValue* right, | 4318 HValue* left, HValue* right, Strength strength) { |
4325 LanguageMode language_mode) { | |
4326 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { | 4319 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
4327 HConstant* c_left = HConstant::cast(left); | 4320 HConstant* c_left = HConstant::cast(left); |
4328 HConstant* c_right = HConstant::cast(right); | 4321 HConstant* c_right = HConstant::cast(right); |
4329 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { | 4322 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
4330 int32_t left_val = c_left->NumberValueAsInteger32(); | 4323 int32_t left_val = c_left->NumberValueAsInteger32(); |
4331 int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f; | 4324 int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f; |
4332 if ((right_val == 0) && (left_val < 0)) { | 4325 if ((right_val == 0) && (left_val < 0)) { |
4333 return H_CONSTANT_DOUBLE(static_cast<uint32_t>(left_val)); | 4326 return H_CONSTANT_DOUBLE(static_cast<uint32_t>(left_val)); |
4334 } | 4327 } |
4335 return H_CONSTANT_INT(static_cast<uint32_t>(left_val) >> right_val); | 4328 return H_CONSTANT_INT(static_cast<uint32_t>(left_val) >> right_val); |
4336 } | 4329 } |
4337 } | 4330 } |
4338 return new(zone) HShr(context, left, right, language_mode); | 4331 return new (zone) HShr(context, left, right, strength); |
4339 } | 4332 } |
4340 | 4333 |
4341 | 4334 |
4342 HInstruction* HSeqStringGetChar::New(Isolate* isolate, Zone* zone, | 4335 HInstruction* HSeqStringGetChar::New(Isolate* isolate, Zone* zone, |
4343 HValue* context, String::Encoding encoding, | 4336 HValue* context, String::Encoding encoding, |
4344 HValue* string, HValue* index) { | 4337 HValue* string, HValue* index) { |
4345 if (FLAG_fold_constants && string->IsConstant() && index->IsConstant()) { | 4338 if (FLAG_fold_constants && string->IsConstant() && index->IsConstant()) { |
4346 HConstant* c_string = HConstant::cast(string); | 4339 HConstant* c_string = HConstant::cast(string); |
4347 HConstant* c_index = HConstant::cast(index); | 4340 HConstant* c_index = HConstant::cast(index); |
4348 if (c_string->HasStringValue() && c_index->HasInteger32Value()) { | 4341 if (c_string->HasStringValue() && c_index->HasInteger32Value()) { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4714 case HObjectAccess::kExternalMemory: | 4707 case HObjectAccess::kExternalMemory: |
4715 os << "[external-memory]"; | 4708 os << "[external-memory]"; |
4716 break; | 4709 break; |
4717 } | 4710 } |
4718 | 4711 |
4719 return os << "@" << access.offset(); | 4712 return os << "@" << access.offset(); |
4720 } | 4713 } |
4721 | 4714 |
4722 } // namespace internal | 4715 } // namespace internal |
4723 } // namespace v8 | 4716 } // namespace v8 |
OLD | NEW |