Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: src/hydrogen-instructions.cc

Issue 10544196: Defer creating Handles for HConstants to the code generation phase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 1381
1382 void HEnterInlined::PrintDataTo(StringStream* stream) { 1382 void HEnterInlined::PrintDataTo(StringStream* stream) {
1383 SmartArrayPointer<char> name = function()->debug_name()->ToCString(); 1383 SmartArrayPointer<char> name = function()->debug_name()->ToCString();
1384 stream->Add("%s, id=%d", *name, function()->id()); 1384 stream->Add("%s, id=%d", *name, function()->id());
1385 } 1385 }
1386 1386
1387 1387
1388 HConstant::HConstant(Handle<Object> handle, Representation r) 1388 HConstant::HConstant(Handle<Object> handle, Representation r)
1389 : handle_(handle), 1389 : handle_(handle),
1390 has_int32_value_(false), 1390 has_int32_value_(false),
1391 has_double_value_(false), 1391 has_double_value_(false) {
1392 int32_value_(0),
1393 double_value_(0) {
1394 set_representation(r); 1392 set_representation(r);
1395 SetFlag(kUseGVN); 1393 SetFlag(kUseGVN);
1396 if (handle_->IsNumber()) { 1394 if (handle_->IsNumber()) {
1397 double n = handle_->Number(); 1395 double n = handle_->Number();
1398 double roundtrip_value = static_cast<double>(static_cast<int32_t>(n)); 1396 double roundtrip_value = static_cast<double>(static_cast<int32_t>(n));
1399 has_int32_value_ = BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(n); 1397 has_int32_value_ = BitCast<int64_t>(roundtrip_value) ==
1400 if (has_int32_value_) int32_value_ = static_cast<int32_t>(n); 1398 BitCast<int64_t>(n);
1399
1400 int32_value_ = DoubleToInt32(n);
1401 double_value_ = n; 1401 double_value_ = n;
1402 has_double_value_ = true; 1402 has_double_value_ = true;
1403 } 1403 }
1404 } 1404 }
1405 1405
1406 1406
1407 HConstant::HConstant(int32_t integer_value, Representation r,
1408 Handle<Object> handle)
Michael Starzinger 2012/07/09 15:36:22 This should not take a handle parameter. This cons
sanjoy 2012/07/09 17:44:58 Done.
1409 : handle_(handle),
1410 has_int32_value_(true),
1411 has_double_value_(true) {
1412 set_representation(r);
1413 SetFlag(kUseGVN);
1414 int32_value_ = integer_value;
1415 double_value_ = FastI2D(integer_value);
1416 }
1417
1418
1419 HConstant::HConstant(double double_value, Representation r,
1420 Handle<Object> handle)
Michael Starzinger 2012/07/09 15:36:22 Likewise.
sanjoy 2012/07/09 17:44:58 Done.
1421 : handle_(handle),
1422 has_int32_value_(false),
1423 has_double_value_(true),
1424 int32_value_(DoubleToInt32(double_value)),
1425 double_value_(double_value) {
1426 set_representation(r);
1427 SetFlag(kUseGVN);
1428 double roundtrip_value = static_cast<double>(
1429 static_cast<int32_t>(double_value));
1430 has_int32_value_ = BitCast<int64_t>(roundtrip_value) ==
1431 BitCast<int64_t>(double_value);
1432 }
1433
1434
1407 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const { 1435 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const {
1408 if (r.IsInteger32() && !has_int32_value_) return NULL; 1436 if (has_int32_value_) {
1409 if (r.IsDouble() && !has_double_value_) return NULL; 1437 return new(zone) HConstant(int32_value_, r, handle_);
1410 return new(zone) HConstant(handle_, r); 1438 } else if (has_double_value_) {
1439 // A double can be safely converted only to a HeapNumber. If it
1440 // was possible to store this double as a integer, we'd have done
1441 // that and has_int32_value_ would be true.
1442 if (r.IsInteger32()) {
1443 return NULL;
1444 } else {
1445 return new(zone) HConstant(double_value_, r, handle_);
1446 }
1447 } else {
1448 // A generic tagged value cannot be safely converted to any other
1449 // representation.
1450 if (r.IsTagged()) {
1451 return new(zone) HConstant(handle_, r);
1452 } else {
1453 return NULL;
1454 }
1455 }
1411 } 1456 }
1412 1457
1413 1458
1414 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const { 1459 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const {
1415 if (!has_double_value_) return NULL; 1460 if (has_int32_value_) {
1416 int32_t truncated = NumberToInt32(*handle_); 1461 return new(zone) HConstant(int32_value_, Representation::Integer32(),
1417 return new(zone) HConstant(FACTORY->NewNumberFromInt(truncated), 1462 handle_);
1418 Representation::Integer32()); 1463 } else if (has_double_value_) {
1464 return new(zone) HConstant(DoubleToInt32(double_value_),
1465 Representation::Integer32(),
1466 Handle<Object>::null());
1467 } else {
1468 return NULL;
1469 }
1419 } 1470 }
1420 1471
1421 1472
1422 bool HConstant::ToBoolean() const { 1473 bool HConstant::ToBoolean() {
1423 // Converts the constant's boolean value according to 1474 // Converts the constant's boolean value according to
1424 // ECMAScript section 9.2 ToBoolean conversion. 1475 // ECMAScript section 9.2 ToBoolean conversion.
1425 if (HasInteger32Value()) return Integer32Value() != 0; 1476 if (HasInteger32Value()) return Integer32Value() != 0;
1426 if (HasDoubleValue()) { 1477 if (HasDoubleValue()) {
1427 double v = DoubleValue(); 1478 double v = DoubleValue();
1428 return v != 0 && !isnan(v); 1479 return v != 0 && !isnan(v);
1429 } 1480 }
1430 if (handle()->IsTrue()) return true; 1481 Handle<Object> literal = handle();
1431 if (handle()->IsFalse()) return false; 1482 if (literal->IsTrue()) return true;
1432 if (handle()->IsUndefined()) return false; 1483 if (literal->IsFalse()) return false;
1433 if (handle()->IsNull()) return false; 1484 if (literal->IsUndefined()) return false;
1434 if (handle()->IsString() && 1485 if (literal->IsNull()) return false;
1435 String::cast(*handle())->length() == 0) return false; 1486 if (literal->IsString() && String::cast(*literal)->length() == 0) {
1487 return false;
1488 }
1436 return true; 1489 return true;
1437 } 1490 }
1438 1491
1439 void HConstant::PrintDataTo(StringStream* stream) { 1492 void HConstant::PrintDataTo(StringStream* stream) {
1440 handle()->ShortPrint(stream); 1493 if (has_int32_value_) {
1494 stream->Add("%d ", int32_value_);
1495 } else if (has_double_value_) {
1496 stream->Add("%lf ", double_value_);
1497 } else {
1498 handle()->ShortPrint(stream);
1499 }
1441 } 1500 }
1442 1501
1443 1502
1444 bool HArrayLiteral::IsCopyOnWrite() const { 1503 bool HArrayLiteral::IsCopyOnWrite() const {
1445 if (!boilerplate_object_->IsJSObject()) return false; 1504 if (!boilerplate_object_->IsJSObject()) return false;
1446 return Handle<JSObject>::cast(boilerplate_object_)->elements()->map() == 1505 return Handle<JSObject>::cast(boilerplate_object_)->elements()->map() ==
1447 HEAP->fixed_cow_array_map(); 1506 HEAP->fixed_cow_array_map();
1448 } 1507 }
1449 1508
1450 1509
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 HType result = HType::Uninitialized(); 2141 HType result = HType::Uninitialized();
2083 for (int i = 0; i < OperandCount(); ++i) { 2142 for (int i = 0; i < OperandCount(); ++i) {
2084 HType current = OperandAt(i)->type(); 2143 HType current = OperandAt(i)->type();
2085 result = result.Combine(current); 2144 result = result.Combine(current);
2086 } 2145 }
2087 return result; 2146 return result;
2088 } 2147 }
2089 2148
2090 2149
2091 HType HConstant::CalculateInferredType() { 2150 HType HConstant::CalculateInferredType() {
2092 return HType::TypeFromValue(handle_); 2151 if (has_int32_value_) {
2152 return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber();
2153 }
2154 if (has_double_value_) return HType::HeapNumber();
2155 return HType::TypeFromValue(Handle<Object>(handle_));
2093 } 2156 }
2094 2157
2095 2158
2096 HType HCompareGeneric::CalculateInferredType() { 2159 HType HCompareGeneric::CalculateInferredType() {
2097 return HType::Boolean(); 2160 return HType::Boolean();
2098 } 2161 }
2099 2162
2100 2163
2101 HType HInstanceOf::CalculateInferredType() { 2164 HType HInstanceOf::CalculateInferredType() {
2102 return HType::Boolean(); 2165 return HType::Boolean();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 // If value was loaded from unboxed double backing store or 2341 // If value was loaded from unboxed double backing store or
2279 // converted from an integer then we don't have to canonicalize it. 2342 // converted from an integer then we don't have to canonicalize it.
2280 if (value()->IsLoadKeyedFastDoubleElement() || 2343 if (value()->IsLoadKeyedFastDoubleElement() ||
2281 (value()->IsChange() && HChange::cast(value())->from().IsInteger32())) { 2344 (value()->IsChange() && HChange::cast(value())->from().IsInteger32())) {
2282 return false; 2345 return false;
2283 } 2346 }
2284 return true; 2347 return true;
2285 } 2348 }
2286 2349
2287 2350
2288 #define H_CONSTANT_INT32(val) \ 2351 #define H_CONSTANT_INT32(val) \
2289 new(zone) HConstant(FACTORY->NewNumberFromInt(val, TENURED), \ 2352 new(zone) HConstant(static_cast<int32_t>(val), \
2290 Representation::Integer32()) 2353 Representation::Integer32(), \
2354 Handle<Object>::null())
2355
2291 #define H_CONSTANT_DOUBLE(val) \ 2356 #define H_CONSTANT_DOUBLE(val) \
2292 new(zone) HConstant(FACTORY->NewNumber(val, TENURED), \ 2357 new(zone) HConstant(val, Representation::Double(), Handle<Object>::null())
2293 Representation::Double())
2294 2358
2295 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \ 2359 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \
2296 HInstruction* HInstr::New##HInstr(Zone* zone, \ 2360 HInstruction* HInstr::New##HInstr(Zone* zone, \
2297 HValue* context, \ 2361 HValue* context, \
2298 HValue* left, \ 2362 HValue* left, \
2299 HValue* right) { \ 2363 HValue* right) { \
2300 if (left->IsConstant() && right->IsConstant()) { \ 2364 if (left->IsConstant() && right->IsConstant()) { \
2301 HConstant* c_left = HConstant::cast(left); \ 2365 HConstant* c_left = HConstant::cast(left); \
2302 HConstant* c_right = HConstant::cast(right); \ 2366 HConstant* c_right = HConstant::cast(right); \
2303 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ 2367 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 2604
2541 2605
2542 void HCheckPrototypeMaps::Verify() { 2606 void HCheckPrototypeMaps::Verify() {
2543 HInstruction::Verify(); 2607 HInstruction::Verify();
2544 ASSERT(HasNoUses()); 2608 ASSERT(HasNoUses());
2545 } 2609 }
2546 2610
2547 #endif 2611 #endif
2548 2612
2549 } } // namespace v8::internal 2613 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698