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