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

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