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

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
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 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 } 1378 }
1379 } 1379 }
1380 1380
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 static bool IsInteger32(double value) {
1389 double roundtrip_value = static_cast<double>(static_cast<int32_t>(value));
1390 return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value);
1391 }
1392
1393
1388 HConstant::HConstant(Handle<Object> handle, Representation r) 1394 HConstant::HConstant(Handle<Object> handle, Representation r)
1389 : handle_(handle), 1395 : handle_(handle),
1390 has_int32_value_(false), 1396 has_int32_value_(false),
1391 has_double_value_(false), 1397 has_double_value_(false) {
1392 int32_value_(0),
1393 double_value_(0) {
1394 set_representation(r); 1398 set_representation(r);
1395 SetFlag(kUseGVN); 1399 SetFlag(kUseGVN);
1396 if (handle_->IsNumber()) { 1400 if (handle_->IsNumber()) {
1397 double n = handle_->Number(); 1401 double n = handle_->Number();
1398 double roundtrip_value = static_cast<double>(static_cast<int32_t>(n)); 1402 has_int32_value_ = IsInteger32(n);
1399 has_int32_value_ = BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(n); 1403 int32_value_ = DoubleToInt32(n);
1400 if (has_int32_value_) int32_value_ = static_cast<int32_t>(n);
1401 double_value_ = n; 1404 double_value_ = n;
1402 has_double_value_ = true; 1405 has_double_value_ = true;
1403 } 1406 }
1404 } 1407 }
1405 1408
1406 1409
1410 HConstant::HConstant(int32_t integer_value, Representation r)
1411 : has_int32_value_(true),
1412 has_double_value_(true),
1413 int32_value_(integer_value),
1414 double_value_(FastI2D(integer_value)) {
1415 set_representation(r);
1416 SetFlag(kUseGVN);
1417 }
1418
1419
1420 HConstant::HConstant(double double_value, Representation r)
1421 : has_int32_value_(IsInteger32(double_value)),
1422 has_double_value_(true),
1423 int32_value_(DoubleToInt32(double_value)),
1424 double_value_(double_value) {
1425 set_representation(r);
1426 SetFlag(kUseGVN);
1427 }
1428
1429
1407 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const { 1430 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const {
1408 if (r.IsInteger32() && !has_int32_value_) return NULL; 1431 if (r.IsInteger32() && !has_int32_value_) return NULL;
1409 if (r.IsDouble() && !has_double_value_) return NULL; 1432 if (r.IsDouble() && !has_double_value_) return NULL;
1433
Michael Starzinger 2012/07/11 14:19:22 Remove this empty newline.
1434 if (handle_.is_null()) {
1435 ASSERT(has_int32_value_ || has_double_value_);
1436 if (has_int32_value_) return new(zone) HConstant(int32_value_, r);
1437 return new(zone) HConstant(double_value_, r);
1438 }
1410 return new(zone) HConstant(handle_, r); 1439 return new(zone) HConstant(handle_, r);
1411 } 1440 }
1412 1441
1413 1442
1414 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const { 1443 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const {
1415 if (!has_double_value_) return NULL; 1444 if (has_int32_value_) {
1416 int32_t truncated = NumberToInt32(*handle_); 1445 if (handle_.is_null()) {
1417 return new(zone) HConstant(FACTORY->NewNumberFromInt(truncated), 1446 return new(zone) HConstant(int32_value_, Representation::Integer32());
1418 Representation::Integer32()); 1447 } else {
1448 // Re-use the existing Handle if possible.
1449 return new(zone) HConstant(handle_, Representation::Integer32());
1450 }
1451 } else if (has_double_value_) {
1452 return new(zone) HConstant(DoubleToInt32(double_value_),
1453 Representation::Integer32());
1454 } else {
1455 return NULL;
1456 }
1419 } 1457 }
1420 1458
1421 1459
1422 bool HConstant::ToBoolean() const { 1460 bool HConstant::ToBoolean() {
1423 // Converts the constant's boolean value according to 1461 // Converts the constant's boolean value according to
1424 // ECMAScript section 9.2 ToBoolean conversion. 1462 // ECMAScript section 9.2 ToBoolean conversion.
1425 if (HasInteger32Value()) return Integer32Value() != 0; 1463 if (HasInteger32Value()) return Integer32Value() != 0;
1426 if (HasDoubleValue()) { 1464 if (HasDoubleValue()) {
1427 double v = DoubleValue(); 1465 double v = DoubleValue();
1428 return v != 0 && !isnan(v); 1466 return v != 0 && !isnan(v);
1429 } 1467 }
1430 if (handle()->IsTrue()) return true; 1468 Handle<Object> literal = handle();
1431 if (handle()->IsFalse()) return false; 1469 if (literal->IsTrue()) return true;
1432 if (handle()->IsUndefined()) return false; 1470 if (literal->IsFalse()) return false;
1433 if (handle()->IsNull()) return false; 1471 if (literal->IsUndefined()) return false;
1434 if (handle()->IsString() && 1472 if (literal->IsNull()) return false;
1435 String::cast(*handle())->length() == 0) return false; 1473 if (literal->IsString() && String::cast(*literal)->length() == 0) {
1474 return false;
1475 }
1436 return true; 1476 return true;
1437 } 1477 }
1438 1478
1439 void HConstant::PrintDataTo(StringStream* stream) { 1479 void HConstant::PrintDataTo(StringStream* stream) {
1440 handle()->ShortPrint(stream); 1480 if (has_int32_value_) {
1481 stream->Add("%d ", int32_value_);
1482 } else if (has_double_value_) {
1483 stream->Add("%lf ", double_value_);
1484 } else {
1485 handle()->ShortPrint(stream);
1486 }
1441 } 1487 }
1442 1488
1443 1489
1444 bool HArrayLiteral::IsCopyOnWrite() const { 1490 bool HArrayLiteral::IsCopyOnWrite() const {
1445 if (!boilerplate_object_->IsJSObject()) return false; 1491 if (!boilerplate_object_->IsJSObject()) return false;
1446 return Handle<JSObject>::cast(boilerplate_object_)->elements()->map() == 1492 return Handle<JSObject>::cast(boilerplate_object_)->elements()->map() ==
1447 HEAP->fixed_cow_array_map(); 1493 HEAP->fixed_cow_array_map();
1448 } 1494 }
1449 1495
1450 1496
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 HType result = HType::Uninitialized(); 2128 HType result = HType::Uninitialized();
2083 for (int i = 0; i < OperandCount(); ++i) { 2129 for (int i = 0; i < OperandCount(); ++i) {
2084 HType current = OperandAt(i)->type(); 2130 HType current = OperandAt(i)->type();
2085 result = result.Combine(current); 2131 result = result.Combine(current);
2086 } 2132 }
2087 return result; 2133 return result;
2088 } 2134 }
2089 2135
2090 2136
2091 HType HConstant::CalculateInferredType() { 2137 HType HConstant::CalculateInferredType() {
2138 if (has_int32_value_) {
2139 return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber();
2140 }
2141 if (has_double_value_) return HType::HeapNumber();
2092 return HType::TypeFromValue(handle_); 2142 return HType::TypeFromValue(handle_);
2093 } 2143 }
2094 2144
2095 2145
2096 HType HCompareGeneric::CalculateInferredType() { 2146 HType HCompareGeneric::CalculateInferredType() {
2097 return HType::Boolean(); 2147 return HType::Boolean();
2098 } 2148 }
2099 2149
2100 2150
2101 HType HInstanceOf::CalculateInferredType() { 2151 HType HInstanceOf::CalculateInferredType() {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 2590
2541 2591
2542 void HCheckPrototypeMaps::Verify() { 2592 void HCheckPrototypeMaps::Verify() {
2543 HInstruction::Verify(); 2593 HInstruction::Verify();
2544 ASSERT(HasNoUses()); 2594 ASSERT(HasNoUses());
2545 } 2595 }
2546 2596
2547 #endif 2597 #endif
2548 2598
2549 } } // namespace v8::internal 2599 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698